Skip to content

Instantly share code, notes, and snippets.

@samba
samba / pyprofile.sh
Last active August 29, 2015 14:00
Python profiling shortcut
#!/bin/sh
'''USAGE:
pyprofile.sh run yourscript.py {your arguments} # Runs your program & stores statistics
pyprofile.sh show # Reports your statistics
Within the report mode, use 'help' to learn additional commands.
Initial recommendation:
sort cumtime ncalls # List function calls by total time spent in each function
stats 30 # Show top 30 function calls (by sorted metric, descending)
@samba
samba / gtm-multiloader.html
Last active August 29, 2015 14:00
GTM MultiLoader
<script>
var GTMContainerIDs = ['GTM-XXXXX', 'GTM-YYYYY' /* Add your container ID(s) here */ ];
(function(w,d,s,l,i,j,f,dl,k,q){
w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});
f=d.getElementsByTagName(s)[0], k=i.length;
q='//www.googletagmanager.com/gtm.js?id=@&l='+(l||'dataLayer');
while(k--){j=d.createElement(s);j.async=!0;j.src=q.replace('@',i[k]);f.parentNode.insertBefore(j,f);}
}(window,document,'script','dataLayer',GTMContainerIDs));
</script>
@samba
samba / keybase.md
Created October 1, 2014 17:53
Keybase Verification

Keybase proof

I hereby claim:

  • I am samba on github.
  • I am samba (https://keybase.io/samba) on keybase.
  • I have a public key whose fingerprint is 3B42 C4DA F1B2 70E8 8046 7EA5 6AAA C9B0 7ACE 561D

To claim this, I am signing this object:

#!/usr/bin/env python
## Adjusts HTML structure and applies style attributes (etc) to static HTML.
## Conceptually inspired by jQuery, of course.
import sys
from xml.etree import ElementTree as tree
class QueryResult(object):
def __init__(self, matches):
@samba
samba / sublime_dropbox.sh
Last active August 29, 2015 14:23
Quick clone Sublime (3) settings into a ZIP on Dropbox (synced)
#!/bin/sh
# For Mac environments, where settings are stored in "~/Library/Application\ Support"...
# For linux it's "~/.sublime-text-3" (I guess...)
zip -r ~/Dropbox/Settings/Sublime.zip ~/Library/Application\ Support/Sublime\ Text\ 3/{Installed\ Packages,Local,Packages,Cache/Theme*}
@samba
samba / domain-pattern-check.py
Last active August 29, 2015 14:26
Resolve DNS by regex pattern. e.g. "g[o]{2}gl[aeo].com"
#!/usr/bin/env python
import socket
import argparse
import sys
import re
def test_domain(domain_name):
try:
return bool(socket.gethostbyname(domain_name))
@samba
samba / nginx-cache.sh
Created June 15, 2012 18:24
Nginx Cache Search/Removal
#!/bin/sh
# Nginx Cache Manager (search, remove content by URL or grep)
# NOTE:
# in my nginx config, I use:
# proxy_cache_key $scheme://$host$uri$is_args$args@$remote_user;
# ... which facilitates easier searching of cache files
cachefiles () {
find /var/lib/nginx/cache -type f $@
}
@samba
samba / setmagic.js
Created June 28, 2012 03:31
Simple set handling for Javascript, with "in" operator
/* Set theory implementation, woot!
* (c) Sam Briesemeister, 2012
*
*
* Uses Javascript objects' properties as a shortcut for determining set content.
*
* Elements must be string-like or numeric.
*
* Usage:
*
@samba
samba / dd-local-monitor.sh
Created August 27, 2012 15:41
DD Imaging util
#!/bin/sh
# usage:
# sudo dd-local-monitor.sh if=/dev/sda bs=24M | gzip > /mnt/external/myimage.blob.gz
main () {
echo "# dd: $@" >&2
dd $@ &
@samba
samba / lib.csv.js
Created August 30, 2012 23:42
CSV Parser in Javascript
/* CSV parser
* (c) Sam Briesemeister, 2012
*
* Features:
* - Parses CSV through a sequential tokenizer
* - Supports alternative field separator and quote characters
* - Ignores empty lines and comments (lines starting with #)
* - Provides label support through lookup function
*
* Usage: