Skip to content

Instantly share code, notes, and snippets.

@schmmd
schmmd / slurm-gpu-stats.py
Created November 20, 2019 19:08
Slurm GPU Stats
#!/usr/bin/env python
import os
import re
import subprocess
import socket
import sys
def pids_of_jid(jid):
result = subprocess.run(["sstat", "-p", "--format=PID", "-j", jid, "--noheader"], stdout=subprocess.PIPE)
import numpy as np
import os
import time
import warnings
import pickle
# from accimage import Image
from PIL import Image
import io
try:
@asroy
asroy / Debugging Mixed Python C++ code in Visual Studio Code
Last active August 25, 2022 17:43
Debugging Mixed Python/C++ code in Visual Studio Code
I've tested it on Fedora 23 and Ubuntu 16.04. I'm using gcc-5.3.1, python-3.4, VS Code-1.14.0
You can debug mixed Python/C++ in the same GUI. It also works for MPI applications. You can switch between the debuggers and corresponding call stacks.
1. Packages needed
1) Visual Studio Code
2) Extensions for VS Code:
"Python" from Don Jayamanne (I'm using 0.6.7)
This allows VS Code act as the front end to debug python.
This gives VS Code ability to attach to a python script that uses module "ptvsd".
@csswizardry
csswizardry / README.md
Last active April 2, 2024 20:17
Vim without NERD tree or CtrlP

Vim without NERD tree or CtrlP

I used to use NERD tree for quite a while, then switched to CtrlP for something a little more lightweight. My setup now includes zero file browser or tree view, and instead uses native Vim fuzzy search and auto-directory switching.

Fuzzy Search

There is a super sweet feature in Vim whereby you can fuzzy find your files using **/*, e.g.:

:vs **/*<partial file name><Tab>
@JosephRedfern
JosephRedfern / YouTube 8m Video ID scraper.py
Last active August 12, 2021 02:22
Scrapes the youtube video IDs for the youtube-8m data set. Probably buggy. Could be threaded.
import requests
from collections import defaultdict
csv_prefix = "https://research.google.com/youtube8m/csv"
r = requests.get("{0}/verticals.json".format(csv_prefix))
verticals = r.json()
block_urls = defaultdict(list)
count = 0
import tensorflow as tf
from tensorflow.python.framework import ops
import numpy as np
# Define custom py_func which takes also a grad op as argument:
def py_func(func, inp, Tout, stateful=True, name=None, grad=None):
# Need to generate a unique name to avoid duplicates:
rnd_name = 'PyFuncGrad' + str(np.random.randint(0, 1E+8))
@udibr
udibr / gruln.py
Last active November 7, 2020 02:34
Keras GRU with Layer Normalization
import numpy as np
from keras.layers import GRU, initializations, K
from collections import OrderedDict
class GRULN(GRU):
'''Gated Recurrent Unit with Layer Normalization
Current impelemtation only works with consume_less = 'gpu' which is already
set.
# Arguments
# A yaml constructor is for loading from a yaml node.
# This is taken from @misha 's answer: http://stackoverflow.com/a/15942429
def opencv_matrix_constructor(loader, node):
mapping = loader.construct_mapping(node, deep=True)
mat = np.array(mapping["data"])
mat.resize(mapping["rows"], mapping["cols"])
return mat
yaml.add_constructor(u"tag:yaml.org,2002:opencv-matrix", opencv_matrix_constructor)
# A yaml representer is for dumping structs into a yaml node.
@epixoip
epixoip / 8x1080.md
Last active March 20, 2024 17:14
8x Nvidia GTX 1080 Hashcat Benchmarks
@fchollet
fchollet / classifier_from_little_data_script_3.py
Last active September 13, 2023 03:34
Fine-tuning a Keras model. Updated to the Keras 2.0 API.
'''This script goes along the blog post
"Building powerful image classification models using very little data"
from blog.keras.io.
It uses data that can be downloaded at:
https://www.kaggle.com/c/dogs-vs-cats/data
In our setup, we:
- created a data/ folder
- created train/ and validation/ subfolders inside data/
- created cats/ and dogs/ subfolders inside train/ and validation/
- put the cat pictures index 0-999 in data/train/cats