Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@braingineer
braingineer / git+clone+ssh+agent+forward+sudo
Created November 13, 2017 21:09 — forked from scottjacobsen/git+clone+ssh+agent+forward+sudo
Git clone using ssh agent forwarding and sudo
SSH agent forwarding is great. It allows you to ssh from one server to
another all the while using the ssh-agent running on your local
workstation. The benefit is you don't need to generate ssh key pairs
on the servers you are connecting to in order to hop around.
When you ssh to a remote machine the remote machine talks to your
local ssh-agent through the socket referenced by the SSH_AUTH_SOCK
environment variable.
So you the remote server you can do something like:
@braingineer
braingineer / tmux-cheatsheet.markdown
Created October 18, 2017 18:58 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@braingineer
braingineer / gdrive_download.py
Created October 7, 2017 18:21
Google drive download
import requests
import argparse
def download_file_from_google_drive(id, destination):
URL = "https://docs.google.com/uc?export=download"
session = requests.Session()
response = session.get(URL, params = { 'id' : id }, stream = True)
token = get_confirm_token(response)
@braingineer
braingineer / 09242017-registering-hooks.ipynb
Last active September 25, 2017 17:14 — forked from anonymous/09242017-registering-hooks.ipynb
registering hooks in pytorch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@braingineer
braingineer / pad1d.py
Created August 23, 2017 02:04
pytorch pad 1d
def pad1d(tensor, pad):
# tensor should be in shape (batch, time, feat)
# pad should be in shape (left, right)
tensor = tensor.permute(0, 2, 1).contiguous() # get features on first dim since we are padding time
original_size = tensor.size() # (batch, feat, time)
final_new_size = (original_size[0], original_size[1], original_size[2] + pad[0] + pad[1])
temp_new_size = original_size[:2] + (1,) + original_size[2:]
assert len(temp_new_size) == 4
tensor = tensor.view(*temp_new_size)
pad = pad + (0, 0)
@braingineer
braingineer / describe.py
Created April 18, 2017 02:00
describe some new dict structure (probably incoming data)
def describe_recursively(datum, level=0, level_increment=2):
indent = lambda i: "|"+"."*i+"|"
info_str = "L{} - TYPE: {:^6} - LEN: {:^5}"
if isinstance(datum, list):
print(indent(level) + info_str.format(level, 'list', len(datum)))
for i, child in enumerate(datum):
describe_recursively(child, level+level_increment, level_increment)
if i>5 and len(datum)>10:
print(indent(level+level_increment)+" ..... ")
describe_recursively(datum[-1], level+level_increment, level_increment)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@braingineer
braingineer / matprint.py
Created March 8, 2017 01:31 — forked from lbn/matprint.py
Pretty print a matrix in Python 3 with numpy
def matprint(mat, fmt="g"):
col_maxes = [max([len(("{:"+fmt+"}").format(x)) for x in col]) for col in mat.T]
for x in mat:
for i, y in enumerate(x):
print(("{:"+str(col_maxes[i])+fmt+"}").format(y), end=" ")
print("")
# Try it!
import numpy as np
@braingineer
braingineer / _run.py
Last active February 24, 2017 21:45
parallel spacy parse for jupyter notebooks
import eidos
from toolz import partition
import spacy
nlp = spacy.load('en')
def parse(nlp, input_, n_threads, batch_size):
nlp.matcher = None
out = []
for doc in nlp.pipe(input_, batch_size=batch_size, n_threads=n_threads):