This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Call scopes directly from your URL params: | |
# | |
# @products = Product.filter(params.slice(:status, :location, :starts_with)) | |
module Filterable | |
extend ActiveSupport::Concern | |
module ClassMethods | |
# Call the class methods with the same name as the keys in <tt>filtering_params</tt> | |
# with their associated values. Most useful for calling named scopes from |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################# | |
# | |
# File: lib/api.rb | |
# | |
################################################################# | |
require 'user' # ActiveRecord model | |
# Connect to the db | |
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MailSender | |
def self.send_mail(smtp_settings, user, mail_subject, mail_body) | |
options = { :address => smtp_settings["address"], | |
:domain => smtp_settings["domain"], | |
:port => smtp_settings["port"].to_i, | |
:user_name => smtp_settings["user_name"], | |
:password => smtp_settings["password"], | |
:authentication => smtp_settings["authentication"], | |
:enable_starttls_auto => true, | |
:openssl_verify_mode => 'none' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# put this in /lib/resque.rb | |
require 'mail' | |
module Emailer | |
class Send | |
@queue = :issue_mailer | |
def self.perform(addressee, subject, body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mail' | |
module SpamBitch | |
module Phone | |
def self.carriers | |
{ claro: 'vtexto.com', att: 'txt.att.net', tmobile: 'sms.tmobile.net' } | |
end | |
def self.send_sms(telephone, msg, carrier) | |
options = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "csv" | |
desc "Import CSV file into an Active Record table" | |
task :csv_model_import, [:filename, :model] => :environment do |task,args| | |
firstline=0 | |
keys = {} | |
CSV.foreach(args[:filename]) do |row| | |
if (firstline==0) | |
keys = row | |
firstline=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'mail' | |
Mail.defaults do | |
delivery_method :smtp, | |
{ address: "smtp.sendgrid.net", | |
port: 587, | |
domain: 'heroku.com', | |
user_name: ENV['SENDGRID_USERNAME'], | |
password: ENV['SENDGRID_PASSWORD'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'mail' | |
GMAIL_USERNAME = "username" | |
GMAIL_PASSWORD = "password" | |
options = { :address => "smtp.gmail.com", | |
:port => 587, | |
:domain => 'gmail.com', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
#------------------------------------------------------------------------------ | |
# Aggregate Print useful information from /proc/[pid]/smaps | |
# | |
# pss - Roughly the amount of memory that is "really" being used by the pid | |
# swap - Amount of swap this process is currently using | |
# | |
# Reference: | |
# http://www.mjmwired.net/kernel/Documentation/filesystems/proc.txt#361 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function update_all { | |
cd $PROJECTS_PATH | |
for i in $(find . -type d); do | |
if [ -d "$i/.git" ]; then | |
echo -e "\033[1mPulling "$i"\033[0m" | |
cd "$i" | |
# pull repos without local changes | |
if git diff-index --quiet HEAD --; then | |
git pull --rebase --quiet > /dev/null | |
if [ -e Gemfile ]; then |