Skip to content

Instantly share code, notes, and snippets.

View korny's full-sized avatar

Kornelius Kalnbach korny

View GitHub Profile
@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 / 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 / jquery_ujs.prompt.js.coffee
Last active July 3, 2017 19:06
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: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 / 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: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)