Skip to content

Instantly share code, notes, and snippets.

View arr-ee's full-sized avatar

Max Barnash arr-ee

  • London, UK
  • 09:52 (UTC +01:00)
View GitHub Profile
@arr-ee
arr-ee / core.clj
Created July 4, 2014 22:16
Tiny Instapaper scraper
(ns instagroup.core
(:require [net.cgrand.enlive-html :as html]
[clj-http.client :as http]
[clj-http.cookies :as cookies]
[clojure.java.io :as io]
[clojure.string :as s]
[clojure.pprint :as pp])
(:import java.io.ByteArrayInputStream)
(:gen-class))
$ dig datastax.com
; <<>> DiG 9.8.3-P1 <<>> datastax.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31423
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;datastax.com. IN A
(defmacro defdyntest
[test-meta test-name & test-body]
`(let [fn# (deftest ~test-name ~@test-body)]
(alter-meta! fn# merge ~test-meta)
fn#))
(let [tname (symbol 'test-1)]
(defdyntest {} tname (println 1)))
; => #'user/tname
;; this should be #'user/test-1
@arr-ee
arr-ee / gist:8996177
Created February 14, 2014 05:17
Javascript is awesome at sorting stuff.
> a
[ 'Wed Dec 11 2013 04:00:00 GMT+0400 (MSK)',
'Tue Dec 10 2013 04:00:00 GMT+0400 (MSK)',
'Sun Dec 15 2013 04:00:00 GMT+0400 (MSK)',
'Sat Dec 14 2013 04:00:00 GMT+0400 (MSK)' ]
> a.map(function(d){return new Date(d)}).sort()
[ Sat Dec 14 2013 04:00:00 GMT+0400 (MSK),
Sun Dec 15 2013 04:00:00 GMT+0400 (MSK),
Tue Dec 10 2013 04:00:00 GMT+0400 (MSK),
Wed Dec 11 2013 04:00:00 GMT+0400 (MSK) ]
@arr-ee
arr-ee / index.html
Last active August 29, 2015 13:55
All palettes from colorbrewer
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/colorbrewer.v1.min.js"></script>
<style>
body {
background: #ccc;
font: 14/1.5 Helvetica, sans-serif;
}
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/colorbrewer.v1.min.js"></script>
<style>
.axis {
shape-rendering: crispEdges;
stroke-width: 2;
}
require 'benchmark'
chars = 'abcdeABCDE!@#$%1234 '
res_str = ''
n = 1000
100_000.times do
res_str << chars[rand(chars.length)]
end
Benchmark.bm(15) do |x|
@arr-ee
arr-ee / gist:6175003
Created August 7, 2013 15:17
Making an object to behave like string
class A;
def initialize a
@a = a
end
def to_str
@a.dup
end
def == o
case
when utterance.silent?
...
when utterance.loud?
...
...
else
...
end
require 'minitest/autorun'
require 'uri'
class UriValidator
ALLOWED_PROTOS = [URI::HTTP, URI::HTTPS, URI::FTP]
def initialize uri
@uri = uri
end