Skip to content

Instantly share code, notes, and snippets.

@bf4
bf4 / tinyurl.rb
Created July 26, 2010 18:31 — forked from woods/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
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 February 10, 2011 22:59 — forked from bruno/campfire_export.rb
campfire transcript export
---
BUNDLE_WITHOUT: ""
# 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
@bf4
bf4 / build.sh
Created December 27, 2012 17:14 — forked from anonymous/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
@bf4
bf4 / Rakefile
Last active December 11, 2015 02:48 — forked from anonymous/bootstrap.rb
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
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})
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})
# 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)