Skip to content

Instantly share code, notes, and snippets.

View michael-gabenna's full-sized avatar

Michael Gabenna michael-gabenna

View GitHub Profile
@michael-gabenna
michael-gabenna / server.js
Created September 29, 2015 20:27 — forked from klzns/server.js
How to proxy index.html with react-transform
var express = require('express');
var webpack = require('webpack');
var httpProxy = require('http-proxy');
var proxy = new httpProxy.createProxyServer();
var config = require('./webpack.config');
var app = express();
var compiler = webpack(config);
app.use(require('webpack-dev-middleware')(compiler, {
@michael-gabenna
michael-gabenna / json2.rb
Last active August 29, 2015 14:26 — forked from tknarr/active_model_serializer_plus.rb
Module to provide a standard attributes= method for ActiveModel classes needing JSON serialization/deserialization
module JSON2
# Extension to the ActiveModel::Serializers::JSON module
# An attributes=() method is provided that uses the same loop a custom-written method would but uses the
# value of the key in the 'attributes' hash to automatically handle contained objects:
# If the value from the 'attributes' hash is a string, symbol or class name and the value of the current
# key is a hash, the 'attributes' value is taken as the class the current attribute is supposed to be and
# the value hash will be passed to the new object's attributes=() method.
# As usual, a class can provide it's own attributes=() method if different handling is required.

Component-Based Rails Applications (#cobra)

What is it?

Cobra is a way to organize your rails application, imagine it like a new way for packaging your rails apps

These are my annotations based on work of @shageman and @benjaminleesmith from Pivotal

Baby steps

<!DOCTYPE html>
<html lang="en">
<head>
<!-- Le styles -->
<link href="../bootstrap/css/bootstrap.css" rel="stylesheet">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
</head>
<body>
# Model using the ghostscript processor
class Content < ActiveRecord::Base
has_attached_file :resource,
:styles => { :preview => ["725x1200>", :jpg], :thumb => ["100x140>", :jpg] },
:processors => [:ghostscript, :thumbnail],
:convert_options => { :all => '-colorspace RGB -flatten -density 300 -quality 100' },
:path => ":page_path/:class/:id/:resource_token/:style/:filename"
end
= simple_form_for @mailing, :url => import_mailings_path, multipart: true do |f|
= f.error_notification
.form-inputs
= f.input :file, as: :file
.form-actions
= f.button :submit, "Enviar Arquivo", class: 'btn btn-primary'
# Original: http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html
(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:
\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(
?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[
\t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\0
31]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\
](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+
class TypeValidator < ActiveModel::Validator
def validate(record)
#validation
end
end
class MyModel
include ActiveModel::Model
validates_with TypeValidator
end