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 / rdelay.py
Last active August 29, 2015 13:57
Delay between processes
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pylab
import datetime as dt
##
# Response time analysis
df_tbi = pd.DataFrame(np.arange(1,8))
df_tbi['response_cal_time'] = np.array([850,4345,19000,5827,3904,2756,8550])
@straypacket
straypacket / pseudo_facebook.py
Last active August 29, 2015 13:57
Udacity EDA course
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pylab
plt.rcParams['font.size'] = 8.0
plt.rcParams['figure.figsize'] = 6.0, 4.0
df = pd.DataFrame.from_csv('/Users/gsc//Dropbox/datasets/pseudo_facebook.tsv', sep='\t')
@straypacket
straypacket / wifi_math.rb
Last active August 29, 2015 13:57
Linalg for wifi
require 'linalg'
include Linalg
# Linear equation to solve:
# a * x = b
#
# Example
# a = DMatrix[[1,0,0],[0,2,0],[0,0,1]]
# b = DMatrix[[1,1],[2,2],[3,3]]
#
@straypacket
straypacket / freq_vs_bayes.py
Last active August 29, 2015 13:57
Using SciPy, NumPy and PyPlot to show vertical error bar graphs. Notes on comparison of Frequentism vs. Bayesianism.
import numpy as np
from scipy import stats
np.random.seed(1)
F_true = 1000 # random range
N = 50 # number of measurements
F = stats.poisson(F_true).rvs(N)
e = np.sqrt(F) # errors on Poisson counts estimated via square root
@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