Skip to content

Instantly share code, notes, and snippets.

View gberger's full-sized avatar

Guilherme Berger gberger

View GitHub Profile
@gberger
gberger / time_to_date.rb
Created February 25, 2014 23:47
Time#to_date (Ruby monkey patch)
class Time
def to_date
Date.parse(self.to_s)
end
end
_ = require('underscore')
w = (str) -> str.split(' ')
cities =
"Arad": {name: "Arad", distance: 366, neighbors: w "Zerind Timisoara Sibiu"}
"Bucharest": {name: "Bucharest", distance: 0, neighbors: w "Urziceni Giurgiu Pitesti Fagaras"}
"Craiova": {name: "Craiova", distance: 160, neighbors: w "Drobeta Pitesti Rimnicu"}
"Drobeta": {name: "Drobeta", distance: 242, neighbors: w "Mehadia Craiova"}
"Eforie": {name: "Eforie", distance: 161, neighbors: w "Hirsova"}
@gberger
gberger / befunge.coffee
Last active August 29, 2015 13:56
Befunge interpreter in CoffeeScript
interpret = (code) ->
commands =
'+' : =>
@stack.push(@stack.pop() + @stack.pop())
'-' : =>
@stack.push(-@stack.pop() + @stack.pop())
'*' : =>
@stack.push(@stack.pop() * @stack.pop())
class Player
attr_accessor :name, :points, :explosions
def initialize(name)
@name = name
@points = 0
@explosions = 0
end
def add_points(pts)
fromNow = (d) ->
unless d instanceof Date
d = new Date(d)
difference = d - new Date()
# string, limit, divider
limits = [
["momentos", 1000, 1]
["%d segundos", 1000*60, 1000]
mapize = (str, pairSeparator, keyValueSeparator, fnKey, fnValue) ->
map = {}
for pair in str.split(pairSeparator)
[key, value...] = pair.split(keyValueSeparator)
map[fnKey(key)] = fnValue(value.join('='))
return map
urlParams = ->
mapize(window.location.search.substring(1), '&', '=', decodeURIComponent, decodeURIComponent)
@gberger
gberger / test-io.sh
Last active August 29, 2015 13:59
Test all io.vtex.com.br dependencies
for i in `find src -type f -name \*.html | xargs grep 'io.vtex.com.br[^"]*' -oh`; do echo $i; echo -ne ' -> '; curl -Is $i | head -1; done
@gberger
gberger / grades.txt
Created April 17, 2014 03:10
Grade equivalence for PUC students who participated in student exchange in the USA
A+ 10
A 10
A- 9.6
B+ 8.8
B 8.4
B- 8
C+ 7.5
C 7
C- 6.5
D+ 6
@gberger
gberger / INF.txt
Last active August 29, 2015 14:01
INF
INF1001 - INTR CIENCIA DA COMPUTACAO
INF1002 - CALCULO NUMERICO
INF1004 - PROGRAMACAO P/ INFORMATICA I
INF1005 - PROGRAMACAO I
INF1006 - PROGRAMACAO P/ INFORMATICA II
INF1007 - PROGRAMACAO II
INF1008 - INTROD ARQ DE COMPUTADORES
INF1009 - LOGICA PARA COMPUTACAO
INF1010 - ESTRUTURAS DE DADOS AVANCADAS
INF1011 - SEMANTICA DE LINGUAGENS
@gberger
gberger / gist:b0eb143d41a0b57070a2
Created June 14, 2014 20:53
Batch convert DOC to PDF
#!/usr/bin/env bash
# Requires LibreOffice
# Use `find` if you need something more advanced
files=`echo *.doc`
for file in $files; do lowriter --convert-to pdf:writer_pdf_Export $file; done