This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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) |