This file contains 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
;; from http://paste.lisp.org/display/69952 | |
(defn sieve [n] | |
(let [n (int n)] | |
"Returns a list of all primes from 2 to n" | |
(let [root (int (Math/round (Math/floor (Math/sqrt n))))] | |
(loop [i (int 3) | |
a (int-array n) | |
result (list 2)] | |
(if (>= i n) |
This file contains 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
(defn digit-sum [val] (apply + (map #(Integer. (str %)) (str val)))) |
This file contains 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 digit_sum(n) | |
n.to_s.each_char.map {|c| c.to_i }.reduce(:+) | |
end |
This file contains 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 factorial(n) | |
(1..n).reduce(:*) | |
end |
This file contains 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 f(x, y=nil, &block) | |
puts x | |
puts y | |
block.call | |
end | |
f(1) { puts "inside block" } | |
f(1, 2) { puts "inside block" } |
This file contains 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 LogReader | |
def initialize(f) | |
@f = f | |
end | |
def process | |
yield(@f.read) | |
end |
This file contains 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
Header line: explaining the commit in one line | |
Body of commit message is a few lines of text, explaining things | |
in more detail, possibly giving some background about the issue | |
being fixed, etc etc. | |
The body of the commit message can be several paragraphs, and | |
please do proper word-wrap and keep columns shorter than about | |
74 characters or so. That way "git log" will show things | |
nicely even when it's indented. |
This file contains 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
#!/usr/bin/env sh | |
## | |
# This is script with usefull tips taken from: | |
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx | |
# | |
# install it: | |
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh | |
# |
This file contains 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
import java.io.IOException; | |
import java.lang.reflect.Method; | |
import java.util.AbstractCollection; | |
import java.util.ArrayList; | |
import java.util.EnumSet; | |
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.Map; | |
import android.media.AudioManager; | |
import android.media.MediaPlayer; |
This file contains 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
=begin | |
This is how you do block comments in Ruby. | |
=end | |
puts "#{2 + 2} equals 4" |