Skip to content

Instantly share code, notes, and snippets.

View danielsz's full-sized avatar

Daniel Szmulewicz danielsz

View GitHub Profile
@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 *@*.*"
(ns ratelimit
"Implement rate limiting using a token bucket"
(:require [clojure.core.async :as async :refer [<!! >! alts! go chan dropping-buffer close! timeout]]))
(defprotocol TokenBucket
(take-token [this])
(release [this]))
(defn- ->period-ms [p]
(if (keyword? p)
@olekukonko
olekukonko / haproxy
Created August 8, 2013 21:30
Different websocket connection HA Proxy vs Nginx
#### HA Proxy
// PROXY BASED ON SUB-DOMAIN
frontend public
bind *:80
acl is_websocket hdr_end(host) -i ws.example.com
use_backend ws if is_websocket
default_backend www
@datagrok
datagrok / ergodox.md
Last active January 14, 2019 07:45
Reflections on my ErgoDox keyboard
@shaharz
shaharz / core.cljs
Last active September 15, 2016 08:55
React.js's CSSTransitionGroup in Om
(ns om-transition.core
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]))
(enable-console-print!)
(def ctg (aget js/React "addons" "CSSTransitionGroup"))
(def app-state (atom ["test"]))
@renegr
renegr / etsy-fu.elm
Created April 16, 2014 14:34
The pleasantness of ELM
{-
As seen on: http://danielsz.github.io/2014/02/28/The-pleasantness-of-Om/
Additional feature: <SPACE> and Time advance
Missing feature: Randomizer for List
-}
import Keyboard
-- Model
type Testimonial = { shopName:String,
shopOwner:String,
@staltz
staltz / introrx.md
Last active May 7, 2024 09:38
The introduction to Reactive Programming you've been missing
@TheItachiUchiha
TheItachiUchiha / ToggleSwitch
Last active March 31, 2023 07:15
A simple Toggle Switch using JavaFX
import javafx.beans.property.SimpleBooleanProperty;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
public class ToggleSwitch extends HBox {
private final Label label = new Label();
@Deraen
Deraen / edn.cljx
Last active August 6, 2023 06:51
Transit / edn date/datetime serialisers
(ns metosin.common.edn
#+clj
(:require [clj-time.format :as f])
#+cljs
(:require [cljs-time.format :as f]
cljs.reader)
#+clj (:import [org.joda.time DateTime LocalDate]))
;;
;; #DateTime tagging