Skip to content

Instantly share code, notes, and snippets.

View munael's full-sized avatar

Muhammad N ElNokrashy munael

View GitHub Profile
@gatopeich
gatopeich / dataclass_from_dict.py
Created February 19, 2019 15:08
Python 3.7 dataclass to/from dict/json
from dataclasses import dataclass, fields as datafields
from ujson import dumps, loads
# Note: ujson seamlessly serializes dataclasses, unlike stdlib's json
@dataclass
class Point:
x: float
y: float
# Shallow dataclass can be rebuilt from dict/json:
@fay59
fay59 / Quirks of C.md
Last active January 23, 2024 04:24
Quirks of C

Here's a list of mildly interesting things about the C language that I learned mostly by consuming Clang's ASTs. Although surprises are getting sparser, I might continue to update this document over time.

There are many more mildly interesting features of C++, but the language is literally known for being weird, whereas C is usually considered smaller and simpler, so this is (almost) only about C.

1. Combined type and variable/field declaration, inside a struct scope [https://godbolt.org/g/Rh94Go]

struct foo {
   struct bar {
 int x;
@WorldSEnder
WorldSEnder / higher-kinded.ts
Last active January 9, 2023 21:37
Higher kinded types in typescript
// The two main components are the interfaces
// Generic<T, Context> and GenericArg<"identifier">
// Generic basically structurally replaces types in T that are GenericArg<S>
// for some `S extends keyof Context` with `Context[S]`
// See the test cases for specific uses.
// ====== TESTING
// Pass through for trivial types
type Test00 = Generic<number>;
@nadavrot
nadavrot / Matrix.md
Last active May 22, 2024 13:38
Efficient matrix multiplication

High-Performance Matrix Multiplication

This is a short post that explains how to write a high-performance matrix multiplication program on modern processors. In this tutorial I will use a single core of the Skylake-client CPU with AVX2, but the principles in this post also apply to other processors with different instruction sets (such as AVX512).

Intro

Matrix multiplication is a mathematical operation that defines the product of

import re
import os
import glob
import pandas as pd
import matplotlib.pyplot as plt
from collections import OrderedDict
fig_size = [12, 9]
@honix
honix / let.red
Last active September 5, 2017 15:24
Red []
let: func [
binds
block
/local
ctx
][
ctx: context append/only append binds copy [result: do] block
select ctx 'result
@snoyberg
snoyberg / Main.hs
Last active April 27, 2021 15:10
Comparing iterators, streams, and loops in Haskell, Rust, and C
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE TypeFamilies #-}
module Main (main) where
import Foreign
import Foreign.C.Types
@buserror
buserror / clock.c
Created February 2, 2017 16:27
protothreads, aka duff's device in use...
/*
*
* Ascii art http://www.network-science.de/ascii/ (font "mini")
*
* -Wall -g -Os -std=gnu99 -mcall-prologues -DF_CPU=8000000
* 8366 118 1373 9857 2681 atmega644_sure_led_clock.axf
*
* -mcall-prologues -fno-inline-small-functions \
* -ffunction-sections -fdata-sections \
* -Wl,--relax,--gc-sections \
@patik
patik / styles.css
Last active April 20, 2024 06:59 — forked from joshbode/numbered_headings.md
Numbered Headings in Markdown via CSS
body { counter-reset: h1counter h2counter h3counter h4counter h5counter h6counter; }
h1 { counter-reset: h2counter; }
h2 { counter-reset: h3counter; }
h3 { counter-reset: h4counter; }
h4 { counter-reset: h5counter; }
h5 { counter-reset: h6counter; }
h6 {}
h2:before {
@anj1
anj1 / subexpr.py
Last active January 20, 2020 22:41
import types
import tensorflow as tf
import numpy as np
# Expressions are represented as lists of lists,
# in lisp style -- the symbol name is the head (first element)
# of the list, and the arguments follow.
# add an expression to an expression list, recursively if necessary.
def add_expr_to_list(exprlist, expr):