Skip to content

Instantly share code, notes, and snippets.

View xdougx's full-sized avatar

Douglas Rossignolli xdougx

View GitHub Profile
@xdougx
xdougx / searching.rb
Last active July 20, 2016 14:47
A intenção era só simplificar e ganhar todos os métodos sem precisar fazer muito, é muito simples fazer em uma classe desprendida do ActiveRecord
module Searchable
included do
scope :gender, ->(gender) { where(:gender => gender) }
scope :birth_on, ->(date) { where(:birthdate =>date) }
scope :birth_before_than, ->(date) { where("#{quoted_table_name}.birthdate < ?", date) }
scope :birth_after_than, ->(date) { where("#{quoted_table_name}.birthdate > ?", date) }
scope :profile, ->(profile){ where(:profile => profile) }
end
module ClassMethods
@xdougx
xdougx / solr_cap.rb
Last active August 29, 2015 14:20 — forked from doitian/solr_cap.rb
namespace :deploy do
task :setup_solr_data_dir do
run "mkdir -p #{shared_path}/solr/data"
end
end
namespace :solr do
desc "start solr"
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec sunspot-solr start --port=8983 --data-directory=#{shared_path}/solr/data --pid-dir=#{shared_path}/pids"

Setting up a SSL Cert from Comodo

I use Namecheap.com as a registrar, and they resale SSL Certs from a number of other companies, including Comodo.

These are the steps I went through to set up an SSL cert.

Purchase the cert

class @ButtonsFactory
# recebe os dados do botão como href, id, class, text e html
constructor: (params) ->
button = $("<a>")
for (key, value) in params
button.attr(key, value)
button
require 'base64'
require 'net/http'
class ImageProxyController < ActionController::Base
def get
url = URI.parse(Base64.decode64(params[:url]))
image = Net::HTTP.get_response(url)
send_data image.body, type: image.content_type, disposition: 'inline'
end
end
@xdougx
xdougx / iptable.conf
Created June 6, 2014 18:49
iptable for postgreesql
# Generated by iptables-save v1.4.12 on Wed Feb 19 15:24:27 2014
*filter
:INPUT ACCEPT [400:37871]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [283:59798]
# rules for postgree
#-A INPUT -d 202.54.1.20/32 -p tcp -m tcp --sport 1024:65535 --dport 5432 -m state --state NEW,ESTABLISHED -j ACCEPT
#-A INPUT -d 202.54.1.20/32 -p tcp -m tcp --sport 5432 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT
#-A INPUT -s 202.54.1.20/32 -d 202.54.1.20/32 -p tcp -m tcp --sport 1024:65535 --dport 5432 -m state --state NEW,ESTABLISHED -j ACCEPT
require 'rufus/scheduler'
class Scheduler
# Starts the scheduler unless it is already running
def self.start_unless_running(pid_file)
with_lockfile(File.join(File.dirname(pid_file), 'scheduler.lock')) do
if File.exists?(pid_file)
pid = IO.read(pid_file).to_i
if pid > 0 && process_running?(pid)
puts "not starting scheduler because it already is running with pid #{pid}"
@xdougx
xdougx / validations.js
Last active August 29, 2015 14:01
Validations.js
var Validations = (function(){
var Validation = function() {
var name = $("[name='nome']");
var email = $("[name='email']");
var empresa = $("[name='empresa']");
var telefone = $("[name='telefone']");
var mensagem = $("[name='mensagem']");
var regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
Thanks to Jason Roelofs for his article at http://jasonroelofs.com/2012/03/12/manage-and-monitor-resque-with-upstart-and-monit/ which got me most of the way there.
upstream unicorn {
server unix:/tmp/unicorn.foo.sock fail_timeout=0;
}
server {
listen 80 default deferred;
listen 443 ssl default;
ssl_certificate /etc/ssl/certs/foo.crt;
ssl_certificate_key /etc/ssl/private/foo.key;