Skip to content

Instantly share code, notes, and snippets.

View aal89's full-sized avatar
🎯
Focusing

Alex Burghardt aal89

🎯
Focusing
View GitHub Profile
@aal89
aal89 / tgidemo.c
Last active November 20, 2019 21:51
CC65 TGI NES demo that compiles (taken from https://github.com/cc65/cc65/blob/master/samples/tgidemo.c).
#include <stdio.h>
#include <stdlib.h>
#include <cc65.h>
#include <conio.h>
#include <tgi.h>
#include <nes.h>
#include <joystick.h>
#define TGI_COLOR_BLACK 0x00
#define TGI_COLOR_GREEN 0x01
@aal89
aal89 / mandelbrot.c
Created November 20, 2019 21:42
CC65 mandelbrot demo for NES that compiles (taken from https://github.com/cc65/cc65/blob/master/samples/mandelbrot.c)
/*****************************************************************************\
** mandelbrot sample program for cc65. **
** **
** (w) 2002 by groepaz/hitmen, TGI support by Stefan Haubenthal **
\*****************************************************************************/
#include <stdlib.h>
#include <time.h>
@aal89
aal89 / hello.c
Created November 20, 2019 21:37
CC65 hello world demo for NES with a fix (wa) for the open gap on the bottom line (taken from https://github.com/cc65/cc65/blob/master/samples/hello.c)
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <joystick.h>
#include <nes.h>
static const char text[] = "get on that nesdev";
int main(void)
{
@aal89
aal89 / currying.swift
Last active September 26, 2019 09:13
Examples whereby we curry an arithmetic operator over a collection of natural numbers and curry a greetings functions over a collection of strings, in Swift.
// ========================== Generic (limited) curry function:
func curry<A, B, C>(_ f: @escaping (A, B) -> C) -> (A) -> (B) -> C {
return { a in { b in f(a, b) }}
}
// ========================== Example 1:
let add = curry((+) as ((Int, Int) -> Int))
let add2 = add(2)
@aal89
aal89 / 420.swift
Last active July 23, 2019 11:32
A pure functional way to blaze some sick clouds in Swift.
// Higher order functions, being curried. Considered pure functional, because they don't have any side effects
// (mutate any given data). They just derive data from data.
let plus = { (first: Int) in { (second: Int) in first + second } }
let multiplesOf = { (first: Int) in { (second: Int) in second % first != 0 } }
// Just a simple first class function, not per se functional. Usable to reduce a collection of integers into the total.
let total: (Int, Int) -> Int = { $0 + $1 }
let calculation = (1...30)
.map(plus(2))
@aal89
aal89 / kbtxtgenerator.js
Created July 18, 2019 08:52
Generates text files with random numbers of a particular size. Size is given in kb's as first parameter, defaults to 100.
const fs = require("fs");
const lineLength = 126;
const sizeInKb = process.argv[2] || 100;
let data = "";
for(var i = 0; i < sizeInKb * 1024; i++) {
if (i && i % lineLength === 0) {
data += "\n";
} else {
@aal89
aal89 / 1mb.txt
Created July 18, 2019 08:51
1mb in text
This file has been truncated, but you can view the full file.
19063699041183922230424640119986913758023341770758751642047601347737139606611941581352175797681575117149435847472379921576378
82010873314125910417098681679467651061196703036344503828425038021866296075656578591024747456403918197240660392231867709196530
05547299081771122978128893134012025555840439838755861696435926779779011155301553716406948852775421829267789075611169229413304
42028620073205237675530442721666962286683534927131293735270935475331266785352417198234822645786435208887529004886675157771888
87716254578233139050956841337551473116293899780647416270305365091493516756140179109318676578254373967658333126619554398248807
73901335039931398874577719039802288956276828455645089612214856059038950787855805249688802161731552101060793394882144824301838
80013352318345613661078428780673839967965501913764666716551387847921893809223464453567368379243079836222406059944397498046708
72409291568897359376555992566277167049359808026761803186968491038946326201866824309514704973489863815255632689038911077381036
1679702913915218
@aal89
aal89 / batchqueue.js
Created July 4, 2019 09:53
Batch queue javascript
function BatchQueue(concurrentTasks) {
this.concurrency = concurrentTasks;
this.running = 0;
this.queue = [];
}
BatchQueue.prototype.pushTask = function(task, callback) {
this.queue.push(task);
this.next();
}
@aal89
aal89 / optional.ts
Last active July 4, 2019 09:01
Optional class to default out variables when they do not exist.
class Optional<T> {
private value: T | null = null;
private constructor(value: T | null) {
this.value = value;
}
public static some<T>(value: T): Optional<T> {
return new Optional(value);
@aal89
aal89 / DataRequest.d.ts
Created April 29, 2019 10:22
Declaration merging. Swift like extensions for TypeScript. Extending an Express Request object per example.
// tslint:disable
declare namespace Express {
export interface Request {
locals: {
data: unknown;
}
}
}