View private_delegate.rb
1 2 3 4 5 6 7
class Module
def private_delegate(*methods)
delegate(*methods)
methods.extract_options!
methods.each { |m| private(m) }
end
end
View bench_rails_memory_usage.rb
1 2 3 4 5 6 7 8 9 10
require "net/http"
 
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
View railsexpress-patched-ruby-for-rbenv.sh
1 2 3 4 5 6 7 8 9 10
#!/bin/bash
# This script creates a custom ruby definition for rbenv
# which incorporates the rvm patches from skaes.
#
# (c) frank.schumacher.privat@gmail.com
#
rubyexpress_repo="https://github.com/skaes/rvm-patchsets.git"
rubybuild_repo="https://github.com/sstephenson/ruby-build.git"
 
mkdir rbenv-railsexpress
View selecta_search_history.zsh
1 2 3 4 5 6 7 8 9 10
function exists { which $1 &> /dev/null }
 
if exists selecta; then
function selecta_select_history() {
local tac
exists gtac && tac="gtac" || { exists tac && tac="tac" || { tac="tail -r" } }
BUFFER=$(fc -l -n 1 | eval $tac | selecta $LBUFFER)
CURSOR=$#BUFFER # move cursor
zle -R -c # refresh
}
View compact.gemspec
1 2 3 4 5 6 7 8 9 10
Gem::Specification.new do |s|
s.name = 'compact'
s.version = '0.0.1'
s.platform = Gem::Platform::RUBY
s.author = 'Stephan Schubert'
s.email = 'stephan@frozencherry.de'
s.summary = 'Hash#compact'
s.description = 'Removes all keys with nil as value.'
s.files = ['compact.rb']
View database_cleaner.rb
1 2 3 4 5 6 7 8 9
RSpec.configure do |config|
 
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
 
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
View mysql_ramdisk_osx.sh
1 2 3 4 5 6 7 8 9 10
diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://2048000`
 
/usr/local/Cellar/mysql/5.6.15/scripts/mysql_install_db \
--basedir=/usr/local/Cellar/mysql/5.6.15 \
--datadir=/Volumes/ramdisk
 
/usr/local/Cellar/mysql/5.6.15/bin/mysqld \
--basedir=/usr/local/Cellar/mysql/5.6.15 \
--datadir=/Volumes/ramdisk \
--plugin-dir=/usr/local/Cellar/mysql/5.6.15/lib/plugin \
View share_counts.md

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

View jquery-plugin-template.js
1 2 3 4 5 6 7 8 9 10
/*!
* jQuery lightweight plugin boilerplate
* Original author: @ajpiano
* Further changes, comments: @addyosmani
* Licensed under the MIT license
*/
 
// the semi-colon before the function invocation is a safety
// net against concatenated scripts and/or other plugins
// that are not closed properly.
View multi_fetch.rb
1 2 3 4 5 6 7 8 9 10
# Usage:
#
# h = { a: 1, b: 2 }
#
# h.multi_fetch(:a) # => [1]
# h.multi_fetch(:a, :b) # => [1, 2]
# h.multi_fetch(:a, :c) # => [1, nil]
# h.multi_fetch(a: 1, c: 3) # => [1, 3]
 
class Hash
Something went wrong with that request. Please try again.