This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for f in `ls ./*.png`; do git mv $f $(echo $f | sed s/control/ctrl/); done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RunningAverageGenerator | |
def initialize seed = [] | |
@sum = seed.reduce(:+) || 0 | |
@count = seed.count || 0 | |
end | |
def << number | |
@count += 1 | |
@sum += number | |
@sum / @count.to_f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> make.power <- function(n) { | |
pow <- function(x) { | |
x ^ n | |
} | |
pow | |
} | |
> cube <- make.power(3) | |
> square <- make.power(2) | |
> cube(3) | |
[1] 27 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> y <- 10 | |
> f <- function(x) { | |
y <- 2 | |
y^2 + g(x) | |
} | |
> g <- function(x) { | |
x * y | |
} | |
> f(3) | |
[1] 34 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:**.to_proc.call(2,5) | |
# => 32, which is 2^5 | |
:+.to_proc.call(2,5) | |
# => 7, which is 2 + 5 |