Skip to content

Instantly share code, notes, and snippets.

@dstein64
dstein64 / scrollview-gitsigns.lua
Last active June 3, 2023 03:32
Sample code showing how to add gitsigns support to nvim-scrollview
local api = vim.api
local scrollview = require('scrollview')
local group = 'gitsigns'
local add = scrollview.register_sign_spec({
group = group,
highlight = 'GitSignsAdd',
symbol = ' ',
}).name
@dstein64
dstein64 / gpu_avail.py
Created April 8, 2022 17:52
Display a table of GPU availability on a Slurm server.
#!/usr/bin/env python3
"""
Display a table of GPU availability on a Slurm server.
Usage:
$ scontrol -M gpu show node | gpu_avail.py
"""
import sys
@dstein64
dstein64 / scrollview_hide.vim
Last active December 24, 2020 03:13
An example script for hiding nvim-scrollview scrollbars shortly after scrolling
" The amount of time, in milliseconds, until scrollbar hides after scrolling.
let s:hide_delay = 800
" Time of the last WinScrolled event
let s:scroll_time = 0
" Keep track of pending updates. Ignore updates if there are already pending
" updates, to prevent lag.
let s:pending = 0
@dstein64
dstein64 / Anagrams.java
Last active October 29, 2020 17:09
Example code for a Stack Overflow comment: https://stackoverflow.com/a/64549281/1509433
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Anagrams {
public static List<String> anagrams(String s) {
List<String> output = new ArrayList<String>();
if (s.length() == 0)
return output;
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#include "revdoor.hpp"
using namespace std;
#include <functional>
#include <iostream>
#include <numeric>
#include <vector>
#include <unordered_map>
using namespace std;
typedef unsigned long ulong;
import kmeans1d
x = [4.0, 4.1, 4.2, -50, 200.2, 200.4, 200.9, 80, 100, 102]
k = 4
clusters, centroids = kmeans1d.cluster(x, k)
print(clusters) # [1, 1, 1, 0, 3, 3, 3, 2, 2, 2]
print(centroids) # [-50.0, 4.1, 94.0, 200.5]
from distutils.spawn import find_executable
import glob
import os
import random
import shutil
import subprocess
import sys
STYLE_IMAGES_PATH = 'paint-by-numbers/test'
CONTENT_IMAGE_PATH = 'boston.jpg'
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
/*
* Calculates factorial.
* Overflow is not checked/handled.
*/
int factorial(int x) {
assert(x >= 0);
@dstein64
dstein64 / bezier_neural_walk.py
Last active March 7, 2021 13:19
Random Bézier Walk in a Random Neural Network
#!/usr/bin/env python
from __future__ import print_function
# Images can be converted to video with ffmpeg.
# > ffmpeg -pattern_type glob \
# -i "*.png" \
# -vcodec libx264 \
# output.avi