Skip to content

Instantly share code, notes, and snippets.

View howardlau1999's full-sized avatar
🎯
Focusing

Howard Lau howardlau1999

🎯
Focusing
View GitHub Profile
//
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \
@howardlau1999
howardlau1999 / insertion_sort.cpp
Last active December 1, 2018 14:22
C++ Templates Metaprogramming
#include <iostream>
struct TrueType {
constexpr static bool value = true;
};
struct FalseType {
constexpr static bool value = false;
};
@howardlau1999
howardlau1999 / quick_sort.cpp
Created December 2, 2018 16:12
C++ Template Metaprogramming
#include <iostream>
struct TrueType {
constexpr static bool value = true;
};
struct FalseType {
constexpr static bool value = false;
};
@howardlau1999
howardlau1999 / calculator.cpp
Created December 5, 2018 05:21
Simple Calculator
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cctype>
#include <stdexcept>
using namespace std;
#include <iostream>
using namespace std;
template <class K, class V>
struct AVLNode {
K key;
V value;
AVLNode *left, *right;
AVLNode(K key, V value) : key(key), value(value), left(NULL), right(NULL) {}
@howardlau1999
howardlau1999 / rbtree.cpp
Last active December 6, 2018 05:02
Red Black Tree
#include <iostream>
enum Color { RED, BLACK };
template <class K, class V>
class RBTree {
struct RBNode {
K key;
V value;
size_t N;
@howardlau1999
howardlau1999 / main.cpp
Created December 18, 2018 06:42
Linux dlfcn
// g++ -rdynamic -o main main.c -ldl
#include <dlfcn.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <iostream>
using namespace std;
typedef int (*calc_func)(int, int);
const char *LIB_PATH = "./libctest.so";
@howardlau1999
howardlau1999 / HeapSort.java
Created December 26, 2018 07:22
Sort animation
import edu.princeton.cs.algs4.*;
public class HeapSort {
private static int currentSinking;
public static void sink(int[] heap, int k, int N) {
while (2 * k <= N) {
int j = 2 * k;
if (j < N && heap[j] < heap[j + 1]) j++;
if (heap[k] > heap[j]) break;// already ordered
exch(heap, k, j);
@howardlau1999
howardlau1999 / raytrace.rs
Last active March 11, 2020 13:07
Ray Tracing
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::io::BufWriter;
use std::ops::Add;
use std::ops::Div;
use std::ops::Mul;
use std::ops::Neg;
use std::ops::Sub;
@howardlau1999
howardlau1999 / ycomb.cpp
Created August 11, 2021 09:30
Y Combinator in C++20
#include <iostream>
int main() {
auto result = [](auto&& g) {
return [](auto&& f) {
return f(f);
}([&g](auto&& f) { return g([&f](auto&& x) { return f(f)(x); }); });
}([](auto&& f) {
return [&f](auto&& x) -> int { return x == 0 ? 1 : x * f(x - 1); };
})(5);