Skip to content

Instantly share code, notes, and snippets.

View esdras's full-sized avatar

Esdras Mayrink esdras

View GitHub Profile
@esdras
esdras / form.html.erb
Last active August 29, 2015 14:00
Upload to s3
<form action="<%= form_url %>" method="post" enctype="multipart/form-data" data-attachment-form='entity' id='upload_company_logo_form'>
<div style='display: none'>
<input type="hidden" name="key" value="<%= s3_object_key %>" /><br/><br/>
<input type="hidden" name="acl" value="public-read" /><br/>
<input type="hidden" name="success_action_redirect" value="<%= success_action_redirect %>" /><br/>
<input type="hidden" name="AWSAccessKeyId" value="<%= ENV['AWS_ACCESS_KEY_ID'] %>" />
<input type="hidden" name="policy" value=<%= policy %> />
<input type="hidden" name="signature" value=<%= signature %> />
</div>
<div class='add-attachment'>
@esdras
esdras / gist:631a04769f24856c6d7f
Last active August 29, 2015 14:01
A DSL to implement factories in ruby
require 'fiber'
class Factory
class Callbacks
def initialize(handler, actions)
@handler, @actions = handler, actions
end
CREATE TEXT SEARCH CONFIGURATION fr ( COPY = french );
ALTER TEXT SEARCH CONFIGURATION fr ALTER MAPPING
FOR hword, hword_part, word WITH unaccent, french_stem;
CREATE TEXT SEARCH CONFIGURATION en ( COPY = english );
ALTER TEXT SEARCH CONFIGURATION en ALTER MAPPING
FOR hword, hword_part, word WITH unaccent, english_stem;
CREATE TEXT SEARCH CONFIGURATION de ( COPY = german );
ALTER TEXT SEARCH CONFIGURATION de ALTER MAPPING
class CreateTransactionsInvoicesTriggers < ActiveRecord::Migration
def up
add_column :credit_card_invoices, :balance_cents, :integer, null: false, default: 0 rescue nil
execute <<-SQL
DROP TRIGGER IF EXISTS update_invoice_after_create_transaction;
SQL
@esdras
esdras / bin-cc.md
Last active August 29, 2015 14:21 — forked from erikhenrique/bin-cc.md

Validação para cartão de crédito.

Bin e padrões para validação de cartão de crédito.

Bandeira Começa com Máximo de número Máximo de número cvc
Visa 4 13,16 3
Mastercard 5 16 3
@esdras
esdras / admins.sql
Last active August 29, 2015 14:23
executing multiple queries from a file in a migration.
CREATE OR REPLACE FUNCTION hash_password_on_insert() RETURNS trigger AS
$FUNCTION$
BEGIN
IF NEW.encrypted_password IS NULL THEN
RAISE EXCEPTION 'password cannot be null';
END IF;
IF char_length(NEW.encrypted_password) < 8 THEN
RAISE EXCEPTION 'password is to short, should be greater than 8 chars';
@esdras
esdras / admin.sql
Created June 21, 2015 01:05
Executing multiple SQL statements from a file
CREATE OR REPLACE FUNCTION hash_password_on_insert() RETURNS trigger AS
$FUNCTION$
BEGIN
IF NEW.encrypted_password IS NULL THEN
RAISE EXCEPTION 'password cannot be null';
END IF;
IF char_length(NEW.encrypted_password) < 8 THEN
RAISE EXCEPTION 'password is to short, should be greater than 8 chars';
@esdras
esdras / plv8.sql
Created June 22, 2015 14:43
plv8-example
CREATE OR REPLACE FUNCTION hash_password() RETURNS trigger AS
$$
if(TG_OP == 'INSERT' || OLD.encrypted_password != NEW.encrypted_password) {
if(NEW.encrypted_password == null) throw new Error('password cannot be null');
if(NEW.encrypted_password.length < 8 || NEW.encrypted_password.length > 72) {
throw new Error('password length must be beteween 8 and 72');
}
module Cache
def write_fragment(key, content, options = nil)
return content unless cache_configured?
key = fragment_key(key)
content = content.to_str
fragments_to_write << key
fragments_to_write << ActiveSupport::Gzip.compress(content)
content
end
@esdras
esdras / install-redis.sh
Last active August 29, 2015 14:26 — forked from four43/install-redis.sh
Install Redis
#!/bin/bash
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use:
# wget https://gist.githubusercontent.com/esdras/5d1f13fa37073ce23f3f/raw/install-redis.sh
# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"