Skip to content

Instantly share code, notes, and snippets.

View y56's full-sized avatar
🌏
(* ̄▽ ̄)/‧☆*"`'*-.,_,.-*'`"*-.,_☆

Eugene Wang y56

🌏
(* ̄▽ ̄)/‧☆*"`'*-.,_,.-*'`"*-.,_☆
View GitHub Profile
@y56
y56 / What's the difference between dict() and {}?
Last active November 21, 2019 04:22
What's the difference between dict() and {}?
https://stackoverflow.com/questions/664118/whats-the-difference-between-dict-and
>>> from timeit import timeit
>>> timeit("a = {'a': 1, 'b': 2}")
0.424...
>>> timeit("a = dict(a = 1, b = 2)")
0.889...
@y56
y56 / Return None if Dictionary key is not available
Last active November 21, 2019 04:26
Return None if Dictionary key is not available
https://stackoverflow.com/questions/6130768/return-none-if-dictionary-key-is-not-available
You can use dict.get()
value = d.get(key)
which will return None if key is not in d. You can also provide a different default value that will be returned instead of None:
value = d.get(key, "empty")
@y56
y56 / to remove the last entry from orderedDict
Created November 21, 2019 04:31
to remove the last entry from orderedDict
from collections import OrderedDict
myOrderedDict = OrderedDict()
myOrderedDict['a'] = 1
myOrderedDict['b'] = 2
myOrderedDict.popitem(last = False) # Setting last to False signals you wanted to remove the first.
@y56
y56 / pycodestyle
Created November 26, 2019 01:51
pycodestyle
That being said, conforming your Python code to PEP 8 is generally a good idea and helps make code more consistent when working on projects with other developers. There is a command-line program, pycodestyle (previously known as pep8), that can check your code for conformance. Install it by running the following command in your terminal:
$ pip install pycodestyle
Then run it on a file or series of files to get a report of any violations.
$ pycodestyle optparse.py
optparse.py:69:11: E401 multiple imports on one line
optparse.py:77:1: E302 expected 2 blank lines, found 1
optparse.py:88:5: E301 expected 1 blank line, found 0
@y56
y56 / autopep8
Created November 26, 2019 01:52
autopep8
The program autopep8 can be used to automatically reformat code in the PEP 8 style. Install the program with:
$ pip install autopep8
Use it to format a file in-place with:
$ autopep8 --in-place optparse.py
Excluding the --in-place flag will cause the program to output the modified code directly to the console for review. The --aggressive flag will perform more substantial changes and can be applied multiple times for greater effect.
@y56
y56 / pip3 install numpy
Created December 4, 2019 01:47
pip3 install numpy
python 要用 pip install numpy
python3 要用 pip3 install numpy
想一想也是很合理
@y56
y56 / firefox-color.y
Created December 17, 2019 03:27
firefox-color
https://color.firefox.com/?theme=XQAAAAIVAQAAAAAAAABBqYhm849SCia2CaaEGccwS-xNKlhW9r_vLXIlVnuJdAic7eRjUc7NRneKMRgQIDK-eQWrkV64LlDNDxf_eMByAZRY7cQeDk2YcCQuge8iz6wsuNPluyBJiPNe5xIoZzicTFzQ6DMdJYDEw-AeRyNROrGJ4T-DeBLGg-1Vj7VZ3d9k5NxuR_XDp27McA_KR92FIt5YLJrt4-wN1xy00G2UBvBL10ttWMmb3Fj4oR16M_W9K9p__-NlUeA
@y56
y56 / to adjust wine font size
Created December 27, 2019 02:40
to adjust wine font size
# wine regedit
Search for "LogPixels" there. You will see something like this:
"LogPixels"=dword:00000060
Change 60 to something more suitable. For example this is what I use with my
two displays (one with resolution 1680x1050 and another one with 1280x1024):
"LogPixels"=dword:00000095
@y56
y56 / global-keyword-in-python
Last active January 2, 2020 02:52
global-keyword-in-python
https://www.geeksforgeeks.org/global-keyword-in-python/
To access a global variable inside a function there is no need to use global keyword.
If we need to assign a new value to a global variable then we can do that by declaring the variable as global.
This output is an error because we are trying to assign a value to a variable in an outer scope. This can be done with the use of global variable.
@y56
y56 / vpn on ubuntu vpngate openvpn
Created January 2, 2020 22:12
vpn on ubuntu vpngate openvpn
https://www.vpnusers.com/viewtopic.php?t=2861
====
You can connect all VPN Gate server by following settings.
HostName: Please get from this page http://www.vpngate.net/en/
UserName: vpn
Password: vpn
Pre-shared key: vpn