Skip to content

Instantly share code, notes, and snippets.

View print_reverse.ras
func bisect(begin: Node*, end: Node*): Node*
return nth(begin, end, len(begin, end) / 2)
func print_reverse(begin: Node*, end: Node*)
if begin == end
return
mid := bisect(begin, end)
if mid != end
print_reverse(next(mid), end)
print_node(mid)
View per-cl.baf
IF
Heard([ANYONE], 251182)
THEN
RESPONSE #100
ReallyForceSpell(Player1, CLERIC_BLESS)
ReallyForceSpell(Player1, CLERIC_AID)
ReallyForceSpell(Player1, CLERIC_DEFENSIVE_HARMONY)
ReallyForceSpell(Player1, CLERIC_PROTECTION_FROM_EVIL_10_FOOT)
ReallyForceSpell(Myself, CLERIC_DRAW_UPON_HOLY_MIGHT)
ReallyForceSpell(Myself, CLERIC_HOLY_POWER)
@pervognsen
pervognsen / wm.el
Last active Oct 1, 2020
Dynamic tiling window manager for Emacs (inspired by dwm/awesome/xmonad for Linux)
View wm.el
(require 'cl)
(defstruct wm-window buffer (point 0) (start 0) (hscroll 0) dedicated)
(defvar wm-windows)
(defvar wm-windows-alist)
(defvar wm-focus)
(defvar wm-workspace 0)
(defvar wm-workspaces nil)
(defvar wm-layout 0)
@pervognsen
pervognsen / mu.cpp
Last active Sep 20, 2020
Mu as of the second stream
View mu.cpp
#include "mu.h"
#define _CRT_SECURE_NO_WARNINGS
#include <malloc.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define _NO_CRT_STDIO_INLINE
#include <stdio.h>
#include <stdarg.h>
#define NO_STRICT
@pervognsen
pervognsen / BTree.cpp
Created Apr 24, 2016
A B+-tree implementation with find, insert and delete in 176 lines of code.
View BTree.cpp
enum { BMAX = 32, BMIN = BMAX / 2, BHEIGHT = 6 };
struct BNode {
uint32_t length;
Key keys[BMAX];
union {
BNode *children[BMAX];
Value values[BMAX];
};
};
View port-scanner.clj
(ns port-scanner
(:import [java.net Socket InetSocketAddress]))
(defn port-open? [hostname port timeout]
(try
(with-open [sock (Socket.)]
(.connect sock (InetSocketAddress. hostname port) timeout)
port)
(catch Exception e false)))
View flame_cholesky.py
def blocks(A, block_size=(1, 1)):
i, j = block_size
while len(A):
yield A[:i, :j], A[:i, j:], A[i:, :j], A[i:, j:]
A = A[i:, j:]
# 2400 ms for 1000x1000 matrix (~0.4 GFLOPS/sec). Equivalent C code is only twice as fast (~0.8 GFLOPS/sec).
# The reason the C code isn't much faster is that it's an O(n^3) algorithm and most of the time is spent in
# the O(n^2) kernel routine for the outer product in A11[:] -= np.outer(A10, A10). Even if we posit that Python
# is 1000x slower than C for the outer loop, that's still 1000n + n^3 vs n^3, which is negligible for n = 1000.
View blocked_matrix_multiply.py
# Version 0: Use slice views to access a matrix like a block matrix.
def blocked_matrix_multiply0(A, B, block_size, panel_size):
m, p, n = A.shape[0], A.shape[1], B.shape[1]
w, h = block_size, panel_size
C = np.zeros((m, n))
for i in range(0, m, w):
for j in range(0, p, h):
row_panel = A[i:i+w, j:j+h]
for k in range(0, n, w):
column_panel = B[j:j+h, k:k+w]
View tricks.py
# Tensor product contractions with Einstein's summation notation. Examples:
# Matrix-matrix multiply is tensor(A, 'ij', B, 'jk')
# Matrix-vector multiply is tensor(A, 'ij', v, 'j')
# Matrix trace is tensor(A, 'ii')
# Matrix transpose is tensor(A, 'ji')
# Matrix diagonal is tensor('i', A, 'ii')
# Inner product is tensor(v, 'i', w, 'i')
# Outer product is tensor(v, 'i', w, 'j')
def tensor(*args, **kwargs):
result = ''
View hejlsberg_fp.asm
; Math48 Floating Point Package
; Version 1.1 Revision 1
; by Anders Hejlsberg
; 2532 Bytes
;HOPTABEL
JP FPADD
JP FPSUB
JP FPMUL
You can’t perform that action at this time.