Skip to content

Instantly share code, notes, and snippets.

View santa4nt's full-sized avatar
💭
😬

Santoso santa4nt

💭
😬
  • Los Angeles, CA
View GitHub Profile
@santa4nt
santa4nt / onew.cc
Last active August 29, 2015 14:19
Sample code for overriding operator new/delete in C++.
#include <new>
#include <iostream>
#include <iomanip>
#include <exception>
#include <cstdlib>
// global overrides of new and delete
void* _new(std::size_t);
@santa4nt
santa4nt / opload.cc
Created April 21, 2015 23:33
A sample usage of traits template technique to do type-agnostic comparison.
#include <iostream>
class C
{
public:
C(const int i) :
_i(i)
{
}
@santa4nt
santa4nt / main.cpp
Last active August 29, 2015 14:19
A sample code using specialized, explicit template instantiation of function templates in C++
#include "sample-expl-templ.hpp"
#include <iostream>
typedef uint16_t WORD;
int main()
{
@santa4nt
santa4nt / SampleLambda.java
Last active August 29, 2015 14:15
A sample usage of the lambda syntax in Java 8.
import java.util.function.Consumer;
public class SampleLambda {
// takes a function object that, in turn, takes a String argument and returns Void;
// this function object is a Consumer because it inherently returns nothing;
// the alternative--Function<T,R>--must have a return type
public static void foo(Consumer<String> func) {
func.accept("foo");
@santa4nt
santa4nt / sample-functor.cc
Last active August 29, 2015 14:15
A sample usage of (template) function taking a "callable" as argument.
#include <functional>
#include <iostream>
#include <string>
using namespace std;
// define a templated function to be able to take any "callable" as argument
template<typename Func>
void foo(Func func)
@santa4nt
santa4nt / sample-raii-scoped-action.cc
Last active August 29, 2015 14:15
A sample C++11 idiom for RAII scoped action.
#include <iostream>
#include <functional>
using namespace std;
class ScopedAction
{
public:
@santa4nt
santa4nt / memoize.py
Created August 29, 2014 21:18
Python decorator to memoize functions.
import unittest
# a generic function decorator to memoize call results
class Memoize(object):
def __init__(self, func):
self.func = func
self._cache = {}
self._count = 0
@santa4nt
santa4nt / Makefile
Last active August 29, 2015 14:02
Convert a raw byte string into a hex string.
CC = gcc
CFLAGS = -Wall -g -x c++
LFLAGS = -lstdc++ -lboost_unit_test_framework
DEFINES = -DUSE_BOOST_UT
OBJDIR = obj
BINDIR = bin
TARGET = bytes2hex
@santa4nt
santa4nt / Makefile
Last active January 3, 2020 07:08
Heapsort implementation in C++.
CC = gcc
CFLAGS = -Wall -g -x c++
LFLAGS = -lstdc++ -lm -lboost_unit_test_framework
DEFINES = -D TOPDOWN -D USE_BOOST_UT
OBJDIR = obj
BINDIR = bin
TARGET = main
@santa4nt
santa4nt / bst.py
Last active August 29, 2015 14:02
Some operation implementations on a Binary Search Tree, done in Python.
import unittest
class BST(object):
def __init__(self, key):
self.key = key
self.left = None
self.right = None