Skip to content

Instantly share code, notes, and snippets.

@fny
fny / jupyter-resource-usage.py
Created August 11, 2022 14:21
Compute resource usage by Jupyter Notebooks at a given address (RAM and CPU)
import subprocess
import requests
import psutil
def get_notebooks(host, port, token = None):
sessions_url = f'http://{host}:{port}/api/sessions/?token={token}' if token else f'http://{host}:{port}/api/sessions'
response = requests.get(sessions_url).json()
notebooks = [{'kernel_id': notebook['kernel']['id'],
'path': notebook['notebook']['path']} for notebook in response]
@fny
fny / list.md
Created January 28, 2022 01:40 — forked from ih2502mk/list.md
Quantopian Lectures Saved
@fny
fny / bash.sh
Created August 11, 2021 02:06
bash-snippets.sh
function concat_with_header() {
# Quoted suffix to pattern match for concatenation (e.g. '*.csv')
local suffix="${1}"
# Name of the output file
local output="${2:-combined.out}"
# Number of lines to use for the header
local header_length="${3:-1}"
# Grab the header from the first file
local header=`echo -e "$(ls -b *$suffix | head -n$header_length)"`
head -1 $header_file > $output; tail -n +"`expr $header_length + 1`" -q *$suffix >> $output
@fny
fny / randomBase64.kt
Created September 9, 2020 17:45
Generate Random Base64 String
package greenlight.etc
import java.security.SecureRandom
import kotlin.math.abs
val BASE58_ALPHABET = "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
fun randomBase58(length: Int): String {
@fny
fny / autossh-tunnel.service
Created May 16, 2020 21:58
Ubuntu service to start an AutoSSH tunnel
[Unit]
Description=AutoSSH tunnel service
After=network-online.target sshd.service
[Service]
Environment="AUTOSSH_GATETIME=0"
Environment="AUTOSSH_PORT=0"
ExecStart=/usr/bin/autossh -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -N -R 2222:localhost:22 -R 8888:localhost:8888 user@middlman.dev
[Install]
@fny
fny / shrink_dataframe.py
Created December 13, 2019 00:12
Reduce Memory Usage of a Pandas Dataframe
import numpy as np
def shrink_df(df, categorize=False, verbose=False):
"""Reduces the memory use of a data frame by using more compact types.
Args:
df (pandas.DataFrame): The dataframe
categorize (bool): Whether strings should be converted to categorical values.
Note this may cause memory use to increase slightly.
verbose (bool): Whether to print memory savings to stdout.
@fny
fny / icd10_to_charlson_comorbidity_index_crosswalk.R
Last active September 14, 2018 21:18
ICD10 to Charlson Comorbidity Index Crosswalk
# icd10_map_charlson from https://github.com/jackwasey/icd/blob/master/data/icd10_map_charlson.RData
df = data.frame("comorbidity" = character(0), "icd10" = character(0), "score" = numeric(0), stringsAsFactors = FALSE)
scores = data.frame(
MI = 1,
CHF = 1,
PVD = 1,
Stroke = 1,
Dementia = 1,
@fny
fny / MIT License Comment Headers.md
Created March 3, 2018 17:38
MIT License Comment Headers

MIT License Comment Headers Formatted for Various Languages

A convenient reference for adding a MIT license to a work.

All prepared texts are hard wrapped at 80 characters unless stated otherwise.

No Wrap

@fny
fny / GNU LGPL Comment Headers.md
Last active May 18, 2022 07:00
GNU LGPL Comment Headers.md

GNU LGPL Comment Headers Formatted for Various Languages

A convenient reference for adding a LGPL license to a work.

All prepared texts are hard wrapped at 80 characters unless stated otherwise.

No Wrap

Keybase proof

I hereby claim:

  • I am fny on github.
  • I am fny (https://keybase.io/fny) on keybase.
  • I have a public key whose fingerprint is 477B 6E2F 415F 02BC AA6C 44E0 1E9C CF9B 131E 417C

To claim this, I am signing this object: