Skip to content

Instantly share code, notes, and snippets.

import subprocess
def shell(*args, **kwargs):
"""Execute a shell command and return the output as a string.
Any additional kwargs are passed directly to subprocess.run.
Examples:
shell("date")
shell("date", "-u")
message = "hello, world"
shell("echo", message)
@awreece
awreece / Simplest Possible Makefile
Created March 2, 2012 07:32
Simplest Possible Makefile
# Comments in makefiles follow the same form as comments in bash.
# Makefiles need to be named "Makefile" or "makefile".
# In makefiles, variables are declared in the following manner (the entire
# string after the equals and up to but excluding the newline is the
# content of the variable)
#
# Note: there are other ways to declare variables that are not explored in this
# tutorial.
TARGET = my_cc
securityDefinitions:
api_key:
in: query
name: key
type: apiKey
api_token:
in: query
name: token
type: apiKey
void print_backtrace(int skip) {
void *backtrace_array[MAX_STACK];
int stack_size = backtrace(backtrace_array, MAX_STACK);
backtrace_symbols_fd(&backtrace_array[skip+1],
stack_size - skip - 1, STDERR_FILENO);
}
void signal_backtrace(int signum) {
fprintf(stderr, "%s\n\n", strsignal(signum));
print_backtrace(2);
#!/usr/bin/env ruby
require 'digest'
module VanitySha
extend self
COMMITTER_PATTERN = /^committer .* \<.*\> (?<timestamp>\d+)(?<timezone>.*$)/
AUTHOR_PATTERN = /^author .* \<.*\> (?<timestamp>\d+)(?<timezone>.*$)/
TIMESTAMP_DELTA_MAX = 10 * 24 * 60 * 60
#!/usr/bin/python
# -*- coding: utf-8 -*-
import argparse
import blessed
from collections import defaultdict
import csv
import jinja2
import logging
import numpy
CREATE TABLE metrics (
id bytea NOT NULL primary key,
description text,
name text COLLATE pg_catalog."C"
);
CREATE TABLE contribution_metrics (
last_update_on timestamp with time zone,
metric bytea NOT NULL,
projected double precision,
psql> explain analyze select investments.id
from contributions
JOIN investments ON contributions.investment_id = investments.id
JOIN contribution_investment_metrics cim on cim.investment_id = investments.id
WHERE contributions.id = '\x58c9c0d3ee944c48b32f814d';
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=27098.32..27106.89 rows=1 width=13) (actual time=1322.324..1322.329 rows=1 loops=1)
Join Filter: (contributions.investment_id = investments.id)
-> Merge Join (cost=27098.
import gdb
from datetime import datetime
import sys
if sys.version_info > (3, 0):
raw_input = input
#
# The gdb constant COMPLETE_EXPRESSION was added in gdb 7.7. For earlier
# version of gdb, we use COMPLETE_SYMBOL which is close enough.
@awreece
awreece / Check cache
Created April 15, 2012 22:20
Check Malloc for False Sharing
areece@areece-laptop:~/coding/gomalloc$ ./malloccheck --checkcache=true --procs=1
Malloc check ran with 1 procs for 1000000 iters of size 16
Cache line shared 0 (0.00%) times
Cache was reused 993536 (99.35%) times
areece@areece-laptop:~/coding/gomalloc$ ./malloccheck --checkcache=true --procs=2
Malloc check ran with 2 procs for 1000000 iters of size 16
Cache line shared 128186 (12.82%) times
Cache was reused 859014 (85.90%) times
areece@areece-laptop:~/coding/gomalloc$ ./malloccheck --checkcache=true --procs=3
Malloc check ran with 3 procs for 1000000 iters of size 16