Skip to content

Instantly share code, notes, and snippets.

View ramsey's full-sized avatar

Ben Ramsey ramsey

View GitHub Profile
@ramsey
ramsey / trapmail.sh
Created June 23, 2009 19:47
Script to redirect mail in a staging environment
#!/bin/sh
################################################################################
# Script to redirect mail in a staging environment
#
# Set this script to executable (chmod 755), and modify php.ini in the staging
# environment to use this script instead of sendmail:
#
# sendmail_path = /path/to/trapmail.sh
#
################################################################################
@ramsey
ramsey / consistent-hashing.php
Created June 9, 2010 19:17
A consistent hashing algorithm implemented in PHP
<?php
$cont = 0;
foreach ($servers AS $ip)
{
for ($k = 0; $k < 40; $k++) {
$ss = "$ip-$k";
$digest = md5($ss, true);
for ($h = 0; $h < 4; $h++) {
$continuum[$cont]['point'] =
(ord($digest[3+$h*4]) << 24 )
@ramsey
ramsey / md5.php
Created November 3, 2011 01:09
MD5 hash lookup script that returns XML
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* MD5 hash lookup script that returns XML
*
* written by Ben Ramsey (ben at benramsey dot com)
* with code by Ilia Alshanetsky (ilia at ilia dot ws)
*
* Copyright (c) 2005, Ilia Alshanetsky
* Copyright (c) 2005, Ben Ramsey
@ramsey
ramsey / flip.cpp
Created November 16, 2011 03:08
Converts ASCII files between Unix, MS-DOS/Windows, or Macintosh newline formats
//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Tue Jan 20 11:13:16 GMT-0800 1998
// Last Modified: Sun Jan 9 10:34:22 PST 2000 (minor changes)
// Last Modified: Thu Aug 2 13:52:52 PDT 2001 (added stdlib.h for new gcc)
// Last Modified Tue Apr 9 12:24:27 PST 2002 (added Mac options)
// Last Modified Mon Jan 20 21:12:52 PST 2003 (enabled conversion from mac to other)
// Last Modified Wed May 18 14:03:03 PDT 2005 (updated for newer C++ compilers)
// Last Modified Sun Aug 21 21:41:47 PDT 2005 (fixed so running -d twice works)
// Web Address: http://www-ccrma.stanford.edu/~craig/utility/flip/flip.cpp
@ramsey
ramsey / generate-opml.php
Created November 16, 2011 20:00
Generate OPML file from Delicious blogroll tag
#!/usr/local/bin/php
<?php
include_once('getRSSLocation.php');
// del.icio.us username and password
$username = 'your_username';
$password = 'your_password';
$cache_file = '/tmp/delicious-blogroll.xml';
$blogs = array();
@ramsey
ramsey / xmlentities.php
Created November 16, 2011 20:04
xmlentities() implemented in PHP (provides functionality similar to htmlentities())
<?php
function xmlentities($s)
{
static $patterns = null;
static $replacements = null;
static $translation = null;
if ($translation === null) {
$translation = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
@ramsey
ramsey / zanshin.zsh-theme
Created February 4, 2012 06:15 — forked from zanshin/zanshin.zsh-theme
My oh-my-zsh theme, a derivative of the Soliah theme
# Shows little symbol '±' if you're currently at a git repo and '○' all other times
function prompt_char {
git branch >/dev/null 2>/dev/null && echo '±' && return
echo '$'
}
PROMPT='
%{$fg[blue]%}%n%{$reset_color%} on %{$fg[yellow]%}%m%{$reset_color%} in %{$fg[green]%}%~%b%{$reset_color%} $(git_time_since_commit)$(check_git_prompt_info)
${vcs_info_msg_0_}$(prompt_char) '
@ramsey
ramsey / csvtosqlite.py
Created September 12, 2012 17:40 — forked from bycoffe/csvtosqlite.py
Creates a sqlite database and table from a CSV file for easier querying
"""
Copyright (c) 2009, Aaron Bycoffe
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright

Keybase proof

I hereby claim:

  • I am ramsey on github.
  • I am ramsey (https://keybase.io/ramsey) on keybase.
  • I have a public key whose fingerprint is E85D 0311 DDFA 5BAC F3A6 10E7 B02D 9798 9C8C 071B

To claim this, I am signing this object:

@ramsey
ramsey / hello1.c
Last active November 6, 2023 07:44
Hello, World in C
#include <stdio.h>
int main()
{
printf("hello, world\n");
}
// Compile, then run `./a.out 1>stdout.txt 2>stderr.txt`
// Then run `echo $?`
// stdout.txt should contain "hello, world"