Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
script = <<-BASH
if [ ! -n "${foobar+x}" ]; then \
echo "foobar is unset"; \
elif [[ ${!foobar[@]} ]]; then \
if [[ $foobar ]]; then \
echo "foobar is set"; \
else \
echo "foobar is set, but empty"; \
@cypher
cypher / canine.rb
Created December 16, 2009 10:33 — forked from h0rs3r4dish/canine.rb
class Canine
VERSION = '1.3'
def initialize(&block)
@commands = Hash.new
@default = @latest = :commands
@empty = nil
@auto = {
:commands => hash_command("commands","Show a list of commands",Proc.new {
@commands.each { |cmd| c = cmd[1]
name = c[:name].to_s
require 'test/unit'
require 'shoulda'
class HelpersTest < Test::Unit::TestCase
# ServerHelpers is the module that has all the sinatra helpers
include ServerHelpers
context "a helper" do
should "return a number" do
assert_equal 42, my_helper_method
This is basically a dirty hack :) I have no idea if messing with the default OSX apache config this way is frowned upon. My view is that it works now, and if it breaks I'll fix it.
Add any domains you want to blacklist to /etc/hosts, pointing at 127.0.0.1. You need to enable web sharing to get apache running of course.
Changes to the default /etc/apache2/httpd.conf
==============================================
Listen 127.0.0.1:80 # so that the world can't see the list
DocumentRoot "/Library/WebServer/Documents/public" # to fit in with passenger, you need to create the public dir (and maybe /tmp too)
# lexically sort filenames
--sort-files
# Pipe the output through a pager by default
# --pager=less
# Highlight the matching text
--color
# Print 1 line of output context
require 'clojure'
class MyClojureObj < Clojure::Object
def initialize
dosync { @foo = 'foo' }
end
def foo; @foo; end
def foo=(f); @foo = f; end
end
# Runs the given array of +commands+ in parallel. The amount of spawned
# simultaneous jobs is determined by the `j' env variable and defaults to 1.
def parallel_execute(commands)
@jobs ||= ENV['j'] ? ENV['j'].to_i : 1
queue = Queue.new
queue = commands.each { |command| queue << command }
Array.new(@jobs) do
Thread.new do
while command = queue.shift
class Proc
# "join" two procs
def +(other)
Proc.new { self.call; other.call }
end
end
# Java Classpath
if [[ -d "${HOME}/classes/" ]]
then
for jar in ${HOME}/classes/*.jar
do
CLASSPATH="${jar}:${CLASSPATH}"
done
fi
@cypher
cypher / config.ru
Created February 17, 2010 09:50
Sample sinatra app that uses lenary's partial helper (http://gist.github.com/119874). Tested using Sinatra 0.9.4
require 'sinatra/base'
require 'my_app'
run MyApp