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 / slugable.rb
Last active August 29, 2015 13:56
An simple way to find an object by slug
module Slugable
module ClassMethods
def find_by_slug(param)
if to_return = where("lower(name) LIKE ?", "#{patternify(param)}")
to_return.first
else
nil
end
end
@rbmrclo
rbmrclo / gist:9888023
Created March 31, 2014 08:41
Ignore concerns for rails_admin
# config/rails_admin.rb
config.excluded_models = Dir.glob(Rails.root.join('app/models/concerns/**.rb')).map {|p| 'Concerns::' + File.basename(p, '.rb').camelize }
require 'resque'
require 'resque_scheduler'
require 'resque/server'
require 'resque_scheduler/server'
schedules = YAML.load_file(Rails.root.join('config', 'schedules.yml'))
$redis = Resque.redis = Redis.current = Redis.new( url: ENV['REDIS_URI'] )
Resque.schedule = schedules
@rbmrclo
rbmrclo / email_validator.rb
Created May 22, 2014 05:57
Email validatior
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
record.errors[attribute] << (options[:message] || 'is not an email')
end
end
end
@rbmrclo
rbmrclo / gist:e4df82f1a8f04b11a325
Last active August 29, 2015 14:18
SHA1Generator
require 'digest/sha1'
#
# A wrapper for generating SHA1 hash value
# Simply done by concatenating all values using the colon symbol for delimiter.
# This algorithm is mostly used by payment gateways.
#
# Usage:
#
# SHA1Generator.digest('foo', 'bar', 'fizz', 'buzz')
# => "e723e86a6000fc8462142eb4821672de107535c1" # 40 chars
@rbmrclo
rbmrclo / Problem-1.php
Created November 16, 2012 11:52
Project Euler Solutions
/*
1.) If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
*/
// Solution in PHP, the simple way:
@rbmrclo
rbmrclo / gist:6162467
Created August 6, 2013 06:17
Postgresql remove string limit of 255 chars
# in rails application.rb
initializer "postgresql.no_default_string_limit" do
ActiveSupport.on_load(:active_record) do
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:string].delete(:limit)
end
end
=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')
@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);
@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.