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
{-| Keep equal elements that are at the same position in both lists | |
Examples: | |
>>> keepEqual "hello" "world" | |
"l" | |
>>> keepEqual (repeat 1) [0..10] | |
[1] |
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
{-- | List the sub-sequences of conscutives elements in the list such that the | |
sum of the element is equal to the given number. | |
Examples: | |
>>> matchingSub 10 [1..5] | |
[[1,2,3,4]] | |
>>> matchingSub 2 $ replicate 3 1 | |
[[1,1],[1,1]] |
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
{- | given two positions in a list, swap them. | |
if (at least) one of the positions is invalid, return Nothing. | |
Examples: | |
>>> swapL 0 2 [0..5] | |
Just [2,1,0,3,4,5] | |
>>> fmap (take 6) $ swapL 0 2 [0..] | |
Just [2,1,0,3,4,5] |
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 BasicObject | |
def to_donut | |
:donut | |
end | |
end | |
## Usage | |
3.to_donut #=> :donut | |
nil.to_donut #=> :donut |
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 Board | |
def squares | |
@squares ||= [[:_, :_, :_],[:_, :_, :_],[:_, :_, :_]] | |
end | |
def square(x, y) | |
squares[y][x] | |
end | |
def place(counter, x, y) |
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
(ns request) | |
(defn request [] {}) | |
(defn body [] {}) | |
(defn file [] {}) | |
(defn set-url | |
[request url] | |
(assoc request :url url)) |
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
use strict; | |
use warnings; | |
{ | |
package Bob; | |
sub hey { | |
if (&_shouting) { | |
"Woah, chill out!" | |
} elsif (&_question) { |
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
-- Short version to show the power of Haskell :-) | |
module DNA(toRNA) where | |
toRNA = map convert where | |
convert 'T' = 'U' | |
convert n = n | |
-- Long version with a bunch of cool stuff that makes me happy |
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 Id::Model | |
def initialize(data = {}) | |
@data = data.reduce({}) do |acc, (k, v)| | |
field = fields[k.to_sym] | |
v ||= field.default! | |
v = field.type.new(v) if field.type.is_a?(Id::Model) && !v.nil? | |
acc.merge(k.to_s => Id::Hashifier.enhash(v)) | |
end | |
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
# set up java | |
sudo apt-get install openjdk-7-jdk | |
echo "export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64" >> ~/.bashrc | |
# get nutch 1.7 | |
curl "http://mirror.ox.ac.uk/sites/rsync.apache.org/nutch/1.7/apache-nutch-1.7-bin.tar.gz" > nutch.tar.gz | |
tar zxvf nutch.tar.gz | |
cd ~/apache-nutch-1.7 | |
# add some urls to crawl (optionally use seeds.txt in this gist) |