This file contains hidden or 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
"""Dump a Nintendo 64 .ctl file to text. | |
Usage: python3 ctl.py <file.ctl> | |
""" | |
import argparse | |
import struct | |
import sys | |
SPACE = ' ' * 80 | |
def pr(indent, *msg): |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
// See: https://stackoverflow.com/a/48812277/82294 | |
template <int N> | |
void add(unsigned long long *dest, unsigned long long *src) { | |
__asm__( | |
"movq (%1), %%rax" | |
"\n\taddq %%rax, (%0)" | |
"\n.local add_offset" | |
"\n.set add_offset,0" | |
"\n.rept %P2" |
This file contains hidden or 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
// Faster solution for: | |
// http://www.boyter.org/2017/03/golang-solution-faster-equivalent-java-solution/ | |
// With threading. | |
// g++ -std=c++11 -Wall -Wextra -O3 -pthread | |
// On my computer (i5-6600K 3.50 GHz 4 cores), takes about ~160 ms after the CPU | |
// has warmed up, or ~80 ms if the CPU is cold (due to Turbo Boost). | |
// How it works: Start by generating a list of losing states -- states where the | |
// game can end in one turn. Generate a new list of states by running the game |