This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git status --porcelain|awk '{print $2}' >>.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git_feature_branch() { | |
# Adds a new git branch named [name_with_underscores_$1]. name is either in clipboard or given as a second argument | |
(( [ "$2" ] && echo $2 ) || clippaste )|python3 -c "print('_'.join(input().split()) + '_$1')"|xargs git checkout -b | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git status --ignored --porcelain=v2|grep '!'|awk '{print $2}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JsonWebView(private val webView: WebView) { | |
private val BASEURL: String = BackendRemote.SERVER_ADDRESS | |
val TAG = JsonWebView::class.java.name | |
@SuppressLint("SetJavaScriptEnabled") | |
fun loadURL(url:URL,cb: (JSONObject) -> Unit) { | |
webView.settings.apply { | |
javaScriptEnabled = true | |
domStorageEnabled = true | |
webView.loadUrl(url.toString()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Generic and pythonic implementation of the Depth First Search traversal algorithm""" | |
from typing import Callable, List, Iterable,TypeVar,Hashable, MutableSequence | |
from pathlib import Path | |
from collections import deque | |
T = TypeVar('T', bound=Hashable) | |
S = TypeVar('S') | |
def iter_top(stack: MutableSequence[S]) -> Iterator[S]: | |
"""Iterate a stack as long as it is full, yielding the top every time""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from contextlib import contextmanager | |
@contextmanager | |
def cd(path: os.PathLike): | |
"""Context manager that sets the cwd to be `path`""" | |
old_path = os.getcwd() | |
os.chdir(path) | |
yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Iterator, TypeVar, Generator | |
T = TypeVar('T') | |
def try_yield(generator: Iterator[T])->Generator[T, None, None]: | |
"""Returns an generator of all the items in `generator` that didn't throw""" | |
while True: | |
try: | |
yield next(generator) | |
except StopIteration: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import TypeVar, Hashable, Callable, Set, Iterable, Iterator | |
T = TypeVar("T") | |
K = TypeVar("K", bound=Hashable) | |
def keyed_filter(iterable: Iterable[T], key: Callable[[T], K]) -> Iterator[T]: | |
"""Yields the iterable without key duplicates. | |
>>> list(keyed_filter(["Alice","Adam","Bob","Ben"],key=lambda x:x[0]) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from contextlib import contextmanager | |
from typing import Union, ContextManager | |
PathType = Union[os.PathLike, str] | |
@contextmanager | |
def cd(path: PathType) -> ContextManager[None]: | |
old_path = Path.cwd() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import TypeVar, Sequence, Optional, Callable | |
T = TypeVar("T") | |
def find_in_sequence( | |
sequence: Sequence[T], predicate: Callable[[T], bool] | |
) -> Optional[T]: | |
"""Returns the element that satisfies the predicate, if exists""" | |
return next((element for element in sequence if predicate(element)), None) |
OlderNewer