Skip to content

Instantly share code, notes, and snippets.

View hypernewbie's full-sized avatar
:shipit:

Xi Ma Chen hypernewbie

:shipit:
View GitHub Profile
@hypernewbie
hypernewbie / canon.c
Created August 29, 2014 05:14
Pachelbel’s Canon in Dmaj in 73 lines of obfuscated C
/* make canon; ./canon | aplay -r 44100 -f U8 */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define rs (1.0/44100.0)
#define fr(x) (440*pow(2,(x-57)*(1.0/12)))
#define s(x, n) sin((x=(x+fr(n)*rs))*6.2831853)
#define tf (((1.0/rs)*60.)*.25/160.0)
#define gv(c) (c-(c>'9'?('a'-10):'0'))
#define gct(i) (gv(ct[(i)*3]) << 8)+(gv(ct[(i)*3+1]) << 4)+(gv(ct[(i)*3+2]))
@hypernewbie
hypernewbie / dlx.c
Created September 30, 2014 05:48
Dancing Links Sudoku
#include <stdio.h>
#define MAX_COL 750
#define MAX_ROW 750
#define SQ_OFFSET 0
#define RW_OFFSET 81
#define CL_OFFSET 162
#define BX_OFFSET 243
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <algorithm>
using namespace std;
size_t GetFileSize(FILE * fp)
{
@hypernewbie
hypernewbie / skiplist.hpp
Last active October 22, 2019 04:56
Skiplist Implementation
/*
The MIT License (MIT) Copyright (c) 2016 UAA Software
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@hypernewbie
hypernewbie / memtrack.h
Created January 9, 2017 23:06
Minimal memory tracker
#define MEMTRACK_SZ 16000
struct memory_tracker {
void* ptr[MEMTRACK_SZ];
int opnums[MEMTRACK_SZ];
int opnum = 0;
// Change this to break somewhere.
int break_opnum = -1;
memory_tracker() {
@hypernewbie
hypernewbie / replay.h
Created October 22, 2019 20:36
Hacky replay record for XBox One layout controller input.
/*
The MIT License (MIT) Copyright (c) 2019 Xi Chen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
@hypernewbie
hypernewbie / ManualGLSLCubemapLookup.cpp
Last active December 6, 2020 21:17
Manual GLSL cubemap lookup. Hopefully correct maybe.
#include <cstdio>
#include <cmath>
struct float2
{
float x = 0.0f;
float y = 0.0f;
float2() {}
float2( float _x, float _y ) { x = _x; y = _y; }
};