Skip to content

Instantly share code, notes, and snippets.

View wubin1989's full-sized avatar

武斌 wubin1989

View GitHub Profile
@wubin1989
wubin1989 / app.js
Created January 8, 2016 05:26 — forked from sogko/app.js
gulp + expressjs + nodemon + browser-sync
'use strict';
// simple express server
var express = require('express');
var app = express();
var router = express.Router();
app.use(express.static('public'));
app.get('/', function(req, res) {
res.sendfile('./public/index.html');
@wubin1989
wubin1989 / gist:7429885ca9790775557f844b5b82b737
Created August 18, 2016 02:34 — forked from osipov/gist:c2a34884a647c29765ed
Install Scala and SBT using apt-get on Ubuntu 14.04 or any Debian derivative using apt-get
sudo apt-get remove scala-library scala
sudo wget www.scala-lang.org/files/archive/scala-2.10.4.deb
sudo dpkg -i scala-2.10.4.deb
sudo apt-get update
sudo apt-get install scala
wget http://scalasbt.artifactoryonline.com/scalasbt/sbt-native-packages/org/scala-sbt/sbt/0.12.4/sbt.deb
sudo dpkg -i sbt.deb
sudo apt-get update
sudo apt-get install sbt
val hook: Thread = new Thread {
override def run() {
println("app exit now...")
}
}
sys.addShutdownHook(hook.run())
@wubin1989
wubin1989 / scala thread pool code
Created August 18, 2016 02:39
scala thread pool code
import java.util.concurrent._
class ThreadIdentifier extends Runnable {
def run {
println("hello from Thread " + Thread.currentThread.getId)
}
}
val pool = Executors.newFixedThreadPool(5)
var schema = new Schema({ name: String }, { collection: 'actor' });
// or
schema.set('collection', 'actor');
// or
var collectionName = 'actor'
var M = mongoose.model('Actor', schema, collectionName)
As you learned the in-place shuffling was the problem. I also have problem frequently, and often seem to forget how to copy a list, too. Using sample(a, len(a)) is the solution.
Here's a simple version using random.sample() that returns the shuffled result as a new list.
import random
a = range(5)
b = random.sample(a, len(a))
print a, b, "two list same:", a == b
# print: [0, 1, 2, 3, 4] [2, 1, 3, 4, 0] two list same: False
#coding=utf-8
import random, nltk
from nltk.corpus import names
def gender_features(word):
'''''提取每个单词的最后一个字母作为特征'''
return {'last_letter': word[-1]}
# 先为原始数据打好标签
labeled_names = ([(name, 'male') for name in names.words('male.txt')] + [(name, 'female') for name in names.words('female.txt')])
# 随机打乱打好标签的数据集的顺序,
for filename in os.listdir(directory):
if filename.endswith(".asm") or filename.endswith(".py"):
# print(os.path.join(directory, filename))
continue
else:
continue
==========================
import glob
To save:
import pickle
f = open('my_classifier.pickle', 'wb')
pickle.dump(classifier, f)
f.close()
To load later:
import pickle
f = open('my_classifier.pickle', 'rb')
@wubin1989
wubin1989 / Add_in_hadoop-env.sh
Created September 5, 2016 02:09 — forked from faustineinsun/Add_in_hadoop-env.sh
Solve Problem: “Unable to load realm info from SCDynamicStore” (Hadoop 2.2.0, Java 1.6, OS X Mavericks) http://faustineinsun.blogspot.com/2014/01/solve-problem-unable-to-load-realm-info.html
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
...
export HADOOP_OPTS="-Djava.security.krb5.realm=OX.AC.UK -Djava.security.krb5.kdc=kdc0.ox.ac.uk:kdc1.ox.ac.uk"