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
ruby-1.9.2-p180 :001 > cat = Object.new | |
=> #<Object:0x0000010085bc58> | |
ruby-1.9.2-p180 :002 > puts cat.methods.sort | |
! | |
!= | |
!~ | |
<=> | |
== | |
=== | |
=~ |
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
ruby-1.9.2-p180 :004 > def cat.has_nine_lives? | |
ruby-1.9.2-p180 :005?> true | |
ruby-1.9.2-p180 :006?> end | |
=> nil | |
ruby-1.9.2-p180 :007 > cat.has_nine_lives? | |
=> true |
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 maxPrimeFactor(n) #=> maxPrimeFactor(600851475143) => 6857 in 2007.562 ms | |
# limit the ridiculous range safely | |
range = n**(1/Math.sqrt(n.to_s.length).floor.to_f) | |
ary = (1..range).to_a | |
# Sieve of Eratosthenes (replace with Sieve of Atkin?) | |
for i in ary | |
for j in ary | |
if i != j | |
if (j % i == 0) | |
ary.delete(j) |
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
#!/bin/bash | |
# run `compass watch` at pwd | |
# run `coffee -o scripts/ -cw coffee/` at pwd | |
type -P compass &>/dev/null || { echo "Compass command not found."; exit 1; } | |
type -P coffee &>/dev/null || { echo "Coffee command not found."; exit 1; } | |
if [ ! -d sass/ ] || [ ! -d scripts/ ] | |
then | |
echo "Project not setup correctly! Put sass files in sass/ and coffee in coffee/" | |
else |
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
# piping example in Ruby | |
def foo(data) | |
data[:a] += 1 | |
data | |
end | |
def bar(data) | |
data[:b] += 10 | |
data |
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
#ruby1.9.3 | |
def defn name, &b | |
Object.send :define_method, name, &b | |
end | |
# this also works (surprisingly), albeit with a warning | |
# def defn name | |
# Object.send(:define_method, name) | |
# 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
# In Clojure, hash-maps are truly functions of keys to values. | |
# So you can do `(:a {:a 1})` and get `1` as the result | |
# Why not put this in Ruby? | |
# access keys of a hash like a function | |
class Object | |
def respond_to?(method) | |
if (method.to_s =~ /^_.*/) == 0 | |
true |
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
"user": { | |
"contributors_enabled": false, | |
"created_at": "Wed Sep 23 18:48:46 +0000 2009", | |
"default_profile": false, | |
"default_profile_image": false, | |
"description": "Mura is a Japanese Fusion Restaurant serving steak, sushi, seafood. Located in North Hills. Serving lunch and dinner.", | |
"favourites_count": 0, | |
"follow_request_sent": null, | |
"followers_count": 665, | |
"following": null, |
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
-- turn an Integer into a list of digits | |
digits = map (read . (:[])) . show | |
-- is a given fraction special? | |
special :: Integer -> Integer -> Bool | |
special n d | |
| (n_rf / d_rf) == ((realToFrac (head ns)) / (realToFrac (head ds))) = True | |
| otherwise = False | |
where n_rf = realToFrac n | |
d_rf = realToFrac d |
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 euler.three | |
(require [clojure.core.reducers :as r])) | |
(declare largest-prime-factor-for) | |
(declare factors-of) | |
(declare source-factors) | |
(declare source-naturals) | |
(declare factor?) | |
(declare prime?) | |
(declare certainty) |
OlderNewer