Skip to content

Instantly share code, notes, and snippets.

View tiagopog's full-sized avatar

Tiago Guedes tiagopog

View GitHub Profile
@tiagopog
tiagopog / virtus.rb
Last active August 29, 2015 14:27
Data objects - Virtus example
require 'virtus'
class User
include Virtus.model
attribute :name, String
attribute :age, Integer
attribute :birthday, Date
end
@tiagopog
tiagopog / h2o.conf
Last active August 29, 2015 14:27
H2O's config file
user: tiagopog
hosts:
"beautydate.dev":
listen:
port: 80
paths:
/:
proxy.reverse.url: http://localhost:3000/
proxy.preserve-host: ON
proxy.timeout.io: 5000
@tiagopog
tiagopog / nginx.conf
Last active August 29, 2015 14:27
NGINX - Local config
user nobody;
worker_processes 1;
#pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
require 'sequel'
DB = Sequel.connect('postgres:///beautydate_dev')
puts DB[:users].where(name: /ti/i).first
@tiagopog
tiagopog / enumerator.rb
Last active August 19, 2016 14:41
Ruby - Enumerator
def print_enum(enum)
puts enum
puts enum.inspect
end
# Example: 1
enum = %w(foo bar).each
print_enum(enum)
3.times { puts enum.next } rescue nil
@tiagopog
tiagopog / jsonapi_utils_lib.rb
Last active September 4, 2015 17:45
JSON API - Helper methods for controllers
module JsonapiUtils
extend ActiveSupport::Concern
include do
helper_method :jsonapi_serialize, :jsonapi_serialize_collection
end
def jsonapi_serialize_collection(records)
records = records.map { |record| @request.resource_klass.new(record) }
jsonapi_serialize(records)
user nobody;
worker_processes 1;
#pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
@tiagopog
tiagopog / simple_rails_rack_example.rb
Last active October 17, 2015 16:39
Simple Rails' Rack example.
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
class MyMiddleware
def initialize(app)
@app = app
end
def call(env)
puts 'foobar'
user nobody;
worker_processes 1;
#pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
@tiagopog
tiagopog / ruby_2_3_features.rb
Last active January 1, 2016 00:14
Summary of Ruby 2.3's feature.
# frozen_string_literal: true
class User
attr_accessor :admin
def initialize(options = {})
@admin = options[:admin] || false
end
def admin?; @admin end