Skip to content

Instantly share code, notes, and snippets.

View 0xradical's full-sized avatar

Thiago Brandão 0xradical

View GitHub Profile
@0xradical
0xradical / hashify.rb
Created November 11, 2013 17:48
Dot-separated to hash using recursive lambda
hashify = ->(str, memo = []){ str =~ /\./ ? (r = str.split(/\./,2); {r[0] => hashify[r[1],memo << r[0]]}) : {str => [memo << str].join('.')} }
# hashify['a.b.c.d'] =>
# {"a"=>{"b"=>{"c"=>{"d"=>"a.b.c.d"}}}}
-- 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
@0xradical
0xradical / transaction_debug.rb
Last active August 29, 2015 13:57
Debugging transactions ...
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]
@0xradical
0xradical / fibers_and_em.rb
Created June 19, 2014 04:36
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
@0xradical
0xradical / let_spec.rb
Created May 8, 2015 20:35
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
@0xradical
0xradical / docker-machine-use-nfs.sh
Last active October 22, 2015 18:12 — forked from olalonde/docker-machine-use-nfs.sh
Use NFS instead of vboxsf in Docker Machine
#!/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
#
@0xradical
0xradical / credo_1.rb
Created May 22, 2018 12:02
Inconsistência no código
# 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
@0xradical
0xradical / credo_2.ex
Created May 22, 2018 12:03
Dependência no mix.exs
defp deps do
[
{:credo,"~> 0.8", only: [:dev, :test], runtime:false}
]
end
@0xradical
0xradical / credo_3.groovy
Created May 22, 2018 12:06
Snippet demonstrando execução do pronto
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"
//...
}
@0xradical
0xradical / credo_4.ex
Created May 22, 2018 12:08
Código exemplo em Elixir
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