Skip to content

Instantly share code, notes, and snippets.

@aharpole
aharpole / badfizzbuzz.js
Created January 30, 2016 01:14
Remarkably wrong FizzBuzz
function counter(){
for (i=0; i<100; i++) {
var countThree=i/3;
var countSeven=i/7;
if (countThree.indexOf(“.”)==null){
document.write(i + “fizz”);
} else {
if (countSeven.indexOf(“.”)==null){
document.write(i + “buzz”);
} else {
@aharpole
aharpole / .powrc
Last active March 12, 2024 23:11 — forked from 8bitDesigner/.powrc
Everything you need to use RVM sanely. Check out the instructions in the rvm-setup file to get started.
if [ -f ".rvmrc" ]; then
source ".rvmrc"
fi
@aharpole
aharpole / script.js
Created March 27, 2015 21:03
a Greasemonkey script for Tower users to Open in Tower using SSH instead of HTTPS
// ==UserScript==
// @name GitHub open in desktop ssh
// @namespace 1427488342954
// @version 0.1
// @updateURL
// @downloadURL
// @include https://github.com/*
// ==/UserScript==
$(document).ready(function() {
@aharpole
aharpole / sm_candidates.txt
Created October 31, 2014 03:41
I had my Fancy Hands assistant research Santa Monica's city council candidates on their stances on the Time Warner/Comcast merger
Kevin Mckeown response which was the longest was, "...corporate mergers and buyouts are not under the
jurisdiction of municipalities. Some years ago the State of California even took away our ability to negotiate with internet/cable/phone providers over franchises...I helped write the long-term plan that put fiber into every utility trench dug in Santa Monica for the past almost 20 years. As a result, Santa Monica is uniquely positioned to provide 100-Gigabit internet through a fiber network we control locally, which means no throttling and absolute net neutrality...The next phase of the plan is to bring this municipally-provided extreme-bandwidth fiber internet to individual residential households. Over the years I’ve been on Council, we’ve twice tried to establish city-wide wifi...I realize I’ve gone a bit beyond the initial question about corporate
internet providers. I hope to make them far less relevant for Santa Monicans, as they do not serve us well and show no sign of getting better." This is a shor
@aharpole
aharpole / 93325f68.rb
Created September 5, 2014 05:53
before/after a massive controller refactoring
def update
p "Update is being called for out_of_money for #{params[:opportunity]}" if !params[:out_of_money].blank?
@opportunity = Opportunity.find(params[:id])
@opportunity.talking_points_boilerplate = params[:talking_points_boilerplate] if params[:talking_points_boilerplate]
@opportunity.description_link_boilerplate = params[:description_link_boilerplate] if params[:description_link_boilerplate]
@opportunity.annotation_boilerplate = params[:annotation_boilerplate] if params[:annotation_boilerplate]
demographics_to_save = []
params.fetch(:demographics,{}).each do |d|
demographics_to_save << d[1]
end
@aharpole
aharpole / ntsb_software.md
Created September 1, 2014 20:55
Why software doesn't have the equivalent of NTSB crash ratings

from Matt Drance:

Struggling to explain to a friend why there’s no software equivalent to NTSB crash ratings. “It’s complicated” is honest, but not acceptable

The explanation is pretty straightforward. Cars are pretty uniform. They have changed a lot, but fundamentally, they are used the same as they have been for over a century, they fail in very consistent ways, and we've thus been able to make some good well-defined tests to determine how safe a car is in the event of a crash.

Software isn't like that. Web applications may have started to follow some consistent structure, and we have some patterns we follow pretty commonly (like talking over HTTP), but the fact remains that the apps and services are super un-uniform.

That poses a real difficulty if you want to develop some standardized tests. It would be pretty easy to develop some standardized tests for an app that only spoke HTTP and used a RESTful protocol to talk to one specific web browser u

@aharpole
aharpole / Gemfile
Created August 18, 2014 20:41
Pinger - a simple tool that you can run on Heroku that will ping a bunch of sites on your behalf
source 'http://rubygems.org'
gem "httparty"
@aharpole
aharpole / rescue_nil.rb
Created May 30, 2014 02:24
safe use of rescue nil
def chunky_peanut_butter
EndlessChunkyPBSupplier.grab(:chunky_pb)
end
def smooth_peanut_butter
Cabinet.fetch(:smooth_peanut_butter) rescue nil
end
def make_pb_and_j
pb = smooth_peanut_butter || chunky_peanut_butter
@aharpole
aharpole / csv.rb
Created April 28, 2014 23:00
headers method in CSV.rb in ruby/ruby trunk
#
# Returns the headers for the first row of this table (assumed to match all
# other rows). An empty Array is returned for empty tables.
#
def headers
if @table.empty?
Array.new
else
@table.first.headers
end