Skip to content

Instantly share code, notes, and snippets.

@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*}
#!/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 / 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:

@samba
samba / htpasswd-ssl.sh
Created June 13, 2014 16:21
htpasswd replacement with openssl
#!/bin/sh
# Writes an APR1-format password hash to the provided <htpasswd-file> for a provided <username>
# This is useful where an alternative web server (e.g. nginx) supports APR1 but no `htpasswd` is installed.
# The APR1 format provides signifcantly stronger password validation, and is described here:
# http://httpd.apache.org/docs/current/misc/password_encryptions.html
help (){
cat <<EOF
Usage: $0 <htpasswd-file> <username>
@samba
samba / md5unicode.js
Last active August 19, 2019 06:14
MD5 in Javascript with Full Unicode support
/* MD5 implementation with Unicode support
* Javascript's standard "charCodeAt" method returns 32-bit big-endian integers,
* which breaks most (JS) MD5 implementations for any input that isn't strictly
* 7-bit ASCII (i.e. within 8 bits). This implementation converts Javascript's
* character ordinals (including UCS-2) to UTF-8 equivalents, and buffers the
* code-points in 8-bit units, so it behaves more like other MD5 implementations
* on Unicode input.
*
* I've put this kit through only a handful test cases, so there maybe issues yet
* unknown. Contributions by way of testing, bug filing/fixing, and optimization
@samba
samba / hubspot-gtm-loader.html
Last active July 5, 2017 22:59
GTM Container Snippet for HubSpot
<!-- Google Tag Manager loader; customized by Analytics Pros [analyticspros.com] -->
<script>
/* Update these for your GTM container(s); be sure they're unique, occurring only once each, not duplicated */
var GTMContainerIDs = ['GTM-XXXXX', 'GTM-YYYYY' ];
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'platform': 'hubspot' // Update this value to reflect other platforms
});
@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 / 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 / lightamd.js
Last active February 11, 2024 22:20
Simplified AMD-style module framework
/* A lightweight module framework intended to provide (simplified)
* AMD-style module support.
*
* Currently its minified form yields 987 bytes, 577 after gzip compression.
*
* It DOES NOT parse module identifiers as paths (e.g. "/a/b" or "../a").
* It assumes that all module IDs are simple strings, and seeks an exact
* match, without attempting to navigate any hierarchy.
*
* It DOES NOT parse incoming modules as string for require() statements.
@samba
samba / backup.sh
Created September 11, 2013 08:29
Backup snapshot script using <fileconvoy.com> as rolling storage
#!/bin/sh
# This script creates encrypted tarballs and then
# 1) Emails them to you, or
# 2) Uploads them to <fileconvoy.com>, and emails you a link and decryption key
# Dependencies: curl, openssl, grep, tar
# Where to find the content to back up
BACKUP_ROOT=/var/backup