Skip to content

Instantly share code, notes, and snippets.

View defclass's full-sized avatar
:octocat:
Working from home

Michael Wong defclass

:octocat:
Working from home
View GitHub Profile
@defclass
defclass / k-means.clj
Last active January 16, 2016 06:55
K-means : An Algorithm for Clustering Data
;; K-means
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; K-means is a Clustering Algorithm.
;; We use it when we have some data, and we want to split the data into separate categories.
;; For instance, an early biologist, let's call him Adam, might measure all
;; sorts of things about the living objects he encounters in the world.
@defclass
defclass / supervisord.sh
Created June 22, 2016 08:56 — forked from danmackinlay/supervisord.sh
an init.d script for supervisord
#! /bin/sh
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
@defclass
defclass / tmux.md
Created August 28, 2016 01:14 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

@defclass
defclass / autoreload.clj
Last active July 8, 2017 10:53
autoreload
;; profiles.lcj
;{:repl {:dependencies [;;[org.clojure/tools.trace "0.7.9"]
; [ns-tracker "0.3.1"]]
; :source-paths ["src" "dev-src"]}}
(ns autoreload
(:require [ns-tracker.core :as tracker]))
(defn check-namespace-changes [track]
(try
@defclass
defclass / docker_images.sh
Created September 25, 2017 06:49 — forked from hydra1983/docker_images.sh
Save and load docker images in batch
#!/bin/bash
readonly DB_FILE="$(pwd)/images.db"
readonly IMG_DIR="$(pwd)/images"
save-images() {
echo "Create ${DB_FILE}"
echo "$(docker images|grep -v 'IMAGE ID'|awk '{printf("%s %s %s\n", $1, $2, $3)}'|column -t)" > "${DB_FILE}"
echo "Read ${DB_FILE}"
@defclass
defclass / pipe_to_docker_examples
Created October 19, 2017 03:14 — forked from ElijahLynn/pipe_to_docker_examples
How to pipe to `docker exec` examples
# These examples assume you have a container currently running.
# 1 Pipe from a file
sudo docker exec --interactive CONTAINER_NAME /bin/bash < the_beginning.sh | tee the_beginning_output.txt`
#2a Pipe by piping
echo "echo This is how we pipe to docker exec" | sudo docker exec --interactive CONTAINER_NAME /bin/bash -
@defclass
defclass / reflect.py
Created January 12, 2018 07:13 — forked from huyng/reflect.py
A simple echo server to inspect http web requests
#!/usr/bin/env python
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
@defclass
defclass / humanize-schema-errors.clj
Created April 24, 2018 04:37 — forked from venantius/humanize-schema-errors.clj
Translate prismatic's schema.core errors to a human readable form. Use this for presenting validation errors to users. Don't use this for programming errors like a missing map key etc.
(ns x.y
(:use [plumbing.core]) ;; Just for the map-vals
(:require [clojure.walk :refer [postwalk prewalk prewalk-demo postwalk-demo]]
[clojure.core.match :refer [match]]
[schema.utils :refer [named-error-explain validation-error-explain]]
[schema.core :as s])
(:import (schema.utils NamedError ValidationError)))
;; Partially FROM:
;; https://github.com/puppetlabs/clj-schema-tools
@defclass
defclass / install.sh
Last active November 9, 2018 03:06 — forked from chuyik/install.sh
Bandwagon(搬瓦工) CentOS 7 安装 shadowsocks-libev 和 kcptun
######################
## shadowsocks-libev
######################
# install dependencies
yum install epel-release -y
yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto udns-devel libev-devel -y
# install shadowsocks-libev
cd /etc/yum.repos.d/
@defclass
defclass / sha1-hash.clj
Created November 19, 2018 07:59 — forked from hozumi/sha1-hash.clj
clojure sha1 hash
(defn sha1-str [s]
(->> (-> "sha1"
java.security.MessageDigest/getInstance
(.digest (.getBytes s)))
(map #(.substring
(Integer/toString
(+ (bit-and % 0xff) 0x100) 16) 1))
(apply str)))