Skip to content

Instantly share code, notes, and snippets.

@swarmer
swarmer / ulimits.txt
Created September 26, 2019 14:47
ulimits.txt
From: https://superuser.com/a/1322187/71861
No need to change anything in the /etc/security/limits.conf file, it is ignored if you are using systemd.
(reproducing a modified answer to another question on the network...)
An alternative for those who prefer not to edit the default /etc/systemd/system.conf and /etc/systemd/user/conf files:
create a new file /etc/systemd/system.conf.d/limits.conf with these contents:
@swarmer
swarmer / gist:2fea2ec506578752762f66f148be0743
Created January 19, 2019 21:49
Sort processes by the number of open file descriptors
for pid in [0-9]*; do echo "PID = $pid with $(ls /proc/$pid/fd/ | wc -l) file descriptors"; done | sort -n -k5
from __future__ import annotations
import argparse
from itertools import islice
import os
from pathlib import Path
from typing import List
import numpy as np
from PIL import Image
from ipywidgets import Image
from io import StringIO
import pydotplus
from sklearn.tree import export_graphviz
dot_data = StringIO()
export_graphviz(tree, feature_names=data.columns,
out_file=dot_data, filled=True)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
Image(value=graph.create_png())
@swarmer
swarmer / bug.cpp
Last active October 21, 2018 01:12
#include <iostream>
#include <memory>
struct A {
A(std::unique_ptr<int> ptr) {
std::cout << *ptr << std::endl;
}
};
@swarmer
swarmer / total_size.py
Created July 17, 2018 16:19
Total object size including numpy arrays
from __future__ import print_function
from sys import getsizeof, stderr
from itertools import chain
from collections import deque
try:
from reprlib import repr
except ImportError:
pass
def total_size(o, handlers={}, verbose=False):
def show_images(images, cols = 1, titles = None):
import matplotlib.pyplot as plt
import numpy as np
"""Display a list of images in a single figure with matplotlib.
Parameters
---------
images: List of np.arrays compatible with plt.imshow.
import cProfile
import pstats
import marshal
import uuid
import functools
def _save_profiling(p):
try:
stats = pstats.Stats(p)
@swarmer
swarmer / convert.py
Created January 9, 2018 21:27
stackoverflow benchmark data
#!/usr/bin/env python3
import csv
import sys
import xml.sax
class StreamHandler(xml.sax.handler.ContentHandler):
def __init__(self, csvwriter):
super().__init__()
#[derive(Debug, PartialEq)]
struct A {
x: i32,
}
fn main() {
let x = Box::new(A { x: 42 });
let v = *x;
}