Skip to content

Instantly share code, notes, and snippets.

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?
@ocher
ocher / gist:5771903
Last active December 18, 2015 10:58
class Puzzle
attr_accessor :field
def initialize
self.field = true
end
def run
puts field.inspect # => true
if false
require 'rubygems'
require 'active_record'
require 'test/unit'
DBName = 'test_custom_select'
DBUser = 'root'
DBPass = ''
unless defined?(JRUBY_VERSION)
# require 'openssl'
(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)