Monthly Archives: January 2017
set up email service for wordpress
install plugin Postman SMTP
go to settings -> Postman SMTP
follow the instructions,
input the email you want to use as admin account of the site
it will automatically detect which email service you are using, e.g. I use google gmail,
it will suggest the SMTP port, and OAuth 2.0 for authentication
redirecting to https://www.google.com/accounts/Logout?continue=https://console.developers.google.com/start/api?id=gmail
register for google API,
register for Authorized JavaScript origins, and Authorized redirect URI in google’s API page
get back
Final step, you should grant permission with google
http://jishichao.com/wp-admin/admin-post.php?action=postman/requestOauthGrant
Then you have everything.
git command
Git task | Notes | Git commands |
---|---|---|
Tell Git who you are | Configure the author name and email address to be used with your commits.
Note that Git strips some characters (for example trailing periods) from |
git config --global user.name "Sam Smith"
|
Create a new local repository | git init |
|
Check out a repository | Create a working copy of a local repository: | git clone /path/to/repository |
For a remote server, use: | git clone username@host:/path/to/repository |
|
Add files | Add one or more files to staging (index): |
|
Commit | Commit changes to head (but not yet to the remote repository): | git commit -m "Commit message" |
Commit any files you’ve added with git add, and also commit any files you’ve changed since then: | git commit -a |
|
Push | Send changes to the master branch of your remote repository: | git push origin master |
Status | List the files you’ve changed and those you still need to add or commit: | git status |
Connect to a remote repository | If you haven’t connected your local repository to a remote server, add the server to be able to push to it: | git remote add origin <server> |
List all currently configured remote repositories: | git remote -v |
|
Branches | Create a new branch and switch to it: | git checkout -b <branchname> |
Switch from one branch to another: | git checkout <branchname> |
|
List all the branches in your repo, and also tell you what branch you’re currently in: | git branch |
|
Delete the feature branch: | git branch -d <branchname> |
|
Push the branch to your remote repository, so others can use it: | git push origin <branchname> |
|
Push all branches to your remote repository: | git push --all origin |
|
Delete a branch on your remote repository: | git push origin :<branchname> |
|
Update from the remote repository
|
Fetch and merge changes on the remote server to your working directory: | git pull |
To merge a different branch into your active branch: | git merge <branchname> |
|
View all the merge conflicts:
View the conflicts against the base file: Preview changes, before merging: |
git diff
|
|
After you have manually resolved any conflicts, you mark the changed file: | git add <filename> |
|
Tags | You can use tagging to mark a significant changeset, such as a release: | git tag 1.0.0 <commitID> |
CommitId is the leading characters of the changeset ID, up to 10, but must be unique. Get the ID using: | git log |
|
Push all tags to remote repository: | git push --tags origin |
|
Undo local changes | If you mess up, you can replace the changes in your working tree with the last content in head:
Changes already added to the index, as well as new files, will be kept. |
git checkout -- <filename> |
Instead, to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it, do this: | git fetch origin
|
|
Search | Search the working directory for foo(): | git grep "foo()" |
__init__.py
from here
What is __init__.py
used for?
The primary use of __init__.py
is to initialize Python packages. The easiest way to demonstrate this is to take a look at the structure of a standard Python module.
package/ __init__.py file.py file2.py file3.py subpackage/ __init__.py submodule1.py submodule2.py
As you can see in the structure above the inclusion of the __init__.py
file in a directory indicates to the Python interpreter that the directory should be treated like a Python package
What goes in __init__.py
?
__init__.py
can be an empty file but it is often used to perform setup needed for the package(import things, load things into path, etc).
One common thing to do in your __init__.py
is to import selected Classes, functions, etc into the package level so they can be convieniently imported from the package.
In our example above we can say that file.py has the Class File. So without anything in our__init__.py
you would import with this syntax:
from package.file import File
However you can import File into your __init__.py to make it available at the package level:
# in your __init__.py from file import File # now import File from package from package import File
Another thing to do is at the package level make subpackages/modules available with the__all__ variable. When the interpeter sees an __all__ variable defined in an __init__.py it imports the modules listed in the __all__ variable when you do:
from package import *
__all__
is a list containing the names of modules that you want to be imported with import * so looking at our above example again if we wanted to import the submodules in subpackage the __all__ variable in subpackage/__init__.py
would be:
__all__ = ['submodule1', 'submodule2']
With the __all__ variable populated like that, when you perform
from subpackage import *
it would import submodule1 and submodule2.
As you can see __init__.py
can be very useful besides its primary function of indicating that a directory is a module.
Python class inherit example
class Staff:
def __init__(self,name,age):
self.name = name
self.age = age
print 'Create Staff: ', self.name
def tell(self):
print 'name:%s; age:%s' % (self.name, self.age)
def speak(self):
print 'I\'m %s'%self.age
class Teacher(Staff):
def __init__(self,name,age,salary):
Staff.__init__(self,name,age)
self.salary = salary
print 'Create Teacher: ', self.name
def tell(self):
Staff.tell(self)
print 'salary: ', self.salary
class Student(Staff):
def __init__(self,name,age,marks):
Staff.__init__(self,name,age)
self.marks = marks
print 'Create Student: ', self.name
def tell(self):
Staff.tell(self)
print 'marks: ', self.marks
tea = Teacher('Eva', 28, 3000)
stu = Student('Adam', 16, 77)
have= [tea,stu]
print
for i in have:
print i.tell()
print
print i.speak()
print
Create Staff: Eva
Create Teacher: Eva
Create Staff: Adam
Create Student: Adam
name:Eva; age:28
salary: 3000
None
I'm 28
None
name:Adam; age:16
marks: 77
None
I'm 16
None
To determine if a character is Chinese
string’scoding should be unicode
to know if one character is Chinese
we can decode utf-8 to unicode
def is_chinese(uchar):
"""判断一个unicode是否是汉字"""
if uchar >= u'\u4e00' and uchar<=u'\u9fa5':
return True
else:
return False
In Python, convert utf-8 to unicode
string.decode('utf-8')
convert unicode to utf-8
string.encode('utf-8')
for i in '下:@uVT4HLJLA: 二、我是用MAC的,所以可以骂你脑残'.decode('utf-8'):
print i, is_chinese(i)
下 True
: False
@ False
u False
V False
T False
4 False
H False
L False
J False
L False
A False
: False
False
二 True
、 False
我 True
是 True
用 True
M False
A False
C False
的 True
, False
所 True
以 True
可 True
以 True
骂 True
get file extension using Python
import os
have = os.listdir()
for i in have:
name, extension = os.path.splitext(i)
print name, extension
.ipynb_checkpoints ext:
Chinese-Sentiment ext:
corenlp-python ext:
corenlp.tar ext: .gz
extract ext:
k-means ext: .ipynb
neg ext: .csv
neg ext: .txt
neg ext: .xls
new_model ext:
new_model2 ext:
pos ext: .csv
pos ext: .txt
pos ext: .xls
Sentiment-Analysis ext:
sentiment ext: .ipynb
sentiPY ext:
snownlp ext:
test100 ext: .ipynb
Untitled ext: .ipynb
Untitled1 ext: .ipynb
Untitled2 ext: .ipynb
use_analysis ext: .csv
week1 ext: .csv
week31_divided(no_use_in_model) ext: .csv
wtf ext:
validate folder
folder=[]
for i in have:
if os.path.splitext(i)[-1]=='':
folder.append(i)
return folder