Skip to content

Instantly share code, notes, and snippets.

@jehiah
jehiah / bash_read_loop_stdin.sh
Created July 30, 2011 23:23
Bash trick #48 while loop reading input from a file
#!/bin/sh
# this loop uses "read" to parse stdin into variables
# stdin is specified at the ending "done" with < input_file, or
# in this case, an inline block of text.
while read host port; do
echo "host $host port $port";
done << EOF
google.com 80
@jehiah
jehiah / wait_run_in_parallel.sh
Created July 22, 2011 16:05
run bash commands in parallel
# This is a simple way to run multiple things in parallel in a bash
# script without making things too complicated
# it's modeled after (and uses) the bash `wait` command
# TIP: to do more complicated steps in parallel put them in a function
function wait_run_in_parallel()
{
local number_to_run_concurrently=$1
if [ `jobs -np | wc -l` -gt $number_to_run_concurrently ]; then
wait `jobs -np | head -1` # wait for the oldest one to finish
@jehiah
jehiah / lru_cache.c
Created April 3, 2011 21:35
a LRU cache in C using uthash
#include <string.h>
#include <uthash.h>
// this is an example of how to do a LRU cache in C using uthash
// http://uthash.sourceforge.net/
// by Jehiah Czebotar 2011 - jehiah@gmail.com
// this code is in the public domain http://unlicense.org/
#define MAX_CACHE_SIZE 100000
@jehiah
jehiah / strnchr.c
Created March 4, 2011 17:20
strnchr because it doesn't exist for some reason
#include <stdlib.h>
/*
Returns a pointer to the first occurrence of character in the C string str.
The terminating null-character is considered part of the C string. Therefore,
it can also be located to retrieve a pointer to the end of a string.
@param str the string to be searched
@param len the number of characters to search
@param character the character to search for
@jehiah
jehiah / simple_args_parsing.sh
Created March 4, 2011 16:56
a simple way to parse shell script arguments
#!/bin/sh
#
# a simple way to parse shell script arguments
#
# please edit and use to your hearts content
#
ENVIRONMENT="dev"
@jehiah
jehiah / bitly.rb
Created February 25, 2011 04:46 — forked from richardtifelt/bitly.rb
# Bit.ly API implementation - thanks to Richard Johansso http://gist.github.com/112191
require 'httparty'
class Api::Bitly
include HTTParty
base_uri 'api.bit.ly'
format :json
# Usage: Bitly.shorten("http://example.com")
def self.shorten(url)
@jehiah
jehiah / get_latest_chromium.sh
Created February 18, 2011 15:49
script to download the latest chromium build nightly
#!/bin/sh
## this is a quick and dirty script to automagically install the latest chromium build on OSX 10.5
## you can set this up as a nightly cron job, or run manually from the command line
# USAGE:
# save script to your home directory aka /Users/$USER/
# open up a command prompt (aka /Applications/Utilities/Terminal)
# run manually from the command line whenever you want the most recent chromium build
# $ sh get_latest_chromium.sh
# start it as a nightly task (runs at 1am or edit the plist below)
@jehiah
jehiah / export_adium.py
Created December 17, 2010 21:39
parse Adium XML log files into a csv
"""
this script parses Adium XML log files into a csv
use -u to specify your usernames to look for
use -d to specify the path (with wildcards) to adium xml logs (be careful to check all installed adium versions)
you can then read data with
import csv
@jehiah
jehiah / twitter_archiver.py
Created December 17, 2010 05:00
python script to archive your tweets
#!/usr/bin/env python
"""
twitter_archiver.py written by Jehiah Czebotar 2010 <jehiah@gmail.com> http://jehiah.cz/
this uses the great 'python twitter tools' library by Mike Verdone
http://mike.verdone.ca/twitter/
usage:
$ pip install twitter
import pylibmc
import Queue
import logging
import functools
"""
This is a transparent pool library that wraps a pylibmc client
from MemcachePool import mc
mc.get(key)