Skip to content

Instantly share code, notes, and snippets.

@depp
depp / test.hs
Created March 5, 2018 05:51
Haskell Benchmark
{-# LANGUAGE BangPatterns #-}
-- https://stackoverflow.com/questions/49080119/why-is-statet-faster-in-this-example
module Main where
import Control.Applicative
import Control.Monad.State.Strict
import Criterion.Main
import Data.IORef
import System.Environment
@depp
depp / pipe.py
Created August 9, 2018 14:12
Simple command piping in Python
# https://stackoverflow.com/questions/51756938/how-to-make-a-generic-method-in-python-to-execute-multiple-piped-shell-commands
import shlex
import subprocess
def run_pipe(cmds):
pipe = subprocess.DEVNULL
procs = []
for cmd in cmds:
proc = subprocess.Popen(cmd, stdin=pipe, stdout=subprocess.PIPE)
procs.append(proc)
@depp
depp / scrape.py
Created February 26, 2019 15:56
Scraping with Python
# https://stackoverflow.com/questions/54876010
from bs4 import BeautifulSoup
import json
import requests
import sys
from urllib.parse import urljoin
def get_list(uri):
"""Scan the manga list for links to manga."""
response = requests.get(uri)
@depp
depp / hello32.asm
Created April 9, 2019 16:10
32-bit Hello World for DOS with DOS/32A
;; 32-bit Hello World
;; This creates a Linear Executable which can be run with DOS/32A.
;; See: http://dos32a.narechk.net/index_en.html
;;
;; To compile,
;; nasm -o hello32.exe -f bin hello32.asm
;; To run,
;; dos32a hello32
;; Screenshot: https://imgur.com/EiaU2py
bits 32
@depp
depp / find_merge_conflicts.py
Created April 23, 2019 19:11
Find Git merge conflicts
# https://stackoverflow.com/questions/55817243/does-git-keep-a-record-of-past-merge-conflicts
import subprocess
import sys
def list_merges():
proc = subprocess.run(
['git', 'rev-list', '--parents', '--min-parents=2', '--all'],
stdout=subprocess.PIPE,
check=True,
encoding='ASCII',
@depp
depp / heightmap_smooth.py
Last active September 17, 2019 14:35
How to Create a Smooth Heightmap
# https://www.reddit.com/r/proceduralgeneration/comments/d5gde4/heightmap_with_strict_neighbour_cell_constraints/
import numpy as np
import scipy.ndimage as ndimage
def generate(w, h, d):
return np.random.randint(0, d, (w, h))
def smooth(arr):
for z in range(np.min(arr), np.max(arr) + 1):
# Set of all tiles at height Z.
@depp
depp / info.txt
Created April 30, 2015 20:56
Race condition example
This is what happens when I run the program. Note that 2 and 4 appear twice, but 0 and 1 never appear. The output is non-deterministic, because there is a race condition, the output could be almost anything.
Arg = 2
Arg = 4
Arg = 3
Arg = 5
Arg = 6
Arg = 2
Arg = 7
Arg = 8
Notice how each number appears only once.
The order is still scrambled, but we don't care about the order.
Arg = 1
Arg = 4
Arg = 2
Arg = 6
Arg = 3
Arg = 7
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
Error::Transient(ref e) => Some(e),
Error::Fatal(ref e) => Some(e),
}
}
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
&Error::Transient(ref e) => Some(e),
@depp
depp / rsrc2macbinary.py
Created March 18, 2021 04:55
Convert resource fork files to MacBinary files
"""rsrc2macbinary.py - convert resource fork to MacBinary file"""
import datetime
import os
import struct
import sys
import zlib
def die(*msg):
print('Error:', *msg, file=sys.stderr)
raise SystemExit(1)