This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# with this function defined... | |
__git_branch () | |
{ | |
local b="$(git symbolic-ref HEAD 2>/dev/null)" | |
if [ -n "$b" ]; then | |
printf "%s" "${b##refs/heads/}" | |
fi | |
} | |
# this gives you warnings for files changed in your branch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec/autorun' | |
def letters(a, b) | |
indexes = b.each_char.map do |letter| | |
a.each_char.each_with_index.select {|l, _| l == letter }.map {|_, i| i } | |
end | |
start = indexes.shift | |
if indexes.empty? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* There are n ships, with i,j,k... spaces for barrels of goods. | |
* There are m players, with x,y,z... number of barrels of goods of different types. | |
* The goods are: indigo, corn, tobacco, sugar, coffee. | |
* A ship can only be loaded if there is space on the ship - 1 space | |
for 1 barrel. | |
* Each ship can only have one type of goods on it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def board(size, tunnels) | |
Hash.new {|_,i| i }. | |
merge(Hash[(1..6).map{|i| [size + i, size - i] }]). | |
merge(tunnels) | |
end | |
def move(board, players, player, roll) | |
players[player] = board[ players[player] + roll ] | |
[players, next_player(players.size, player, roll)] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Monad | |
# (a -> b) -> (a -> [b]) | |
def lift(f) | |
lambda {|x| unit.call(f.call(x)) } | |
end | |
# (a -> b) -> (M a -> M b) | |
def liftM(f) | |
bind(lift(f)) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersController < ApplicationController | |
def create | |
respond_to do |format| | |
format.html do | |
@user = UserService.create(params[:user], true) | |
redirect_to @user | |
end | |
format.json do | |
@user = UserService.create(params[:user], false) | |
render :json => @user, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Self-schizophrenia example | |
class A | |
def foo | |
"foo" | |
end | |
def bar | |
"bar" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def next_working_day(count = 1) | |
negative = count < 0 | |
count = count.abs | |
date = negative ? yesterday : tomorrow | |
loop do | |
count -= 1 if date.working_day? | |
return date if count.zero? | |
date += (negative ? -1 : 1).day |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> module Main where | |
> | |
> import Data.List (sort) | |
I don't need to know anything about the precise positions of the Wire's | |
end points, all that is important is the relative positions (the problem | |
states that only 2 wires cross at one point, so I don't have to worry about | |
the angles of the wires). | |
Given the wire that is lowest on the left building, I know that another wire |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enable :sessions | |
get "/foo" do | |
session[:something] = "hello" | |
"set" | |
end | |
get "/bar" do | |
session[:something] | |
end |
NewerOlder