Skip to content

Instantly share code, notes, and snippets.

@Squab
Squab / genfile.py
Created January 10, 2015 21:11
Generate a big file with Python
if __name__ == "__main__":
f = open('input.txt', 'w')
for x in range(0,2000000):
s = "SADD set %s\n" % str(x)
f.write(s)
@Squab
Squab / cmd.py
Created January 10, 2015 21:13
Make a Python script behave like a Linux command (take a filename or stdin)
import sys
if __name__ == "__main__":
f = None
try:
filename = sys.argv[1]
f = open(filename, 'r')
except IndexError:
f = sys.stdin.readlines()
@Squab
Squab / redis-mass-insert.md
Last active November 15, 2022 13:07
Prepares data for Redis Mass Insertion with the redis-cli --pipe command

redis-mass-insertion

Lightweight Python script to prepare Redis commands for mass insertion.

Code

#!/usr/bin/env python
"""
    redis-mass.py
@Squab
Squab / hostname.conf
Created March 1, 2015 00:45
Get hostname in upstart script Ubuntu 14.04
description "example hostname script"
author "Tim Simmons"
setuid bob
start on runlevel [2345]
stop on runlevel [!2345]
# retry if ended unexpectedly
respawn
@Squab
Squab / celery.conf
Created March 9, 2015 20:03
Example upstart
description "runs the celery worker"
author "Tim Simmons"
setuid celery
start on runlevel [2345]
stop on runlevel [!2345]
# retry if ended unexpectedly
respawn
@Squab
Squab / findtype.rs
Created March 29, 2015 02:49
Find type of something in Rust
#![feature(core)]
fn print_type_of<T>(_: &T) -> () {
let type_name =
unsafe {
std::intrinsics::type_name::<T>()
};
println!("{}", type_name);
}
@Squab
Squab / arr.py
Last active August 29, 2015 14:18
ctypes Arrays with Rust
from ctypes import *
thelib = CDLL("liblib.dylib")
floatstruct = c_float * 3
f = floatstruct(0.32, 0.44, 0.55)
thelib.arr.restype = c_float
p = pointer(f)
@Squab
Squab / app.py
Created April 25, 2015 22:21
Simple JSON API mock
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/')
def hello_world():
return jsonify({'text': 'Hello World!', 'name': 'Tim'})
if __name__ == '__main__':
app.run(debug=True)
@Squab
Squab / zones.json
Created April 26, 2015 00:21
spag collections
{
"aliases": {
"create_zone": "v2:zones:create",
"create_domain": "v1:domains:create"
},
"v2": {
"zones": {
"create": {
"body": {
"ttl": 300,