Skip to content

Instantly share code, notes, and snippets.

View stavxyz's full-sized avatar
😿

samuel stavxyz

😿
View GitHub Profile
@stavxyz
stavxyz / script.sh
Last active June 6, 2022 17:53
BASHISM - If you are a civilized person, you'll start all your bash scripts like this
#!/usr/bin/env bash
# Undefined variables are errors.
set -euoE pipefail
errcho ()
{
printf "%s\n" "$@" 1>&2
}
@stavxyz
stavxyz / expected.json
Last active June 19, 2019 00:58
JSON migrations with `jq`
{
"A": "1!",
"b": "2",
"Z": "spam!",
"?": [
83,
65,
84,
85,
82,
@irvingpop
irvingpop / ssh_key.tf
Last active April 8, 2024 07:18
Terraform external data source example - dynamic SSH key generation
# ssh key generator data source expects the below 3 inputs, and produces 3 outputs for use:
# "${data.external.ssh_key_generator.result.public_key}" (contents)
# "${data.external.ssh_key_generator.result.private_key}" (contents)
# "${data.external.ssh_key_generator.result.private_key_file}" (path)
data "external" "ssh_key_generator" {
program = ["bash", "${path.root}/../ssh_key_generator.sh"]
query = {
customer_name = "${var.customer_name}"
customer_group = "${var.customer_group}"
@stavxyz
stavxyz / app.py
Last active March 22, 2016 19:47
bottle, tornado and upgraded json logs using pythonjsonlogger
import random
import bottle
THUMBS_UP = u'\U0001F44D'
THUMBS_DOWN = u'\U0001F44E'
@bottle.route('/hello/<name>')
@yoavniran
yoavniran / ultimate-ut-cheat-sheet.md
Last active April 13, 2024 16:19
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai, Sinon, and Jest
@stavxyz
stavxyz / breakout.md
Last active October 23, 2015 18:01
stdout columns to list of dicts - now supporting tabs or whatever and multi-columns

To take any bunch of printed columns from stdout and turn them into lists of dictionaries...

def parse_block(block, headers=True, delimiter=None):
    """Return a list of items for each row.

    If there are headers in the block of text, they will
    be parsed out and a list of dicts will be returned.
@exhuma
exhuma / colourised_log_example.py
Last active September 1, 2017 12:04
Simple python log formatter for colourised terminal output.
"""
Example for a colourised logging output.
This example uses "blessings" to handle console escape sequences. ``blessings``
itself is a very harmless package in that it does not have any external
dependencies. And it's code-base is very clean and small.
The example extends the core logging formatter (logging.Formatter) and
colourises the complete line. This takes advantage of any upstream updates
related to logging. When writing this against Python 2.7, the parent code
@binarymatt
binarymatt / gist:5978228
Created July 11, 2013 19:00
python is awesome
import collections
def extract_top_ten(str):
return collections.Counter(str.split()).most_common(10)
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: