Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
1AU

Andrew Cantino cantino

💭
1AU
View GitHub Profile
@cantino
cantino / base64-md5-test.rb
Created Feb 28, 2019
Four ways to compute the base64 md5 checksum used by ActiveStorage
View base64-md5-test.rb
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 Aug 23, 2016
Basic Ruby Vagrantfile
View 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 Oct 15, 2015
Example my_obfuscate configuration file that validates against the Rails schema.rb
View example_my_obfuscate_configuration.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 Sep 21, 2015
Recursive Ruby data structure diff
View object_comparison_helper.rb
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 Aug 29, 2015
Ruby each_codepoint hangs on IO stream
View README.md
View rubyists.csv
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 Aug 29, 2015
A breadth-first Tower of Hanoi solver in Go
View output.md

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 Jun 16, 2018
Use google-api-ruby-client with the Google Contacts API
View example_output.txt
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 Dec 23, 2015
Run this in a JavaScript console.
View runthis
[][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]][([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]]]]+([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]]]+([][[]]+[])[+[[+!+[]]]]+(![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[+!+[]]]]+([][[]]+[])[+[[+[]]]]+([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[
@cantino
cantino / gradient.go
Last active Dec 18, 2015
Some practice Go programs.
View gradient.go
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)