Skip to content

Instantly share code, notes, and snippets.

View kdonovan's full-sized avatar

Kali Donovan kdonovan

View GitHub Profile
@kdonovan
kdonovan / assessment.md
Last active November 7, 2016 23:19
Bloc.io candidate assessment

Full Stack Mentor - Candidate Assessment

Javascript

Hi Mentee,

The for loop looks good - it starts with btnNum set to zero and increases it by one each time through, then stops looping when btnNum is 3. The tricky part here is when the different parts of code are executed. Each time through the loop the document.getElementById('btn-' + btnNum).onclick = runs immediately with the current value of btnNum, so it finds the correct button and attaches the function to be executed when the button is clicked. However, the function it attaches is not executed until the button is clicked.

It's kinda like telling the computer "use this bag of code when the button is clicked", and the computer saying "OK, I've got the bag but I'm not going to even look inside it until I know I have to use it". When the button IS clicked, THEN the computer will try to run the code, and at that point the variables it's referencing may have different values than they did when the bag was put together.

#!/usr/bin/env ruby
# Based on comments on https://gist.github.com/Simbul/1781656
# This pre-commit hook will prevent any commit to forbidden branches
# (by default, "staging" and "master").
# Put this file in your local repo, in the .git/hooks folder
# and make sure it is executable.
# The name of the file *must* be "pre-commit" for Git to pick it up.
@kdonovan
kdonovan / some_model.rb
Created September 26, 2011 11:07
Example using precision from geokit gem to ensure geocoding is sane
class SomeModel < ActiveRecord::Base
validate :geocode_address
def address
[street_address, city, state, zip].select{|a| !a.blank?}.join(', ')
end
# ...
@kdonovan
kdonovan / apn_sender
Created June 17, 2011 01:04
Contents of the file apn_sender's generator puts in script/apn_sender (for those on Rails 3, where the generator isn't working yet)
#!/usr/bin/env ruby
# Daemons sets pwd to /, so we have to explicitly set RAILS_ROOT
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
require 'rubygems'
require 'apn'
require 'apn/sender_daemon'
APN::SenderDaemon.new(ARGV).daemonize
@kdonovan
kdonovan / Jammit pre-commit hook
Created November 2, 2010 22:45
Git pre-commit hook to automatically run Jammit when assets are committed and add the processed files to the commit as well.
#!/usr/bin/env ruby
# This pre-commit hook automatically processes changed assets with Jammit
# and adds the changed files to the commit.
RAILS_ROOT = File.expand_path('.')
ASSET_DIR = File.join(RAILS_ROOT, 'public', 'assets')
status_lines = `git diff-index --cached HEAD`
files_committing = status_lines.map{|l| l.split(/\t/).last.strip }