View test_async.py
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 asyncio | |
import inspect | |
async def test_coro(): | |
await asyncio.sleep(1) | |
print('coro') | |
return 1 | |
View mil.py
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 __future__ import print_function | |
def get_mil(d, v0, ds): | |
t = d * 1.0 / v0 | |
mil = (5 * t * t - ds) * 1000 / d | |
return int(mil * 10 + 0.5) / 10.0 | |
cols = [600, 700, 800, 900, 1000, 1100, 1200] | |
header = [''] + cols | |
print(*header, sep='\t') |
View lrucache.py
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 collections import OrderedDict | |
class LRUCache(object): | |
def __init__(self, size=5): | |
self.size = size | |
self.cache = OrderedDict() | |
def get(self, key): | |
if key in self.cache: |
View oct_to_hex.py
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 re | |
regex = re.compile(r'\\(\d+)' | |
def repl(m): | |
return r'\x' + hex(int(m.group(1), 8)).replace('0x', r'').zfill(2) | |
lines = vscode.editor.lines | |
lines = [line.decode() for line in lines] | |
lines = [regex.sub(repl, line) for line in lines] |
View remove_dup_onetab_items.js
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
function get_close_nodes_for_duplicate_onetab_items() { | |
let closeNodes = []; | |
let cache = {}; | |
let selector = '#contentAreaDiv > div > div:nth-child(2) > div > div:nth-child(2)'; | |
let nodes = Array.from(document.querySelectorAll(selector)); | |
for (let node of nodes) { | |
let linkNode = node.querySelector('a.clickable'); | |
let closeNode = node.querySelector('img:nth-child(3)'); | |
let url = linkNode.getAttribute('href'); | |
if(cache[url]) { |
View remove-padding.js
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
document.querySelectorAll('.torrent-details tr').forEach(function (node) { | |
var name = node.querySelector('.col-name').textContent; | |
if (name.match(/^_____padding_file_/)) { | |
console.log(name); | |
node.querySelector('.deselect-file').click(); | |
} | |
}) |
View remove-padding.js
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
document.querySelectorAll('.torrent-details tr').forEach(function (node) { | |
var name = node.querySelector('.col-name').textContent; | |
if (name.match(/^_____padding_file_/)) { | |
console.log(name); | |
node.querySelector('.deselect-file').click(); | |
} | |
}) |
View previous_and_next.py
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 itertools import tee, islice as slice, chain, izip as zip | |
def previous_and_next(iterable, fill_value=None): | |
prevs, items, nexts = tee(iterable, 3) | |
prevs = chain([fill_value], prevs) | |
nexts = chain(slice(nexts, 1, None), [fill_value]) | |
return zip(prevs, items, nexts) |
View sparse_mat.py
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 tables as tb | |
from numpy import array | |
from scipy import sparse | |
def store_sparse_mat(path, name, m, separator='__'): | |
if (m.__class__ not in [sparse.csr.csr_matrix, sparse.csc.csc_matrix]): | |
raise TypeError("This code only works for csr/csc matrices") | |
with tb.openFile(path, 'a') as f: | |
for par in ('data', 'indices', 'indptr', 'shape'): |
NewerOlder