Skip to content

Instantly share code, notes, and snippets.

View pykong's full-sized avatar
🎯
Focusing

Ben Felder pykong

🎯
Focusing
View GitHub Profile
# 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
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.
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:]
@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)
from itertools import cycle
lst = ['a', 'b', 'c']
pool = cycle(lst)
for item in pool:
print(item)
@pykong
pykong / build_nested_dict.py
Last active November 13, 2017 22:07
Use this logic instead of a sequence of key checks.
l0 = {}
l1 = l0.setdefault("key_l1", {})
l2 = l1.setdefault("key_l2", [])
l2.append("3")
{'key_l1': {'key_l2': ['3']}}
# Write this:
if (mark.a, mark.b) == (region.a, region.b):
...
# much cleaner than:
if mark.a == region.a and mark.b == region.b:
...
@pykong
pykong / get_active_view.py
Created November 18, 2017 19:41
Often used.
def get_active_view(self):
"""Return the active view in the currently active window."""
return sublime.active_window().active_view()
@pykong
pykong / get_neighbours.py
Last active December 5, 2017 18:23
Gets both numbers adjacent to input number.
import bisect
def get_neighbours(num, interval):
interval = set(interval)
interval.discard(num)
interval = list(interval)
interval.sort()
if num < interval[0] or interval[-1] < num: