Skip to content

Instantly share code, notes, and snippets.

@sashazykov
sashazykov / bitcoin_address_validator.rb
Created January 9, 2013 09:04
Rails 3 bitcoin address validator. Validator syntaxis: validates :address, :bitcoin_address => true, :presence => true
require 'digest'
class BitcoinAddressValidator < ActiveModel::EachValidator
def validate_each(record, field, value)
unless value.blank? || valid_bitcoin_address?(value)
record.errors[field] << "Bitcoin address is invalid"
end
end
private
@corroded
corroded / link_to_with_current.rb
Created September 21, 2011 09:28
Adds current class to link if on the current page
@shaneog
shaneog / gist:1198248
Created September 6, 2011 17:12
elasticsearch ubuntu 11.04
cd ~
# Install the required JDK
sudo apt-get install openjdk-6-jre-headless
# Download, extract and move ElasticSearch
wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.17.6.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
sudo mv elasticsearch-* elasticsearch
@rbscott
rbscott / elasticsearch.conf
Created June 28, 2011 19:46
upstart job for elastic search
# ElasticSearch Service
description "ElasticSearch"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
@ramontayag
ramontayag / pairprogramming.screenrc
Created June 24, 2011 18:03
.screenrc setting for remote pairing
multiuser on
acladd user1,user2,user3
vbell off
hardstatus string "%1`"
# change the hardstatus settings to give an window list at the bottom of
# the screen, with the time and date and with the current window highlighted
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'
@ramontayag
ramontayag / tutorial.md
Created June 24, 2011 16:21
Rails 3.1: How to embed a dummy Rails app in a gem for Cucumber testing purposes

Intro

Problem: I learned how to run RSpec to test classes and modules in my gem. But, if I wanted to test my gem as if it were already included in a Rails app, I couldn't find much info about it online.

I usually do unit tests with RSpec, and I test the whole stack with Cucumber. So here we will just setup Cucumber to run the Rails app that you embed in your gem.

Before we begin:

  • This tutorial is for people who already know how to make gems, and who have used RSpec and Cucumber before in a Rails app.
  • MyGem and my_gem below refer to the name of the gem we are creating. Replace this with your own name.
@trydionel
trydionel / backbone.rails.js
Created November 28, 2010 16:47
Makes Backbone.js play nicely with default Rails setup
//
// Backbone.Rails.js
//
// Makes Backbone.js play nicely with the default Rails setup, i.e.,
// no need to set
// ActiveRecord::Base.include_root_in_json = false
// and build all of your models directly from `params` rather than
// `params[:model]`.
//
// Load this file after backbone.js and before your application JS.
@zerowidth
zerowidth / paginated_collection.js
Created November 18, 2010 22:04
first whack at pagination with backbone.js
// includes bindings for fetching/fetched
PaginatedCollection = Backbone.Collection.extend({
initialize: function() {
_.bindAll(this, 'parse', 'url', 'pageInfo', 'nextPage', 'previousPage');
this.page = 1;
},
fetch: function(options) {
options || (options = {});
this.trigger("fetching");
@justintv
justintv / .bashrc
Created August 17, 2009 00:53
Display git branch in bash prompt
# If you work with git, you've probably had that nagging sensation of not knowing what branch you are on. Worry no longer!
export PS1="\\w:\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)\$ "
# This will change your prompt to display not only your working directory but also your current git branch, if you have one. Pretty nifty!
# ~/code/web:beta_directory$ git checkout master
# Switched to branch "master"
# ~/code/web:master$ git checkout beta_directory
# Switched to branch "beta_directory"
#!/usr/bin/env ruby
#
# Find bloating passengers and kill them gracefully. Run from cron every minute.
#
# required for passenger since cron has no environment
ENV['HTTPD'] = 'httpd'
MEM_LIMIT = ARGV[0] || 500