Skip to content

Instantly share code, notes, and snippets.

View mitnk's full-sized avatar
🦋
Wandering

Hugo Wang mitnk

🦋
Wandering
View GitHub Profile
@mitnk
mitnk / tailf_least_postgresql_log.sh
Last active August 29, 2015 14:03
Tailf lastest PostgreSQL Log
path=`ps ax | grep -i 'postmaster' | grep -o '\-D\(/Library/Post.*\)' | awk -F D '{print $NF}'`
log_dir="${path}/pg_log"
log_name=`sudo ls -1t ${log_dir} | head -n1`
log_file="${log_dir}/${log_name}"
echo ""
echo "=========== $log_file =========="
echo ""
sudo tail -f "$log_file"
@mitnk
mitnk / simplify_dict_cn_scb.js
Created August 12, 2014 08:41
Simplify dict cn 的生词本
// ==UserScript==
// @name Simplify Dict.cn
// @namespace http://mitnk.com
// @version 0.1
// @description Simplify dict cn 的生词本
// @match http://scb.dict.cn/card.php*
// @copyright 2014+, mitnk
// for tampermonkey on Chrome.
// ==/UserScript==
@mitnk
mitnk / dbg.h
Last active August 29, 2015 14:17
A C logger header
// via: http://c.learncodethehardway.org/book/ex20.html
#ifndef __dbg_h__
#define __dbg_h__
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <time.h>
@mitnk
mitnk / migrate.py
Last active January 24, 2017 01:58
xonsh migrate history items
from xonsh.history.json import JsonHistory
from xonsh.history.sqlite import SqliteHistory
hist_json = JsonHistory(gc=False)
# if you want to have a check first
print('have {} json items'.format(len(list(hist_json.all_items())))) # may very slow here
hist_db = SqliteHistory(gc=False)
for item in hist_json.all_items():
@mitnk
mitnk / history_couchdb.py
Last active March 17, 2022 22:12
xonsh history backend with couchdb
"""
xonsh history backend with couchdb.
Copy this file to "~/.xonsh/history_couchdb.py" and put the following
into your "~/.xonshrc" file.
import os.path
import sys
xonsh_ext_dir = os.path.expanduser('~/.xonsh')
if os.path.isdir(xonsh_ext_dir):
@mitnk
mitnk / main.rs
Created December 22, 2018 09:41
Lifetime with Thread (Mutex, Arc) in Rust
// Thanks: https://stackoverflow.com/a/53894298/665869
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::thread;
type Map = HashMap<String, String>;
fn handle_n_times(count: i32, arc_map: Arc<Mutex<Map>>) {
for i in 0..count {
let clone_arc = arc_map.clone();