Skip to content

Instantly share code, notes, and snippets.

View esdras's full-sized avatar

Esdras Mayrink esdras

View GitHub Profile
@esdras
esdras / Main.elm
Created March 24, 2016 23:06 — forked from robinheghan/Main.elm
AWS Lambda Elm
module Main where
import Signal
type alias Message =
{ operation : String
, message : String
}
# add to fix issue with mysql 7+
# https://github.com/rails/rails/pull/13247#issuecomment-158787912
# http://stackoverflow.com/questions/21075515/creating-tables-and-problems-with-primary-key-in-rails
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
alias :connect_no_sql_mode :connect
def connect
connect_no_sql_mode

Getting started with Webpack, TypeScript, Babel and React

Introduction

The Javascript world is full of buzzwords, there is four only in the title of this article. With all these tools coming and going so fast, it's tuff to keep up the pace. I'm a ruby developer and recently I felt the need to improve my productivity in frontend development. With rails we have the asset pipeline but it seems that the javascript world has better tools to offer. While I was doing my research I stumbled upon these tools and started to see the values they bring, hopefully those values will be clear to you at the end of this article.

If you're like me and are not familiar with these tools, it can be daunting to get started. There is so much to learn and it's tempting to go back and just use jQuery. I made this tutorial because I myself wanted to learn. This tutorial will help you to implement a hello world app using these tools.

@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 "*****************************************"
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 / 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');
}
@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 / 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 / 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
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