Skip to content

Instantly share code, notes, and snippets.

@nullhook
nullhook / compute.cpp
Last active November 23, 2023 03:13
compute shader using metal-cpp
View compute.cpp
#include <iostream>
#define NS_PRIVATE_IMPLEMENTATION
#define CA_PRIVATE_IMPLEMENTATION
#define MTL_PRIVATE_IMPLEMENTATION
#include "Metal.hpp"
MTL::Buffer* outputs;
MTL::Buffer* input0;
@nullhook
nullhook / linearized_bufs
Last active December 8, 2023 11:57
tinygrad buffers at each level
View linearized_bufs
[MemBuffer(idx=0, dtype=dtypes.float, st=ShapeTracker(views=(View(shape=(1, 3, 224, 224), strides=(0, 50176, 224, 1), offset=0, mask=None, contiguous=True),))), ConstBuffer(val=1.5707963267948966, dtype=dtypes.float, st=ShapeTracker(views=(View(shape=(1, 3, 224, 224), strides=(0, 0, 0, 0), offset=0, mask=None, contiguous=False),))), MemBuffer(idx=1, dtype=dtypes.float, st=ShapeTracker(views=(View(shape=(1, 3, 224, 224), strides=(0, 50176, 224, 1), offset=0, mask=None, contiguous=True),))), ConstBuffer(val=6.283185307179586, dtype=dtypes.float, st=ShapeTracker(views=(View(shape=(1, 3, 224, 224), strides=(0, 0, 0, 0), offset=0, mask=None, contiguous=False),))), ConstBuffer(val=1.0, dtype=dtypes.float, st=ShapeTracker(views=(View(shape=(1, 3, 224, 224), strides=(0, 0, 0, 0), offset=0, mask=None, contiguous=False),))), MemBuffer(idx=1, dtype=dtypes.float, st=ShapeTracker(views=(View(shape=(1, 3, 224, 224), strides=(0, 50176, 224, 1), offset=150528, mask=None, contiguous=False),))), ConstBuffer(val=0.6931471805599
@nullhook
nullhook / chars.cc
Last active June 9, 2021 03:17
char type conversions in c++
View chars.cc
#include <iostream>
#include <locale>
#include <string>
#include <fstream>
#include <codecvt>
// utf8/utf16/utf32 can be directly written to file without conversions
// sizeof(T) gives you bytes of the type
// .size() .length() gives count of chars
// if char16_t is stored the open the file with utf16 encoding
@nullhook
nullhook / .js
Last active June 30, 2020 16:11
tiny helper to create DOM elements
View .js
const $T = text => document.createTextNode(text)
function $E(tag, props, kids) {
const elem = document.createElement(tag)
for (const k in props) {
elem[k] = props[k]
}
for (const kid of kids) {
elem.appendChild(kid)
}
@nullhook
nullhook / .jsx
Created December 15, 2019 10:17
media queries with styled components
View .jsx
// ****************************************/
// Media Queries
// ****************************************/
// -----------------------------------------
import { css } from 'styled-components';
// Media breakpoints
const desktopXL = 1680;
const desktop = 1280;
@nullhook
nullhook / A.jsx
Last active July 20, 2022 08:46
Advance React Patterns
View A.jsx
// A component with accessors
// The accessors can only be accessed inside the actual component
function C(props) {
// ...
}
C.bar = () => {
// this method can be accessed within the component
}
View media-queries.sass
// ****************************************/
// Media Queries
// ****************************************/
// Media breakpoints
$mq-desktop-xl: 1680px
$mq-desktop: 1382px
$mq-desktop-small: 1280px
$mq-tablet-landscape: 1024px
$mq-tablet-portrait: 768px