Skip to content

Instantly share code, notes, and snippets.

View bartojs's full-sized avatar

justin barton bartojs

View GitHub Profile
@bartojs
bartojs / jnr-gist.clj
Last active May 16, 2020 03:14
Call libC using jnr-ffi in clojure
boot -d com.github.jnr/jnr-ffi repl
=> (import jnr.ffi.LibraryLoader)
=> (definterface LibC (^int puts [^String s]))
=> (def libname (if (.contains (.toLowerCase (System/getProperty "os.name")) "windows") "msvcrt" "c"))
=> (def libc (.load (LibraryLoader/create LibC) libname))
@bartojs
bartojs / cljs.sh
Created March 10, 2015 08:27
cljs hello world
curl -LO https://github.com/clojure/clojurescript/releases/download/r3058/cljs.jar
mkdir -p src/hello
echo '(ns hello.core) (enable-console-print!) (println "Hello world!")' > src/hello/core.cljs
java -cp cljs.jar:src clojure.main -e '(require `cljs.closure) (cljs.closure/build "src" {:output-to "out/main.js"})'
echo '<html><body><script src="out/goog/base.js"></script><script src="out/main.js"></script><script>goog.require("hello.core")</script></body></html>' > index.html
open index.html
@bartojs
bartojs / keybase.md
Created April 15, 2015 01:36
Keybase proof

Keybase proof

I hereby claim:

  • I am bartojs on github.
  • I am bartojs (https://keybase.io/bartojs) on keybase.
  • I have a public key whose fingerprint is 968F 927F 138D 6A70 21FA 8BA7 3198 8EC7 8631 3EC7

To claim this, I am signing this object:

@bartojs
bartojs / influxdb windows
Last active August 29, 2015 14:24
build influxdb windows
build:
GOPATH=`pwd` GOOS=windows GOARCH=amd64 go get -u -f github.com/influxdb/influxdb/cmd/influxd
GOPATH=`pwd` GOOS=windows GOARCH=amd64 go build -o bin/influxd.exe github.com/influxdb/influxdb/cmd/influxd
#GOPATH=`pwd` GOOS=windows GOARCH=amd64 go get -u -f github.com/influxdb/telegraf/cmd/telegraf
#GOPATH=`pwd` GOOS=windows GOARCH=amd64 go build -o bin/telegraf.exe github.com/influxdb/telegraf/cmd/telegraf
@bartojs
bartojs / build.boot
Last active December 3, 2015 00:34
boot-clj task to generate project.clj for cursive clojure
;; add to build.boot to generate project.clj for cursiveclojure
;; adds clojurescript if boot-cljs is used
(deftask lein []
(let [coords [(symbol (or (get-env :project) "boot-project")) (or (get-env :version) "0.1.0-SNAPSHOT")]
proj (into {} (keep #(if-let [x (get-env %)] [% x])
[:url :licence :description :dependencies]))
cljs? (.matches (pr-str (:dependencies proj)) ".*adzerk/boot-cljs .*")
projcljs (update-in proj [:dependencies] conj '[org.clojure/clojurescript "1.7.170"])]
(spit "project.clj" (cons 'defproject (apply concat coords (if cljs? projcljs proj))))))
@bartojs
bartojs / build.boot
Last active December 3, 2015 00:30
sftp with publickey using apache-sshd
;; 1) download this build.boot file
;; 2) download & install http://boot-clj.com
;; 3) cp ~/.ssh/id_rsa.pub authorized_keys
;; 4) boot run
;; -- this will run the server for a minute on port 2222
;; 5) test with scp -v -i ~/.ssh/id_rsa -P 2222 mytestfile-original.txt localhost:mytestfile-transferred.txt
;; 6) check scp output for which keys are sent - remember to check if ssh-agent is running (which will cache keys)
(set-env! :dependencies '[[org.apache.sshd/sshd-core "0.9.0"]
[org.apache.sshd/sshd-sftp "0.9.0"]])
@bartojs
bartojs / build.boot
Created December 3, 2015 00:24
formatter for clojure using cljfmt
;; boot fmt -f myfile.clj
;; boot fmt -f src
;; -- it will change files inplace
(set-env! :dependencies '[[cljfmt "0.3.0"]])
(require '[cljfmt.core :as fmt]
'[clojure.java.io :as io])
(defn fmt-file [f]
@bartojs
bartojs / build.boot
Last active March 23, 2023 11:29
gmail rest api java/clojure example with oauth2 and labels
;; 1) first goto https://console.developers.google.com/start/api?id=gmail
;; -- to turn on gmail api for your account
;; 2) then create a oauth consent with app name
;; 3) then add oauth clientid and download to ./clientsecret.json
;; 4) boot run
;; -- when running first time a browser will open to accept authorizaton
(set-env! :dependencies '[[com.google.apis/google-api-services-gmail "v1-rev34-1.21.0"]
[com.google.api-client/google-api-client "1.20.0"]
[com.google.oauth-client/google-oauth-client-jetty "1.20.0"]])
@bartojs
bartojs / profile.boot
Created December 3, 2015 01:51
boot clj profile for fmt and lein tasks
(deftask fmt
"fmt file or dir using cljfmt (changes files)"
[f files VAL str "file(s) to format"]
(set-env! :dependencies '[[cljfmt "0.3.0"]])
(require 'cljfmt.core
'clojure.java.io)
(let [reformat-string (resolve 'cljfmt.core/reformat-string)
file (resolve 'clojure.java.io/file)
fmt-file (fn [f]
(println "formatting" (.getName f))