Skip to content

Instantly share code, notes, and snippets.

@vvvvalvalval
vvvvalvalval / aynchronous-errors.clj
Last active August 4, 2024 12:45
Asynchronous error management in Clojure(Script)
;; Synchronous Clojure trained us to use Exceptions, while asynchronous JavaScript has trained us to use Promises.
;; In contexts where we work asynchronously in Clojure (in particular ClojureScript), it can be difficult to see a definite way of managing failure. Here are some proposals.
;; OPTION 1: adapting exception handling to core.async CSPs
;; As proposed by David Nolen, with some macro sugar we use Exceptions in go blocks with core async in the same way we would do with synchronous code.
(require '[clojure.core.async :as a :refer [go]])
;; defining some helper macros
(defn throw-err "Throw if is error, will be different in ClojureScript"
@caskolkm
caskolkm / logging.cljc
Last active March 14, 2019 10:31
Simple Clojurescript logging using Google Closure logging tools, now in cljc :)
(ns app.logging
(:refer-clojure :exclude [time])
(:require #?(:clj [clojure.tools.logging :as log]
:cljs [goog.log :as glog]))
#?(:cljs (:import goog.debug.Console)))
#?(:cljs
(def logger
(glog/getLogger "app")))
@catharinejm
catharinejm / Concat.java
Created August 15, 2015 23:28
Clojure lazy concat without stack overflow
/**
* Copyright (c) Rich Hickey. All rights reserved.
* The use and distribution terms for this software are covered by the
* Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
* which can be found in the file epl-v10.html at the root of this distribution.
* By using this software in any fashion, you are agreeing to be bound by
* the terms of this license.
* You must not remove this notice, or any other, from this software.
**/
@tslocke
tslocke / core.cljs
Last active March 5, 2018 20:19
ClojureScript port of Brandon Bloom's dispatch-map
(ns dispatch-map.core
(:refer-clojure :exclude [dispatch-fn isa?]))
(declare empty-cache reset-cache! update-map cache-best prefers?)
(defprotocol IHierarchy
(-isa [this child parent]))
(defn isa?
"Returns true if (= child parent), or child is directly or
@ooobo
ooobo / export swinsian selected.scpt
Last active July 19, 2025 00:26
AppleScript: export songs from Swinsian playlist and rename as numbered files
-- great for exporting a playlist from Swinsian to another music playing software, while keeping the order of the playlist.
-- to install: open Script Editor.app, paste this, go File > Export, choose File Format: application, save anywhere you like.
-- to use: select tracks to export in Swinsian, then run the app you just saved.
-- note: doesn't handle those files already existing in selected folder. pads for two-digits, adds artist - title.ext
set theFolder to choose folder
set text item delimiters to "."
tell application "Swinsian"
set selected to selection of window 1
-- check that the playlist is not empty
@visibletrap
visibletrap / stack-trace.clj
Created October 29, 2015 08:32
A convenient function to peek Clojure's stack trace at a certain position in code
(defn stack-traces []
(->> (Thread/currentThread)
(.getStackTrace)
(map (juxt #(.getClassName %) #(.getMethodName %) #(.getLineNumber %)))
(map #(clojure.string/join ":" %))))
@DayoOliyide
DayoOliyide / thread-info.clj
Last active July 30, 2022 15:50
Get all thread information in clojure
(defn print-threads [& {:keys [headers pre-fn]
:or {pre-fn identity}}]
(let [thread-set (keys (Thread/getAllStackTraces))
thread-data (mapv bean thread-set)
headers (or headers (-> thread-data first keys))]
(clojure.pprint/print-table headers (pre-fn thread-data))))
(defn print-threads-str [& args]
(with-out-str (apply print-threads args)))
@ipbastola
ipbastola / clean-up-boot-partition-ubuntu.md
Last active March 24, 2026 21:06
Safest way to clean up boot partition - Ubuntu 14.04LTS-x64, Ubuntu 16.04LTS-x64

Safest way to clean up boot partition - Ubuntu 14.04LTS-x64, Ubuntu 16.04LTS-x64

Reference

Case I: if /boot is not 100% full and apt is working

1. Check the current kernel version

$ uname -r 
@jcf
jcf / log.clj
Created September 4, 2016 11:22
Refresh logback.xml from a Clojure REPL
(ns app.log
(:require [clojure.java.io :as io])
(:import ch.qos.logback.classic.joran.JoranConfigurator
ch.qos.logback.classic.LoggerContext
org.slf4j.LoggerFactory))
(defn reload-logback
[]
(let [context ^LoggerContext (LoggerFactory/getILoggerFactory)
configurator (JoranConfigurator.)
@ghadishayban
ghadishayban / productions.clj
Last active November 20, 2021 00:06
unified generators
;;
;; Example usages at the bottom of the file
;;
(defn productions
"Returns a sequence of values by repeatedly calling `produce!` until it
returns `fin`. The sequence can be used lazily/caching or reducible/non-caching.
The arity-2 variant's `produce!` takes no arguments and returns a value
or the terminator.