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 / 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 / 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 / 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 / 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 / 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)
@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" },
class Utilities
@findPos: (obj) ->
obj = obj.get(0) if obj.html?
curLeft = curTop = 0
if obj.offsetParent
loop
curLeft += obj.offsetLeft
curTop += obj.offsetTop
break unless obj = obj.offsetParent
{ x: curLeft, y: curTop }
@cantino
cantino / CoffeeScript.xml
Created March 8, 2010 02:09
Partial CoffeeScript highlighting support for RubyMine
<?xml version="1.0" encoding="UTF-8"?>
<filetype binary="false" default_extension="" description="CoffeeScript" name="CoffeeScript">
<highlighting>
<options>
<option name="LINE_COMMENT" value="#" />
<option name="COMMENT_START" value="`" />
<option name="COMMENT_END" value="`" />
<option name="HEX_PREFIX" value="" />
<option name="NUM_POSTFIXES" value="" />
<option name="HAS_BRACKETS" value="true" />
@cantino
cantino / coffee_interactive.sh
Created March 7, 2010 23:16
Adding readline support to coffeescript
#!/bin/sh
if [ ! `which rlwrap` ]; then
echo "Please sudo port install rlwrap"
exit
fi
rlwrap coffee -i