Skip to content

Instantly share code, notes, and snippets.

Avatar

Benjamin Fleischer bf4

View GitHub Profile
View tinyurl.rb
#!/usr/bin/env ruby
#
# A complete URL-shortening web application, written in Ruby/Sinatra. Run it
# from the command line, and then visit http://localhost:4567/
#
# Or to run it under apache/passenger, you'll need a config.ru file with the
# following contents:
#
# require 'tinyurl'
# run Sinatra::Application
View content_post.rb
post_data = {}
post_data[:name] = 'Title for my link'
post_data[:link] = 'http://path.to/my/link'
post_data[:caption] = 'A caption'
post_data[:description] = 'A description'
post_data[:picture] = 'http://path.to/myimage.jpg'
post_data[:actions] = { :name => 'My site name', :link => 'http://link.to/my/site'}.to_json
client.post("feed", nil, post_data)
@bf4
bf4 / config
Created Feb 10, 2011 — forked from bruno/campfire_export.rb
campfire transcript export
View config
---
BUNDLE_WITHOUT: ""
View string_to_date.rb
# method to evaluate the block for a default value if the
# conversion to date fails
# string.to_date return nil if the string is blank
# so we yield to get the default value from the block there
# or on a parse error
def string_to_date(string,&block)
string.to_date || yield
rescue => e
block_given? ? yield : raise
end
View build.sh
#!/usr/bin/env bash
export PATH="$PATH:/usr/texbin/"
which pandoc &>/dev/null
if [ $? -eq 0 ]
then
if [ ! -n "$1" ]
then
echo 'defaulting to pdf'
file_name='scalingphp.pdf'
else
View Rakefile
gem 'rake', '=0.8.7'
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
#TODO don't shell out quite as much
namespace :bootstrap do
task :dev => ['bootstrap:copy_configs', 'bootstrap:bundle_gems', 'bootstrap:database'] do
run_cmd "bundle exec rake db:test:prepare"
end
View contemplative.rb
require 'action_view'
require 'ostruct'
require 'erb'
require 'flog'
require 'ruby_parser'
require 'sexp_processor'
ERBHandler = ActionView::Template::Handlers::ERB.new
def new_template(body, details={format: :html})
View contemplative.rb
require 'action_view'
require 'ostruct'
require 'erb'
require 'flog'
require 'ruby_parser'
require 'sexp_processor'
ERBHandler = ActionView::Template::Handlers::ERB.new
def new_template(body, details={format: :html})
View additional_monkey_patches.rb
# encoding: utf-8
# code from: http://techtime.getharvest.com/blog/harvest-is-now-on-ruby-1-dot-9-3
# and also: https://gist.github.com/1976864
# Serialized columns in AR don't support UTF-8 well, so set the encoding on those
class ActiveRecord::Base
def unserialize_attribute_with_utf8(attr_name)
traverse = lambda do |object, block|
if object.kind_of?(Hash)
You can’t perform that action at this time.