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 code installs a custom signal handler for the SIGSEGV signal | |
// (segmentation fault) and then purposefully creates a segmentation | |
// fault. The custom handler `handler` is then entered, which now | |
// increases the instruction pointer by 1, skipping the current byte | |
// of the faulty instruction. This is done for as long as the faulty | |
// instruction is still active; in the below case, that's 2 bytes. | |
// Note: This is for 64 bit systems. If you prefer 32 bit, change | |
// `REG_RIP` to `REG_EIP`. I didn't bother putting an appropriate | |
// `#ifdef` here. |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#ifdef _MSC_VER | |
#include <intrin.h> /* for rdtscp and clflush */ | |
#pragma optimize("gt",on) | |
#else | |
#include <x86intrin.h> /* for rdtscp and clflush */ | |
#endif |
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
const {isMainThread, Worker, workerData, parentPort} = require("worker_threads"); | |
const {safeEval} = require("safe-eval"); | |
if (isMainThread) { | |
// functionObject must be pure function | |
module.exports = {executeAsync: function(functionObject = function(...paramsObject) {return undefined;}, ...paramsObject) { | |
return new Promise(function(resolve, reject) { | |
const worker = new Worker(__filename, { | |
workerData: { | |
functionString: functionObject.toString(), | |
argumentsObject: paramsObject, |
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
from typing import Iterator, Any | |
def natural(start: int = 0) -> Iterator[int]: | |
n = start | |
while True: | |
yield n | |
n += 1 | |
def sieve_prime() -> Iterator[int]: | |
def sieve(i: Iterator[int]) -> Iterator[int]: |
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
from typing import Tuple, Iterator, Any | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib import animation | |
# from matplotlib.collections import PathCollection | |
from matplotlib.figure import Figure | |
from matplotlib.lines import Line2D | |
np.seterr(all='raise') |
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
template<typename type> | |
inline void swap_sort(type& a, type& b) { | |
if (a > b) { | |
type temp = a; | |
a = b; | |
b = temp; | |
} | |
} | |
#include<array> | |
// source: http://ndevilla.free.fr/median/median.pdf |
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
package main | |
import ( | |
"log" | |
"net/http" | |
) | |
func main() { | |
fs := http.FileServer(http.Dir("./")) | |
http.Handle("/", http.StripPrefix("/", fs)) |
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
import random | |
import pygame | |
from pygame.locals import * | |
class snake: | |
def __init__(self, points, velocity): | |
self.points = points | |
self.velocity = velocity | |
self.head = points[-1] | |
self.tail = points[0] |
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
from typing import Callable | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import sparse_uls | |
np.random.seed(1234) | |
def forward_transform(N: int, K: int) -> np.ndarray: |
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
/* | |
* fork.c | |
* Experimental fork() on Windows. Requires NT 6 subsystem or | |
* newer. | |
* | |
* Copyright (c) 2012 William Pitcock <nenolod@dereferenced.org> | |
* | |
* Permission to use, copy, modify, and/or distribute this software for any | |
* purpose with or without fee is hereby granted, provided that the above | |
* copyright notice and this permission notice appear in all copies. |
OlderNewer