Skip to content

Instantly share code, notes, and snippets.

@puredanger
puredanger / roman.clj
Created November 28, 2012 19:15
Roman numeral kata in Clojure
(use 'clojure.test)
(def numerals {1 "I",
4 "IV",
5 "V",
9 "IX",
10 "X",
40 "XL",
50 "L",
90 "XC"
anonymous
anonymous / pipe.clj
Created December 18, 2012 12:49
(defn pipe
"Returns a vector containing a sequence that will read from the
queue, and a function that inserts items into the queue.
Source: http://clj-me.cgrand.net/2010/04/02/pipe-dreams-are-not-necessarily-made-of-promises/"
[]
(let [q (LinkedBlockingQueue.)
EOQ (Object.)
NIL (Object.)
s (fn queue-seq []
@lyhcode
lyhcode / jsoup_demo.groovy
Created December 30, 2012 13:34
Groovy + Jsoup
@Grab('org.jsoup:jsoup:1.7.1')
def doc = org.jsoup.Jsoup.connect("https://news.google.com/nwshp?hl=zh-TW&tab=wn").get()
doc.select("#s_POPULAR .titletext").each {
node->
println "title=${node.text()}"
}
@markhibberd
markhibberd / characters.md
Last active January 14, 2021 18:32
Haskell Character Data

Overview

There are lots of representations for strings. In most languages they pick one set of tradeoffs and run with it. In haskell the "default" implementation (at least the one in the prelude) is a pretty bad choice, but unlike most other languages (really) good implementations exist for pretty much every way you can twist these things. This can be a good thing, but it also leads to confusion, and frustration to find the right types and how to convert them.

Types

@adambard
adambard / errors.clj
Created May 13, 2013 05:48
An example of functional error handling in clojure.
(ns example.errors)
(defn clean-address [params]
"Ensure (params :address) is present"
(if (empty? (params :address))
[nil "Please enter your address"]
[params nil]))
(defn clean-email [params]
"Ensure (params :email) matches *@*.*"
@rjmcguire
rjmcguire / chan.d
Last active August 23, 2016 08:52
go statement implementation for D with simple Fiber co-op scheduler #dlang #golang
import core.sync.mutex : Mutex;
import core.thread : Thread, Fiber;
/**
* chan allows messaging between threads without having to deal with locks, similar to how chan works in golang
*/
shared
class chan(T) {
Mutex lock;
private bool closed_; bool closed() {synchronized (lock) {return closed_;}} void Close() { synchronized(lock) { closed_ = true; } }
(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]
@kdabir
kdabir / README.md
Last active August 29, 2015 13:56
This script pulls your starred repos on github and shows some interesting stats at the end. It was created as an example demonstrating how Gstorm is useful in scripts.

This script is created as an example to show how easy it is to use gstorm to crunch and consume data from rest apis.

Usage

Either download the script and run:

groovy ghstarred.groovy <your_github_id>

Or hotload it:

@martintrojer
martintrojer / blocking.clj
Last active September 4, 2018 13:36
core.async thoughts
;; ------------------------
(defn- log-time [{:keys [ns name line]} f & args]
(let [start (System/nanoTime)
res (apply f args)
elapsed (quot (- (System/nanoTime) start) 1000)]
(log/debug (format "%s/%s:%s %dus" ns name line elapsed))
res))
(defn enable-timing [var]
@lttlrck
lttlrck / gist:9628955
Created March 18, 2014 20:34
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote