Skip to content

Instantly share code, notes, and snippets.

@stestagg
stestagg / IPs.py
Created February 18, 2013 15:37
Iterate over all IP addresses in a range..
def get_addr_range(start, end):
def to_int(ip):
return sum([int(p) << (24 - (8 * e)) for e, p in enumerate(ip.split("."))])
def to_ip(val):
return ".".join(str((val & (0xff << s)) >> s) for s in range(24, -1, -8))
for addr in xrange(to_int(start), to_int(end) + 1):
yield to_ip(addr)
@stestagg
stestagg / api.py
Last active December 15, 2015 05:59
import functools
import flask
import inspect
import sys
import traceback
def infer_args(func):
argspec = inspect.getargspec(func)
if argspec.defaults is None:
class A
def foo
puts "A"
end
def self.bar
puts "B"
end
end
#!/bin/bash
function error {
echo -e ">>>>>>>>>>>>>>>>>>>>>>\n$@\n<<<<<<<<<<<<<<<<<<<<<<"
}
set -e
if [ -e test ]; then
echo "'test/' already exists"
<snippet>
<content><![CDATA[
package ${TM_FILEPATH/(.*((?<pfx>com|net|uk|org)\/))?(?<dir>[^\/]+)\/([^\/]+$)?/$+{pfx}.$+{dir}/g};
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>package</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.java</scope>
<description>Automatically calculate package line from file path</description>
</snippet>
@stestagg
stestagg / gil.pyx
Last active December 21, 2015 13:09
cdef extern from "unistd.h":
cdef void sleep(int time)
def lock(time):
print "starting to block"
sleep(10)
print "stop blocking"
@stestagg
stestagg / rediscopy.py
Created April 23, 2014 15:18
Fairly quickly clone a redis DB across hosts
#!/usr/bin/env python2.7
"""
Copy data from one redis instance to another
"""
import argparse
import sys
# pip install redis fin
@stestagg
stestagg / colorshift.less
Created April 25, 2014 16:11
Better color shifting for less-css
// Less color functions are absolute, i.e. if you lighten a really light color by 50%, you'll probably just get pure-white,
// because lighten works relative to the full scale from black -> white
// These functions shift a color relative to it's current value, (if you have a 50% grey, and shift it by 50%, you should end up with a 75% grey)
// Because less doesn't support functions as well as I would like, the solution is quite hacky.
// To set a property to a shifted value, call .color_shift, passing it in.
// For example: .color_shift(background, blue, 70%); produces: background: #b3b3ff; (light-blue)
@stestagg
stestagg / script.py
Created September 24, 2014 09:43
Template for shell script boilerplate
#!/usr/bin/env python
import sys
import argparse
def parse_args(args=None):
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", action="count", default=0,
help="Increase verbosity", dest="verbosity")
@stestagg
stestagg / gist:19165152c7567538a07d
Created October 26, 2014 23:00
Install wpa_supplicant for raspberry pi/arch from x86 machine
mount /dev/sdX2 root
cd root
pacman -r . --config etc/pacman.conf --arch armv6h -S wpa_actiond wpa_supplicant