Skip to content

Instantly share code, notes, and snippets.

View dschaehi's full-sized avatar
🎯
Focusing

Jae Hee Lee dschaehi

🎯
Focusing
View GitHub Profile
#!/usr/local/miniconda3/bin/python
# A snippet for reading a Unicode string from clipboard, convert the string to one that is ASCII compatible, and then paste it to the clipboard. This converts for example "ß" to "ss"..
# The code is based on the answer https://stackoverflow.com/a/25802742/3706018.
import pasteboard
import subprocess
from unidecode import unidecode
pb = pasteboard.Pasteboard()
asciidata = unidecode(pb.get_contents())
@dschaehi
dschaehi / max_norm.py
Last active April 3, 2019 15:48
Forces tensors to have norms within a range
class MaxNorm(object):
def __init__(self, max_value=1, frequency=5):
self.frequency = frequency
self.max_value = max_value
self.tiny = _finfo(torch.FloatTensor([])).tiny
def __call__(self, module):
if hasattr(module, "weight"):
w = module.weight.data
norms = w.norm(p=2, dim=w.dim() - 1, keepdim=True)
@dschaehi
dschaehi / custom.css
Last active June 12, 2019 17:34
Jupyter Notebook Solarized theme. Install jupyterthemes with the solarized dark theme and overwrite custom.css
@font-face {
font-family: "DejaVu Sans Mono";
font-weight: normal;
font-style: normal;
src: local('"DejaVu Sans Mono"'), url('fonts/dejavu.ttf') format('truetype');
}
@font-face {
font-family: "DejaVu Sans Mono";
font-weight: normal;
font-style: italic;
@dschaehi
dschaehi / emacs-zotero-bib-fetch.el
Created June 28, 2019 13:03 — forked from andersjohansson/emacs-zotero-bib-fetch.el
Emacs-zotero-bib-fetch: fork of zotelo to use better-bibtex's pull export
;;; emacs-zotero-bib-fetch.el --- Manage Zotero collections from emacs
;;
;; Filename: emacs-zotero-bib-fetch.el
;; Author: Anders Johansson, based on zotelo by Spinu Vitalie
;; Maintainer: Anders Johansson
;; Copyright (C) 2011-2014, Anders Johansson and Spinu Vitalie
;; Created: 1 Jul 2014
;; Version: 1.2
;; URL: https://github.com/andersjohansson/emacs-zotero-bib-fetch
;; Keywords: zotero, emacs, reftex, bibtex, bibliography manager
@dschaehi
dschaehi / index.css
Last active September 17, 2022 09:06
Jupyterlab Solarized Dark Theme
/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/
/*
The following CSS variables define the main, public API for styling JupyterLab.
These variables should be used by all plugins wherever possible. In other
words, plugins should not define custom colors, sizes, etc unless absolutely
necessary. This enables users to change the visual theme of JupyterLab
@dschaehi
dschaehi / jupyterlab_shortcuts.json
Last active June 17, 2022 06:17
Jupyter Lab Keyborad Shortcuts
{
"shortcuts": [
{
"command": "notebook:toggle-all-cell-line-numbers",
"keys": [
"Alt L"
],
"selector": ".jp-Notebook:focus"
},
// Moving cells
@dschaehi
dschaehi / install-cuda-10-bionic.sh
Created August 10, 2019 13:11 — forked from bogdan-kulynych/install-cuda-10-bionic.sh
Install CUDA 10 on Ubuntu 18.04
#!/bin/bash
# Install CUDA Toolkit 10
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub && sudo apt update
sudo dpkg -i cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
sudo apt update
sudo apt install -y cuda
@dschaehi
dschaehi / emacs.json
Created March 29, 2020 08:01
Karabiner Elements complex modifications for emacs
{
"title": "Emacs keys",
"rules": [
{
"description": "Change right_option + a to right_control + a",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "a",
@dschaehi
dschaehi / extract_features.py
Last active March 15, 2022 21:27
Extracting ResNet Features Using PyTorch
from collections import OrderedDict
from torchvision import models
def gen_feature_extractor(model, output_layer):
layers = OrderedDict()
for (k, v) in model._modules.items():
layers[k] = v
if k == output_layer:
@dschaehi
dschaehi / hamming_score.py
Created November 6, 2021 10:32
The Hamming score in PyTorch
import torch
def hamming_score(pred, answer):
out = ((pred & answer).sum(dim=1) / (pred | answer).sum(dim=1)).mean()
if out.isnan():
out = torch.tensor(1.0)
return out
answer = torch.tensor([[0, 1, 0], [0, 1, 1], [1, 0, 1], [0, 0, 1]])