Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
JoshCheek / screenshot.png
Last active August 29, 2015 14:01
Sierpinski Triangle generator (coloured on terminal), possible pattern for tile art.
screenshot.png
@JoshCheek
JoshCheek / cost_of_processing_credit_cards.rb
Created May 29, 2014 19:58
What it costs Turing to process student payments with Credit Cards vs ACH.
# 2.9% + $0.30 per transaction - https://stripe.com/us/pricing
def cost_to_process_credit_cards(payments)
charges = payments.map { |a| a * 0.029 } + payments.map { 0.3 }
charges.inject(0, :+).round(2)
end
# $0.25 per transaction - https://gist.github.com/amfeng/897dde5a36b91530b99e
def cost_to_process_ach(payments)
payments.map { 0.25 }.inject(0, :+).round(2)
end
@JoshCheek
JoshCheek / unicode_method_names.rb
Last active August 29, 2015 14:02
Having fun with unicode method names as a response to https://twitter.com/avdi/status/473614688975351809
# looks like github highlights non-ascii characters, but they look normal in n editor
send def really⁉
__method__ # => :really⁉
end
send def kill_it_with_fire‼‼
__method__ # => :kill_it_with_fire‼‼
end
@JoshCheek
JoshCheek / ux.md
Last active August 29, 2015 14:02
UX, people, it matters!

I went to brunch with a friend at 10:30am, took a car2go there, took an uber back b/c I had a few drinks. They called me at 7pm to tell me I hadn't ended my trip, and wouldn't b/c I had parked in the resturaunt's parking lot (I guess you're not allowed to do that). Walked 3 blocks in the cold rain to another car2go so I could get back there to end it, but the car was gone by the time I got there, so took another uber down to the car and drove it back. Paid attention this time: it gave me an "end trip" button, which I hit, it told me to put the key in the holder, I did, it sent my trip data to the server, and gave me a big splash screen saying "End Trip: turn off lights, apply parking break" I was like "wtf, that's what I did last time!" then, I noticed below all that, where I didn't notice it, it said I needed to flash my card against the reader outside the car again -.- $81 for that trip, plus the $10 uber, plus whatever they charge me to get back. Hopefully they'll realize that this is all a consequence of

@JoshCheek
JoshCheek / method-chaining-notes.rb
Created June 10, 2014 18:50
Notes for method chaining.
# Quick object model:
# classes = containers for methods
# objects = containers for instance variables
# You invoke the method on the object
# It looks it up in its class
# The method executes in the context of the object
# This gives it access to instance variables
# From the outside, you *CANNOT* access instance variables
# You can only invoke methods which have access to them
@JoshCheek
JoshCheek / whatev.js
Created June 10, 2014 20:31
Atom editor, get body of window and write it to a ruby process
var spawn = require('child_process').spawn;
var text = atom.workspace.activePaneItem.selectAll()[0].getText();
ar rb = spawn("ruby", ['-e', 'puts $stdin.read.encoding'], {"env": process.env});
rb.stdout.on("data", function(o) { console.log("STDOUT: "+o); });
rb.stderr.on("data", function(o) { console.log("STDERR: "+o); });
rb.stdin.write(text);
rb.stdin.end();
@JoshCheek
JoshCheek / wtf.rb
Created June 15, 2014 06:02
Kernel#system talks directly to stdout
require 'stringio'
File.open '/dev/null', 'w' do |black_hole|
$stdout = STDOUT = black_hole
puts 'Stdout goes into the black hole'
system 'echo but system still gets through... bug?'
end
@JoshCheek
JoshCheek / object_model.rb
Last active August 29, 2015 14:02
Object model results
# Classes are containers for methods
# Objects are containers for instance variables
# scopes are containers for local variables
# and execute in the context of an object
# When you call a method on an object
# it looks it up in the class
# if it doesn't find it there
# it continues looking it up in the chain of superclasses
# Module is a container for methods
# When you include it into a class
require 'minitest/autorun'
require 'minitest/pride'
class FormatPhoneNumber
class BadNumberError < StandardError
end
def initialize(raw_number)
@raw_number = raw_number
end
@JoshCheek
JoshCheek / rails_directory_structure.txt
Created June 25, 2014 14:24
Rails Directory Structure
Gemfile - Where you specify your dependencies
Gemfile.lock - Bundler resolved dependencies
your dependencies dependencies
and versions that match all the Gemfile's requirements
Readme - Text file about your project
Rakefile - Task runner
$ rake -T # see all tasks
$ rake db:create # run the db:create task
app/
assets/ - resources that get run through the asset pipeline