Skip to content

Instantly share code, notes, and snippets.

View plot.awk
#!/usr/bin/awk -f
# This program is a copy of guff, a plot device. https://github.com/silentbicycle/guff
# My copy here is written in awk instead of C, has no compelling benefit.
# Public domain. @thingskatedid
# Run as awk -v x=xyz ... or env variables for stuff?
# Assumptions: the data is evenly spaced along the x-axis
# TODO: moving average
@israelst
israelst / getAllColors.js
Last active Mar 19, 2019
Get all colors used in a webpage.
View getAllColors.js
const els = document.querySelectorAll('*');
const isColorProperty = property => property.toLowerCase().indexOf('color') > -1;
colors = new Set();
for(el of els)
for(property in getComputedStyle(el))
if(isColorProperty(property))
colors.add(getComputedStyle(el)[property])
console.dir(colors.entries())
View overlay.css
.overlay{
position: relative;
}
.overlay > *{
position: relative;
z-index: 1;
}
.overlay:before{
@israelst
israelst / chunk_indexes.py
Last active Feb 3, 2019
Helper functions to data structures hacking
View chunk_indexes.py
def chunk_indexes(size, chunk_size):
start = (size % chunk_size) or chunk_size
upper_boundary = list(range(start, size + 1, chunk_size))
lower_boundary = [0] + upper_boundary[:-1]
return zip(lower_boundary, upper_boundary)
@israelst
israelst / GNIP_Historical_parse.py
Created May 25, 2016
GNIP Historical PowerTrack parse
View GNIP_Historical_parse.py
# coding: utf-8
import json
fd = open('all.json')
lines = fd.readlines()
tweets = map(json.loads, lines)
ptBR_tweets = filter(lambda l: l['language']=='pt', tweets)
@israelst
israelst / keys_from_dicts.py
Created Oct 1, 2015
Return a list of unique keys from a list of dicts.
View keys_from_dicts.py
def keys_from_dicts(dicts):
all_keys = sum(map(dict.keys, dicts), [])
return list(set(all_keys))
@israelst
israelst / mini-gitflow-example.sh
Last active Aug 29, 2015
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):
View mini-gitflow-example.sh
(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 / preprocess.js
Last active Aug 29, 2015
Function that turns Facebook insights into a flat structure.
View preprocess.js
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 / insights.html
Last active Aug 29, 2015
Show facebook post data with d3.parcoords
View insights.html
<!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 / csv2json.py
Last active Dec 25, 2015
From csv to json in one twitt
View csv2json.py
import csv, json
f = open('sample.csv', 'r')
reader = csv.DictReader(f, fieldnames=("col1","col2"))
print json.dumps(list(reader))
You can’t perform that action at this time.