Skip to content

Instantly share code, notes, and snippets.

View xyhp915's full-sized avatar
😇
monadic life ...

Charlie xyhp915

😇
monadic life ...
View GitHub Profile
@xyhp915
xyhp915 / _doc.md
Created January 14, 2021 14:09 — forked from mhuebert/_doc.md
clj(s) environment config w/ Shadow-CLJS using a build hook

Objectives/approach

  • Load config conditionally, based on a release flag passed in at the command line. We use juxt/aero to read a static config.edn file, passing in the release flag as aero's :profile.
  • Config should be exposed at runtime (in the browser / cljs) and macro-expansion time (clj). We store config in a plain map, app.env/config. Our build hook, app.build/load-env, updates this using alter-var-root!.
  • Whenever config has changed, shadow-cljs must invalidate its caches so that changes are picked up immediately. We do this in app.build/load-env by putting the current environment in the shadow build state, under [:compiler-options :external-config ::env].

Why this approach?

  • Reading config directly from macros breaks compiler caching - changing config will not cause changes to propagate to the build.
  • :clojure-defines (ie. goog-define) are not exposed in clj, & therefore can't be used by macros. We want one single way to expose config that
@xyhp915
xyhp915 / 00_destructuring.md
Created January 6, 2021 07:38 — forked from john2x/00_destructuring.md
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

@xyhp915
xyhp915 / lein-tools-deps-cursive.md
Created October 31, 2020 12:35 — forked from mfikes/lein-tools-deps-cursive.md
Using `lein-tools-deps` from Cursive (on macOS)

Note: These workarounds covered issues in lein-tools-deps 0.3.0-SNAPSHOT. If using 0.4.1 or later, you should not encounter the issues below.

The following provides some workarounds for some issues when using lein-tools-deps from Cursive on macOS.

Path to clojure

By default, the lein-tools-deps plugin won't see /usr/local/bin/clojure when Cursive processes project.clj, as it evidently has a degenerate path.

You will see an error like the following in the IntelliJ Event Log when it tries to process your project.clj file:

@xyhp915
xyhp915 / iterator.js
Created April 28, 2020 04:22 — forked from jed/iterator.js
Turning callbacks into async iterators, with a React hook-like API.
// Example usage:
//
// void async function() {
// let [clicks, onclick] = iterator()
// document.querySelector('button').addEventListener('click', onclick)
// for await (let click of clicks) console.log(click)
// }()
export default function iterator() {
let done = false
const first = source => {
if (!source) return 'empty source'
return [source[0], source.slice(1)]
}
// console.log('first', first('abc'), first(''))
const inject = value => source => [value, source]
// console.log('inject', inject(1)('123'), inject(2)(''))
@xyhp915
xyhp915 / gzipRequestTest.js
Created August 14, 2019 08:47 — forked from nickfishman/gzipRequestTest.js
Second attempt at conditional gzip decoding based on the Content-Encoding response header with the mikeal/request library for Node.js. This DOES work.
var request = require('request'),
zlib = require('zlib');
var headers = {
"accept-charset" : "ISO-8859-1,utf-8;q=0.7,*;q=0.3",
"accept-language" : "en-US,en;q=0.8",
"accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"user-agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
"accept-encoding" : "gzip,deflate",
};
@xyhp915
xyhp915 / pget.go
Created June 21, 2019 04:02 — forked from montanaflynn/pget.go
Bounded Parallel Get Requests in Golang
package main
import (
"fmt"
"net/http"
"sort"
"time"
)
// a struct to hold the result from each request including an index
@xyhp915
xyhp915 / Connect to Google Home
Created January 2, 2019 02:59 — forked from willwhui/Connect to Google Home
Connect to Google Home
Connect to Google Home
@xyhp915
xyhp915 / thread-info.clj
Created December 26, 2018 12:07 — forked from DayoOliyide/thread-info.clj
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)))
@xyhp915
xyhp915 / ssh.md
Created November 22, 2018 05:38 — forked from suziewong/ssh.md
SSH端口转发

ssh

    -C  压缩数据传输
    -f  后台登录用户名密码
    -N  不执行shell[与 -g 合用]
    -g  允许打开的端口让远程主机访问        
    -L  本地端口转发
    -R  远程端口转发

-p ssh 端口