Skip to content

Instantly share code, notes, and snippets.

@qwtel
qwtel / retry.js
Created March 18, 2017 15:36
Solid retry logic with rxjs5
// emits a value after `init` ms, then after `init * exp` ms, then `init * exp * exp` ms, etc.
function expInterval(init, exp) {
return Observable.create((observer) => {
let n = init;
let id;
function next() {
observer.next(n);
n *= exp;
id = setTimeout(next, n);
import styled from 'styled-components';
const Button = styled.button`
background: white;
color: palevioletred;
font-size: 1em;
margin: 1em;
padding: 0.25em 1em;
border: 2px solid palevioletred;
border-radius: 3px;
@qwtel
qwtel / jsonml.js
Created September 17, 2016 05:10
The problem with HTML? Not enough JSON!
function render() {
return (
['aside', { id: 'sidebar' },
['div', { className: 'sidebar' },
['div', { className: ['container', 'sidebar-sticky'] },
['div', { className: 'sidebar-about' },
['h1', { className: 'font-accent' },
['a', { tabindex: '1', href: site.baseurl },
site.title
],
Atom Sync Settings Backup
@qwtel
qwtel / example.md
Last active August 26, 2016 08:29
Ring REST JSON and namespaced clojure.spec

Handy for a ring REST server that is spec'd via the upcomming clojure.spec library in Clojure 1.9, since it encourages the use of namespaced keywords.

A request like

POST /endpoint Content-Type: application/json {"name": "Test", "id": -1}

will be parsed as

{:my.spec/name "Test"
@qwtel
qwtel / project.clj
Created July 4, 2016 17:38
Very basic ClojureScript Leiningen setup with cljs-devtools
(defproject hello-world "0.0.0"
;; lein obviously does dependency management
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.92"]]
;; and uses plugins for non-standard tasks
:plugins [[lein-cljsbuild "1.1.3"]
[lein-figwheel "0.5.4-4"]]
;; this will build cljs on `lein compile`
@qwtel
qwtel / project.clj
Last active July 4, 2016 13:24
Very basic ClojureScript Leiningen configuration: https://www.youtube.com/watch?v=eWGFYRyWT0Y
(defproject hello-world "0.0.0"
;; lein obviously does dependency management
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.92"]]
;; and uses plugins for non-standard tasks
:plugins [[lein-cljsbuild "1.1.3"]
[lein-figwheel "0.5.4-4"]]
;; this will build cljs on `lein compile`
@qwtel
qwtel / cda.clj
Last active March 2, 2016 12:09
A Simple CDA Implementation in Clojure http://qwtel.com/a-simple-cda-implementation-in-clojure
(ns interact.cda
(:require [clojure.test :refer :all]))
(defn insert-by [f c e]
(let [[lt gt] (split-with #(f % e) c)]
(concat lt [e] gt)))
(def insert (partial insert-by <))
(testing "insert"
@qwtel
qwtel / goog.clj
Last active February 7, 2016 17:03
find words in an input, lower-case only, brute force
(ns goog
(:require [clojure.string :as str]))
(def words-by-count (->> (slurp "/usr/share/dict/words" :encoding "ASCII")
str/split-lines
(map str/lower-case)
distinct
(map seq)
(group-by count)))
@qwtel
qwtel / ethpyramid.sol
Created January 30, 2016 16:31
ETH Pyramid Contract
contract Pyramid {
struct Participant {
bytes desc;
address etherAddress;
bytes bitcoinAddress;
}
Participant[] public participants;
uint public payoutIdx = 0;