Skip to content

Instantly share code, notes, and snippets.

@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 / Tutorial1.py
Created October 29, 2012 02:07
QSTK Tutorial 1
'''
(c) 2011, 2012 Georgia Tech Research Corporation
This source code is released under the New BSD license. Please see
http://wiki.quantsoftware.org/index.php?title=QSTK_License
for license details.
Created on September, 12, 2011
@author: Tucker Balch
@contact: tucker@cc.gatech.edu
@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 / 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#)
@guilespi
guilespi / get-data.clj
Created October 29, 2012 02:25
Build a matrix from stock datasets
(defn select-value
"Given a dataset indexed by date, returns the value corresponding to a specified column
if existent for a specific date"
[ds column date]
(let [row (ds {:Date date})]
(when-not (nil? row) (incanter.core/$ 0 column row))))
(defn get-data
"Given a list of `symbols`, its data and a list of specific `timestamps`, builds a matrix(sequence)
with each column corresponding to a stock and the value extracted using `column`