Skip to content

Instantly share code, notes, and snippets.

View goyusia's full-sized avatar
💭
I may be slow to respond.

byunghoo.yu goyusia

💭
I may be slow to respond.
View GitHub Profile
@goyusia
goyusia / average_cpp_tmp.cpp
Last active August 29, 2015 14:19
Calculate Average (C++ Template Metaprogramming)
#include <type_traits>
#include <cstdio>
template<int... Items>
struct intlist;
template<typename intlist, int I>
struct push_back;
template<int I, int Head, int... Remainder>
@goyusia
goyusia / my_strcmp.cpp
Created April 20, 2015 11:47
custom strcmp
#include <cstdio>
#include <cstring>
#include <cassert>
typedef enum {
MyOrderedAscending = -1,
MyOrderSame,
MyOrderedDescending
} MyComparisonResult;
@goyusia
goyusia / mystd_sort.cpp
Created April 26, 2015 08:38
Sort implementation similar with std::sort().
/*
## Sort Implementation
* Selection Sort (Iterative / Recursive)
* Bubble Sort (Iterative / Recursive)
* Insertion Sort (Iterative / Recursive)
* Interfaces is similar with std::sort()
* Support comparator
*/
@goyusia
goyusia / Makefile
Last active October 4, 2015 12:11
Different local stack variable policy (g++/clang)
CXX_FLAGS = -W
SRC = different_stack_variable_policy.cpp
all:
@make gcc
@echo ""
@make clang
gcc:
@g++ $(SRC) $(CXX_FLAGS)
@goyusia
goyusia / infinitely_loop_bug_by_stack_allocation.cpp
Created October 4, 2015 12:57
Compiler-dependent infinitely loop bug by stack allocation policy
/*
g++ main.cpp -W -Wall
./a.out
addr x : 7ffc853ffcf4
addr y : 7ffc853ffcf8
addr diff: -4
addr i : 7ffc853ffce4
addr array: 7ffc853ffcf0
curr addr : 7ffc853ffcf0
@goyusia
goyusia / Makefile
Last active October 21, 2015 15:48
partial class in C++ (voodoo magic)
CXX = clang++
CXX_FLAGS = -W -Wall -std=c++11
all: sample.o partial_a.o partial_b.o main.o
clang++ $^ -o a.out $(CXX_FLAGS)
run: all
./a.out
sample.o: sample.cpp
@goyusia
goyusia / Makefile
Created October 23, 2015 16:12
new history teaching
main:
make current; \
make dystopia
current: new_history_teaching.cpp
rm -rf a.out
clang++ $^ -W -Wall
./a.out
dystopia: new_history_teaching.cpp
@goyusia
goyusia / buggy_path_join.py
Created November 1, 2015 04:55
buggy os.path.join
import os
a = '/home/haruna/devel/libsora.so/content'
b = '../static/sample'
c = 'sidetail-sora.gif'
print(os.path.join(a, b, c))
#/home/haruna/devel/libsora.so/content/../static/sample/sidetail-sora.gif
a = '/home/sora/devel/libsora.so/content'
b = '/static/sample'
@goyusia
goyusia / fibonacci_with_signal.c
Created November 3, 2015 02:12
fibonacci with signal handler
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
static int prev_fib = 0;
static int curr_fib = 1;
void sig_handler(int signo)
{
if (signo == SIGINT) {
@goyusia
goyusia / hello_world.cpp
Created November 6, 2015 13:08
Calculate Average of "Hello, World!".
/*
Calculate Average of "Hello, World!".
$ clang++ hello_world.cpp -std=c++11
$ ./a.out
Rello, aorld
82 101 108 108 111 44 32 97 111 114 108 100 22 3 0
*/
#include <string>
#include <cstdio>