Skip to content

Instantly share code, notes, and snippets.

@madwork
madwork / install.sh
Last active August 29, 2015 14:00
Max OS X 10.9 + chruby + Ruby 2.1.1
brew install wget chruby openssl libyaml libxml2
# https://github.com/sstephenson/ruby-build/issues/550#issuecomment-40863879
cd /usr/local
git checkout 0181c8a Library/Formula/readline.rb
brew install readline
export ARCHFLAGS="-arch x86_64"
export CFLAGS="-g -O2"
export LDFLAGS="-L/usr/local/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/openssl/lib"
@madwork
madwork / utf8-sanitizer.rb
Last active August 29, 2015 14:02
Utf8 Sanitizer Middleware
# Utf8Sanitizer
# Rack/Ruby on Rails: ArgumentError: invalid byte sequence in UTF-8
# raise 400 error
# http://dev.mensfeld.pl/2014/03/rack-argument-error-invalid-byte-sequence-in-utf-8/
class Utf8Sanitizer
SANITIZE_ENV_KEYS = %w(
HTTP_REFERER
PATH_INFO
REQUEST_URI
REQUEST_PATH
@madwork
madwork / caesar_cipher.rb
Created April 17, 2015 17:40
Caesar Cipher Implementation in Ruby
# CaesarCipher
# Example:
# cipher = CaesarCipher.new "Ruby is a dynamic, open source programming language!"
# cipher.encrypt(13)
# => "ehol vf n qlanzvp, bcra fbhepr cebtenzzvat ynathntr!"
class CaesarCipher
attr_accessor :sentence
def initialize(sentence)
@sentence = sentence
@madwork
madwork / decode_session_cookie.rb
Last active October 22, 2020 18:13 — forked from profh/decode_session_cookie.rb
Rails 4.1+ Decode Session
@madwork
madwork / keybase.md
Created July 1, 2015 10:34
keybase prove github madwork

Keybase proof

I hereby claim:

  • I am madwork on github.
  • I am madwork (https://keybase.io/madwork) on keybase.
  • I have a public key whose fingerprint is E0C0 7490 6640 693C 8AEC BD3E 6BF4 9CEC 089D 7137

To claim this, I am signing this object:

@madwork
madwork / parse-cookie.coffee
Last active February 4, 2016 01:07
Node cookie parser for Rails 4.1 json encypted cookies
@madwork
madwork / app.html
Created September 9, 2015 09:20
Angular 1.3 Bind Once
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Bind Once</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.13/angular-sanitize.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.13/angular.min.js"></script>
</head>
<body ng-app>
<p><input type="text" ng-model="foo"></p>
@madwork
madwork / .pryrc
Created September 24, 2015 15:31
Pry confie file
require 'benchmark'
# sublime text as editor
Pry.config.editor = 'subl -w'
Pry.config.color = true
Pry.config.pager = true
# alias 'q' for 'exit'
Pry.config.commands.alias_command 'q', 'exit-all'
@madwork
madwork / association_ids.rb
Last active March 10, 2017 11:27
Self executable gist
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
#gem 'rails', github: 'rails/rails'
gem 'rails', github: 'rails/rails', branch: '4-2-stable'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
@madwork
madwork / stripe-1.58.0_test.rb
Created March 14, 2017 15:51
Self executable gist for StripeObject marshalling issue
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'stripe', '1.58.0'
gem 'minitest'
GEMFILE
system 'bundle'
end