Skip to content

Instantly share code, notes, and snippets.

@JordanReiter
JordanReiter / beep_after.sh
Created September 15, 2015 18:30
Simple script that beeps twice after successful completion of a command, and five times if it fails
SUCCESS_BEEPS=2
ERROR_BEEPS=5
prog=$1
shift
args=$@
function countbeep() {
head -c $1 < /dev/zero | tr '\0' "\a"
}
@JordanReiter
JordanReiter / semantic-tables.less
Created February 24, 2015 18:27
Automatic pretty tables for Bootstrap 3
/*
This is inspired by the "Using Bootstrap the Right (Semantic) Way" article
https://www.ostraining.com/blog/coding/bootstrap-right-way/
Every time I added a table to a page, I was always adding bootstrap classes to it, like so:
<table class="table table-bordered table-striped">
This LESS file automatically gives all tables the styles from these classes.
@JordanReiter
JordanReiter / Logarithmic generator
Created December 13, 2012 16:01
A logarithmic generator: 1, 2, …, 8, 9, 10, 20, 30, …, 80, 90, 100, 200, …. Especially useful those times when you want to see how a function behaves over a wide range of numbers but don't want to have to actually look at all of those numbers.
def log_gen(n):
import math
y = 1
while y < n:
adder = max(1, math.pow(10, int(math.log10(y))))
yield int(y)
y = y + adder
@JordanReiter
JordanReiter / new-scratch-file.scpt
Created November 16, 2012 16:10
AppleScript file -- create scratch file in TextWrangler
property file_formats : {¬
"cfm", ¬
"html", ¬
"js", ¬
"py", ¬
"sh", ¬
"txt"}
property scratch_folder : "Macintosh HD:path:to:scratch:folder:" as alias
@JordanReiter
JordanReiter / console.polyfill.js
Created September 28, 2012 18:57
Simple console polyfill -- does nothing if console is not defined.
window.console = window.console || (function() {
var empty = function () {},
functions = "log info warn error assert dir clear profile profileEnd".split(" "),
ff = 0,
fun = null,
return_obj = {};
for(ff = 0; fun = functions[ff]; ff += 1) {
return_obj[fun] = empty
}
return return_obj
@JordanReiter
JordanReiter / uploader.py
Created September 7, 2012 16:56
Python snippet for uploading file to another server
import errno
import os
import paramiko
class Uploader(object):
def __init__(self, host, basepath='', username=None, password=None, keyfile=None, *args, **kwargs):
self.host = host
self.basepath = basepath
self.username = username
@JordanReiter
JordanReiter / django_env_functions.sh
Created June 7, 2012 15:13
Some bash functions that make working with Django && virtualenv a lot easier
#!/bin/bash
#
# Helper functions for Django projects in virtual env
#
# include in your .bashrc file:
#
# . ~/django_env_functions.sh
#
$MANAGE_PATH = "project/code"
@JordanReiter
JordanReiter / subprocess_timeout.py
Created April 18, 2012 18:40 — forked from kirpit/bash.py
Enables to run subprocess commands in a different thread with TIMEOUT option!
import subprocess, threading
class Command(object):
'''
Enables to run subprocess commands in a different thread
with TIMEOUT option!
Based on jcollado's solution:
http://stackoverflow.com/questions/1191374/subprocess-with-timeout/4825933#4825933
'''