Skip to content

Instantly share code, notes, and snippets.

View jeffreyiacono's full-sized avatar

Jeff Iacono jeffreyiacono

  • Eight Sleep
  • San Francisco
  • X @jfi
View GitHub Profile
@jeffreyiacono
jeffreyiacono / fit-model-that-combines-predictors.R
Last active August 29, 2015 14:04
PML: combining predictors
library(ISLR)
library(ggplot2)
library(caret)
data(Wage)
# remove logwag as predicting wage, so this would be a pretty good predictor :)
Wage <- subset(Wage, select = -c(logwage))
# cross-validation data
@jeffreyiacono
jeffreyiacono / galton_child_parent_height.R
Last active August 29, 2015 14:05
Galton Child vs Parent height freq-sized scattersplot
library(UsingR)
library(ggplot2)
library(reshape)
data(galton)
freqData <- as.data.frame(table(galton$child, galton$parent))
names(freqData) <- c("child", "parent", "freq")
freqData$child <- as.numeric(as.character(freqData$child))
freqData$parent <- as.numeric(as.character(freqData$parent))
@jeffreyiacono
jeffreyiacono / blocks.rb
Created November 5, 2014 05:47
fun with ruby blocks
def something a, b, &block
sum = a + b
another_private_thing = "only something can see this"
puts "I'm in something, executing code."
puts "I added #{a} + #{b} and got #{sum}"
puts "and I can access my local vars: another_private_thing = #{another_private_thing}"
yield sum, another_private_thing
@jeffreyiacono
jeffreyiacono / 01-plots-with-manual-color-scale.R
Last active August 29, 2015 14:15
R plots with manual color scale
d <- rnorm(1000)
df <- data.frame(x = seq(1, length(d), by = 1), y = d)
df$zscore <- (df$y - mean(df$y, na.rm = TRUE)) / sd(df$y, na.rm = TRUE)
ggplot(df, aes(x = x, y = y, group = abs(zscore) >= 1.95)) + geom_point(aes(color = abs(zscore) >= 1.95))
ggplot(df, aes(x = x, y = y, group = abs(zscore) >= 1.95)) + geom_point(aes(color = abs(zscore) >= 1.95)) + scale_color_manual(values = c("FALSE" = "grey", "TRUE" = "red"))
@jeffreyiacono
jeffreyiacono / keybase.md
Created May 29, 2015 10:30
keybase verification

Keybase proof

I hereby claim:

  • I am jeffreyiacono on github.
  • I am jfi (https://keybase.io/jfi) on keybase.
  • I have a public key whose fingerprint is 9313 2A1C 7607 9701 D3EF B96F 28F3 F2D8 4DE7 2229

To claim this, I am signing this object:

@jeffreyiacono
jeffreyiacono / hoppity.rb
Created November 12, 2009 21:39
fb careers challenge puzzle: hoppity
#!/usr/bin/ruby
# get file name arg from command line
File.open(ARGV[0], 'r') do | f |
# read the first line containing the integer
(1..f.readline.strip.to_i).each do | i |
# div by 3?
if ( i % 3 ) == 0 then
# and by 5?
if ( i % 5 ) == 0 then
#! /usr/bin/ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
DIRECTORY_QUERY_URL_FOR = "https://web.middlebury.edu/database/directory/?cn="
"A".upto("Z") do |letter|
url = "#{DIRECTORY_QUERY_URL_FOR}#{letter}"
@jeffreyiacono
jeffreyiacono / widgets.js
Created January 29, 2011 20:25
javascript for widget deletion
$.ajax({
url: this.href,
type: 'POST',
dataType: 'script',
data: {_method: 'delete'},
beforeSend: function() { console.log("in before send ...") },
complete: function() { console.log("in complete ...") }
});
@jeffreyiacono
jeffreyiacono / widgets_controller.rb
Created January 29, 2011 20:20
widgets controller
class WidgetsController < ApplicationController
def destroy
@widget = Widget.find(params[:id])
respond_to do |format|
if @widget.delete
format.html { flash[:notice] = "Item Removed"; redirect_to widgets_path }
# change format.json to format.js and it works properly
format.js { render :status => :ok }
else
format.html { flash[:alert] = "Something went terribly wrong"; redirect_to widgets_path }
@jeffreyiacono
jeffreyiacono / select_timestamp.rb
Created July 15, 2011 04:13
UI T/F select which sets a objects timestamp
# Given that I have a model Item that inherits from ActiveRecord::Base and it has an attribute #locked_at,
# I want to be able to select T/F from a select in UI to set #locked_at's timestamp
# === VIEW ===
# app/views/items/edit.html.haml, using formtastic
# Attempt #1:
# I could set locked_at => Time.now by setting it in the select's collection,
# but revisiting this form will not show the properly selected option, unless you do :selected => Time.now,
# which seems kludgy. Worse, if unlocked (locked_at => nil), this select option will not be