Skip to content

Instantly share code, notes, and snippets.

View unixpickle's full-sized avatar

Alex Nichol unixpickle

View GitHub Profile
@unixpickle
unixpickle / clockd
Created August 21, 2011 02:25
clockd: command line timer
#!/usr/bin/php
<?php
// make sure that they are in a shell
if (empty($_SERVER['SHELL'])) {
die('Shells only please');
}
$configFile = $_SERVER['HOME'] . '/.clockd';
main($argv);
@unixpickle
unixpickle / FileHasher.h
Created November 13, 2011 20:37
MD5FileHasher
#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonDigest.h>
#define kDefaultHashBufferSize 0x1000
@class FileHasher;
typedef void (^FileHasherCallback) (FileHasher * hasher,
BOOL finished,
NSUInteger bytesCompleted);
@unixpickle
unixpickle / pidof.sh
Created June 20, 2012 00:36
Get the process ID for a process name
#!/bin/bash
#
# Quickly get a PID for a given process name.
#
if [ $# -lt 1 ]; then
echo 'Usage: pidof <command name>' >&2
exit 1
fi
lines=`ps aux -c | grep "$1" | sed -e 's/^[^0-9]*\([0-9]*\).*/\1/g'`
@unixpickle
unixpickle / balance.rb
Created July 2, 2012 14:51
Calculate your bank account's future!
printf "Enter initial balance: "
balance=gets.chomp.to_f
printf "Enter interest %%: "
interest=gets.chomp.to_f
printf "Enter weekly income: "
weekly=gets.chomp.to_f
printf "Enter number of weeks[10]: "
weeksStr=gets.chomp
weeks=0
if weeksStr == ''
@unixpickle
unixpickle / plexdblist.sh
Created July 10, 2012 23:26
List all of the items in Plex (w/ view count)
#!/bin/bash
#
# Simply pass in your plex library database file and have some fun!
# NOTE: your DB file is probably called "com.plexapp.plugins.library.db"
#
if [ $# != 1 ]; then
echo "plexdblist - lists the media items in a plex DB file."
echo "Usage: plexdblist <database>"
exit 1
@unixpickle
unixpickle / Pile.hs
Created August 21, 2012 23:06
Evenly Split Integers Into Two Groups
module BinaryPile (
binarySplit
) where
import Data.List
sortClosest :: (Num a, Ord a) => a -> [a] -> [a]
sortClosest _ [] = []
sortClosest x (y:ys) = (sortClosest x closer) ++ [y] ++ (sortClosest x farther)
where diff = abs $ y - x
@unixpickle
unixpickle / polynomials.c
Created March 7, 2013 00:33
#25 AMC 12 B
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
const struct {
long long real;
long long imag;
} factors[] = {
{1, 0},
{-1, 0},
@unixpickle
unixpickle / possibilityCount.m
Created March 9, 2013 01:16
Musical Chairs
%{
Solves the following problem:
Eight people are seated at a circular table. Each person gets up and sits
down again - either in the same chair or in the chair immediately to the
left or right of the one they were in. How many different ways can the
eight people be reseated?
%}
function count = possibilityCount(positions, index)
if index > 8
@unixpickle
unixpickle / problem.hs
Created April 3, 2013 02:12
Find the mirror image of the Hofstadter G function
import Data.Maybe
data FunctionParameters = FunctionParameters [Int] deriving (Show)
main :: IO ()
main = do
let params = allFunctionParameters []
putStrLn $ show $ workingParams params 0
workingParams :: [FunctionParameters] -> Integer -> (Maybe FunctionParameters, Integer)
@unixpickle
unixpickle / rollcount.js
Created September 10, 2013 00:59
Get the probability of rolling heads 10 times in a row after n rolls
/**
* This program makes it easy to compute (in exponential time)
* what the odds are that you will either roll 10 heads or
* 10 of the same (but possibly tails) face in a row after n rolls.
*/
function BinDist(fn) {
this.fn = fn;
}