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 pgbytea.rb
pg.exec_params("CREATE TABLE foos (data bytea)")
para ="C*") # => "\x00\x01\x02\x03\x04\x05…\xFE\xFF"
pg.exec_params("INSERT INTO foos ($1)", [para])
pg.exec_params("SELECT * FROM foos").to_a # => [{"data"=>"\\x"}]
apeiros / submitForm.js
Created Sep 9, 2014
send a "virtual" form with values from JS
View submitForm.js
;(function($) {
// Sends a (virtual) form with values.
// Unlike an AJAX Post/Get, this actually makes the browser send the form and process the response. Which means that
// the site is being changed (or a file will be downloaded)
// Example usage:
// $.submitForm('/my/resource', {'someFormParam': 'andItsValue'}, {'method': 'PUT'});
// Notes:
View servr.rb
require 'webrick'
include WEBrick
s =
:Port => 9951,
:DocumentRoot => File.expand_path(File.dirname(__FILE__))
"text" => "text/plain",
trap("INT") { s.stop }
apeiros / unreachable.rb
Created Jul 25, 2014
Mark code as unreachable
View unreachable.rb
class Unreachable < StandardError
module Kernel
module_function def unreachable(msg="This place in the code should never have been reached")
raise Unreachable, msg
apeiros / column_dsl.rb
Last active Aug 29, 2015
How to break up the method definition line, so the line is not too long?
View column_dsl.rb
module Jacob
class Model
class ColumnDsl
# [snip]
def integer(name, null: false, default: nil, size: nil, primary_key: false, auto_increment: false, unique: false)
# [snip]
# [snip]
apeiros / crypto.rb
Last active Aug 29, 2015
What's wrong in crypto - compare
View crypto.rb
### The stuff to encrypt
data = 'hello world!'
password = 'test123'
# Note: all 3 implementations are supposed to do exactly the same
### Raw OpenSSL
# Decisions, decisions, decisions...
cipher = 'AES-256-CBC' # which ciphers are not trivially broken?
View encryption.rb
require "openssl"
require 'digest/sha2'
require 'securerandom'
# Automatically upgradable encryption provider
module Encryption
class InvalidData < StandardError
class InvalidPattern < InvalidData
def initialize(version)
View gist:11266128
def that_method(parameter)
array_list = ['Thing', 'Another Thing']
array_list.include? parameter
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(:+)
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/u.encoding) # -> raises SyntaxError, "invalid multibyte escape: /\xff/"
You can’t perform that action at this time.