Skip to content

Instantly share code, notes, and snippets.

View niwinz's full-sized avatar

Andrey Antukh niwinz

View GitHub Profile
@niwinz
niwinz / strint.clj
Created August 9, 2016 13:22 — forked from cemerick/strint.clj
BSD-licensed string interpolation for clojure
;;; strint.clj -- String interpolation for Clojure
;; originally proposed/published at http://cemerick.com/2009/12/04/string-interpolation-in-clojure/
;; Copyright (c) 2009, 2016 Chas Emerick <[email protected]>
;;
;; All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are met:
;;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Level;
@niwinz
niwinz / README.md
Created March 30, 2016 06:03 — forked from olivergeorge/Nicer Assert README.md
Assert macro patch to show details about failed assertions.

This is an attempt to make assert more friendly by including more details in the assertion error.

  • show the result of the assertion expression
  • show local variable values used in assertion form

In other words, this should make assertion errors easier to reason about:

AssertionError Assert failed: Should be equal
@niwinz
niwinz / javaslang-and-clojure-bench.clj
Last active April 4, 2016 11:19
Javaslang and Clojure persistent data structures benchmark
#!/usr/bin/env boot
;; BOOT_CLOJURE_NAME=org.clojure/clojure
;; BOOT_CLOJURE_VERSION=1.8.0
;; BOOT_VERSION=2.5.5
;; BOOT_JVM_OPTIONS="-Xms4g -Xmx4g -XX:+UseG1GC -XX:+AggressiveOpts -server"
(set-env! :dependencies '[[criterium "0.4.4"]
[io.javaslang/javaslang "2.0.2"]])
@niwinz
niwinz / rstore.cljs
Last active November 24, 2016 11:09
Stream & Events based state management toolkit for ClojureScript.
;; Copyright (c) 2015-2016 Andrey Antukh <[email protected]>
;; All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are met:
;;
;; * Redistributions of source code must retain the above copyright notice, this
;; list of conditions and the following disclaimer.
;;
;; * Redistributions in binary form must reproduce the above copyright notice,
#!/bin/bash
# Overwrite ./target with a tmpfs ramdisk. Prompts for sudo.
function usage() {
echo 'Usage: `ramdisk-target.sh recreate|restore`'
}
if [ ! -f "project.clj" ]; then
echo "Not in Clojure project."
exit 2
@niwinz
niwinz / multimethods.py
Last active August 29, 2015 14:13
clojure like multimethods implemented in python3
from threading import Lock
from inspect import isclass
from functools import partial
def isa(cls_child: "class", cls_parent: "class") -> bool:
if not isclass(cls_child):
return False
if not isclass(cls_parent):
return False
@niwinz
niwinz / express.cljs
Created December 26, 2014 16:16
Lightweight sugar syntax for expressjs with clojurescript.
(ns express
"Ligweight interface to requirejs."
(:refer-clojure :exclude [set get])
(:require [cljs.nodejs :as node]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Constants
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^{:doc "Global express import."
@niwinz
niwinz / views.py
Last active August 29, 2015 14:05
Generic Views
from django.core.urlresolvers import reverse
from django.core.paginator import Paginator
from django.core.paginator import InvalidPage
from django.core.paginator import EmptyPage
from django.core.paginator import PageNotAnInteger
from django.views.generic import View
from django.template import RequestContext
from django.template.loader import render_to_string
from django.shortcuts import render_to_response
(ns blog.errors.core
(:require-macros
[cljs.core.async.macros :refer [go]]
[blog.utils.macros :refer [<?]])
(:require
[cljs.core.async :refer [>! <! chan close!]]))
;; convert Node.js async function into a something
;; that returns a value or error on a channel
(defn run-task [f & args]