Skip to content

Instantly share code, notes, and snippets.

View jweslley's full-sized avatar

Jonhnny Weslley jweslley

View GitHub Profile
@jweslley
jweslley / LaTeX Brazilian
Created August 25, 2009 16:38
LaTeX Brazilian
% apt-get install texlive-portuguese
\usepackage[brazilian]{babel}
/*
* This is the Towers of Hanoi example from the prolog tutorial [1]
* converted into Scala, using implicits to unfold the algorithm at
* compile-time.
*
* [1] http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_3.html
*/
object TowersOfHanoi {
import scala.reflect.Manifest
package net.abhinavsarkar.util;
import java.util.Iterator;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
@jweslley
jweslley / recover grub
Created July 6, 2010 15:11
recover grub
sudo grub
root (hd0,1)
setup (hd0)
quit
@jweslley
jweslley / seeds.rb
Created July 21, 2010 14:08
Rails: loading seeds from csv
require 'csv'
CSV.foreach('path/to/seed.csv', headers: true, col_sep: ';') do |row|
Model.create row.to_hash
end
@jweslley
jweslley / big_o.r
Created April 12, 2011 16:58
Running time of common time complexities
big_O.plot <- function(count,log="") {
n <- seq(count)
plot(n, n*n, log=log, type='l', col='red',
ylab="Running time", xlab='n (# of elements)')
lines(n, n*log(n), col='green')
lines(n, n, col='blue')
lines(n, log(n), col='black')
title('Running time of common time complexities')
@jweslley
jweslley / asciiplot.sh
Created December 28, 2011 18:52
ASCII plot
usage(){
echo "Usage: $(basename $0) [-c <cols>] [-r <rows>] [-p <pch>]"
exit 2
}
cols=50
rows=20
pch="*"
while getopts "c:r:p:h" option; do
case "$option" in
@jweslley
jweslley / rails.logrotate
Created January 30, 2012 14:01
Logrotate for Rails
#
# File: /etc/logrotate.d/rails
# Test: logrotate -f /etc/logrotate.d/rails
#
/var/www/*/log/*.log {
daily
dateext
notifempty
missingok
rotate 30
@jweslley
jweslley / export_csv.sql
Created August 9, 2012 19:43
Dump MySQL table into CSV file
SELECT * INTO OUTFILE 'result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM my_table;
@jweslley
jweslley / gitlab.sh
Last active December 16, 2015 12:49
Backup script to Gitlab
#!/bin/sh
# Usage:
# - Save this file in /etc/cron.daily/gitlab
# - Enable execution permission: chmod +x /etc/cron.daily/gitlab
set -e
DB_USERNAME=username
DB_PASSWORD=secret
BACKUP_DIR='/path/to/backup/'