This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; test server blocks for 5 seconds | |
;; this code gets the response successfully | |
;; the time macro reports just a little over 5 seconds | |
(time | |
(let [response (http/get "http://localhost:4567/" {:timeout 3000})] | |
@response)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def names {:foo 'FOO}) | |
(defmacro def* [dname dval] | |
`(def ~dname ~dval)) | |
;; This doesn't resolve the (get names :foo) => 'FOO | |
(macroexpand-1 '(def* (get names :foo) 300)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Like update-in, but doesn't call the fn | |
;; (or set a key) if the key doesn't already exist. | |
(defn maybe-update-in [data ks fn] | |
(if ((last ks) (-> data (get-in (butlast ks)) keys set)) | |
(update-in data ks fn) | |
data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.string :as str]) | |
(require '[clojure.set :as set]) | |
(require '[clojure.pprint :as pp]) | |
(defn map-names [names] | |
(first | |
(reduce | |
(fn [mem n1] | |
(let [avail (set/difference names (get mem 1)) | |
sel (->> avail shuffle (some #(when (not= n1 %1) %1)))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id":"1", | |
"signalTypes":["reward"], | |
"selectQuery": "{!edismax bf=\"recip(abs(ms(NOW/HOUR,timestamp_dt)),3.16e-11,1,.1)\"}*:*", | |
"aggregates":[ | |
{"type":"count", "sourceFields":["id"], "targetField": "count_f"}, | |
{ | |
"type": "script", | |
"params": { | |
"aggregateScript": "result.addField('rewards_fs', event.getFirstFieldValue('params.reward_f'))", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Gruber wrote this regex for matching URLs, but it took a small amount of massage to use it in JavaScript. So here. | |
//Sauce: http://daringfireball.net/2010/07/improved_regex_for_matching_urls | |
var p = /^\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i; | |
p.exec('party fun www.twitter.com yay') //winning. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "dependencies": { | |
// "http-server": "0.6.1", | |
// "express": "4.6.1", | |
// "request": "2.37.0", | |
// "errorhandler": "1.0.1" | |
// } | |
var express = require('express'); | |
var request = require('request'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns foo | |
(:import [org.scribe.builder ServiceBuilder] | |
[org.scribe.builder.api.FlickrApi] | |
[org.scribe.model Verifier OAuthRequest Verb])) | |
(let [builder (doto (ServiceBuilder.) | |
(.provider FlickrApi) | |
(.apiKey "YOURKEY") | |
(.apiSecret "YOURSECRET"))] | |
(def service (.build builder))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns truth.core) | |
(defn get-data [] | |
{:data {:name {:first "matt"}}}) | |
(defmacro truth [lbl val tests redefs] | |
(loop [t tests] | |
(if-not (seq t) | |
true | |
`(with-redefs [~@(mapcat identity redefs)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Adding handle: conn: 0x7fad39804000 | |
* Adding handle: send: 0 | |
* Adding handle: recv: 0 | |
* Curl_addHandleToPipeline: length: 1 | |
* - Conn 0 (0x7fad39804000) send_pipe: 1, recv_pipe: 0 | |
* About to connect() to localhost port 8765 (#0) | |
* Trying ::1... | |
* Connected to localhost (::1) port 8765 (#0) | |
> GET /api HTTP/1.1 | |
> User-Agent: curl/7.30.0 |