This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function create_iterator(list){ | |
var index = 0; | |
return function(){ | |
if(index == list.length){ | |
return false; | |
}else{ | |
return list[index++]; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function create_fibonacci(){ | |
var n1 = -1, | |
n2 = 1, | |
n = 0; | |
return function(){ | |
n = n1 + n2; | |
n1 = n2; | |
n2 = n; | |
return n; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function apply_template($template_path, $vars = array()){ | |
ob_start(); | |
extract($vars); | |
include($template_path); | |
$ob_contents = ob_get_contents(); | |
ob_end_clean(); | |
return $ob_contents; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function test($expected, $obtained){ | |
if($expected != $obtained){ | |
return "Falha, $expected é diferente de $obtained"; | |
}else{ | |
return "Ok"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this one comes from the book | |
def divide(x, y) | |
return {:q => 0, :r => 0} if x==0 | |
result = divide(x/2, y) | |
result[:q] *= 2 | |
result[:r] *= 2 | |
result[:r] += 1 if x.odd? | |
if result[:r] >= y | |
result[:r] -= y | |
result[:q] += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
p(){ | |
cd $(find ~/Projects/ -name $1) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def merge(x, y): | |
if len(x) == 0: | |
return y | |
if len(y) == 0: | |
return x | |
last = y.pop() if x[-1] < y[-1] else x.pop() | |
# 'merged' is required because the append method is in place | |
merged = merge(x, y) | |
merged.append(last) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def max_sum(vector): | |
return cubic_solution(vector) | |
def cubic_solution(vector): | |
max_sum = 0 | |
for i in range(len(vector) + 1): | |
for j in range(i): | |
partial_sum = sum(vector[j:i]) | |
max_sum = max(partial_sum, max_sum) | |
return max_sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv, json | |
f = open('sample.csv', 'r') | |
reader = csv.DictReader(f, fieldnames=("col1","col2")) | |
print json.dumps(list(reader)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Curto Café Facebook Page</title> | |
<script src="preprocess.js" charset="utf-8"></script> | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
<script src="http://syntagmatic.github.io/parallel-coordinates/d3.parcoords.js" charset="utf-8"></script> | |
<link href="http://syntagmatic.github.io/parallel-coordinates/d3.parcoords.css" rel="stylesheet" /> | |
</head> |
OlderNewer