This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val hook: Thread = new Thread { | |
override def run() { | |
println("app exit now...") | |
} | |
} | |
sys.addShutdownHook(hook.run()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent._ | |
class ThreadIdentifier extends Runnable { | |
def run { | |
println("hello from Thread " + Thread.currentThread.getId) | |
} | |
} | |
val pool = Executors.newFixedThreadPool(5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var schema = new Schema({ name: String }, { collection: 'actor' }); | |
// or | |
schema.set('collection', 'actor'); | |
// or | |
var collectionName = 'actor' | |
var M = mongoose.model('Actor', schema, collectionName) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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')]) | |
# 随机打乱打好标签的数据集的顺序, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
OlderNewer