Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
function is_mac() {
if [ `uname -s` = "Darwin" ]; then
return 0
else
return 1
fi
}

Keybase proof

I hereby claim:

  • I am felipernb on github.
  • I am felipernb (https://keybase.io/felipernb) on keybase.
  • I have a public key whose fingerprint is 8D4A 1D47 F552 1FBF 3D38 B844 E377 FFCC 6551 ABB6

To claim this, I am signing this object:

@felipernb
felipernb / gist:4130285
Created November 22, 2012 09:48
Extracts unique uris from nginx access log
cat access.log | awk -F'"' '{print $2}'| cut -d ' ' -f2 | uniq > uris.log
@felipernb
felipernb / BowlingGame.java
Created October 30, 2012 17:05
Bowling Game in Java
package com.feliperibeiro.bowling;
public class BowlingGame {
int[] rolls;
int currentRoll;
public BowlingGame() {
this.rolls = new int[21];
}
@felipernb
felipernb / factorial.c
Created October 22, 2012 18:53
Factorial in C
long recurFact(int n) {
if (n == 0) return 1L;
return n * recurFact(n-1);
}
long iterFact(int n) {
long fact = 1;
for (; n > 1; n--) fact *= n;
return fact;
}
@felipernb
felipernb / skyline.rb
Created October 19, 2012 12:39
Skyline problem in Ruby
#http://acm.uva.es/p/v1/105.html
buildings = [[1,11,5], [2,6,7], [3,13,9], [12,7,16], [14,3,25], [19,18,22], [23,13,29], [24,4,28]]
def skyline(buildings)
#initialize the skyline setting 0 in all points
line_size = 0
buildings.each {|b| line_size = [line_size, b[2]].max}
line = Array.new(line_size+1).fill(0)
buildings.each {|b| (b[0]..b[2]-1).each {|x| line[x] = [line[x], b[1]].max}}
@felipernb
felipernb / maximum_subarray.go
Created October 15, 2012 08:39
Maximum Subarray in Go
func MaxSubarray(a []int) []int {
currentSumStart := 0
currentSum := 0
maxSumStart := 0
maxSumEnd := 0
maxSum := 0
for currentSumEnd := 0; currentSumEnd < len(a); currentSumEnd++ {
currentSum += a[currentSumEnd]
@felipernb
felipernb / factorial.go
Created October 6, 2012 19:56
Factorial in Go
func factorial(n int) int64 {
fact := int64(1)
for i := int64(n); i > 0; i-- { fact *= i }
return fact
}
@felipernb
felipernb / quicksort.py
Created September 27, 2012 10:06
Quicksort in Python
import random
def quicksort(a, l, r):
if l >= r:
return a
p = partition(a, l, r)
quicksort(a, l, p)
quicksort(a, p+1, r)
return a
@felipernb
felipernb / insertion_sort.go
Created September 26, 2012 14:05
Insertion Sort in Go
package sorting
func InsertionSort(a []int) []int {
for i := 1; i < len(a); i++ {
n := a[i]
j := i
for j > 0 && a[j-1] > n {
a[j] = a[j-1]
j--
}