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
def collect_files(pn) | |
if pn.file? | |
return pn | |
end | |
pn.children.collect {|cn| collect_files(cn)}.flatten | |
end | |
def collect_directories(pn) | |
if pn.directory? | |
pn.children.collect {|cn| collect_directories(cn)}.flatten.reject{|i| i.nil?}.push(pn) |
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
# you want to recursively copy the contents of one folder to another | |
# but you don't want to actually copy the first folder into the second | |
#3 ways to try to copy the contents of one directory to another: | |
require 'pathname' | |
require 'fileutils' | |
include FileUtils | |
p = Pathname.new('input') | |
o = Pathname.new('output') |
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
CGI.escapeElement( Ox.dump(@doc), "p", "div", "span", ... ) |
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
task :rmbak do | |
Dir["**/**~"].each do |f| ## "**/**" selects everything | |
puts "removing #{f}" ## works in ruby, but isn't recursive on command line | |
FileUtils.rm(f) | |
end | |
puts "rmbak: complete" | |
end |
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
def troff_stuff | |
Zlib::GzipReader.open(@file) do |troff| | |
troff.read | |
end | |
end | |
def exec_groff_less | |
IO.popen("groff -Wall -pt -mandoc -Tascii | less -J", 'w') do |io| | |
io.write troff_stuff | |
end |
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
require 'celluloid' | |
require 'pry' | |
module SuckerPunch | |
module Job | |
def self.included(base) | |
base.send(:include, ::Celluloid) | |
base.class_eval do |
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
objects = Hash.new {|h, c| h[c] = Array.new } | |
ObjectSpace.each_object do |o| | |
objects[o.class] << o | |
end | |
require 'pry'; binding.pry |
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
require 'rinda/tuplespace' | |
# Workers will be initialized a Rinda::TupleSpace | |
# (which we can use as a stand-in for Redis | |
class MapReduceWorker | |
def initialize(tuplespace) | |
@ts = tuplespace | |
@name = "MapReduceJob" | |
end |
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
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/bacon.js/0.7.10/bacon.js"></script> | |
</head> | |
<body> | |
<div>Running total: <span id="amount"></span></div> | |
<div id="ledger"> | |
<input type="text" id="entry"> | |
<button>Awesome!</button> |
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
def hash_for_binding(b) | |
vars = b.eval('local_variables') | |
vars.inject({}) { |memo, var| | |
memo[var] = b.eval(var.to_s) | |
memo | |
} | |
end |
OlderNewer