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 / gist:1114452
Created July 29, 2011 18:41 — forked from dhh/gist:1014971
Use concerns to keep your models manageable (fix unscoped issue w/ trashed scope)
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@jeffreyiacono
jeffreyiacono / mongoid_counter_cache.rb
Created February 4, 2012 22:52
counter cache extension for mongoid orm
module Mongoid
module CounterCache
extend ActiveSupport::Concern
module ClassMethods
# Use Case:
#
# keep a cached count of embedded collections in the parent collection(s)
#
# for example, if a Post embeds many Comments, and there have been 2
@jeffreyiacono
jeffreyiacono / Rakefile
Created February 8, 2012 20:15
rake task for precompiling assets using sprockets within a sinatra app + view helpers
require 'rubygems'
require 'bundler'
Bundler.require
require './application'
namespace :assets do
desc 'compile assets'
task :compile => [:compile_js, :compile_css] do
end
@jeffreyiacono
jeffreyiacono / lolrus.js
Created March 18, 2012 04:53
simple normalization of jquery event so offsetX / offsetY can be used cross browsers
/**
* normalizeEvent
*
* Firefox does not implement offsetX, OffsetY, so we have to detect for this an
* manually calculate it ourselves using the pageX, pageY less the event
* target's left offset and right offset
*
* If using a browser that supports offsetX, OffsetY, just return the event,
* don't need to do anything
*/
@jeffreyiacono
jeffreyiacono / 00-start-end-higher-lower.R
Last active July 18, 2016 03:10
Color-coded Start / End Plotting with R
library(ggplot2)
library(reshape2)
df <- data.frame(grp = 1:25, start = rnorm(25, 10, 5), end = rnorm(25, 5, 3))
df$end_higher <- df$start < df$end
mdf <- melt(df, id.vars = c("grp", "end_higher"))
names(mdf) <- c("grp", "end_higher", "category", "value")
mdf$grp <- factor(mdf$grp)
@jeffreyiacono
jeffreyiacono / 00-start-end.R
Last active July 18, 2016 03:04
Start / End Plotting with R
library(ggplot2)
library(reshape2)
# data setup
df <- data.frame(grp = 1:25, start = rnorm(25, 100, 10), end = rnorm(25, 10, 5))
# ** plotting using base plot functions
par(mfrow = c(1, 1))
rng <- range(df$start, df$end)
@jeffreyiacono
jeffreyiacono / 0_reuse_code.js
Created May 18, 2016 16:58
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jeffreyiacono
jeffreyiacono / 00-plot-percentiles-by-boundaries.R
Last active January 21, 2016 01:08
Plot percentiles by boundaries
options(repos = c(CRAN = "http://cran.rstudio.com"))
install.packages("ggplot2")
install.packages("dplyr")
require(ggplot2)
require(dplyr)
points <- 10000
buckets <- 20
@jeffreyiacono
jeffreyiacono / sigmoid.m
Created November 25, 2013 06:22
sigmoid in octave
x = -10:0.1:10;
plot(x, 1 ./ (1 + e .^ -x))
@jeffreyiacono
jeffreyiacono / remove_merged_branches.rb
Created August 19, 2013 03:29
remove all the merged branches
for b in `git branch --merged | grep -v \*`; do git branch -D $b; done