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 / 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 / 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 / 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 / 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 / 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 / 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 / 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])