Skip to content

Instantly share code, notes, and snippets.

View rbmrclo's full-sized avatar
Coffee 👨‍💻Code 🍸Cocktails

Robbie Marcelo rbmrclo

Coffee 👨‍💻Code 🍸Cocktails
View GitHub Profile
@rbmrclo
rbmrclo / routes.rb
Last active March 29, 2018 14:34
Rails Best Practices: Routing Concerns in Rails 4
# Routing Concerns is an attempt to DRY up your config/routes.rb.
# The basic idea is to define common sub-resources (like comments)
# as concerns and include them in other resources/routes.
# Here’s the obvious example:
concern :commentable do
resources :comments
end
concern :remarkable do
@rbmrclo
rbmrclo / age.rb
Last active January 2, 2016 11:09
Calculate age by birthday - compatible with leap year.
module Age
class << self
def today
Time.now.utc.to_date
end
# Formats the date as mm/dd/yyyy
def formatted_bday(bday)
@rbmrclo
rbmrclo / minify.rb
Created December 9, 2013 08:52
Minify javascript using uglifier
require 'uglifier'
File.open("outfile.min.js", "w") do |file|
file.write Uglifier.compile(File.read("infile.js"))
end
# Or with a one liner from the Terminal
ruby -e "require 'uglifier'; puts Uglifier.compile(File.read('infile.js'))" > outfile.min.js
@rbmrclo
rbmrclo / obfuscate.rb
Created November 27, 2013 08:11
Obfuscate an id
module Obfuscate
def cipher
OpenSSL::Cipher::Cipher.new('aes-256-cbc')
end
def cipher_key
'any string that you want'
end

A Capistrano Rails Guide

by Jonathan Rochkind, http://bibwild.wordpress.com

why cap?

Capistrano automates pushing out a new version of your application to a deployment location.

I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".

@rbmrclo
rbmrclo / gist:7095300
Created October 22, 2013 04:37
Liquid
class Liquify
attr_accessor :content, :template
class ::InvalidInputException < Exception; end;
def initialize(content)
@content = content
end
def template
@rbmrclo
rbmrclo / Pletora's mouse
Created August 23, 2013 14:14
Fix mouse pletora
xinput set-int-prop "DualPoint Stick" "Device Enabled" 8 0
@rbmrclo
rbmrclo / README
Created August 23, 2013 04:44 — forked from vangberg/README
# Deploying a Sinatra app to Heroku
## Database
The location of the database Heroku provides can be found in the environment
variable DATABASE_URL. Check the configure-block of toodeloo.rb for an example
on how to use this.
## Server
Heroku is serving your apps with thin, with means you have all your thin goodness available,
such as EventMachine.
@rbmrclo
rbmrclo / sc-dl.js
Created August 22, 2013 05:36 — forked from pheuter/sc-dl.js
(function(d) {
var dl = d.createElement('a');
dl.innerText = 'Download MP3';
dl.href = "http://media.soundcloud.com/stream/"+d.querySelector('#main-content-inner img[class=waveform]').src.match(/\.com\/(.+)\_/)[1];
dl.download = d.querySelector('em').innerText+".mp3";
d.querySelector('.primary').appendChild(dl);
dl.style.marginLeft = '10px';
dl.style.color = 'red';
dl.style.fontWeight = 700;
})(document);
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')