Skip to content

Instantly share code, notes, and snippets.

View straypacket's full-sized avatar

Daniel Pereira straypacket

  • Shibuya, Tokyo, Japan
View GitHub Profile
@straypacket
straypacket / dc_demo.html
Last active December 31, 2015 19:19
DC.js demo
<!DOCTYPE html>
<html lang="en">
<head>
<title>dc.js - Demo</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="http://nickqizhu.github.io/dc.js/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="http://nickqizhu.github.io/dc.js/css/dc.css"/>
@straypacket
straypacket / mongo.js
Last active December 29, 2015 14:49
Journal: Context for MongoDB + geo alerts
// Aggregate users and count location updates
db.locations.aggregate([
{ $group: {_id: "$locatable_id", number: {$sum: 1} }},
{ $sort: { "number": -1}}
])
// Get all updates from a user, ordered by time
db.locations.find(
{ "locatable_id": ObjectId("51ac7bccee4340adef00000d") },
{'_id': 0, 'coordinates': 1, 'created_at': 1}
@straypacket
straypacket / number-of-disc-intersections.rb
Last active December 28, 2015 07:48
Codility - Number-of-disc-intersections Still working on it :/
def solution(a)
radii = {}
a.count.times do |c|
(c-a[c]..c+a[c]).to_a.each do |r|
radii[r] = [] if !radii.key?(r)
radii[r] << c
end
end
combs = []
@straypacket
straypacket / genomic-range-query.rb
Created November 14, 2013 00:44
Codility - Lesson 3 Genomic-range-query 66/100
def solution(s, p, q)
v = {"A" => 1, "C" => 2, "G" => 3, "T" => 4}
min_nuc = []
if s!= nil and p != nil and q != nil
if p.length > 0 and q.length > 0
if p.length == q.length
p.length.times.each do |i|
max = 5
s[p[i]..q[i]].each_char do |c|
max = v[c] if v[c] < max
@straypacket
straypacket / frog-river-one.rb
Last active December 28, 2015 04:58
Codility - Lesson 2 Frog-River-One (100/100) Max-Counters (88/100)
def solution(x, a)
counter = 0
path = {}
if x != nil and a != nil
if x > 0 and a.length > 0
pos = 0
a.each do |i|
if !path.key?(i) and i <= x
counter += 1
end
@straypacket
straypacket / README.md
Last active December 26, 2015 17:59
PyTables + PostgreSQL

Usage

Schema

The file schema.py defines the schema used for PyTables, and therefore should be run first.

We'll be creating three tables, according to the data already available in the PostgreSQL server:

  • SensorData - This table will have data from each MAC address, per day

  • minified_raw_data - This sub-table has raw data from the routers

@straypacket
straypacket / hierarchical_clustering.rb
Last active December 26, 2015 04:49
Analysis of passers-by vs stable clients, over wifi mac monitoring
# Do this in a rails console @ footprint-tracker
# Weekend
we = [12, 13, 14, 19, 20]
#Workdays
wd = [11, 15, 16, 17, 18, 21, 22, 23]
#2D Matrices for weekend and worddays, Weekdays x Requests_per_distinct_mac
we_a = []
wd_a = []
@straypacket
straypacket / sinatra.rb
Last active December 20, 2015 16:29
Sample Sinatra server
##
# Call with:
# curl -i -H "Accept: application/json" "http://localhost:4567/?foo=1"
# or post with:
# curl -X POST -H "Accept: application/json" "http://localhost:4567/?foo=1" --data "foo=2"
##
require 'rubygems'
require 'sinatra'
require 'json'
@straypacket
straypacket / tws.py
Last active December 19, 2015 08:19
Tornado websocket server and html client
import tornado.httpserver
import tornado.websocket
import tornado.ioloop
import tornado.web
import time
import random
# Preload data
# ... use from previous gists
#import numpy as np
@straypacket
straypacket / index.html
Created June 26, 2013 23:58
Hierarchical edge bundling, adapted from Mike Bostock's work and Danny Holten's paper: http://www.win.tue.nl/~dholten/papers/bundles_infovis.pdf
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<link type="text/css" rel="stylesheet" href="flare-style.css"/>
<style type="text/css">
path.arc {
cursor: move;
fill: #fff;
}