Skip to content

Instantly share code, notes, and snippets.

def formatted_address(order, nl="\n")
name = strip_extra_spaces(order.name)
addr1 = strip_extra_spaces(order.addr1)
addr2 = order.addr2.blank? ? '' : strip_extra_spaces(order.addr2)
city = order.city.blank? ? '' : strip_extra_spaces(order.city)
county = order.county.blank? ? '' : strip_extra_spaces(order.county)
postcode = order.postcode.blank? ? '' : strip_extra_spaces(order.postcode)
country = order.country
@jgarlick
jgarlick / gist:1844115
Created February 16, 2012 11:09
4.3BSD Monopoly
BSD MONOP(6)
NAME
monop - Monopoly game
SYNOPSIS
/usr/games/monop
DESCRIPTION
monop is reminiscent of the Parker Brothers game Monopoly for 1 to 9
players. The program assumes that the rules of Monopoly are known. It
follows the standard rules, with the exception that if a property goes up
for auction and there are only two solvent players, no auction is held
class AccountsController < ApplicationController
def new
@account = Account.new
end
def create
@account = Account.new(params[:account])
if @account.save
redirect_to @account, notice: 'Account was successfully created.'
else
def find_pair(array, value)
lookup = {}
array.each_with_index do |i, index|
if i < value
search = value - i
i2 = lookup[search]
if i2 then return [i2, i] else lookup[i] = index end
end
end
return nil
#!/usr/local/bin/perl
while (chomp($t=)){
$c=1; $d=1; @b=();
foreach (split(/;/,$ARGV[0])){
if( /^al/ ){ tr/0-9//cd; $c-=$_; $c=1 if $c<1; }
elsif( /^ar/ ){ tr/0-9//cd; $c+=$_; }
elsif( /^tl/ ){ $c=1; }
elsif( /^tr/ ){ $c=length $t; }
elsif( /^go/ ){ tr/0-9//cd; $c=$_; }
elsif( /^cb/ ){ @b=(); }
[[[[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]]], [[[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]]], [[[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]]], [[[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]]], [[[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]], [[[[]], [[]]], [[[]], [[]]], [[[]], [[]]]]]]
stack = []
stored_string = ""
random_choices = []
scanner = StringScanner.new(text)
while match = scanner.scan_until(/[\{\}\|]|\[(one of|or|at random)\]/)
stored_string << match.slice(0, match.length - scanner.matched_size)
case scanner.matched
when "{", "[one of]"
stack.push([random_choices, stored_string])
module Test
def hello
self.bye
end
def self.extended(base)
puts base.hello
end
end
@jgarlick
jgarlick / gist:4257714
Created December 11, 2012 10:50
draw scene
/* draw_scene.c
*
* Code to draw the main scene when in flight
*
*/
#include "main.h"
/* highly unoptimised scene rendering */
void draw_scene( void )
{
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, user = require('./routes/user')
, http = require('http')
, path = require('path')