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 / 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 / i3blocks_openweathermap.md
Last active August 21, 2018 22:54
i3blocks openweathermap

openweathermap for i3blocks

dependencies

  • i3blocks
  • httpie
  • jq
  • ttf-font-icons (aur)

configuration

@sunng87
sunng87 / keybase.md
Last active February 6, 2016 05:17
keybase.md

Keybase proof

I hereby claim:

  • I am sunng87 on github.
  • I am sunng (https://keybase.io/sunng) on keybase.
  • I have a public key whose fingerprint is ED91 D234 CAE9 7367 9AD4 6EA6 2E27 E20F C4DE EA3E

To claim this, I am signing this object:

@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))))
(defn assoc-some [m & kvs]
(if-not (even? (count kvs))
(throw (IllegalArgumentException. "even number of key-values required."))
(if-let [kvs (not-empty (filter #(some? (second %)) (partition 2 kvs)))]
(apply assoc m (flatten kvs))
m)))
@sunng87
sunng87 / gist:e9b5e6e5de67f6dc3558
Created September 25, 2014 08:06
Flash socket policy file server.
#! /usr/bin/python
import SocketServer
class FlashPolicyHandler(SocketServer.StreamRequestHandler):
timeout = 5
"""
The RequestHandler class for our server.
It is instantiated once per connection to the server, and must
override the handle() method to implement communication to the
@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 / ip_only.py
Created June 29, 2013 09:45
Displaying IP address of wlan0 on LCD.
#!/usr/bin/python
from Adafruit_CharLCD import Adafruit_CharLCD
from subprocess import *
from time import sleep, strftime
from datetime import datetime
lcd = Adafruit_CharLCD()
cmd = "ip -4 addr show wlan0 | grep inet | awk '{print $2}' | cut -d/ -f1"
@sunng87
sunng87 / index.html
Created March 13, 2013 14:06
tornado + websocket + rpi
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="dns-prefetch" href="//1-ps.googleusercontent.com"></head>
<body>
<div class="main">
<h2>Shake your phone</h2>
@sunng87
sunng87 / Disney Wiki Crawler.cljs
Last active August 15, 2018 13:57
ClojureScript to download pages from Disney Wiki. Target to nodejs.
(ns crawler.core
(:require [cljs.nodejs :as node]))
(def http (node/require "http"))
(def fs (node/require "fs"))
(def local-path-root "out/")
(.mkdir fs local-path-root (fn [e]))
(defn start-req [url res-fn]