Skip to content

Instantly share code, notes, and snippets.

Benjamin Fleischer bf4

Block or report user

Report or block bf4

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
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 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] = ''
post_data[:caption] = 'A caption'
post_data[:description] = 'A description'
post_data[:picture] = ''
post_data[:actions] = { :name => 'My site name', :link => ''}.to_json"feed", nil, post_data)
bf4 / Facebook Phonebook Export
Created Feb 8, 2011
Modified from, need to enable on each page, doesn't iterate
View Facebook Phonebook Export
// ==UserScript==
// @name FB phonebook Exporter
// @namespace elleestcrimi
// @include*
// ==/UserScript==
var $;
// Add jQuery
bf4 / config
Created Feb 10, 2011 — forked from bruno/campfire_export.rb
campfire transcript export
View config
View Sunspot with Solr start page offset
+module Sunspot
+ # monkey patch for Sunspot v 1.1.1 to add support for solr "start" query parameter
+ # we can now optionally add a :start number to offset search results
+ # in this scenario, we want the first 3 results for the carousel, and then 5 more
+ # the code as is requires the start to be set to 3 and the per_page to 8 for this to work
+ # a better solution would be to modify the per_page= method but I was unable to do this
+ # with alias_method_chain, BF 12/6
+ module Query
+ class Pagination
bf4 / rails_attribute_serializer_macro.rb
Created Jul 20, 2012
Rails attribute serializer macro
View rails_attribute_serializer_macro.rb
module Macros
module Serializer
# usage
# include Macros::Serializer
# e.g. a field named :metadata must be a Hash
# serializer :metadata, Hash
def self.included(host_class)
# field must be a symbol
bf4 / logical_active_record.rb
Last active Oct 9, 2015
Failed attempt at a Logical ActiveRecord layer
View logical_active_record.rb
# modeled off the Physical / Service / Logical layers
# advocated by
module Logical
class ARModelName
attr_accessor :physical
private :physical
def initialize(physical)
@physical = physical.is_a?(PHYSICAL) ? physical :
bf4 / ruby_module_pattern.rb
Created Aug 23, 2012
Ruby Module pattern
View ruby_module_pattern.rb
module NameSpace
module MyClass
def self.included(host_class)
host_class.instance_eval do
has_one :thing
attr_accessible :something
validate :foo
extend ClassMethods
bf4 / null_object.rb
Created Aug 23, 2012
Ruby NullObject pattern
View null_object.rb
# see
class NullObject
def to_a; []; end
def to_s; ""; end
def to_f; 0.0; end
def to_i; 0; end
def tap; self; end
def nil?; true; end
def present?; false; end
def empty?; true; end
You can’t perform that action at this time.