Skip to content

Instantly share code, notes, and snippets.

@martinos
martinos / Dockerfile
Last active December 20, 2015 11:29 — forked from shingara/Dockerfile
## Docker file of shingara/chruby container
FROM base
MAINTAINER Cyril Mougel "[email protected]"
RUN apt-get update
RUN apt-get install -q -y wget
RUN apt-get install -q -y ca-certificates
RUN apt-get install -q -y make
locale: fr
pic_square_url:
profile_url:
sex:
facebook_session_key:
new_contest_notifications: t
winner_notifications:
new_referral_notifications:
facebook_access_token:
account_id:
@martinos
martinos / .bashrc
Last active December 18, 2015 20:49
preexec
. ~/.preexec.bash
# called before each command and starts stopwatch
function preexec () {
export PREEXEC_CMD="$BASH_COMMAND"
export PREEXEC_TIME=$(date +'%s')
}
# called after each command, stops stopwatch
# and notifies if time elpsed exceeds threshold
def find_file_created_at(base_dir, time_range)
Dir["#{base_dir}/**/*"].select { |f| File.file?(f) && time_range.cover?(File.ctime(f)) }.map{|f| [File.ctime(f), f]}
end
time_range = Time.new(2011,5,5)..Time.new(2011,5,12)
files = find_file_created_at('.', time_range);1
require 'fileutils'
files.each do |time, file|
div {
//background-color: #3f0;
}
#one {
width:100px;
height: 100px;
background-color: #A2D4F3;
}
date_range = Time.new(2011,5,11)..Time.new(2011,5,12)
Dir['**/*'].select { |f| File.file?(f) && date_range.cover?(File.ctime(f)) }
@martinos
martinos / local_io.rb
Created January 28, 2013 22:56
For testing io stdin and stdout interaction.
module SpecHelper
def local_io(in_str)
old_stdin, old_stdout = $stdin, $stdout
$stdin = StringIO.new(in_str)
$stdout = StringIO.new
yield
$stdout.string
ensure
$stdin, $stdout = old_stdin, old_stdout
end
# This is a test for Gist.io
~~~ruby
def coco
puts 'coco'
end
~~~
@martinos
martinos / test_helper.rb
Created October 19, 2012 00:58
Helper for testing executable in gem.
require 'open3'
def ruby_run(cmd, stdin_str)
bundler_gem = '-r bundler/setup' if Gem.loaded_specs.keys.include?('bundler')
libs = '-I ./lib'
full_cmd = %{ruby #{libs} #{bundler_gem} ./bin/#{cmd}}
stdout_str, stderr_str = ['', '']
exit_code = 0
Open3.popen3(full_cmd) do |stdin, stdout, stderr, wait_thr|
stdin.write stdin_str
stdin.close
@martinos
martinos / rubyc.thor
Created May 18, 2011 17:03
ruby helper command for command line
module ::Enumerable
def count_by
self.inject({}) do |memo, elem|
key = yield elem
memo[key] ||= 0
memo[key] += 1
memo
end
end