Skip to content

Instantly share code, notes, and snippets.

View tranghaviet's full-sized avatar

Ha Viet Trang tranghaviet

View GitHub Profile
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
@tranghaviet
tranghaviet / GaussianNB_example.py
Created May 1, 2017 09:47
A GaussianNB example
import numpy as np
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
Y = np.array([1, 1, 1, 2, 2, 2])
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
clf.fit(X, Y)
print(clf.predict([[-0.8, -1]]))
clf_pf = GaussianNB()
@tranghaviet
tranghaviet / using_lamda_in_python.py
Last active April 5, 2017 16:15
using lamda to create anonymous function in python (one-line function)
# định nghĩa 1 function không nhận đầu vào, luôn trả về True, gán nó cho biến ``f``
In [1]: f = lambda: True
# gọi hàm này và nó trả về giá trị True
In [2]: f()
Out[2]: True
# định nghĩa 1 function trả về số lớn hớn số đã cho 1 đơn vị, gán function này cho biến f
In [3]: f = lambda x: x + 1
# hàm này cần 1 argument, câu gọi hàm dưới đây bị thiếu argument
In [4]: f()
---------------------------------------------------------------------------
@tranghaviet
tranghaviet / yield_in_python.py
Created April 5, 2017 16:12
yeild in python
>>> def dummy():
... print "You won't see me when created"
... yield 1
... print "You didn't see me"
... yield 2
... print "Bye bye"
...
>>> gen = dummy()
>>> gen.next()
You won't see me when created