Skip to content

Instantly share code, notes, and snippets.

View djblue's full-sized avatar

Chris Badahdah djblue

View GitHub Profile
@apropos-cast
apropos-cast / Jan-18-2019-Show-Notes.md
Last active January 18, 2019 05:03
Show notes for Apropos on January 18, 2019.
@jeroenvandijk
jeroenvandijk / git.zsh.clj
Last active August 29, 2019 17:16
bash to closh porting examples (https://github.com/dundalek/closh)
(defcmd git [& [dispatch :as args]]
(if (= dispatch "browse")
(let [{:keys [code stderr]
remote-url :stdout} (sh-value "git" "remote" "get-url" "origin")]
(if (zero? code)
(do (println "Opening" remote-url)
(sh "open" (clojure.string/trim remote-url)))
(println stderr)))
(eval `(sh "git" ~@args))))
"""
A super simple Jupyter cell magic that writes the cell to `main.cpp` or
specified file, compiles the file using g++ and executes the code using
`./a.out`
Limitations: the cell must be a complete C++ program.
"""
from IPython.core.magic import (register_line_magic,
register_cell_magic)
import subprocess
@mfikes
mfikes / keys-vals.md
Last active November 23, 2020 13:27

The following works in Clojure:

(keys (filter (comp odd? val) {:a 1 :b 2 :c 3}))

The docstrings for keys and vals don't indicate that you can do this. Is this accidential or intentional?

I vaguely recall Alex Miller indicating at some point that this capability was deemed useful and is intentionally allowed. Yes, this is an appeal to authority, but nevertheless, it makes a fairly convincing argument.

@borkdude
borkdude / repl.clj
Last active March 4, 2021 22:44
REPL session of babashka and sci internals @ London Clojurians December 2020
(ns ldnclj.repl
(:require [babashka.main :as bb]
[cheshire.core :as json]
[edamame.core :as e]
[sci.core :as sci]
[sci.impl.analyzer :as ana]
[sci.impl.interop :as interop]
[sci.impl.interpreter :as i]
[sci.impl.parser :as p]))
@borkdude
borkdude / logger.clj
Last active April 27, 2021 20:23
Simple logger that works in bb
(ns logger)
(defmacro log [& msgs]
(let [m (meta &form)
_ns (ns-name *ns*) ;; can also be used for logging
file *file*]
`(binding [*out* *err*] ;; or bind to (io/writer log-file)
(println (str ~file ":"
~(:line m) ":"
~(:column m))
@borkdude
borkdude / http-socket-server.clj
Last active May 3, 2021 22:59 — forked from souenzzo/http-socket-server.clj
tiny http server via java sockets in babashka
#!/usr/bin/env bb
(import (java.net ServerSocket))
(require '[clojure.string :as string] '[clojure.java.io :as io])
(with-open [server-socket (new ServerSocket 8080)
client-socket (.accept server-socket)]
(loop []
(let [out (io/writer (.getOutputStream client-socket))
in (io/reader (.getInputStream client-socket))
@borkdude
borkdude / gh-releases.rb
Last active September 27, 2021 16:14
Brew install babashka script
# install with brew reinstall --build-from-source ./gh-releases.rb
# set GITHUB_TOKEN to a personal Github token
# then run: gh-releases list :org babashka :repo :babashka
class GhReleases < Formula
desc ""
homepage ""
license ""
url "file:///dev/null"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
@grillermo
grillermo / .vimrc
Created March 6, 2015 17:50
Ctrlp using ag the silver searcher
"" The Silver Searcher
if executable('ag')
" Use ag over grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" " ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
@mauricioszabo
mauricioszabo / with_code.clj
Last active April 18, 2022 04:25
Open Socket REPL on CLR or Clojerl
#Clojerl
./bin/clje \
-e "(do (require 'clojure.core.server) \
(clojure.core.server/start-server \
{:name \"socket-repl\" \
:port 4444 \
:accept 'clojure.main/repl \
:address \"localhost\"}))" -r
#CLR