Skip to content

Instantly share code, notes, and snippets.

View cantino's full-sized avatar
💭
1AU

Andrew Cantino cantino

💭
1AU
View GitHub Profile
@cantino
cantino / base64-md5-test.rb
Created February 28, 2019 23:41
Four ways to compute the base64 md5 checksum used by ActiveStorage
require 'digest'
# From activestorage
def compute_checksum_in_chunks(io)
Digest::MD5.new.tap do |checksum|
while chunk = io.read(5242880)
checksum << chunk
end
io.rewind
end.base64digest
@cantino
cantino / Vagrantfile
Created August 23, 2016 15:38
Basic Ruby Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.provision "shell", privileged: false, inline: <<-SHELL
@cantino
cantino / example_my_obfuscate_configuration.rb
Created October 15, 2015 00:25
Example my_obfuscate configuration file that validates against the Rails schema.rb
#!/usr/bin/env ruby
require "rubygems"
require "my_obfuscate"
obfuscator = MyObfuscate.new({
:people => {
:email => { :type => :email, :skip_regexes => [/^[\w\.\_]+@my_company\.com$/i] },
:ethnicity => :keep,
:crypted_password => { :type => :fixed, :string => "SOME_FIXED_PASSWORD_FOR_EASE_OF_DEBUGGING" },
:salt => { :type => :fixed, :string => "SOME_THING" },
@cantino
cantino / object_comparison_helper.rb
Created September 21, 2015 21:23
Recursive Ruby data structure diff
module ObjectComparisonHelper
def deep_hash_diff(obj1, obj2, path = 'root', differences = [])
if obj1.class != obj2.class
differences << "object types differ at #{path}: #{obj1.class} vs #{obj2.class}"
else
case obj1
when Hash, HashWithIndifferentAccess
differences << "key sets differ at #{path}: #{obj1.keys.inspect} vs #{obj2.keys.inspect}" if obj1.keys.to_set != obj2.keys.to_set
obj1.each do |key, value|
deep_hash_diff(value, obj2[key], "#{path}.#{key}", differences)
@cantino
cantino / README.md
Last active August 29, 2015 14:27
Ruby each_codepoint hangs on IO stream
We can make this file beautiful and searchable if this error is corrected: It looks like row 3 should actually have 1 column, instead of 2 in line 2.
San Francisco 4821
London 1409
Seattle, WA 1083
New York, NY 2056
Portland, OR 949
Chicago, IL 930
Tokyo, Japan 1518
London, UK 894
japan 880
Germany 856
@cantino
cantino / output.md
Last active August 29, 2015 14:16
A breadth-first Tower of Hanoi solver in Go

Example Output

Lower numbers in the towers represent larger disks, so higher integers must always be to the right of smaller ones.

World:
0 [1]
1 [2]
2 [3 4 5 6]
---------------
@cantino
cantino / example_output.txt
Last active June 16, 2018 18:28
Use google-api-ruby-client with the Google Contacts API
2.1.2 :004 > pp Google::Contacts.new(client).contacts
[{:emails=>{:other=>{:address=>"fake@gmail.com", :primary=>true}},
:phone_numbers=>
{:main=>"(555) 123-1234", :home=>"123-123-1234", :mobile=>"555-555-5555"},
:handles=>
{:home=>{:address=>"something", :protocol=>"AIM"},
:other=>{:address=>"something-else", :protocol=>"AIM"}},
:nickname=>nil,
:websites=>[],
@cantino
cantino / runthis
Last active December 23, 2015 00:59
Run this in a JavaScript console.
[][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]][([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]]]]+([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]]]+([][[]]+[])[+[[+!+[]]]]+(![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[+!+[]]]]+([][[]]+[])[+[[+[]]]]+([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[
@cantino
cantino / gradient.go
Last active December 18, 2015 09:39
Some practice Go programs.
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
pic := make([][]uint8, dx)
for i := range(pic) {
pic[i] = make([]uint8, dy)
for j := range(pic[i]) {
pic[i][j] = uint8((i + j)/2)