Skip to content

Instantly share code, notes, and snippets.

@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 / pizza.py
Last active January 13, 2019 02:11
Calculate the ratio of ingredients needed for the perfect quantity of pizza dough
#!/usr/bin/env python
# Calculate the ratio of ingredients needed for the perfect quantity of pizza dough
#
# $ pizza.py --target-oz=49
# target: 49.00oz 1389gram
# flour: 800 grams (400 x 2)
# water: 520 grams
# salt: 16 grams
# sugar: 12 grams
@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 / update_github_hipchat_hook.py
Created January 15, 2013 03:21
This is a script that updates hipchat hooks on a github repository to only have a small set of actions they trigger based on (ie: push, issues).
#!/usr/bin/env python
"""
This is a script that updates hipchat hooks on github repository to only have a small set of actions they trigger based on.
created by Jehiah Czebotar 2013
Usage:
update_github_hipchat_hook.py --repo=jehiah/json2csv --access_token={{...}}
"""
@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 / over.py
Created May 9, 2018 00:54
Script to filter output from `uniq -c` to only items that appear more than `--frequency=n` times.
#!/bitly/local/bin/python
import tornado.options
import logging
import sys
if __name__ == "__main__":
tornado.options.define("frequency", type=int)
tornado.options.parse_command_line()
for line in sys.stdin:
import os
import httplib
import tornado.web
class ErrorHandler(tornado.web.RequestHandler):
"""Generates an error response with status_code for all requests."""
def __init__(self, application, request, status_code):
tornado.web.RequestHandler.__init__(self, application, request)
self.set_status(status_code)
@jehiah
jehiah / check_swap_paging_rate.sh
Created January 19, 2014 21:37
Nagios Monitor for the rate pages are swapped in/out
#!/bin/bash
# Show the rate of swapping (in number of pages) between executions
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=-1
EXITFLAG=$OK
WARN_THRESHOLD=1
@jehiah
jehiah / check_forkrate.sh
Created January 19, 2014 21:32
check_forkrate.sh script to monitor system fork rate with nagios
#!/bin/bash
# Copyright bitly, Aug 2011
# written by Jehiah Czebotar
DATAFILE="/var/tmp/nagios_check_forkrate.dat"
VALID_INTERVAL=600
OK=0
WARNING=1
CRITICAL=2
@jehiah
jehiah / semver.py
Created April 10, 2017 14:18
Semver 2.0.0 compatible version comparison w/o regexes
def compare(a, b):
"""
Compare two version strings.
:return -1, 0, 1
:rtype: int
"""
a = map(_cast_int, a.split('+', 2)[0].split('.'))
b = map(_cast_int, b.split('+', 2)[0].split('.'))