Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am caarlos0 on github.
  • I am becker (https://keybase.io/becker) on keybase.
  • I have a public key whose fingerprint is C4AE F954 837E 8203 58B9 90C4 E61E 2F7D C14A B940

To claim this, I am signing this object:

#!/bin/bash -e
# common stuff
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y ubuntu-restricted-extras git zsh terminator curl xsel \
gnome-tweak-tool vim-nox smbclient htop openssh-server s3cmd openvpn network-manager-openvpn
# chrome
wget -O chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
@caarlos0
caarlos0 / elections.rb
Last active June 4, 2016 13:00
My Ruby script to list the top-3 president candidates in Brazilian 2014 elections. Updated with second round data as well. http://carlosbecker.com/posts/elections/
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|
@caarlos0
caarlos0 / MyClassTest.java
Last active June 4, 2016 13:02
An example of how to use JUnit `@Rule` to test methods who are expected to thrown an exception.
package sample;
import org.junit.*;
import org.junit.rules.ExpectedException;
import sample.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
public class MyClassTest {

I found the Eclipse IDE to be painfully slow. My solution for that is to change some memory configs in eclipse.ini and remove some useless things (useless for me, at least).

cd $ECLIPSE_HOME
find . -iname '*jpa*' -exec rm -rf {} \;
find . -iname '*cvs*' -exec rm -rf {} \;

things I changed in my eclipse.ini:

@caarlos0
caarlos0 / for.less
Created June 6, 2014 15:00
LESS loop with variable interpolations (recursive).
.generate-cols(@n, @i: 1) when (@i =< @n) {
@var: ~"col@{i}";
input.col@{i},
.col@{i} {
width: @@var;
}
.table-default td.col@{i} {
max-width: @@var;
}
.generate-cols(@n, (@i + 1));
@caarlos0
caarlos0 / eq.or.higher.than.9.2.sql
Created June 3, 2014 19:25
PostgreSQL query monitoring (deadlocks and shit)
SELECT bl.pid AS blocked_pid,
a.usename AS blocked_user,
ka.query AS blocking_statement,
now() - ka.query_start AS blocking_duration,
kl.pid AS blocking_pid,
ka.usename AS blocking_user,
a.query AS blocked_statement,
now() - a.query_start AS blocked_duration
FROM pg_catalog.pg_locks bl
JOIN pg_catalog.pg_stat_activity a ON a.pid = bl.pid
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans
#!/bin/sh -e
echo "Creating a new jekyll site..."
jekyll new bug
cd bug
echo "Creating needed folders..."
mkdir -p _assets/stylesheets
mkdir _plugins
---------------------------------------------------------------------------------------------------------
# app/helpers/application_helper.rb
---------------------------------------------------------------------------------------------------------
def horizontal_simple_form_for(record, options={}, &block)
options[:html] ||= {}
options[:html][:class] = "form-horizontal #{options[:html][:class]}".rstrip
options[:wrapper] = :bootstrap_horizontal
simple_form_for(record, options, &block)
end
---------------------------------------------------------------------------------------------------------