Skip to content

Instantly share code, notes, and snippets.

@bjourne
bjourne / gist:8958a3918b6f0e61840a5fc10a546b4b
Created April 11, 2025 14:23
Emacs recompiles too much
Missing ‘lexical-binding’ cookie in "/opt/emacs/share/emacs/31.0.50/site-lisp/subdirs.el"
Missing ‘lexical-binding’ cookie in "/opt/emacs/share/emacs/site-lisp/subdirs.el"
Warning (files): Missing ‘lexical-binding’ cookie in "/tmp/emacs-async-comp-magit-submodule-YeXZ8E.el".
You can add one with ‘M-x elisp-enable-lexical-binding RET’.
See ‘(elisp)Selecting Lisp Dialect’ and ‘(elisp)Converting to Lexical Binding’
for more information.
Compiling /home/bjourne/.config/emacs/packages/magit-20250401.1753/magit-submodule.el...
In magit-submodule-remove:
magit-submodule.el:380:11: Warning: ‘if-let’ is an obsolete macro (as of 31.1); use ‘if-let*’ instead.
import sympy as sp
def sigmoid(x):
return 1 / (1 + sp.exp(-x))
w1, w2, w3, w4, w5, w6 = sp.symbols("w1 w2 w3 w4 w5 w6")
x1 = 0.5
x2 = 0.2
z1 = x1*w1 + x2*w3
z2 = x1*w2 + x2*w4
h1 = sigmoid(z1)
Base 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
--------------------------------------------------------
0x03E8: E8 E9 EA EB EC ED EE EF F0 F1 F2 F3 F4 F5 F6 F7
0x03F8: F8 F9 FA FB FC FD FE FF 00 00 FF 00 04 05 06 07
0x0408: 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17
0x0418: 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27
0x0428: 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37
0x0438: 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47
0x0448: 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57
0x0458: 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67
756 42% Automatic GC
752 42% - redisplay_internal (C function)
737 41% - jit-lock-function
737 41% - jit-lock-fontify-now
737 41% - jit-lock--run-functions
737 41% - #<byte-code-function B8A>
737 41% - font-lock-fontify-region
737 41% - c-font-lock-fontify-region
712 40% - font-lock-default-fontify-region
712 40% - font-lock-fontify-keywords-region
@bjourne
bjourne / repr.cl
Created November 15, 2024 13:59
Emacs c-mode really slow syntax highlighting
__kernel void
foo(
uint dc_dim, uint sc_dim,
uint fy_dim, uint fx_dim,
__global const float * restrict F,
uint sy_dim, uint sx_dim,
__global const float * restrict S,
uint padding,
__global float * restrict D
) {
@bjourne
bjourne / gist:842695100e99c8fd6ef87fcdd0a6ed0b
Last active November 15, 2024 13:54
CPU-Profiler-Report
19470 68% - redisplay_internal (C function)
19451 68% - jit-lock-function
19451 68% - jit-lock-fontify-now
19440 68% - jit-lock--run-functions
19437 68% - #<compiled -0x15696eac41f91343>
19437 68% - font-lock-fontify-region
19425 68% - c-font-lock-fontify-region
18788 66% - font-lock-default-fontify-region
18596 65% - font-lock-fontify-keywords-region
10090 35% - c-font-lock-cut-off-declarators
@bjourne
bjourne / vgg16_cifar.py
Last active August 21, 2024 00:18
VGG16 in PyTorch
from itertools import islice
from pathlib import Path
from torch.nn import *
from torch.nn.functional import cross_entropy, mse_loss, one_hot
from torch.nn.init import constant_, kaiming_normal_, normal_
from torch.optim import SGD
from torch.optim.lr_scheduler import CosineAnnealingLR
from torch.utils.data import DataLoader
from torchinfo import summary
from torchtoolbox.transform import Cutout
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <xmmintrin.h>
#include <mmintrin.h>
#include "matrix.h"
#include "z_order.h"
using namespace nda;
@bjourne
bjourne / bsearch.c
Created August 11, 2023 17:21
Fast and slow (?) bsearch
static uint32_t *
fast_bsearch_u32(uint32_t *base, size_t nmemb, uint32_t key) {
while (nmemb) {
size_t half = nmemb >> 1;
if (base[half] < key) {
base += nmemb - half;
}
nmemb = half;
}
return base;
// Compile and run with:
//
// gcc -O3 -march=native fast-strlen.c -lpthread -o fast-strlen
// && ./fast-strlen
//
// Use gcc because clang is too smart and optimizes away parts of the
// benchmark. Results on Xeon(R) CPU E5-2650 v4 @ 2.20GHz with gcc
// 9.4.0:
//
// Scanning 10 times over 4.00GB...