Skip to content

Instantly share code, notes, and snippets.

View NegatioN's full-sized avatar

Joakim Rishaug NegatioN

View GitHub Profile
@NegatioN
NegatioN / vim.txt
Last active August 4, 2023 08:24
Vim stuff
\%23c Matches in a specific column. (23), example :%s/\%1c/#/ (insert # on first column of all rows)
:% (all rows), :. (this row), :$ (last row), :.,$ (this->last row), :5,$ (5th->last row)
s, substitute. :%s/a/b/g, change all a->b on all rows.
u, undo
p, paste
m+a, set mark a [works for a-z]
'+a, go to mark a [works for a-z]
<<, de-indent row
>>, indent row
J, join rows
@NegatioN
NegatioN / onehot.py
Last active July 7, 2023 17:07
PyTorch Multi-dimensional One hot encoding
def _to_one_hot(y, num_classes):
scatter_dim = len(y.size())
y_tensor = y.view(*y.size(), -1)
zeros = torch.zeros(*y.size(), num_classes, dtype=y.dtype)
return zeros.scatter(scatter_dim, y_tensor, 1)
print(_to_one_hot(torch.as_tensor([2, 4, 7]), num_classes=10))
print(_to_one_hot(torch.as_tensor([[1, 5 ,6], [2, 4, 7]]), num_classes=10))
@BretFisher
BretFisher / docker-for-mac.md
Last active November 8, 2024 13:45
Getting a Shell in the Docker Desktop Mac VM

2021 Update: Easiest option is Justin's repo and image

Just run this from your Mac terminal and it'll drop you in a container with full permissions on the Docker VM. This also works for Docker for Windows for getting in Moby Linux VM (doesn't work for Windows Containers).

docker run -it --rm --privileged --pid=host justincormack/nsenter1

more info: https://github.com/justincormack/nsenter1


@codingPingjun
codingPingjun / create_prior_box.py
Created January 27, 2017 03:11
SSD prior box creation
import pickle
import numpy as np
import pdb
img_width, img_height = 300, 300
box_configs = [
{'layer_width': 38, 'layer_height': 38, 'num_prior': 3, 'min_size': 30.0,
'max_size': None, 'aspect_ratios': [1.0, 2.0, 1/2.0]},
{'layer_width': 19, 'layer_height': 19, 'num_prior': 6, 'min_size': 60.0,
'max_size': 114.0, 'aspect_ratios': [1.0, 1.0, 2.0, 1/2.0, 3.0, 1/3.0]},
@joshlk
joshlk / faster_toPandas.py
Last active July 22, 2024 14:15
PySpark faster toPandas using mapPartitions
import pandas as pd
def _map_to_pandas(rdds):
""" Needs to be here due to pickling issues """
return [pd.DataFrame(list(rdds))]
def toPandas(df, n_partitions=None):
"""
Returns the contents of `df` as a local `pandas.DataFrame` in a speedy fashion. The DataFrame is
repartitioned if `n_partitions` is passed.
@magicznyleszek
magicznyleszek / jekyll-and-liquid.md
Last active September 16, 2024 18:47
Jekyll & Liquid Cheatsheet

Jekyll & Liquid Cheatsheet

A list of the most common functionalities in Jekyll (Liquid). You can use Jekyll with GitHub Pages, just make sure you are using the proper version.

Running

Running a local server for testing purposes: