Skip to content

Instantly share code, notes, and snippets.

View vemv's full-sized avatar
🎷
smooth opurrator

vemv vemv

🎷
smooth opurrator
View GitHub Profile
@onetom
onetom / dialog.clj
Created June 30, 2023 17:49
Pop up an Apple Script Yes/No dialog from Clojure
(ns dialog
"Display a Yes/No dialog, which appears on the very top of every app and grabs
the focus and also gives it back to the REPL, after making the choice, unlike
a Swing dialog, for example.
It's useful for confirming irreversible operations, like file or DB deletion.
It uses AppleScript, so it only works on macOS and on a local REPL."
(:require
[clojure.java.shell :as shell]))
@jdtsmith
jdtsmith / toggle-debug-on-hidden-error.el
Last active August 25, 2023 02:31
Elisp: get stack trace for functions with suppressed errors (filter functions, post command hooks, etc.)
;;;; Power debugging
(defun my/reraise-error (func &rest args)
"Call function FUNC with ARGS and re-raise any error which occurs.
Useful for debugging post-command hooks and filter functions, which
normally have their errors suppressed."
(condition-case err
(apply func args)
((debug error) (signal (car err) (cdr err)))))
(defun toggle-debug-on-hidden-errors (func)
@bsless
bsless / multi-what.clj
Last active November 16, 2021 19:20
What if multimethods were implemented with closures and not dispatch tables?
(defprotocol IDoubleDispatch
(-add [this k f])
(-remove [this k]))
(defmulti ->= type)
(defmethod ->= String [^String x] #(.equals x %))
(defmethod ->= clojure.lang.Keyword [^clojure.lang.Keyword x] #(.equals x %))
(defmethod ->= clojure.lang.Symbol [^clojure.lang.Symbol x] #(.equals x %))
(defmethod ->= Long [^long x]
#(if (int? %) (= x (unchecked-long %)) false))
@thumbnail
thumbnail / lein.zsh
Last active August 22, 2020 08:34
leiningen current verion prompt
function lein_current_version() {
command grep defproject project.clj 2> /dev/null | grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn} -o "\".*"\" | sed "s/\"//g"
}
function lein_prompt() {
cat project.clj &> /dev/null || return 0
ZSH_THEME_LEIN_PROMPT_PREFIX="%{$fg_bold[green]%}"
ZSH_THEME_LEIN_PROMPT_SUFFIX="%{$reset_color%} "
echo "$ZSH_THEME_LEIN_PROMPT_PREFIX$(lein_current_version)$ZSH_THEME_LEIN_PROMPT_SUFFIX"
}
@pjstadig
pjstadig / core.clj
Created March 20, 2017 13:06
A little type hint hint
(ns typehint.core)
;; A little type hint hint...
(set! *warn-on-reflection* true)
;; There are two ways to type hint the return value of a function, but one is
;; (technically) wrong:
(defn ^String as-string0
@reborg
reborg / rich-already-answered-that.md
Last active May 4, 2024 22:18
A curated collection of answers that Rich gave throughout the history of Clojure

Rich Already Answered That!

A list of commonly asked questions, design decisions, reasons why Clojure is the way it is as they were answered directly by Rich (even when from many years ago, those answers are pretty much valid today!). Feel free to point friends and colleagues here next time they ask (again). Answers are pasted verbatim (I've made small adjustments for readibility, but never changed a sentence) from mailing lists, articles, chats.

How to use:

  • The link in the table of content jumps at the copy of the answer on this page.
  • The link on the answer itself points back at the original post.

Table of Content

How to calculate your hourly rate as a freelancer?

Many people struggle with this question. Some just try to make as much as a full-time employee makes (and ignore that they won't be able to bill as many days). Others follow tips on startup related websites that suggest to ask for 20% to 50% more than an salary would yield (and ignore the additional risk and expenses they have).

Below you will find some numbers to help you calculate how high your hourly or daily rate should be.

Your yearly income should be higher than an average salary

  • You take more risk than full time employees, phases without income are likely
@ghoseb
ghoseb / clj_spec_playground.clj
Last active March 30, 2019 22:35
Examples of Clojure's new clojure.spec library
(ns clj-spec-playground
(:require [clojure.string :as str]
[clojure.spec :as s]
[clojure.test.check.generators :as gen]))
;;; examples of clojure.spec being used like a gradual/dependently typed system.
(defn make-user
"Create a map of inputs after splitting name."
([name email]
module ActiveRecord
module Batches
def find_each_with_order(options = {})
if block_given?
find_in_batches_with_order(options) do |records|
records.each { |record| yield record }
end
else
enum_for :find_each, options do
options[:start] ? where(table[primary_key].gteq(options[:start])).size : size
@ghadishayban
ghadishayban / doseq.clj
Created April 24, 2016 05:19
doseq that doesn't blow up with too much bytecode, and w/o (fn []) thunks
(defmacro doseqs
[seq-exprs & body]
(let [stk (gensym "stack__")
level (gensym "level__")
seq-exprs (partition 2 seq-exprs)
bindings (vec (map first seq-exprs))
init-exprs (vec (map second seq-exprs))
nbinds (count init-exprs)