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
@pragmaticivan
pragmaticivan / Jenkinsfile
Created March 22, 2018 19:20 — forked from jonico/Jenkinsfile
Example for a full blown Jenkins pipeline script with multiple stages, input steps, injected credentials, heroku deploy, sonarqube and artifactory integration, multiple Git commit statuses, PR merge vs branch build detection, REST API calls to GitHub deployment API, stage timeouts, stage concurrency constraints, ...
#!groovy
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
/*
Please make sure to add the following environment variables:
HEROKU_PREVIEW=<your heroku preview app>
HEROKU_PREPRODUCTION=<your heroku pre-production app>
HEROKU_PRODUCTION=<your heroku production app>
@pragmaticivan
pragmaticivan / install-chrome-headless.sh
Created February 1, 2018 22:24 — forked from ipepe/install-chrome-headless.sh
Installing headless chrome on Ubuntu.
#!/bin/bash
# from https://chromium.woolyss.com/
# and https://gist.github.com/addyosmani/5336747
# and https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:canonical-chromium-builds/stage
sudo apt-get update
sudo apt-get install chromium-browser
chromium-browser --headless --no-sandbox http://example.org/
@pragmaticivan
pragmaticivan / certgen.rb
Created February 8, 2016 18:46 — forked from sheerun/certgen.rb
Docker TLS certificate generator
# Generates necessary certificates to ~/.docker
#
# Usage:
# bundle install
# ruby certgen.rb <domain>
require 'certificate_authority'
require 'fileutils'
if ARGV.empty?
Verifying that +pragmaticivan is my blockchain ID. https://onename.com/pragmaticivan
class MainController < ApplicationController
def index
@verse = Verse.order("RANDOM()").limit(1).first
@book = Book.find(@verse.book_id).name
end
end

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.

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|
@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],

Rails Rspec APIs Testing Notes

Folders Structure

  spec
  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views
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)