Skip to content

Instantly share code, notes, and snippets.

@natew
natew / song.rb
Created September 8, 2012 23:22
Rails model for parsing artist information from a song
class Song
# Regular expressions
RE = {
:featured => /(featuring | ?ft\.? |feat\.? |f\. |w\/){1}/i,
:remixer => / remix| rmx| edit| bootleg| mix| remake| re-work| rework| extended remix| bootleg remix/i,
:mashup_split => / \+ | x | vs\.? /i,
:producer => /^(produced by|prod\.? by |prod\. )/i,
:cover => / cover/i,
:split => /([^,&]+)(& ?([^,&]+)|, ?([^,&]+))*/i, # Splits "one, two & three"
:open => /[\(\[\{]/,
@natew
natew / reddit_rank.rb
Created October 16, 2012 06:23
Reddit ranking algorithm in rails
# Ranking algorithm
def set_rank
find_id = matching_id || id
shared_song = Song.find(find_id) if find_id
if shared_song
favs_count = shared_song.user_broadcasts_count
time_created = shared_song.created_at
else
favs_count = 1
time_created = created_at
@natew
natew / breadcrumbs.css
Created October 16, 2012 06:26
Simple automatic breadcrumbs in rails 3
#breadcrumbs {
a {
float: left;
&:hover {
color: #fff;
&.after:after {
color: #aaa;
}
@natew
natew / jquery.allon.js
Created October 16, 2012 06:28
jQuery function to mass bind events based on a parent
$.fn.allOn = function(onEvent, bindings) {
for (var target in bindings) {
(function(t) {
$(this).on(onEvent, t, function(e) {
bindings[t].call(this, e, $(this));
});
})(target);
}
}
@natew
natew / deploy.rb
Created October 24, 2012 18:59
deploy.rb
# Bundler
require "bundler/capistrano"
# Pretty colors
require 'capistrano_colors'
# Assets
load 'deploy/assets'
# Whenever
@natew
natew / Capfile
Created November 16, 2012 22:20
deploy.rb
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
# Uncomment if you are using Rails' asset pipeline
# load 'deploy/assets'
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
@natew
natew / deploy.rb
Created January 30, 2013 23:16
deploy.rb for 2u.fm
# Bundler
require "bundler/capistrano"
# Pretty colors
require 'capistrano_colors'
# Assets
load 'deploy/assets'
# Whenever
@natew
natew / deploy.rb
Last active December 16, 2015 17:39
deploy.rb rolling restart with unicorn deploy.rb in your rails app /config/deploy.rb on your server: /etc/unicorn/site.conf /etc/init.d/unicorn /etc/nginx/sites-available/sitename.conf
require "bundler/capistrano"
load 'deploy/assets'
# Pretty colors
require 'capistrano_colors'
# rbenv and ssh forwarding
set :default_environment, { 'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH" }
set :default_run_options, { :pty => true, :shell => '/bin/zsh' }
set :ssh_options, { :forward_agent => true }
@natew
natew / rackup.ru
Created July 24, 2013 17:28
Turn any directory into a simple rack server to serve static files
# This is the root of our app
@root = File.expand_path(File.dirname(__FILE__))
run Proc.new { |env|
# Extract the requested path from the request
path = Rack::Utils.unescape(env['PATH_INFO'])
index_file = @root + "#{path}index.html"
if File.exists?(index_file)
# Return the index
@natew
natew / deploy.rb
Last active March 16, 2022 06:35
Puma + Nginx + Capistrano
require 'bundler/capistrano'
require 'capistrano_colors'
load 'deploy/assets'
# ssh forwarding and shell
set :default_run_options, { :pty => true }
set :ssh_options, { :forward_agent => true }
set :scm_verbose, true
set :scm, :git