Skip to content

Instantly share code, notes, and snippets.

View paxbun's full-sized avatar

Chanjung Kim paxbun

View GitHub Profile
@paxbun
paxbun / msvc.py
Last active October 7, 2018 10:18
Call cl.exe from python
import os
env = os.environ
tools = 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.15.26726\\bin\\Hostx64\\x64'
os.environ['PATH'] = tools
include = [
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.15.26726\\include',
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.15.26726\\atlmfc\\include',
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\VS\\include',
'C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17134.0\\ucrt',
@paxbun
paxbun / main.ino
Created April 26, 2019 08:22
MPU9250 Arduino Test Code
/*
Library: https://github.com/bolderflight/MPU9250
Ports
MPU9250 Arduino Mega
VCC 3.3V
GND GND
SCL SCL
SDA SDA
*/
@paxbun
paxbun / Mnist.cc
Created June 1, 2019 09:06
MNIST Classifier implementation
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <random>
#include <stdexcept>
#include <vector>
float const eta = 0.01;
@paxbun
paxbun / Main.cc
Last active November 13, 2019 11:56
Finds shortest paths in given map.
// This code reads map from input.txt, finds shortest paths, and writes path
// information to output.txt.
// Map legend:
// 0: Road
// 1: Obstacle
// 2: Starting point
// 3: Destination
// 4: Path
@paxbun
paxbun / drawMap.m
Created September 20, 2019 00:20
Find shortest paths
function drawMap(map)
save_hold = ishold();
[height, width] = size(map);
rectangle('Position', [0.5 -0.5-height width height]);
for i = 1:height
for j = 1:width
here = map(i, j);
if here == 'S'
rectangle('Position', [j-0.3 -i-0.3 0.6 0.6],...
'FaceColor', [1 0 0],...
@paxbun
paxbun / ArrayTraits.hh
Last active April 1, 2020 09:27
Struct templates for array traits
#include <cstddef>
template <typename T>
struct ArrayDimension;
template <typename T, size_t N>
struct ArrayDimension<T[N]>
{
static constexpr size_t Value = ArrayDimension<T>::Value + 1;
};
@paxbun
paxbun / ThreadPool.cc
Created November 9, 2019 04:18
Simple thread pool implementation with C++17 standard libraries
#include "ThreadPool.hh"
void ThreadPool::Run()
{
_threads.reserve(_numThreads);
for (size_t i = 0; i < _numThreads; ++i)
_threads.push_back(std::thread(std::bind(&ThreadPool::_Thread, this)));
}
void ThreadPool::Stop(bool wait_for_remaining_tasks)
@paxbun
paxbun / splitBySpace.hs
Created November 14, 2019 08:30
Split string by space
module SplitBySpace (splitBySpace) where
splitBySpaceDone :: ([Char], [[Char]]) -> ([Char], [[Char]])
splitBySpaceDone ("", y) = ("", y)
splitBySpaceDone (x, y) = ("", [x] ++ y)
splitBySpaceAppend :: Char -> ([Char], [[Char]]) -> ([Char], [[Char]])
splitBySpaceAppend a (x, y) = ([a] ++ x, y)
splitBySpaceInternal :: [Char] -> ([Char], [[Char]])
@paxbun
paxbun / Parser.cc
Last active November 18, 2019 04:25
Infix to Postfix
#include <iostream>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
unordered_map<char, unsigned> const prec = {
{ '^', 1 },
@paxbun
paxbun / Calculator.js
Created November 17, 2019 10:19
Simple calculator
const ops = "+-*/";
const nums = "0123456789";
function split(expr) {
let rtn = [];
let stack = '';
for (let i = 0; i < expr.length; ++i) {
if (ops.includes(expr[i])) {
rtn.push(stack);
rtn.push(expr[i]);