Skip to content

Instantly share code, notes, and snippets.

View prestancedesign's full-sized avatar

Michael Salihi prestancedesign

View GitHub Profile
@baskeboler
baskeboler / clipboard.clj
Last active April 11, 2021 01:21 — forked from brake/clipboard.clj
Write pretty printed Clojure data structures to the clipboard
(ns clipboard.core
(:require [fipp.edn :as fipp])
(:import (java.awt.datatransfer DataFlavor Transferable StringSelection)
(java.awt Toolkit)
(java.io StringWriter))
(defn get-clipboard
"get system clipboard"
[]
(-> (Toolkit/getDefaultToolkit)
@nbardiuk
nbardiuk / script.clj
Last active November 28, 2020 19:29
Clojure shebang wtih arguments
#!/usr/bin/env -S clj -Sdeps '{:deps {clj-http/clj-http {:mvn/version "3.11.0"} cheshire/cheshire {:mvn/version "5.10.0"}}}'
(require '[clj-http.client :as http])
(require '[cheshire.core :as json])
(require '[clojure.pprint :refer [pprint]])
(let [url (or (first *command-line-args*) "https://httpbin.org/get?q=a")
{:keys [body headers]} (http/get url)]
(pprint headers)
(pprint (json/decode body)))
@zelark
zelark / torrent-viewer.clj
Last active July 13, 2021 13:53
babashka script for viewing torrents files
#!/usr/bin/env bb
(require '[clojure.java.io :as io])
(require '[bencode.core :refer [read-bencode]])
(require '[clojure.walk :refer [prewalk]])
(require '[clojure.pprint :refer [pprint]])
(import 'java.io.PushbackInputStream)
(defn bytes->strings [coll]
(prewalk #(if (bytes? %) (String. % "UTF-8") %) coll))
@spacegangster
spacegangster / bem.cljc
Last active November 9, 2020 05:17
Add modifiers to CSS classes as in BEM naming (in Clojure)
(ns space-ui.bem
"Add modifiers to CSS classes as in BEM method.
See rationale here: http://getbem.com/naming/
For BEM with elements see: https://github.com/druids/ccn
Compared to CCN this gist supports maps."
(:require [clojure.string :as str]))
@roman01la
roman01la / re-frame.clj
Last active October 21, 2020 11:32
Debugging re-frame subscriptions
(ns utils.re-frame
(:require [cljs.compiler :as cljsc]))
(defn- anonymous-function-declaration? [form]
(and (list? form)
(= 'fn (first form))
(vector? (second form))))
(defn- query-id->js-fn-name [query-id]
(let [ns-part (when-let [ns-part (namespace query-id)]
@borkdude
borkdude / CT2020-Q3-01.md
Last active October 31, 2020 21:18
Clojurists Together Project Updates

Clojurists Together Project Update Q3 2020 August 16-31

Here is an overview of the work I did per project. During this period I focused mostly on a new babashka release, v0.2.0. Most of the issues worked on in sci also end up in babashka.

Babashka

  • Allow resources to be read from jar files #528
@spacegangster
spacegangster / timezones.edn
Last active July 15, 2020 14:52
List of standard timezones, scraped from a popular mailing service
;; UPD hey, I'm not sure now if those zones are correct throughout the year
;; see this https://www.creativedeletion.com/2015/01/28/falsehoods-programmers-date-time-zones.html
;; Sorry for misleading you
[{:option/value "Pacific/Tarawa" :option/label "(GMT +12:00) Tarawa"}
{:option/value "Pacific/Auckland" :option/label "(GMT +12:00) New Zealand Time"}
{:option/value "Pacific/Norfolk" :option/label "(GMT +11:00) Norfolk Island (Austl.)"}
{:option/value "Pacific/Noumea" :option/label "(GMT +11:00) Noumea, New Caledonia"}
{:option/value "Australia/Sydney" :option/label "(GMT +10:00) Australian Eastern Time (Sydney)"}
{:option/value "Australia/Queensland" :option/label "(GMT +10:00) Australian Eastern Time (Queensland)"}
{:option/value "Australia/Adelaide" :option/label "(GMT +9:30) Australian Central Time (Adelaide)"}
@gerritjvv
gerritjvv / in.clj
Created July 8, 2020 10:08
Clojure - finding something in a list
(defn in? [vs ls]
(boolean (some (partial (set vs)) ls)))
(in? [1 2] [3 4 2 5]) => false
(in? [1 2] [3 1 4 2 5]) => true
(defn in? [v ls]
(loop [[x & rs] ls]
(if-not x
@retrogradeorbit
retrogradeorbit / build-acmetool.clj
Last active January 12, 2021 19:43
build new up to date acmetool package on digital ocean droplet
#!/usr/bin/env spire
;; spin up a digital ocean droplet
;; build latest acmetool
;; patch and update debian package
;; download acmetool binary and new package
;; destroy droplet
;; requirements:
;; spire 0.1.0-alpha.15 or above
@saikyun
saikyun / zig_watch.clj
Last active April 8, 2021 09:40
babashka command to watch a folder for changes to .zig-files
#!/usr/bin/env bb
(if *command-line-args*
(def in (str (first *command-line-args*)))
(do
(println "Which bin to run?")
(def in (str *input*))))
(println "Watching" "*.zig" "->" (str "./" in))