This file contains hidden or 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 Array | |
| def random_slice length | |
| length = [size,length].min # prevent infinite loops | |
| values_at(*(1..length).inject([]){|a,_|a.include?(r=rand(size))?redo:a<<r}) | |
| end | |
| end |
This file contains hidden or 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 String | |
| def - other | |
| @___m = Array.new(self.size) { [] } | |
| ___d(self, other) | |
| end | |
| private | |
| def ___d first, other | |
| n, m = first.size-1, other.size-1 |
This file contains hidden or 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
| module Enumerable | |
| def sum(*args, &block) | |
| if block_given? | |
| map &block | |
| else | |
| self | |
| end.inject(*args) { |sum, x| sum + x } | |
| end | |
| end |
This file contains hidden or 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 'sample' | |
| class DecisionTree | |
| def initialize deciders | |
| @deciders = deciders | |
| @tree = {} | |
| end | |
| def << sample # TODO should be able to add to multiple subtrees |
This file contains hidden or 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 'classifiers' | |
| require 'extractors' | |
| require 'elastic_matcher' | |
| include Classifiers | |
| classifier :default do |cache| | |
| KnnClassifier.new(Detexify::Extractors::Strokes::Features.new, lambda { |v,w| (v-w).r }, :cache => cache) | |
| end |
This file contains hidden or 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
| module RedirectPuts | |
| class Interceptor | |
| def initialize io | |
| @io = io | |
| end | |
| private | |
| def puts stuff | |
| @io.puts stuff |
This file contains hidden or 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
| # constant-time comparison algorithm to prevent timing attacks | |
| def secure_compare(a, b) | |
| if a.length == b.length | |
| result = 0 | |
| for i in 0..(a.length - 1) | |
| result |= a[i] ^ b[i] | |
| end | |
| result == 0 | |
| else | |
| false |
This file contains hidden or 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
| [Sun, 08 Nov 2009 23:27:56 GMT] [error] [<0.533.0>] Uncaught error in HTTP request: {exit,normal} | |
| [Sun, 08 Nov 2009 23:27:56 GMT] [info] [<0.533.0>] Stacktrace: [{mochiweb_request,recv,3}, | |
| {mochiweb_request,stream_unchunked_body,5}, | |
| {mochiweb_request,recv_body,2}, | |
| {couch_httpd,json_body,1}, | |
| {couch_httpd,json_body_obj,1}, | |
| {couch_httpd_db,db_req,2}, | |
| {couch_httpd_db,do_db_req,2}, | |
| {couch_httpd,handle_request,5}] |
This file contains hidden or 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
| diff --git a/rails/reload_classes.rb b/rails/reload_classes.rb | |
| index ff881bf..ca34ebe 100644 | |
| --- a/rails/reload_classes.rb | |
| +++ b/rails/reload_classes.rb | |
| @@ -1,37 +1,10 @@ | |
| -module CouchPotato | |
| - module Persistence | |
| - | |
| - def self.persistent_classes #:nodoc: | |
| - @persistent_classes ||= [] |
This file contains hidden or 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 -w | |
| ENV['CLASSPATH'] = (['./src']+ Dir["./lib/*.jar"] + [ENV['CLASSPATH']]).join(':') | |
| exec 'sh ~/code/vimclojure/bin/ng-server' |