Skip to content

Instantly share code, notes, and snippets.

View pykong's full-sized avatar
🎯
Focusing

Ben Felder pykong

🎯
Focusing
View GitHub Profile
from itertools import cycle
lst = ['a', 'b', 'c']
pool = cycle(lst)
for item in pool:
print(item)
@pykong
pykong / dict_pop.py
Last active November 12, 2017 15:44
Note that if the second argument, i.e. None is not given, KeyError is raised if the key is not in the dictionary. Providing the second argument prevents the conditional exception. This is unlike the mydict.get() method, which defaults to None. https://stackoverflow.com/questions/15411107/delete-a-dictionary-item-if-the-key-exists
mydict.pop("key", None)
old_string = "this is going to have a full stop. some written sstuff!"
k = old_string.rfind(".")
new_string = old_string[:k] + ". - " + old_string[k+1:]
Don't use a password. Generate a passphraseless SSH key and push it to your VM.
If you already have an SSH key, you can skip this step… Just hit Enter for the key and both passphrases:
$ ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa.
# list remotes
git remote -v
# add remote
git remote add upstream https://github.com/SublimeLinter/SublimeLinter3.git
# sync with main repo
git pull upstream master
git add *
git status -s
git commit -m "YOUR COMMIT MESSAGE"
git push origin feature_name
@pykong
pykong / list_v_tuple.py
Created November 1, 2017 19:21
Be careful with single item tuples!
l = ['Your Code Here']
t = ('Your Code Here')
for item in l:
print(item)
for item in t:
print(item)
@pykong
pykong / boolean_indices.py
Created November 1, 2017 18:11
In Python, not only is 0 False and 1 True, but True is 1 and False is 0. This means you can do weird things like:
>>> a = 1
>>> (a==1) + (a>0) + (a==2)
2
sudo xed ~/.netrc
machine github.com
login USER_NAME
password ACCESS_TOKEN
machine api.github.com
login USER_NAME
password ACCESS_TOKEN