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 / blocks_and_lambdas.rb
Created January 14, 2013 01:33
using blocks and lambdas
def ampersandy(n)
yield n
end
ampersandy(10) do |x|
x + 10
end
# => 20
l = lambda { |x| x + 10 }
@jeffreyiacono
jeffreyiacono / lambda_vs_proc_return.rb
Created January 14, 2013 01:11
Proc vs lambda: when a return is used inside a proc, it does something called a non-local return — that is, instead of returning from the code executing inside the proc, it returns from its calling context.
def return_proc
p = Proc.new { return "Now you see me" }
p.call
return "Now you don't!"
end
return_proc
# => "Now you see me"
def return_lambda
@jeffreyiacono
jeffreyiacono / csv_DATA.rb
Created January 13, 2013 20:25
fun with ruby's DATA object
require "csv"
CSV.parse(DATA, headers: true).each do |row|
puts row["kURL"]
end
__END__
kId,kName,kURL
1,Google UK,http://google.co.uk
2,"Yahoo, UK",http://yahoo.co.uk
@jeffreyiacono
jeffreyiacono / complete_cases.R
Created January 9, 2013 08:31
remove NA from R data
no_nas <- complete.cases(something_with_nas)
@jeffreyiacono
jeffreyiacono / config_environment.rb
Created January 8, 2013 04:53
fix Rails vulnerability
# Disable the default XML params parser - its full of holes
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::XML)
@jeffreyiacono
jeffreyiacono / rand-R-stuff.md
Created December 19, 2012 02:48
some random R stuff

Some R Stuff

with => temporary attach table and xtabs => summarize data attach => ex. customer_payments$amount_cents

... same as ...

attach(customer_payments)

@jeffreyiacono
jeffreyiacono / date_stuff.js
Created December 14, 2012 22:04
javascript data stuff
var today = new Date();
console.log("today: " + today);
console.log("today.getTime(): " + today.getTime());
console.log("today.toISOString(): " + today.toISOString());
console.log("today.getTimezoneOffset(): " + today.getTimezoneOffset()); # returns in number of minutes
console.log("today.getTimezoneOffset() * 60 * 1000: " + today.getTimezoneOffset() * 60 * 1000) # num mins * 60 = sec * 1000 to play nice w/ #getTime()
today.setTime(today.getTime() - (today.getTimezoneOffset() * 60 * 1000));
console.log("today.toISOString(): " + today.toISOString());
@jeffreyiacono
jeffreyiacono / class_struct.rb
Created December 13, 2012 07:28
fun with Classes and Struct.new
class SomeClass < Struct.new(:first_name, :last_name)
def initialize(first_name, last_name)
super(first_name, last_name)
end
end
sc = SomeClass.new("jeff", "iacono")
# => #<struct SomeClass first_name="jeff", last_name="iacono">
sc['first_name']
@jeffreyiacono
jeffreyiacono / js-string-ext-trim.js
Created December 10, 2012 02:39
extend js String to implement basic trim methods
function strltrim() {
return this.replace(/^\s+/,'');
}
function strrtrim() {
return this.replace(/\s+$/,'');
}
function strtrim() {
return this.replace(/^\s+/,'').replace(/\s+$/,'');
@jeffreyiacono
jeffreyiacono / pinger-notifier.sh
Created November 30, 2012 08:40
simple script that uses pinger + sendmail to notify you of a pinger failure for a given set of urls
#!/bin/bash
# usage:
#
# ./pinger-notifier.sh url_1 [url_2 ...]
#
# this use https://github.com/jeffreyiacono/pinger and assumes
# it's setup via the command line (see: https://github.com/jeffreyiacono/pinger#usage)
set -e