Skip to content

Instantly share code, notes, and snippets.

View sunng87's full-sized avatar
👑
keep calm and git push -f

Ning Sun sunng87

👑
keep calm and git push -f
View GitHub Profile
@sunng87
sunng87 / gist:372a0a45a07357569eb6
Last active March 23, 2024 00:57
defprotocol with var-args support
(defmacro defprotocol+ [name & funcs]
(let [vararg-sym (symbol "&")
normalized-func-specs (map #(let [[n a] %]
(if (.contains a vararg-sym)
[(symbol (str n "*"))
(vec (remove (fn [_a]
(= _a vararg-sym)) a))
[n a]]
[n a]))
funcs)
@sunng87
sunng87 / rdp.py
Last active December 29, 2023 08:55
Greptimedb script for Ramer–Douglas–Peucker algorithm
import math
@coprocessor(
returns=["lon", "lat"],
)
def simplify(**params) -> (vector[f64], vector[f64]):
from greptime import query
results = query().sql(params["sql"])
lon = results[0]
@sunng87
sunng87 / Jetty11.java
Last active September 3, 2023 18:30
Dead simple setup of Jetty servers
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS org.eclipse.jetty:jetty-server:11.0.15
//DEPS org.eclipse.jetty:jetty-servlet:11.0.15
import static java.lang.System.*;
import java.io.IOException;
import org.eclipse.jetty.server.Server;
@sunng87
sunng87 / reflection.clj
Created November 20, 2015 10:04
clojure: access private field/method via reflection
(defn invoke-private-method [obj fn-name-string & args]
(let [m (first (filter (fn [x] (.. x getName (equals fn-name-string)))
(.. obj getClass getDeclaredMethods)))]
(. m (setAccessible true))
(. m (invoke obj args))))
(defn private-field [obj fn-name-string]
(let [m (.. obj getClass (getDeclaredField fn-name-string))]
(. m (setAccessible true))
(. m (get obj))))
@sunng87
sunng87 / leancustomerdevelopment.org
Created May 23, 2022 09:58
Notes on Lean Customer Development
@sunng87
sunng87 / init.el
Created April 30, 2022 13:04
My emacs configuration
(require 'package)
;; (dolist (source '(("marmalade" . "http://marmalade-repo.org/packages/")
;; ("elpa" . "http://tromey.com/elpa/")
;; ("melpa" . "http://melpa.milkbox.net/packages/")
;; ("org" . "http://orgmode.org/elpa/")))
;; (add-to-list 'package-archives source t))
;;
;; ("marmalade" . "http://elpa.emacs-china.org/marmalade/")
;; ("org" . "http://elpa.emacs-china.org/org/")
;; ("elpa" . "http://elpa.emacs-china.org/gnu/")
@sunng87
sunng87 / lighttpd.conf
Created May 28, 2011 01:00
Share directory with lighttpd
server.document-root="/your/path/to/share"
server.port = 8099
#server.bind = "192.168.1.100"
dir-listing.activate = "enable"
@sunng87
sunng87 / verify-cert.sh
Created March 22, 2016 06:22
test if p12 certificate is valid or not
#!/usr/bin/bash
TEMP_KEY=/tmp/tmpkey
openssl pkcs12 -in $1 -nodes -out $TEMP_KEY
openssl s_client -connect gateway.push.apple.com:2195 -cert $TEMP_KEY -key $TEMP_KEY
@sunng87
sunng87 / init.el
Created September 19, 2011 07:26
My emacs configuration, start with emacs-starter-kit
;;; init.el --- Where all the magic begins
;;
;; Part of the Emacs Starter Kit
;;
;; This is the first thing to get loaded.
;;
;; "Emacs outshines all other editing software in approximately the
;; same way that the noonday sun does the stars. It is not just bigger
;; and brighter; it simply makes everything else vanish."
;; -Neal Stephenson, "In the Beginning was the Command Line"
@sunng87
sunng87 / gist:d4c06119224cd9ee4a927fccbb591af0
Created May 13, 2020 08:14
regex for matching json key/value
"(tomcat|jetty)":\s*"((\\"|[^"])*)",?