Skip to content

Instantly share code, notes, and snippets.

Stefan Rusterholz apeiros

Block or report user

Report or block apeiros

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View patches__spreadsheet.rb
# encoding: utf-8
require 'spreadsheet'
require 'stringio'
class Spreadsheet::Workbook
View namespaced_tasks.rb
class Namespace
def initialize(current=[], &block)
@current = current
instance_eval(&block)
end
def namespace(name, &block)
Namespace.new(@current+[name], &block)
end
View after.rb
def invoke(verb, path, expected_code, additional_params=nil)
if additional_params
response = RestClient.public_send(verb, restclient_uri(path), additional_params.to_json, core_params(verb))
else
response = RestClient.public_send(verb, restclient_uri(path), core_params(verb))
end
rescue RestClient::Exception => e
e
rescue
response
View my_app__link.rb
View equal.rb
def ==(other)
other.data == @data
rescue NoMethodError
false
end
View match_all.rb
class String
def match_all(regex)
if block_given?
scan(regex) { yield $~ }
else
enum_for(:scan, regex).map { $~ }
end
end
end
@apeiros
apeiros / hash_map.rb
Created Mar 13, 2014
Implement Hash#map_keys, #map_keys!, #map_values, #map_values!, #map_pairs and #map_pairs!
View hash_map.rb
class Hash
def map_keys
map_pairs { |key, value| [yield(key), value] }
end
def map_keys!
map_pairs! { |key, value| [yield(key), value] }
end
def map_values
@apeiros
apeiros / keybase.md
Created Mar 18, 2014
Verifying myself: I am apeiros on Keybase.io.
View keybase.md

Keybase proof

I hereby claim:

  • I am apeiros on github.
  • I am apeiros (https://keybase.io/apeiros) on keybase.
  • I have a public key whose fingerprint is 8069 6F42 1FD4 35A8 F0FD 23B6 97C0 D061 072D 0718

To claim this, I am signing this object:

@apeiros
apeiros / regex_literal_1.rb
Created Mar 26, 2014
Regex, encodings, invalid sequences
View regex_literal_1.rb
# encoding: utf-8
#p(/\xff/.encoding) # -> raises SyntaxError, "invalid multibyte escape: /\xff/"
p(/\xff/n.encoding)
#p(/\xff/u.encoding) # -> raises SyntaxError, "invalid multibyte escape: /\xff/"
p(/x/.encoding)
p(/x/n.encoding)
p(/x/u.encoding)
View sum_input.rb
#!/usr/bin/ruby -w
# grab the input, convert it, sum it, and spit out the answer
$stdin.each_line do |line|
puts line.scan(/\d+/).map(&:to_i).reduce(:+)
end
You can’t perform that action at this time.