Skip to content

Instantly share code, notes, and snippets.

View korny's full-sized avatar

Kornelius Kalnbach korny

View GitHub Profile
@korny
korny / gist:1245309
Created September 27, 2011 15:08
Middleware to highlight twice-escaped HTML
class HighlightEscapedHTML
def initialize(app)
@app = app
end
def call(env)
dup._call(env)
end
def _call(env)
@korny
korny / gist:1324313
Created October 29, 2011 10:25
Chiliproject Test Suite
rake
/Users/murphy/.rvm/rubies/ruby-1.8.7-p352/bin/ruby -I"lib:test" -I"/Users/murphy/.rvm/gems/ruby-1.8.7-p352@chiliproject/gems/rake-0.9.2.2/lib" "/Users/murphy/.rvm/gems/ruby-1.8.7-p352@chiliproject/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/unit/**/*_test.rb"
(Test LDAP server not configured)
* DEFERRED: #link_to_if_authorized authorized user should be tested.
* DEFERRED: #link_to_if_authorized unauthorized user should be tested.
* DEFERRED: IssuesHelper#show_detail with a estimated hours attribute should format the time into two decimal places.
* DEFERRED: IssuesHelper#show_detail with a estimated hours attribute should format the old time into two decimal places.
* DEFERRED: IssuesHelper#show_detail should test custom fields.
* DEFERRED: IssuesHelper#show_detail should test attachments.
* DEFERRED: #number_of_rows with one project should return the number of rows just for that project.
@korny
korny / gist:1433450
Created December 5, 2011 12:32
Rails env loading benchmark on Ruby 1.8.7, Ruby EE, 1.9.2, and 1.9.3
> rvm 1.8.7,ree-1.8.7-2011.03,1.9.2,1.9.3 do "ruby -v; time rails runner 'nil'"
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin10.8.0]
real 0m1.404s
user 0m1.195s
sys 0m0.207s
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin11.0.0], MBARI 0x6770, Ruby Enterprise Edition 2011.03
real 0m1.347s
user 0m1.135s
@korny
korny / jquery_ujs.prompt.js.coffee
Last active May 29, 2024 08:02
Simple prompt functionality for Rails / jQuery UJS, modelled after "confirm". Tested with Rails 4 (edge).
# Usage: link_to …, prompt: { message: 'Some message', default: 'default value', param: 'name of parameter' }
# The prompt will ask for "message" and use "default" as the default value.
# Unless user selects cancel, "param"=<new value> will be sent to the given path.
# Optionally, you can just use `prompt: "message"`.
$.rails.prompt = (message, defaultValue) ->
window.prompt message, defaultValue
$.rails.handlePrompt = (element) ->
config = element.data 'prompt'
@korny
korny / gist:5992006
Last active December 19, 2015 17:29
CodeRay scanning / highlighting speed
$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
$ ruby test/scanners/suite.rb | grep Average
Average speed for C scanner: 2997 kB/s scanning / 1315 kB/s highlighting to HTML page.
Average speed for Clojure scanner: 3103 kB/s scanning / 1051 kB/s highlighting to HTML page.
Average speed for C++ scanner: 4761 kB/s scanning / 1180 kB/s highlighting to HTML page.
Average speed for CSS scanner: 3160 kB/s scanning / 1494 kB/s highlighting to HTML page.
Average speed for Delphi scanner: 2865 kB/s scanning / 991 kB/s highlighting to HTML page.
Average speed for diff output scanner: 1433 kB/s scanning / 668 kB/s highlighting to HTML page.
@korny
korny / gist:6951979
Created October 12, 2013 16:31
Simplistic backport of Enumerable#slice_before from Ruby 1.9 to Ruby 1.8.
class Array
def slice_before
[].tap do |chunks|
each do |item|
chunks << [] if yield(item) || chunks.empty?
chunks.last << item
chunks
end
end
end
@korny
korny / shadowrun-dice-calculator.rb
Created January 6, 2014 02:38
A helper script for Shadowrun dice calculations, especially the probability of Glitches. Includes Shadowrun 5 rules. This is public domain.
module Math
class << self
def fac n
return 1 if n < 2
(1..n).inject { |prod, i| prod * i }
end
def choose n, k
fac(n) / (fac(n-k) * fac(k))
end
@korny
korny / block_given.rb
Created January 8, 2014 19:05
block_given? doesn't work in a delegating BasicObject
class Foo < BasicObject
def test_block_given?
block_given?
end
private
def method_missing(method, *args, &block)
3.send(method, *args, &block)
end
end
@korny
korny / srt-parser.js
Created July 3, 2014 13:00
Simple SRT parser in JavaScript
function srtTimeToSeconds(time) {
var match = time.match(/(\d\d):(\d\d):(\d\d),(\d\d\d)/);
var hours = +match[1],
minutes = +match[2],
seconds = +match[3],
milliseconds = +match[4];
return (hours * 60 * 60) + (minutes * 60) + (seconds) + (milliseconds / 1000);
}
@korny
korny / gist:4f6ea67986d3d5efa462
Created December 17, 2014 11:14
Ruby 1.8/1.9 change regarding super inside a proc
class Human
def self.speak what
what
end
end
class Pirate < Human
def self.speak what
proc { super }.call
end