Skip to content

Instantly share code, notes, and snippets.

View regedarek's full-sized avatar
🏠
Working from home

Darek Finster regedarek

🏠
Working from home
View GitHub Profile
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active July 21, 2024 01:20
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh

Polymorphism

Sometimes relationships need to be flexible, and that's where we look to polymorphism. Say we want to implement:

  • A Person
  • A Company
  • A PhoneNumber that can connect to a Person or a Company

At the Database Level

@nesquena
nesquena / jbuilder.rb
Created February 14, 2012 01:15
JBuilder and RABL Syntax Comparison
Jbuilder.encode do |json|
json.content format_content(@message.content)
json.(@message, :created_at, :updated_at)
json.author do |json|
json.name @message.creator.name.familiar
json.email_address @message.creator.email_address_with_name
json.url url_for(@message.creator, format: :json)
end
@robotarmy
robotarmy / Gemfile
Created March 23, 2012 23:55
Adding Rake to Sinatra with Rspec
gem 'sinatra'
group :development,:test do
gem 'rspec'
gem 'rack-test'
end
@panthomakos
panthomakos / benchmark.rb
Created May 3, 2012 20:06
Benchmark Your Bundle
#!/usr/bin/env ruby
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
]
@IanVaughan
IanVaughan / uninstall_gems.sh
Created June 9, 2012 20:37
Uninstall all rbenv gems
#!/usr/bin/env bash
uninstall() {
list=`gem list --no-versions`
for gem in $list; do
gem uninstall $gem -aIx
done
gem list
gem install bundler
}
@wjlroe
wjlroe / README.md
Created August 13, 2012 10:20
How to serve static files with POW

Problem

You wanna serve up static files, but are bored by the usual trick of:

python -m SimpleHTTPServer

This is pretty simple but why type this every time? Let's use Pow for some zero-effort web serving. If you have Pow already set up, then just drop the provided config.ru file into the root of your static files. Then link your directory into ~/.pow so Pow can see it and that's it!

Let's say you have a directory with mockups you wanna show people, they are in ~/Dropbox/Mockups/ then you might do this:

@regedarek
regedarek / gist:3734225
Created September 16, 2012 20:20 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@mostlyobvious
mostlyobvious / osx_rails_env_setup_in_all_steps.md
Created October 1, 2012 23:29 — forked from solnic/osx_rails_env_setup_in_6_steps.md
Steps to get up'n'running with Rails on OS X and Ubuntu

Steps to set up a Rails development environment on OS X:

  • install Apple Command Line Tools
  • install homebrew[1]: ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
  • install rvm: curl -L https://get.rvm.io | bash -s stable
  • source $HOME/.rvm/scripts/rvm
  • rvm install --disable-binary 1.9.3
  • rvm use --default 1.9.3
@mytrile
mytrile / application.rb
Created November 9, 2012 08:53
Cookie based authentication strategy in Devise
# config/application.rb
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(#{config.root}/lib/devise)
# rest of the file
end
end