Skip to content

Instantly share code, notes, and snippets.

View andyl's full-sized avatar
🎯
Focusing

andyl

🎯
Focusing
View GitHub Profile
gem 'json'
only :app do
gem 'sinatra'
source 'http://gems.github.com'
gem 'famoseagle-carrot', :require_as => 'carrot'
end
only :daemon do
gem 'eventmachine'
require File.expand_path(File.dirname(__FILE__) + '/vendor/gems/environment')
#require 'sinatra'
Bundler.require_env(:app)
get '/' do
'Hello world!'
end
----- Gemfile -----
gem 'sinatra'
----- app.rb ------
require 'vendor/gems/environment'
Bundler.require_env
get '/' do
"hello world"
end
----- Gemfile -----
gem 'sinatra'
----- app.rb ------
require 'vendor/gems/environment'
Bundler.require_env
get '/' do
"hello world"
end
@andyl
andyl / set_routes.thor
Created December 15, 2010 17:54
set_routes script
class Vhost < Thor
include Thor::Actions
no_tasks do
def initialize(*args)
@vhost_dir = File.expand_path "~/.vhost"
@app_dir = File.expand_path "~/lcl/nconf"
@adblock_file = File.expand_path "~/util/bin/templates/adblock.txt"
super args
end
@andyl
andyl / gist:818611
Created February 9, 2011 15:08
Example Spec: Using Constants and Sinatra Extensions
require 'spec_helper'
=begin
Example One - this works
In this example, the constant (ZZZ) is set in the
Spec, and detected in the target code.
=end
module TestModule
class TestClass
@andyl
andyl / gist:818821
Created February 9, 2011 17:06
Rspec / SinatraExtension: Solution Suggested by namelessjon
require 'spec_helper'
=begin
Example One - this is working
In this example, the constant (ZZZ) is set in the
Spec, and detected in the target code.
=end
module TestModule
class TestClass
@andyl
andyl / ctags_vim_paths_gemfile.rb
Created February 18, 2011 19:08
Generates Ctags and Vim Paths from Gemfile.lock
#!/usr/bin/ruby
require 'rubygems'
require 'bundler'
=begin
This script was written to incorporate Bundler and Gemfile.lock into
Vim's tag and file-finding tools.
=end
# This code generates ctags. If a Gemfile.lock is found
@andyl
andyl / parslet.rb
Created March 7, 2011 04:44
parslet line parsing
#!/usr/bin/env ruby
require 'rubygems'
require 'parslet'
class LineParser < Parslet::Parser
rule(:eol) { match['\n\r'] }
rule(:eol?) { eol.maybe }
rule(:line) { (any.repeat).as(:line) }
rule(:line_eol) { line >> eol? }
@andyl
andyl / simple_parse.rb
Created March 7, 2011 05:17
simple parsing test
#!/usr/bin/env ruby
require 'rubygems'; require 'parslet'
class Xp < Parslet::Parser
rule(:b) { str("\n").absnt? }
root(:b)
end
# this generates an error - I think it should just return "a"...