Skip to content

Instantly share code, notes, and snippets.

View jonmagic's full-sized avatar

Jonathan Hoyt jonmagic

View GitHub Profile
@jonmagic
jonmagic / seconds.csv
Last active December 8, 2015 10:38
This is binary data captured from a car stereo and it's companion cd changer. The stereo updates it's screen with the cd track minutes and "seconds". Each row below corresponds to the "seconds". Column 1 is the seconds, 2 is binary, 3 is 2 inverted. The goal is figuring out how to generate the seconds from 0's & 1's without the table below.
seconds message inverted-message
4 110 001
5 00101 11010
6 10100 01011
7 01100 10011
8 11101 00010
9 00011 11100
10 10010 01101
11 0000101 1111010
12 1000100 0111011
alias st='osascript /path/to/theme-switcher.scpt'
module Addon
def self.included(base)
base.class_eval do
before_save :update_addon
end
end
def update_addon
puts "updating addon"
end
@jonmagic
jonmagic / results.txt
Last active August 29, 2015 14:21
I've got two arrays with identical elements in different orders that I need to compare and the order doesn't matter. Should I use sort or array subtraction?
Rehearsal --------------------------------------------
sort 1.140000 0.010000 1.150000 ( 1.166011)
subtract 0.610000 0.030000 0.640000 ( 0.672543)
----------------------------------- total: 1.790000sec
user system total real
sort 1.240000 0.010000 1.250000 ( 1.254706)
subtract 0.620000 0.030000 0.650000 ( 0.672024)
@jonmagic
jonmagic / callback-block.rb
Last active August 29, 2015 14:16
Callbacks in Ruby
irb(main):001:0> class Foo
irb(main):002:1> def set_callback(&block)
irb(main):003:2> @callback = block
irb(main):004:2> end
irb(main):005:1>
irb(main):006:1* def run
irb(main):007:2> 10.times do |n|
irb(main):008:3* @callback.call(n) if @callback
irb(main):009:3> end
irb(main):010:2>
require "benchmark"
class Foo
def initialize(bar)
@bar = bar
end
attr_reader :bar
def do_case
samples = Dir.glob("/Users/jonmagic/Desktop/samples/*.wav")
load_samples samples
define :cry do
sample samples.choose
sleep 1.6
end
define :beat do
sample :loop_compus, attack: 0.01, sustain: 1, release: 0.5
@jonmagic
jonmagic / gist:10012852
Last active August 29, 2015 13:58
How to sign out of Gmail.
1. Click on the little picture or icon in the upper right and click "Sign out”.
2. Then on the next screen click "Sign in with a different account”.
3. Click “Remove”
4. Click the X next to the account you want to sign out of.
5. Click “Done”
6. Congratulations now you are signed out.

Keybase proof

I hereby claim:

  • I am jonmagic on github.
  • I am jonmagic (https://keybase.io/jonmagic) on keybase.
  • I have a public key whose fingerprint is 803A EE9B 6F2C DC04 7FCF B59C A6BE 6D15 DF67 5762

To claim this, I am signing this object:

@jonmagic
jonmagic / email.rb
Last active December 20, 2022 17:17
A handy Rails model for storing emails with a little logic to let a User have multiple email addresses but a single primary address.
class Email < ActiveRecord::Base
# Nope, it's not RFC compliant. F*** that regex.
# http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html
EmailRegex = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i.freeze
before_validation :strip_spaces
# Public: The email address.
# column :address