Skip to content

Instantly share code, notes, and snippets.

@mountain
mountain / bind-events-with-bean-qwery-bonzo-but-without-ender.coffee
Created November 30, 2011 16:47
How to bind events in bean? With qwery and bonzo but without ender
###
csmain.coffee
link for this section:
http://playground.wahlque.org/tutorials/coffeescript/004-webworkers/
###
define [
'underscore',
'domReady',
'qwery',
@mountain
mountain / antinode
Created June 12, 2012 00:51
Shell wrapper for node.js antinode static server
#!/bin/bash
#
# A wrapper for runner
#
CUR="${BASH_SOURCE[0]}";
if([ -h "${CUR}" ]) then
while([ -h "${CUR}" ]) do CUR=`readlink -m "${CUR}"`; done
fi
pushd . > /dev/null
cd `dirname ${CUR}` > /dev/null
@mountain
mountain / corpus_utilities.clj
Created February 25, 2014 06:47
corpus utilities
(use 'clojure.java.io)
(use 'com.guokr.nlp.seg)
(def corpus-root "/path/to/directory")
(def corpus-dir (clojure.java.io/file corpus-root))
(def corpus-files (file-seq corpus-dir))
(def corpus-writer (writer (str corpus-root "/corpus.txt")))
(defn line-by-line [wrtr lhdl] (fn [file] (with-open [rdr (reader file)] (doseq [line (line-seq rdr)] (.write wrtr (str (lhdl line) "\n"))))))
@mountain
mountain / ldaschema.clj
Created March 4, 2014 04:23
save lda schema
(def lda (second (get-model "model")))
(spit "2014.sch" (clojure.string/join "\n" (map #(clojure.string/join ";" %) (map vec (vec (.getTopWords lda 12))))))
@mountain
mountain / NGramIterator.java
Created March 4, 2014 16:59
ngram iterator
package ngram;
import java.util.Iterator;
public class NGramIterator implements Iterator<StringBuilder> {
private char[] ring;
private int n;
private int cur;

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

Keybase proof

I hereby claim:

  • I am mountain on github.
  • I am mingliyuan (https://keybase.io/mingliyuan) on keybase.
  • I have a public key whose fingerprint is ED86 CD82 A682 45D7 5CC5 2C3E 6EFF 88CB 304F 50A2

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am mountain on github.
  • I am mingliyuan (https://keybase.io/mingliyuan) on keybase.
  • I have a public key whose fingerprint is ED86 CD82 A682 45D7 5CC5 2C3E 6EFF 88CB 304F 50A2

To claim this, I am signing this object:

# -*- coding: utf-8 -*-
import numpy as np
import sys
import keras
from keras.layers import Input, Dense
from keras.models import Model
@mountain
mountain / search_crossword_chinese_poetries.py
Last active February 17, 2020 03:09
search crossword for Chinese poetries
# -*- coding: utf-8 -*-
'''
This simple program is used to search for crossword sentences in selected Chinese poetries
The selected Chinese poetries here is stored in a text file - tang_poetry_5char.txt.
You can change to your version of candidates
You should install networkx by pip