Skip to content

Instantly share code, notes, and snippets.

View betawaffle's full-sized avatar

Andrew Hodges betawaffle

View GitHub Profile
@betawaffle
betawaffle / process.pl
Created May 13, 2011 18:07
Linear Regex Replaces with Perl
#!/usr/bin/perl -w
use strict;
while (<>) {
s/\t/|/g; # Convert Tabs to Pipes
s/\r?\n/[]\r\n/g; # Add [] at EOL and Convert to CRLF
s/^\|+\[\]\r\n//g; # Remove Empty Lines
print;
@betawaffle
betawaffle / main.cpp
Created May 21, 2011 15:37
Number to Words
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
string convert(unsigned long n) {
static char *formats[16] = {
"", "%s%s%s", "%s%s", "%s%s-%s",
"%s hundred", "%s hundred and %s%s", "%s hundred and %s", "%s hundred and %s-%s",
@betawaffle
betawaffle / license
Created May 22, 2011 12:27 — forked from defunkt/license
license bash script
#!/bin/sh -e
# Usage: license
# Prints an MIT license appropriate for totin' around.
#
# $ license > COPYING
#!/bin/sh
echo "Copyright (c) `date +%Y` `git config --get user.name`
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@betawaffle
betawaffle / rvm.zsh
Created May 24, 2011 21:30
Easy Switch RVM Completions
local ruby18='ruby-1.8.7-p334'
local ruby19='ruby-1.9.2-p180'
function rb18 {
if [ -z "$1" ]; then
rvm use "$ruby18"
else
rvm use "$ruby18@$1"
fi
}
@betawaffle
betawaffle / pong.coffee
Created June 24, 2011 00:35
Text-based Pong Game
util = require 'util'
after = (time, args..., callback) -> setTimeout callback, time, args...
class Game
score: 0
score_step: 20
constructor: (@client, @difficulty = 800) ->
@send 'HELO :Welcome to Pong!'
@send 'HELP :When you receive a PING <code>,'
@send 'HELP :reply quickly with PONG <code>,'
@betawaffle
betawaffle / gist:1049470
Created June 27, 2011 18:40
Create Method
@create: (msg, opts) ->
title = opts.title if typeof opts.title is 'string'
type = typeof msg
if type is 'object'
title or= msg.attr('title')
type = msg.get(0).nodeName
switch type
when 'string' then break
when 'INPUT', 'SELECT', 'TEXTAREA'
msg = msg.attr('value')
def process(filename)
File.open filename, 'r' do |f|
ln = 0
begin
while l = f.gets
l.strip!
ln += 0
yield l, ln
end
def estimated_tax
line1 = expected_agi
line2 = deductions
line3 = line1 - line2
line4 = 3700 * exemptions
line5 = line3 - line4
line6 = tax(line5)
line7 = alt_min_tax
line8 = line6 + line7
line9 = credits
module Helpers
def each_ln(filename)
File.open filename, 'r' do |f|
ln = 0 # Line Number
begin
while l = f.gets
l.strip!
ln += 1
yield l, ln
end
@betawaffle
betawaffle / gist:1112597
Created July 28, 2011 21:23
Write a ruby method that takes in an array of integers and returns back the largest integer. Do not use .max
def biggest(list)
list.inject do |a, b|
a < b ? b : a
end
end
# Even more concise:
def biggest(list)
list.inject { |a, b| a < b ? b : a }