Skip to content

Instantly share code, notes, and snippets.

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
#!/bin/bash
# This script creates a custom ruby definition for rbenv
# which incorporates the rvm patches from skaes.
#
# (c) [email protected]
#
rubyexpress_repo="https://github.com/skaes/rvm-patchsets.git"
rubybuild_repo="https://github.com/sstephenson/ruby-build.git"
mkdir rbenv-railsexpress
@stephanschubert
stephanschubert / selecta_search_history.zsh
Last active August 23, 2016 10:20
Reverse command history search with selecta's fuzzy matching for ZSH
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
}
@stephanschubert
stephanschubert / compact.gemspec
Last active August 29, 2015 14:02
Hash#compact removes all keys with nil as value.
Gem::Specification.new do |s|
s.name = 'compact'
s.version = '0.0.1'
s.platform = Gem::Platform::RUBY
s.author = 'Stephan Schubert'
s.email = '[email protected]'
s.summary = 'Hash#compact'
s.description = 'Removes all keys with nil as value.'
s.files = ['compact.rb']
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
@stephanschubert
stephanschubert / mysql_ramdisk_osx.sh
Created January 21, 2014 13:36
Move MySQL db into 1GB ramdisk on OSX
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 \
@stephanschubert
stephanschubert / share_counts.md
Last active October 10, 2017 19:58 — forked from jonathanmoore/gist:2640302
How to retrieve the share counts for an URL from various social media platforms.

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

@stephanschubert
stephanschubert / jquery-plugin-template.js
Created November 25, 2013 13:16
Template for authoring a state-of-the-art jQuery plugin.
/*!
* 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.
@stephanschubert
stephanschubert / multi_fetch.rb
Created November 25, 2013 12:58
Hash#multi_fetch - Fetch multiple keys from a Hash and support default values when a key is missing.
# 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
@stephanschubert
stephanschubert / using.rb
Last active December 24, 2015 23:58
Find all classes which include a module.
def using(klass)
Module.constants.find_all do |name|
klass > Object.const_get(name) if name != name.upcase
end
end