Skip to content

Instantly share code, notes, and snippets.

<body>
<script>
var colors = ["#F7977A","#F9AD81","#FDC68A","#FFF79A","#C4DF9B","#A2D39C","#82CA9D","#7BCDC8","#6ECFF6","#7EA7D8","#8493CA","#8882BE","#A187BE","#BC8DBF","#F49AC2","#F6989D"];
var i = 0;
setInterval(function(){
i++
if (i>=colors.length) {
i=0;
}
<body>
<script src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js'></script>
<script>
var colors = ["#F7977A","#F9AD81","#FDC68A","#FFF79A","#C4DF9B","#A2D39C","#82CA9D","#7BCDC8","#6ECFF6","#7EA7D8","#8493CA","#8882BE","#A187BE","#BC8DBF","#F49AC2","#F6989D"];
var i = 0;
setInterval(function(){
i++
if (i>=colors.length){
i=0;
@shayanjm
shayanjm / gist:02ae7d57c0c1a616cbd2
Created May 16, 2014 05:56
express4 boilerplate
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.send('hello world');
});
app.listen(3000);
// problem 05 every some
/*
Return a function that takes a list of valid users, and returns a function that returns true
if all of the supplied users exist in the original list of users.
You only need to check that the ids match.
## Example
var goodUsers = [
(time
(dosync
(ensure newswire)
(ref-set ref2 {:titles (:titles @newswire)
:urls (:urls @newswire)
:sentiments (pmap #(find-sentiment (get-nyt-article-contents %)) (:urls @newswire))})))
@shayanjm
shayanjm / get-ngd.clj
Created July 15, 2014 20:46
A rough implementation of Normalized Google Distance in Clojure
; Rough implementation of Normalized Google Distance algorithm
; Assumed total number of indexed pages = 42,000,000,000
(defn get-ngd
"Returns the normalized google distance of two searchable terms. Returns nil if no results available for either query, or if there is no overlap for either query. The closer the result trends to 0, the more closely 'related' the terms are."
[term1 term2]
(let [m 42000000000
fx (Integer. (:totalResults (:searchInformation (google-search term1))))
fy (Integer. (:totalResults (:searchInformation (google-search term2))))
fxy (Integer. (:totalResults (:searchInformation (google-search (str term1 "+" term2)))))
ngdnumerator (- (max (math/log10 fx) (math/log10 fy)) (math/log10 fxy))
@shayanjm
shayanjm / sentiments.clj
Created July 17, 2014 15:59
Sentiment analysis using Stanford CoreNLP in Clojure
(def nlp
(let [props (new java.util.Properties)]
(.setProperty props "annotators" "tokenize,ssplit,parse,sentiment")
(new edu.stanford.nlp.pipeline.StanfordCoreNLP props)))
(defn find-sentiment
"Determines the sentiment of each sentence in a given glob of text. Results in a collection of integers ranging from [0-4]: where 0 is 'Very negative', 2 is 'neutral', and 4 is 'Very positive'"
[blob]
(let [glob (apply str blob)]
(let [main-sentiment 0
@shayanjm
shayanjm / gist:0b3f616a473885ab466a
Created August 3, 2014 05:13
Postfix notation in Clojure
(defmacro postfix-notation
"I'm too indie for prefix notation"
[expression]
(conj (butlast expression) (last expression)))
@shayanjm
shayanjm / iterable-seq.clj
Last active August 29, 2015 14:04
iter-seq function (Scala iterable -> Clojure lazy-seq) and implementation function
(defn iter-seq
"Takes a Scala iterable, and turns it into a lazy-seq"
[iter]
(lazy-seq
(when (.hasNext iter)
(cons (.next iter)
(iter-seq iter)))))
(defn iterable-seq
"Takes a Scala iterable s, and returns a lazy-seq of its contents."
@shayanjm
shayanjm / test.clj
Created February 2, 2016 22:52
Kafka + Transit = Niceness
(ns project.core
(:require [cognitect.transit :as transit])
(:use kafka-clj.client :reload)
(:import [java.io ByteArrayInputStream ByteArrayOutputStream]))
;; Set up connector here
(let [data (ByteArrayOutputStream. 4096)
writer (transit/writer data :json)]
(transit/write writer link-difference)