Skip to content

Instantly share code, notes, and snippets.

@israelst
israelst / insights.html
Last active August 29, 2015 14:20
Show facebook post data with d3.parcoords
<!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>
@israelst
israelst / preprocess.js
Last active August 29, 2015 14:20
Function that turns Facebook insights into a flat structure.
function preprocess(post){
var flatPost = post.insights.data.reduce(function(post, insight){
post[insight.name] = insight.values[0].value;
return post;
}, {});
flatPost.likes = post.likes.summary.total_count;
flatPost.comments = post.comments.summary.total_count;
flatPost.shares = (post.shares || {'count': 0}).count;
@israelst
israelst / mini-gitflow-example.sh
Last active August 29, 2015 14:20
This is a example to show a reduced version of gitflow. We are considering two remotes at local repository, the origin (fork) and the upstream (central):
(master) $ # starting a new task
(master) $ git pull --ff-only upstream master
(master) $ git checkout -b feature/new-task
(feature/new-task) $ # some coding
(feature/new-task) $ git add -p
(feature/new-task) $ git commit -m "The answer of all questions of the universe"
(feature/new-task) $ git push origin feature/new-task
(feature/new-task) $ # Do a pull request from feature/new-task to master and wait for coworker acceptance
(feature/new-task) $ git checkout master
(master) $ git pull --ff-only upstream master
@israelst
israelst / lazy_fib.js
Last active September 27, 2015 08:27
A lazy fibonacci example written in javascript
function create_fibonacci(){
var n1 = -1,
n2 = 1,
n = 0;
return function(){
n = n1 + n2;
n1 = n2;
n2 = n;
return n;
}
@israelst
israelst / iterator.js
Created September 25, 2011 04:49
An example of how to maintain state with closures
function create_iterator(list){
var index = 0;
return function(){
if(index == list.length){
return false;
}else{
return list[index++];
}
}
}
@israelst
israelst / template.php
Created November 5, 2011 00:27
Templating PHP
<?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;
}
@israelst
israelst / tester.php
Created November 5, 2011 10:00
Mini tester
<?php
function test($expected, $obtained){
if($expected != $obtained){
return "Falha, $expected é diferente de $obtained";
}else{
return "Ok";
}
}
@israelst
israelst / division.rb
Created March 15, 2012 03:29
Division, Papadimitriou Book
# 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
@israelst
israelst / keys_from_dicts.py
Created October 1, 2015 21:02
Return a list of unique keys from a list of dicts.
def keys_from_dicts(dicts):
all_keys = sum(map(dict.keys, dicts), [])
return list(set(all_keys))
#!/bin/bash
p(){
cd $(find ~/Projects/ -name $1)
}