Skip to content

Instantly share code, notes, and snippets.

View brodock's full-sized avatar

Gabriel Mazetto brodock

View GitHub Profile
@brodock
brodock / wordcounter_bot.rb
Created March 14, 2014 15:27
This snippet is used to get a bunch of articles from a txt file (each url in a new line) and count the amount of words of each, sum it up at the end
require 'mechanize'
require 'readability'
require 'progress'
require 'nokogiri'
list = File.readlines('./urls_to_count.txt').map{|line| line.chomp}
agent = Mechanize.new
articles = []
list.with_progress("Loading articles") do |url|
@brodock
brodock / update-alternatives-ruby
Last active December 29, 2015 15:49
Setting update-alternatives for ubuntu as a way to change system ruby with compiled one
# update-alternative (install)
sudo update-alternatives --install /usr/bin/ruby ruby2.0 /opt/rubies/2.0.0-p353/bin/ruby 0
sudo update-alternatives --install /usr/bin/erb erb2.0 /opt/rubies/2.0.0-p353/bin/erb 0
sudo update-alternatives --install /usr/bin/gem gem2.0 /opt/rubies/2.0.0-p353/bin/gem 0
sudo update-alternatives --install /usr/bin/irb irb2.0 /opt/rubies/2.0.0-p353/bin/irb 0
sudo update-alternatives --install /usr/bin/rake rake2.0 /opt/rubies/2.0.0-p353/bin/rake 0
sudo update-alternatives --install /usr/bin/rdoc rdoc2.0 /opt/rubies/2.0.0-p353/bin/rdoc 0
sudo update-alternatives --install /usr/bin/ri ri2.0 /opt/rubies/2.0.0-p353/bin/ri 0
sudo update-alternatives --install /usr/bin/testrb testrb2.0 /opt/rubies/2.0.0-p353/bin/testrb 0
@brodock
brodock / gist:6196371
Created August 9, 2013 19:18
Correção de escrita de nomes com acentuação em português (capitalize)
require 'unicode_utils'
UnicodeUtils.titlecase(word).gsub(/(( )(da|de|di|do|du|das|dos|e|a|o))/i) {|s| s.downcase}
@brodock
brodock / gist:4950205
Last active December 13, 2015 17:48
Ruby on Ubuntu
# Source: Brightbox (http://wiki.brightbox.co.uk/docs:ruby-ng)
sudo apt-get install python-software-properties
sudo apt-add-repository ppa:brightbox/ruby-ng
sudo apt-get update
sudo apt-get install ruby rubygems ruby-switch
sudo apt-get install ruby1.9.3
# Switching ruby version:
ruby-switch --list
sudo ruby-switch --set ruby1.9.1
@brodock
brodock / grouparray.php
Created September 17, 2012 23:29
GroupArray
<?php
/**
* Estrutura de dados semelhante ao Array() do php, que permite armazenar mais
* de um dado em uma mesma chave
*
* @author Gabriel Mazetto
*/
class GroupArray {
@brodock
brodock / .zshrc
Created July 22, 2012 01:26
Oh My Zshell
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
@brodock
brodock / gist:3092672
Created July 11, 2012 19:34
Relatorio Header
public function default_table($dadostabela, $css_class, $header) {
// TODO: Verificar como vai funcionar permissões para visualização dos relatórios
//$bulkoperations = has_capability('moodle/course:bulkmessaging', CONTEXT_SYSTEM);
//criacao da tabela
$table = new report_unasus_table();
$table->attributes['class'] = "relatorio-unasus $css_class generaltable";
$table->tablealign = 'center';
@brodock
brodock / .gitconfig
Last active October 6, 2015 14:18
.gitconfig
[user]
name = Gabriel Mazetto
email = brodock@gmail.com
[color]
ui = auto
diff = auto
status = auto
[alias]
co = checkout
cm = commit
@brodock
brodock / gist:2925680
Created June 13, 2012 18:29
Middleware Connection
<?php
/**
* Classe de conexão com o Middleware UFSC (Singleton)
*/
class Academico {
/**
* Referência ao acesso a base de dados
*/
@brodock
brodock / bash git branch
Created March 23, 2010 18:35
Git branch on Shell
# colocar no ~/.profile
# Git Branch
function parse_git_branch {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'
}
GREEN="\[\e[0;32m\]"
YELLOW="\[\e[0;33m\]"
NC="\[\e[0m\]"