Skip to content

Instantly share code, notes, and snippets.

@guilespi
guilespi / census2011.r
Created May 18, 2013 18:15
Census data 2011
> viviendas <- read.table("Viviendas.dat", header=T, sep="\t")
> head(viviendas)
DPTO LOC SECC SEGM VIVID VIVVO01 VIVVO03 VIVVO04 VIVDV01 VIVDV02 VIVDV03 VIVDV05 VIVDV06 VIVDV07 VIVHV01 VIVHV01_1 CATEVIV
1 1 20 1 1 1 9 3 2 0 0 0 0 0 0 0 0 0
2 1 20 1 1 2 1 4 0 0 0 0 0 0 0 0 0 0
3 1 20 1 1 3 3 1 0 1 1 1 1 1 1 1 1 1
4 1 20 1 1 4 3 1 0 1 1 1 1 1 1 1 1 1
5 1 20 1 1 5 3 1 0 1 1 1 1 1 1 1 1 1
6 1 20 1 1 6 1 6 0 0 0 0 0 0 0 0 0 0
@guilespi
guilespi / call.clj
Created January 29, 2013 19:28
Build yourself a dialer with Clojure and Asterisk
(ns dispatchers.call
(:require [clj-asterisk.manager :as manager]
[clj-asterisk.events :as events]
[dispatchers.model :as model])
(:import java.util.UUID))
;; Signal the end of the call to the waiting promise in order to
;; release the channel
(defmethod events/handle-event "Hangup"
[event context]
(ns notify-blaster.models.validation.user)
(def rules
{ :username {:validations
{:required true
:unique true
:max-length 50}
:messages
{:required "User name is required"
:unique "User name %s is already in use, please choose another one"
(ns notify-blaster.models.validation.core)
(def ^{:dynamic true} *is-unique?* (fn [value] false))
(def ^{:dynamic true} *default-messages* {:unique "Value %s is aready taken, please choose another one"
:required "Field is required"
:min-length "Field is shorter than required"
:max-length "Field is longer than required"
:range "Field value %s is not in range"
:email "Field must be a valid email address"
:matches "Fields do not match"})
@guilespi
guilespi / response times by language.sql
Created October 31, 2012 01:46
StackOverflow response times by language, easy questions
select TagName,
avg(cast(ResponseTime as bigint)) as Average,
stdev(cast(ResponseTime as bigint)) as StandardDev
from
(SELECT
Questions.CreationDate,
Questions.Title,
Tags.TagName,
Answers.CreationDate as ResponseDate,
datediff(minute, Questions.CreationDate,
@guilespi
guilespi / response time by hour.sql
Created October 31, 2012 01:43
StackOverflow response times by language, grouped by hour
DECLARE @tagname varchar(20) = ##language:string##
select ResponseHour,
avg(cast(ResponseTime as bigint)) as Average,
stdev(cast(ResponseTime as bigint)) as StandardDev
from
(SELECT
Questions.CreationDate,
Questions.Title,
@guilespi
guilespi / questions by category.sql
Created October 31, 2012 01:42
How many language questions are in each difficulty category
DECLARE @tagname varchar(20) = ##language:string##
select DifficultyGroup, Count(1) Total,
avg(cast(ResponseTime as bigint)) as Average,
stdev(cast(ResponseTime as bigint)) as StandardDev
from
(SELECT
Questions.CreationDate,
Questions.Title,
Tags.TagName,
@guilespi
guilespi / qstk-tutorial1.clj
Created October 29, 2012 03:05
QSTK Tutorial 1 in Clojure
(ns qstk.tutorial1
(:use [clj-time.core :exclude 'extend])
(:use clj-time.format)
(:use clj-time.coerce)
(:require incanter.io)
(:require incanter.core))
(def ^{:dynamic true} *QS* (get (System/getenv) "QS"))
(defn get-NYSE-days
@guilespi
guilespi / run.clj
Created October 29, 2012 03:02
Running the QSTK tutorial in clojure
(defn run
[]
(let [symbols ["AAPL","GLD","GOOG","$SPX","XOM"]
start-day (date-time 2012 1 1)
end-day (date-time 2012 12 31)
time-of-day (hours 16)
timestamps (get-NYSE-days start-day end-day time-of-day)
symbols-data (read-symbols-data "Yahoo" symbols)
adj-close-data (incanter.core/to-dataset
(get-data timestamps symbols (keyword "Adj Close") symbols-data time-of-day))]
@guilespi
guilespi / row-operation.clj
Created October 29, 2012 02:59
Iterating over a dataset to apply specific functions to each row
(defmacro apply-filtered
"Given two sequences, apply a function to each pair of elements when condition is met
anaphoras n and m exists for each indexed element
e.g. (apply-filtered / [1 2 3] [1 0 3] when (> m 0)) => (1 nil 1)
"
[op a b & condition]
`(for [x# (range (count ~a))]
(let [n# (nth ~a x#)