Skip to content

Instantly share code, notes, and snippets.

Thiago Brandão Damasceno thiagobrandam

View GitHub Profile
View deep_find.rb
# return path for deep find in nested hashes
def deep_find(hash, term)
paths = []
_deep_find(hash, term, root = "", paths)
paths
end
def _deep_find(hash, term, root, paths)
if hash.is_a?(Hash)
@thiagobrandam
thiagobrandam / credo_4.ex
Created May 22, 2018
Código exemplo em Elixir
View credo_4.ex
defmodule ProntoCredoExample.Example do
@moduledoc """
This module serves as an example for
cyclomatic complexity
"""
def do_something_complex(a, b, c, d, param) do
g = 0
e = case param
@thiagobrandam
thiagobrandam / credo_3.groovy
Created May 22, 2018
Snippet demonstrando execução do pronto
View credo_3.groovy
stage ('Rodando testes') {
// ...
sh "PRONTO_GITHUB_ACCESS_TOKEN=${githubToken}"
PRONTO_PULL_REQUEST_ID=${GITHUB_PR_NUMBER} pronto run -f
github_status github_pr -c "origin/master"
//...
}
@thiagobrandam
thiagobrandam / credo_2.ex
Created May 22, 2018
Dependência no mix.exs
View credo_2.ex
defp deps do
[
{:credo,"~> 0.8", only: [:dev, :test], runtime:false}
]
end
@thiagobrandam
thiagobrandam / credo_1.rb
Created May 22, 2018
Inconsistência no código
View credo_1.rb
# aqui o operador de soma está separado por um espaço
def add (a, b) do: a + b
# aqui o operador de subtração não está
def subtract(a, b), do: a-b
@thiagobrandam
thiagobrandam / docker-machine-use-nfs.sh
Last active Oct 22, 2015 — forked from olalonde/docker-machine-use-nfs.sh
Use NFS instead of vboxsf in Docker Machine
View docker-machine-use-nfs.sh
#!/bin/bash
#
# This script will mount /Users in the boot2docker VM using NFS (instead of the
# default vboxsf). It's probably not a good idea to run it while there are
# Docker containers running in boot2docker.
#
# Usage: sudo ./boot2docker-use-nfs.sh
#
View let_spec.rb
require 'rspec'
class BankAccount
attr_reader :balance
def initialize(initial_value = nil)
@balance = initial_value || 0
end
def deposit(amount)
@balance += amount
end
View fibers_and_em.rb
# Trying to grasp fibers and EM!
# Using this example: http://www.slideshare.net/kbal11/ruby-19-fibers (slide 54)
# Fiber#resume(*params) => when first called, it passes all params as block params to
# Fiber.new
# In the next calls of resumes, *params is the return value of any Fiber.yield
# Fiber.yield stops execution of current fiber
# So, in the run-loop from EM, the fiber stops execution and gives up control
@thiagobrandam
thiagobrandam / transaction_debug.rb
Last active Aug 29, 2015
Debugging transactions ...
View transaction_debug.rb
ObjectSpace.each_object(ActiveRecord::ConnectionAdapters::Transaction).map do |a|
[a.object_id, a.class, a]
end
ObjectSpace.each_object(ActiveRecord::ConnectionAdapters::Mysql2Adapter).map do |a|
[a.object_id, a.class, a]
end
ObjectSpace.each_object(ActiveRecord::ConnectionAdapters::Mysql2Adapter).map do |a|
[a.object_id, a.open_transactions]
View transliterate.sql
-- Copyright (c) 2009, Ionut Gabriel Stan. All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without modification,
-- are permitted provided that the following conditions are met:
--
-- * Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- * Redistributions in binary form must reproduce the above copyright notice,
-- this list of conditions and the following disclaimer in the documentation
You can’t perform that action at this time.