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 / forking_and_waiting.rb
Last active December 14, 2015 18:39
forking and waiting with Ruby
pids = []
[0, 1, 2].each do |i|
pids << fork do
sleep 5 - i
puts "Hi from #{i}\n"
end
end
puts "done forking" # note: if you >> this file to another file, you will need $stdout.flush to ensure proper write ordering
pids.each { |pid| Process.wait pid }
@jeffreyiacono
jeffreyiacono / git_mv_a_bunch_of_files.sh
Created March 6, 2013 05:47
git remove a bunch of files
for f in `ls ./*.png`; do git mv $f $(echo $f | sed s/control/ctrl/); done
@jeffreyiacono
jeffreyiacono / running_average_generator.rb
Created February 26, 2013 20:15
running average generator, written while reading about python generators @ http://excess.org/article/2013/02/itergen2
class RunningAverageGenerator
def initialize seed = []
@sum = seed.reduce(:+) || 0
@count = seed.count || 0
end
def << number
@count += 1
@sum += number
@sum / @count.to_f
@jeffreyiacono
jeffreyiacono / high_def.md
Created February 9, 2013 21:57
image + volcanos + colorBrewer

high def

view at https://raw.github.com/jeffreyiacono/images/master/R/high_def_volcano.png

@jeffreyiacono
jeffreyiacono / camo.md
Created February 9, 2013 21:43
random heat, camo, and rainbow via images + matrix + runif

Camo

view at https://raw.github.com/jeffreyiacono/images/master/R/random_camo.png

@jeffreyiacono
jeffreyiacono / color_ramp_palette_plots.R
Last active December 12, 2015 08:49
fun with R's colorRampPalette + plot
pal <- colorRampPalette(c("red", "blue"))
plot(rnorm(1000), seq(1, 1000, by = 1)
, col = pal(1000)
, xlab = "x"
, ylab = "y"
, main = "Fun with rnorm + colorRampPalette")
# => view Plot 1
@jeffreyiacono
jeffreyiacono / lattice_plots_with_medians_and_lm.R
Last active December 11, 2015 15:08
example of lattice plots with medians for x, y and linear regression lines for two grouped sets of data
library(lattice)
x <- rnorm(100)
y <- x + rnorm(100, sd = 0.5)
f <- gl(2, 50, labels = c("Group 1", "Group 2"))
xyplot(y ~ x | f,
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.lmline(x, y, col = 2)
@jeffreyiacono
jeffreyiacono / closures.R
Created January 17, 2013 07:18
closures
> make.power <- function(n) {
pow <- function(x) {
x ^ n
}
pow
}
> cube <- make.power(3)
> square <- make.power(2)
> cube(3)
[1] 27
@jeffreyiacono
jeffreyiacono / lexical.R
Created January 17, 2013 05:02
demonstration of R's lexical scoping
> y <- 10
> f <- function(x) {
y <- 2
y^2 + g(x)
}
> g <- function(x) {
x * y
}
> f(3)
[1] 34
@jeffreyiacono
jeffreyiacono / procs.rb
Created January 14, 2013 01:37
fun with #to_proc
:**.to_proc.call(2,5)
# => 32, which is 2^5
:+.to_proc.call(2,5)
# => 7, which is 2 + 5