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
| # :PROCESS: ruby, "ruby %f 2>&1" | |
| # :PROCESS: markdown, "rdiscount" | |
| # :PUBLISHER: blog, atompub | |
| # :PUBLISHER: source, gist | |
| # :BRACKET_CODE: "[ruby]", "[/ruby]" | |
| # :TEXT: | |
| # In parts 1 and 2 of this series, we look at some of Ruby's built-in ways to | |
| # start subprocesses. In this article we'll branch out a bit, and examine some | |
| # of the tools available to us in Ruby's Standard Library. In the process, |
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
| APPNAME = org.avdi.myapp | |
| VERSION = 1.0.0 | |
| DEVICE = tcp | |
| PACKAGEFILE = $(APPNAME)_$(VERSION)_all.ipk | |
| VMNAME = "Palm Emulator (1.2.0.33)" | |
| EMUPORT = 5522 | |
| M4 = m4 | |
| PACKAGE = palm-package | |
| INSTALL = palm-install | |
| INSTALLFLAGS = -d $(DEVICE) |
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 'tempfile' | |
| def browse_string(body) | |
| Tempfile.open('browse_string') do |f| | |
| browser = ENV.fetch('BROWSER') { 'firefox' } | |
| f.write(body) | |
| f.close | |
| puts "Starting browser #{browser} with response..." | |
| unless system(browser, f.path) | |
| warn "Error starting browser #{browser}" |
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
| ;; Hack up emacs-rails/flymake integration to make autotest happy | |
| ;; adapted from flymake.el | |
| (defun abg-flymake-create-temp-inplace-without-ext (file-name prefix) | |
| (unless (stringp file-name) | |
| (error "Invalid file-name")) | |
| (or prefix | |
| (setq prefix "flymake")) | |
| (let* ((temp-name (concat (file-name-sans-extension file-name) "." prefix))) | |
| (flymake-log 3 "create-temp-inplace: file=%s temp=%s" file-name temp-name) |
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 'right_aws' | |
| require 'progressbar' | |
| module Simpledb | |
| # Count the objects in a domain | |
| def sdb_count(domain, options={}) | |
| results = session.select("select count(*) from #{domain}") | |
| results[:items].first["Domain"]["Count"].first.to_i | |
| 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 'sinatra' | |
| require 'json' | |
| require 'addressable/uri' | |
| require File.expand_path('rack_stereoscope.rb', File.dirname(__FILE__)) | |
| configure do | |
| use Rack::Reloader; | |
| use Rack::Lint; | |
| use Rack::Stereoscope; | |
| 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 map_hash_to_hash(original, options={}) | |
| original.inject({}){|a, (key,value)| | |
| catch(:skip) do | |
| value = if (options[:deep] && Hash === value) | |
| map_hash_to_hash(value) {|k,v| yield(k, v) } | |
| else | |
| value | |
| end | |
| new_key, new_value = yield(key,value) | |
| a[new_key] = new_value |
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 transform_hash(original, options={}, &block) | |
| original.inject({}){|result, (key,value)| | |
| value = if (options[:deep] && Hash === value) | |
| transform_hash(value, options, &block) | |
| else | |
| value | |
| end | |
| block.call(result,key,value) | |
| result | |
| } |
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
| # Single-level flatten | |
| arr = [ [1], [2,3], [4, [5]] ] | |
| # Too flat! | |
| arr.flatten # => [1, 2, 3, 4, 5] | |
| # Just right! | |
| arr.inject([]){|a,e| a.concat(e)} # => [1, 2, 3, 4, [5]] |
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
| export EDITOR="/home/avdi/share/bin/emacs-newwindow" |