Skip to content

Instantly share code, notes, and snippets.

View scturtle's full-sized avatar
🐢

scturtle

🐢
View GitHub Profile
@scturtle
scturtle / flash_attention.py
Last active April 11, 2024 16:38
flash attention v1 v2 in numpy
import numpy as np
N_inp = 64
N_out = 64
d = 128
Q = np.random.randn(N_out, d)
K = np.random.randn(N_inp, d)
V = np.random.randn(N_inp, d)
O = np.random.randn(N_out, d)
@scturtle
scturtle / matmul.py
Created April 8, 2024 11:44
how matmul is tiled in cuda
import numpy as np
from threading import Barrier, Thread
from collections import namedtuple
dim3 = namedtuple("dim3", ["x", "y", "z"], defaults=(1, 1))
TILE = 16
def cdiv(a, b):
#!/usr/bin/env python3
import re
from pathlib import Path
from typing import List
MARK = "// -----// IR Dump"
PAT = re.compile(r'IR Dump \w+ (\w+)')
def main(infile: Path, outdir: Path):
assert infile.exists(), f'{infile} not exists'
@scturtle
scturtle / script.js
Created December 1, 2023 06:39
adventofcode daylight mode userscript
// ==UserScript==
// @name adventofcode daylight mode
// @namespace Violentmonkey Scripts
// @match https://adventofcode.com/*
// @grant none
// @version 1.0
// @author scturtle
// @description 2023/11/27 16:52:13
// ==/UserScript==
@scturtle
scturtle / build.sh
Last active October 23, 2023 03:06
build minimal emacs
# ubuntu/debian
# sudo apt install libjansson-dev texinfo gnutls-bin
# homebrew
brew install jansson texinfo
# build
CFLAGS="-O2 -DNDEBUG" ./configure \
--without-all --without-x --without-ns --without-libgmp \
--with-json --with-modules --with-threads \
@scturtle
scturtle / ftpserver.py
Created June 20, 2011 16:03
simple ftp server by python
#!/usr/bin/env python2
# coding: utf-8
import os,socket,threading,time
#import traceback
allow_delete = False
local_ip = socket.gethostbyname(socket.gethostname())
local_port = 8888
currdir=os.path.abspath('.')
@scturtle
scturtle / index.html
Created August 13, 2012 15:33
python websocket server
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<title>WebSocket test</title>
</head>
<body>
<script>
if (window.MozWebSocket) {
window.WebSocket = window.MozWebSocket;
@scturtle
scturtle / txt2epub.py
Created September 10, 2011 07:17
txt to epub
# coding: utf-8
import os
#书籍信息
title='test book'
creator='scturtle'
description='blablablabla'
#章节文件
txtlist=['1.txt','2.txt']
@scturtle
scturtle / evol.py
Created April 18, 2014 10:09
generic algorithm using DEAP
from deap import base, creator, tools, algorithms
from random import randint, random, gauss
from PIL import Image, ImageDraw
from functools import partial
from math import sqrt
import numpy
PIC = Image.open('head.jpg')
SIZE = 100
@scturtle
scturtle / emutool.py
Created May 16, 2023 16:22
emuiibo data generator
import json
import time
import random
import struct
import urllib.request
from pathlib import Path
# https://www.amiiboapi.com/api/amiibo/
database = json.load(open("amiibos.json"))