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 calc | |
([n] | |
(reduce #(+ %1 | |
(let [x (- (/ (* 20.0 %2) n) 10.0)] | |
(* (Math/pow Math/E (* x (- x)) ) (/ 20.0 n) ))) 0 | |
(range n)))) | |
(def N 10000) | |
(def M 5000) |
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
require 'rubygems' | |
require 'active_record' | |
require 'test/unit' | |
DBName = 'test_custom_select' | |
DBUser = 'root' | |
DBPass = '' | |
unless defined?(JRUBY_VERSION) | |
# require 'openssl' |
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 Puzzle | |
attr_accessor :field | |
def initialize | |
self.field = true | |
end | |
def run | |
puts field.inspect # => true | |
if false |
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
if defined?(JRUBY_VERSION) | |
# Based on: https://gist.github.com/jorgenpt/1356797 | |
# unfortunately it opens a new thread each time timeout is invoked :-/ | |
class HTTPClient | |
module Timeout | |
def timeout(sec, klass=nil) | |
return yield(sec) if sec == nil or sec.zero? | |
thread = Thread.new { yield(sec) } | |
if thread.join(sec).nil? |