Skip to content

Instantly share code, notes, and snippets.

@shakna-israel
shakna-israel / LetsDestroyC.md
Created January 30, 2020 03:50
Let's Destroy C

Let's Destroy C

I have a pet project I work on, every now and then. CNoEvil.

The concept is simple enough.

What if, for a moment, we forgot all the rules we know. That we ignore every good idea, and accept all the terrible ones. That nothing is off limits. Can we turn C into a new language? Can we do what Lisp and Forth let the over-eager programmer do, but in C?


@DavidBuchanan314
DavidBuchanan314 / cursed_mandelbrot.c
Last active June 28, 2023 15:12
Compile-time mandelbrot in pure C. Outputs a PGM image file to stdout. Output can be seen at https://twitter.com/David3141593/status/1062468528115200001
#include <stdio.h>
#define SQ(x) (x)*(x)
#define M0(x,y) SQ(x)+SQ(y)<4?0:0xe0
#define M1(x,y,x0,y0) (SQ(x)+SQ(y)<4)?M0(SQ(x)-SQ(y)+(x0),2*(x)*(y)+(y0)):0xc0
#define M2(x,y,x0,y0) (SQ(x)+SQ(y)<4)?M1(SQ(x)-SQ(y)+(x0),2*(x)*(y)+(y0),x0,y0):0xa0
#define M3(x,y,x0,y0) (SQ(x)+SQ(y)<4)?M2(SQ(x)-SQ(y)+(x0),2*(x)*(y)+(y0),x0,y0):0x80
#define M4(x,y,x0,y0) (SQ(x)+SQ(y)<4)?M3(SQ(x)-SQ(y)+(x0),2*(x)*(y)+(y0),x0,y0):0x60
#define M5(x,y,x0,y0) (SQ(x)+SQ(y)<4)?M4(SQ(x)-SQ(y)+(x0),2*(x)*(y)+(y0),x0,y0):0x40
import numpy as n
def s(x):return 1.0/(1+n.exp(-x))
def d(x):return x*(1.0-x)
class N:
def __init__(self,x,y):self.x,self.y=x,y;self.w1,self.w2,self.o=n.random.rand(self.x.shape[1],4),n.random.rand(4,1),n.zeros(self.y.shape)
def f(self):self.l1=s(n.dot(self.x,self.w1));self.o=s(n.dot(self.l1,self.w2))
def b(self):r=n.dot(self.l1.T,(2*(self.y-self.o)*d(self.o)));q=n.dot(self.x.T,(n.dot(2*(self.y-self.o)*d(self.o),self.w2.T)*d(self.l1)));self.w1+=q;self.w2+=r
X=n.array([[0,0,1],[0,1,1],[1,0,1],[1,1,1]]);y=n.array([[0],[1],[1],[0]]);a=N(X,y)
for i in range(1500):a.f();a.b()
print(a.o)
@jstimpfle
jstimpfle / buf.c
Created May 24, 2018 23:25
C code starting point for getting most of what std::vector offers
static void _buf_init(void **buf, int *cap, int elsize, const char *file, const int line)
{
fprintf(stderr, "_buf_init(%p, %s, %d)\n", buf, file, line);
*buf = NULL;
*cap = 0;
}
static void _buf_reserve(void **buf, int *cap, int cnt, int elsize, const char *file, const int line)
{
fprintf(stderr, "_buf_reserve(%p, %s, %d)\n", buf, file, line);
@gricard
gricard / webpack4upgrade.md
Last active February 29, 2024 20:23
Just some notes about my attempt to upgrade to webpack 4

If you enjoyed reading this, I'm intending to do more blogging like this over here: https://cdgd.tech

This is not a complaint about Webpack or v4 in any way. This is just a record of my process trying it out so I could provide feedback to the webpack team

Hmm... I don't see any docs for 4.0 on https://webpack.js.org. I guess I'll just wing it. All I need to do is npm i -D webpack@next, right?

+ webpack@4.0.0-beta.2
@CAFxX
CAFxX / persistent_pipes_linux.md
Last active January 4, 2024 04:32
Persistent pipes/circular buffers for Linux

📂 Persistent "pipes" in Linux

In a project I'm working on I ran into the requirement of having some sort of persistent FIFO buffer or pipe in Linux, i.e. something file-like that could accept writes from a process and persist it to disk until a second process reads (and acknowledges) it. The persistence should be both across process restarts as well as OS restarts.

AFAICT unfortunately in the Linux world such a primitive does not exist (named pipes/FIFOs do not persist

@anapsix
anapsix / chat.sh
Last active March 18, 2022 18:24
Chat server with Netcat and Bash, inspired by ITA Software 2011 interview challenge
#!/bin/bash
#
# Implementation of BASH + NCAT chat server
#
# Author: Anastas Dancha <anapsix@random.io>
# Contact: anapsix@random.io
#
#debug="true"
anonymous
anonymous / fish.py
Created August 30, 2013 17:41
><> python interpreter.
#!/usr/local/bin/python3.2
"""
Python interpreter for the esoteric language ><> (pronounced /ˈfɪʃ/).
Usage: ./fish.py --help
More information: http://esolangs.org/wiki/Fish
Requires python 2.7/3.2 or higher.
@jlongster
jlongster / gist:1712455
Created January 31, 2012 19:37
traditional lisp macros
;; outlet code for implementing traditional macro expansion
;; macros
(define (expand form)
(cond
((variable? form) form)
((literal? form) form)
((macro? (car form))
(expand ((macro-function (car form)) form)))
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Created: 2010/12/05
// Updated: 2018/09/12
// License: MIT
//
// Copyright (c) 2010-2018 Diego Perini (http://www.iport.it)
//