Skip to content

Instantly share code, notes, and snippets.

View ricardotealdi's full-sized avatar

Ricardo Tealdi ricardotealdi

View GitHub Profile
package br.com.tealdi.testing;
import java.text.Normalizer;
public class Hyphenator {
public String hyphenizeIt(String text) {
return trimmingHyphens(
removeNonCharactersButHyphen(
convertSpacesIntoHyphens(
@ricardotealdi
ricardotealdi / js-di-example.js
Created November 9, 2011 20:56
Javascript dependency injection example
var Calculator = (function () {
"use strict";
function sum(firstNumber, secondNumber) {
return firstNumber + secondNumber;
}
return {
sum : sum
};
@ricardotealdi
ricardotealdi / word_generator.rb
Last active February 11, 2018 11:50
Simple Pronounceable Word Generator in Ruby
class WordGenerator
VOGALS = %w(a e i o u y)
CONSONANTS = [*?a..?z] - VOGALS
MOD_RESULT = [0, 1].freeze
def initialize(length)
@length = length
@mod_result = MOD_RESULT.sample
end
@ricardotealdi
ricardotealdi / consumer.pl
Created July 7, 2015 22:12
Directory Based Queue
use strict;
use warnings;
use Directory::Queue::Simple;
my $dirq = Directory::Queue::Simple->new(path => "/tmp/test");
my $done = 0;
for(my $name = $dirq->first(); $name; $name = $dirq->next()) {
next unless $dirq->lock($name);
my $data = $dirq->get($name);
printf("Body: \"%s\"\n", $data);
@ricardotealdi
ricardotealdi / learner.rb
Last active November 8, 2015 17:18
Improve vocabulary script by repetition
data = {
"amid" => ["em meio a", "no meio de", "entre"],
"bliss" => ["êxtase", "felicidade"],
"at first glance" => ["à primeira vista"],
"slumber" => ["dormir"],
"thrash out" => ["debater", "discutir"],
"plea" => ["apelo"],
"attire" => ["vestuário", "traje"],
"blunt" => ["brusco"],
"newlyweds" => ["recém-casados"],
@ricardotealdi
ricardotealdi / update_outdated.sh
Created February 29, 2016 20:01
Update outdated gems
clear; bundle outdated --strict 3>&1 1>&2 2>&3 |
grep '*' |
grep -v -E "(test|development)" |
awk '{ print $2 }' 3>&1 1>&2 2>&3 |
while read gem
do
echo -e "\nUpdating $gem...\n"
bundle update $gem
bundle exec rspec --fail-fast
test_exit_status=$?
@ricardotealdi
ricardotealdi / tictactoe.rb
Last active March 26, 2016 02:53
tic tac toe
# Usage: ruby -e "$(curl -s https://gist.githubusercontent.com/ricardotealdi/797f25e4020c5f8e8aff/raw/<HASH>/tictactoe.rb)"
board_add = -> (board, x, y, piece) { board[y][x] ? nil : board[y][x] = piece }
board_print = lambda do |board|
puts ""
puts ' 1 2 3'
board.each_with_index do |row, index|
format_row = row.map { |it| it.nil? ? ' ' : it.to_s.upcase }.join ' | '
puts(
@ricardotealdi
ricardotealdi / reporter.rb
Last active June 14, 2016 14:39
Periodic reporter with InfluxDB on Ruby
require 'influxdb'
require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/hash/deep_merge'
require 'yaml'
require 'thread'
class Registry
def initialize(options = {})
@mutex = Mutex.new
@metrics = {}