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 natural? | |
"Returns true if n is a natural number (greater than zero, and with no | |
fractional component), else false." | |
[n] | |
(and (> n 0) (zero? (rem n 1)))) | |
(defn nth-sgonal | |
"For a given s-gonal number P(s,n) = x, returns n (n is a natural number if | |
x is a term of the given s-gonal sequence)." | |
^double [^long x ^long s] |
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- stirling-loop-internal | |
[^long n ^long k compfunc] | |
{ :pre [(<= k n)] } | |
(let [workitems (for [n' (range 1 (inc n)) k' (range 0 (inc (- n k))) | |
:when (and (>= (- n' k') 0) (>= k (- n' k')))] [n' (- n' k')])] | |
(loop [current (first workitems) items (rest workitems) results {}] | |
(cond | |
(= current [n k]) ((compfunc current results) current) | |
(= (current 0) (current 1)) | |
(recur (first items) (rest items) |
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 bell | |
"Returns the nth Bell number" | |
[n] | |
(cond | |
(= n 0) 1 | |
(= n 1) 1 | |
:else (reduce + (map #(abs (stirling-2 n %)) (range 0 (inc 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
(server/add-middleware | |
friend/authenticate | |
{ :credential-fn (partial creds/bcrypt-credential-fn users) | |
:workflows [(workflows/interactive-form)] | |
:login-uri "/login" | |
:unauthorized-redirect-uri "/login" | |
:default-landing-uri "/" }) | |
(pre-route [:any "/app/*"] { :as req } (let [id (friend/identity req)] | |
(when-not (friend/authorized? [::user] id) (friend/throw-unauthorized id {})))) |
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 ruby | |
require 'flickraw' | |
FlickRaw.api_key = "YOUR FLICKR API KEY" | |
FlickRaw.shared_secret = "YOUR FLICKR SHARED SECRET" | |
ARGV[0] ||= "kittens" | |
search_query = ARGV[0] |
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 put (s) | |
print s | |
STDOUT.flush | |
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
# add this to your config.rb | |
ready do | |
wikitargets = Hash.new | |
wikiwords = Hash.new | |
sitemap.resources.select {|p| p.ext == ".html" }.each do |p| | |
unless p.data['wikitag'].nil? | |
wikitargets[p.data['wikitag']] = p.url | |
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
from math import sqrt, ceil, trunc | |
# Sieve of Eratosthenes | |
def seive(max): | |
nums = range(max + 1) | |
nums[0] = None | |
nums[1] = None | |
for i in range(2, max + 1): | |
if nums[i]: | |
c = i * 2 |
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
print(sum([x for x in range(1000) if x % 3 == 0 or x % 5 == 0])) |
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
/** @jsx React.DOM */ | |
var ReadingTimeWidget = React.createClass({ | |
getInitialState: function() { | |
return ({ | |
secondsRequired: null, | |
}); | |
}, | |
componentWillMount: function() { | |
var cdiv = this.props.contentDiv; |