Skip to content

Instantly share code, notes, and snippets.

Nikolai Zujev jaymecd

Block or report user

Report or block jaymecd

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jaymecd
jaymecd / time.ps1
Last active May 21, 2019
measure command time
View time.ps1
function time([scriptblock]$scriptblock) {
$sw = [Diagnostics.Stopwatch]::StartNew()
. $scriptblock
$sw.Stop()
Write-Output ""
Write-Output " >> Execution time: $($sw.Elapsed)"
}
time { Install-Module -Name PSWindowsUpdate }
@jaymecd
jaymecd / python_decorator_guide.md
Created May 15, 2019 — forked from Zearin/python_decorator_guide.md
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)
View python_decorator_guide.md

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.


Q: How can I make a chain of function decorators in Python?


If you are not into long explanations, see [Paolo Bergantino’s answer][2].

@jaymecd
jaymecd / substr.js
Last active May 12, 2019
ES6 training
View substr.js
const substr = (str, start = 0, length = str.length) => {
if (start === 0 && length === str.length) {
return str;
}
if (start > str.length || length <= 0) {
return '';
}
const startIndex = (start < 0) ? Math.max(0, str.length - Math.abs(start)) : start;
@jaymecd
jaymecd / python-logging.md
Created May 8, 2019 — forked from mariocj89/python-logging.md
Understanding logging in Python
View python-logging.md

Logging trees

Introduction

When applications are running in production, they become black boxes that need to be traced and monitored. One of the simplest, yet main, ways to do so is logging. Logging allows us - at the time we develop our software - to instruct the program to emit information while the system is running that will be useful for us and our sysadmins.

@jaymecd
jaymecd / cf_create_or_update.py
Created Apr 3, 2019 — forked from svrist/cf_create_or_update.py
Update or create a CloudFormation stack given a name and template + params'
View cf_create_or_update.py
'Update or create a stack given a name and template + params'
from __future__ import division, print_function, unicode_literals
from datetime import datetime
import logging
import json
import sys
import boto3
import botocore
@jaymecd
jaymecd / amend-git-author.md
Created Dec 3, 2018
Amend GIT author within branch starting from COMMIT_ID
View amend-git-author.md

To reset commit author its required:

  1. to update default user name/email. (--global could added)
$ git config user.name example user
$ git config user.email example@email.com
  1. set checkpoint to keep orignal commit tree.
@jaymecd
jaymecd / pip_target_freeze.py
Created Nov 28, 2018
Get `pip freeze` packages for target directory, which was installed using `pip install -t <path>`
View pip_target_freeze.py
#!/usr/bin/env python
# RUN: pip_target_freeze.py <path>
from pip._vendor import pkg_resources
import sys
def find_on_path(path):
dists = pkg_resources.find_on_path(None, path)
dists = sorted(dists, key=lambda item: str(item))
@jaymecd
jaymecd / cloudinit.yaml
Created Jun 19, 2018 — forked from ktstevenson/cloudinit.yaml
Cloud-init directive to add AWS SSM checking at boot time
View cloudinit.yaml
#cloud-config
write_files:
- content: |
#!/bin/bash
REGION=$( curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | python -c "import sys, json; print json.load(sys.stdin)['region']" )
aws --region $REGION ssm list-associations --max-items 1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "No privs to run Amazon SSM agent. Stopping..."
sudo stop amazon-ssm-agent
fi
@jaymecd
jaymecd / delete_all_object_versions.sh
Created Jun 18, 2018 — forked from weavenet/delete_all_object_versions.sh
Delete all versions of all files in s3 versioned bucket using AWS CLI and jq.
View delete_all_object_versions.sh
#!/bin/bash
bucket=$1
set -e
echo "Removing all versions from $bucket"
versions=`aws s3api list-object-versions --bucket $bucket |jq '.Versions'`
markers=`aws s3api list-object-versions --bucket $bucket |jq '.DeleteMarkers'`
View python argparse subcommand subparsers.py
import argparse
from mock import Mock
m = Mock()
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
query_group = subparsers.add_parser('query')
add_group = subparsers.add_parser('add')
You can’t perform that action at this time.