Skip to content

Instantly share code, notes, and snippets.

require 'redis'
# SADD key, member
# Adds the specified <i>member</i> to the set stored at <i>key</i>.
redis = Redis.new
redis.sadd 'my_set', 'foo' # => true
redis.sadd 'my_set', 'bar' # => true
redis.sadd 'my_set', 'bar' # => false
redis.smembers 'my_set' # => ["foo", "bar"]
@dnagir
dnagir / rspec-syntax-cheat-sheet.rb
Created November 5, 2010 09:29
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
# Watches ./wp-content/themes/**/*.scss for changes and recompiles
# them into css files in the same place.
#
# Installation:
# [sudo] gem install watchr
#
# Usage:
# watchr ./path/to/this/script.rb
#
# ^C to exit.

Bundler is rather slow at installing new/updated gems when someone else has committed changes to the Gemfile.lock. I decided to find a quicker way. I think this is quicker, it gives me progress output so it feels quicker anyway.

$ bundle check | egrep "[a-zA-Z0-9_-]+ \([0-9.]+\)" | sed -Ee \
  's/^.* ([a-zA-Z0-9_-]+) \(([0-9.]+)\).*$/\1 -v="\2"/' | xargs -L1 gem install
Fetching: SystemTimer-1.2.3.gem (100%)
Building native extensions.  This could take a while...
Successfully installed SystemTimer-1.2.3
1 gem installed

Fetching: net-ssh-2.1.4.gem (100%)

@fwielstra
fwielstra / api.js
Created June 14, 2011 14:46
An example NodeJS / Mongoose / Express application based on their respective tutorials
/* The API controller
Exports 3 methods:
* post - Creates a new thread
* list - Returns a list of threads
* show - Displays a thread and its posts
*/
var Thread = require('../models/thread.js');
var Post = require('../models/post.js');
@phred
phred / unserialize.php
Created September 7, 2011 19:04
Simple reliable and non-regex method to unserialize PHP session data
//
// This is the result of about an hour's delving into PHP's hairy-ass serialization internals.
// PHP provides a session_decode function, however, it's only useful for setting the contents of
// $_SESSION. Say, for instance, you want to decode the session strings that PHP stores in its
// session files -- session_decode gets you nowhere.
//
// There are a bunch of nasty little solutions on the manual page[1] that use pretty hairy regular
// expressions to get the job done, but I found a simple way to use PHP's unserialize and recurse
// through the string extracting all of the serialized bits along the way.
//
@lucasfais
lucasfais / gist:1207002
Created September 9, 2011 18:46
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt

DISCLAIMER: The examples in this article are Rails-based, and I'm only an intermediate Rails developer at best. The focus of this article is on general maintenance patterns rather than specific implementation details, but if you see something ugly in the code samples, please give me some feedback!

When I launched the Practicing Ruby journal back in August 2011, I was just as excited about designing my own publishing software as I was about working on new articles. After several unsuccessful attempts at using existing services, I had finally thrown in the towel and decided that for this journal to be what I wanted it to be, it needed to run on its own custom software.

For the first few weeks, I was adding new bits of functionality as quickly as Jordan Byron and I could code them up. However, by mid-October we had built a tool that was good enough for day-to-day use, and I was generally happy with our progress. The unfortunate consequence of rea

@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@xdite
xdite / gist:3072362
Created July 8, 2012 19:10
deploy/asset.rb
# -*- encoding : utf-8 -*-
set :assets_dependencies, %w(app/assets lib/assets vendor/assets Gemfile.lock config/routes.rb)
namespace :deploy do
namespace :assets do
desc <<-DESC
Run the asset precompilation rake task. You can specify the full path \
to the rake executable by setting the rake variable. You can also \