Skip to content

Instantly share code, notes, and snippets.

View austintaylor's full-sized avatar

Austin Taylor austintaylor

View GitHub Profile
@austintaylor
austintaylor / For comparison: profile.erb
Created March 15, 2012 15:19
A different approach to HTML templating
<h1><%= _('Profile') %></h1>
<%= form_for @profile, :url => user_profile_path(@profile), :html => {:class => 'profile'} do |f| %>
<%= render 'shared/errors', :model => @profile %>
<dl>
<dt><%= f.label :name, _('Name') %></dt>
<dd><%= f.text_field :name %></dt>
</dl>
<dl>
<dt><%= f.label :email, _('Email') %></dt>
<dd><%= f.text_field :email %></dt>
@austintaylor
austintaylor / either.hs
Created January 10, 2012 21:57
Needing the `Either a` monad in Ruby
loadStuff :: Map -> Either String (ThingOne, ThingTwo)
loadStuff params = do
thingOne <- loadThingOne params
thingTwo <- loadThingTwo params thingOne
checkSomething thingTwo
return (thingOne, thingTwo)
@austintaylor
austintaylor / gist:1173652
Created August 26, 2011 15:23
Bash function to show your local IP address
function ip() {
ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk '{ print $2 }'
}
@austintaylor
austintaylor / .gitconfig
Created May 20, 2011 19:25
My todo file hack
[core]
excludesfile = /Users/austin/.gitignore
@austintaylor
austintaylor / EvalMath.hs
Created May 13, 2011 14:28
Haskell module example
import ShuntingYard
data Result = I Int | B Bool deriving (Eq)
instance Show Result where
show (I x) = show x
show (B x) = show x
evalMath :: String -> Result
evalMath = rpn . shuntingYard . tokenize
@austintaylor
austintaylor / powerset.hs
Created April 25, 2011 19:16
Powerset: Haskell vs. Ruby
import Control.Monad (filterM)
powerset :: [a] -> [[a]]
powerset = filterM (\x -> [True, False])
@austintaylor
austintaylor / 0_map.hs
Created April 20, 2011 15:02
5 ways to do the same thing
products = concatMap (\x -> map (*x) [1..10]) [1..10]
@austintaylor
austintaylor / DateSelect.hs
Created April 19, 2011 19:26 — forked from aiwilliams/date_select.js.coffee
CoffeeScript vs. Ruby/Haml vs. Haskell
import Text.Html
dateSelect year = dateSelect "born_on_month" [1..12] monthName
+++ dateSelect "born_on_day" [1..31] show
+++ dateSelect "born_on_year" [year-80..year] show
where monthName x = words "January February March April May June July August September October November December" !! (x - 1)
dateSelect n xs f = (select << map (dateOption f) xs) ! [name n]
dateOption f x = (option << f x) ! [value $ show x]
@austintaylor
austintaylor / event_inspector.js
Created April 12, 2011 18:59
Used this to track down a crazy JS bug one time. Still makes me smile.
var eventColors = {
mouseover: 'red',
mouseout: 'blue',
click: 'yellow'
}
var highlight = function(event) {
Event.stop(event);
element = Event.element(event);
Element.setStyle(element, {backgroundColor: eventColors[event.type]});
@austintaylor
austintaylor / ShuntingYard.hs
Created April 11, 2011 03:29
A basic math evaluator in Haskell
type Precedence = Int
data Associativity = AssocL | AssocR
data Token = Operand Int | Operator String (Int -> Int -> Int) Associativity Precedence | ParenL | ParenR
instance Show Token where
show (Operator s _ _ _) = s
show (Operand x) = show x
show ParenL = "("
show ParenR = ")"