Skip to content

Instantly share code, notes, and snippets.

View pragmaticivan's full-sized avatar
Permanent 418 status code.

Ivan Santos pragmaticivan

Permanent 418 status code.
View GitHub Profile
#...
set :app_path, "#{deploy_to}/#{current_path}"
#...
desc "Deploys the current version to the server."
task :deploy => :environment do
deploy do
#...
server {
listen 80;
server_name example.com;
rewrite ^/(.*) https://$server_name permanent;
}
server {
# Your application host will be used as a convention for directories and other stuffs
set $application_host "example.com";
# Rails application server timeout (we have to match the value here to not display Gateway Timeout error)

Rails Rspec APIs Testing Notes

Folders Structure

  spec
  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views
require 'net/http'
require 'uri'
require 'json'
uri = URI('http://divulga.tse.jus.br/2014/divulgacao/oficial/143/dadosdivweb/br/br-0001-e001431-w.js')
class String; def percent_of(n) "#{(self.to_f / n.to_f * 100.0).round(2)}%"; end; end
begin
data = JSON(Net::HTTP.get_response(uri).body)
system('clear')
puts "\n\n----\n#{data['ht']} - #{data['ea'].percent_of(data['e'])} dos votos apurados\n----"
data['cand'].take(3).each do |candidate|

Rocky Mountain Ruby

SOA from the Start - Workshop Part


What will we show

We are building a set of applications that have will show deals (aka. 'inventory items') available in or near a given city. These items can also be organized by a 'category' (aka. tags), to cater to the various customers' areas of interest.

To bootstrap things, and to get us focussed on some key areas of developing in a SOA, we have gone ahead and built these apps out at varying stages. The workshops will focus on showing some of this code, and intersperse exercises to add features, or to refactor.

class MainController < ApplicationController
def index
@verse = Verse.order("RANDOM()").limit(1).first
@book = Book.find(@verse.book_id).name
end
end
@pragmaticivan
pragmaticivan / grape.rake
Created October 12, 2014 04:42
Grape Rake (routes)
namespace :grape do
desc "Condensed API Routes"
task :routes => :environment do
mapped_prefix = '' # where mounted in routes.rb
format = "%46s %3s %7s %50s %12s: %s"
API.routes.each do |grape_route|
info = grape_route.instance_variable_get :@options
puts format % [
info[:description] ? info[:description][0..45] : '',
info[:version],
public function findAll($options = array()){
$defaults = array();
$options = array_merge($defaults,$options);
$fields = "blogs.id, blogs.orelha, blogs.titulo, concat(blogs.slug,'.html') as slug, blogs.bigode, blogs.texto, blogs.fonte,
blogs.autor, blogs.data_hora, blogs.ext_arquivo, blogs.legenda, blogs.creditos, blogs.censurada,
blogs.video, blogs.comentarios, blogs.tags, blogs.ativo, blogs.hits,
blogs.ordem, imagens_areas.destaque, imagens_areas.legenda, imagens_areas.creditos, imagens_areas.imagens_id,
imagens.ext_arquivo, imagens.censurada,categorias.slug as slug_categoria, categorias.categoria as categoria_name,
categorias.id as id_categoria, categorias.ext_arquivo as imagem_categoria";
if (isset($options['comments']) and $options['comments']) {
@pragmaticivan
pragmaticivan / controller.php
Created May 18, 2011 14:33
Possibilidade de array no only e except para as before actions
/**
* Executa os métodos adicionados no before e after action.
*
* @param array $methods
* @return void
*/
private function execute_methods($methods) {
foreach ($methods as $key => $value) {
if (is_array($value)) {
if (isset($value['only'])) {
@pragmaticivan
pragmaticivan / movie.php
Created March 31, 2012 21:59
Movie Helper
class MovieHelper {
/**
* Armazena a opção de hospedagem do video (VIMEO ou Youtube)..
*
* @access public
* @var string
*/
private $location;