Skip to content

Instantly share code, notes, and snippets.

@ChunMinChang
ChunMinChang / os_detect.sh
Created January 13, 2016 04:12
Detect your OS
case "$OSTYPE" in
solaris*) echo "SOLARIS" ;;
darwin*) echo "OSX" ;;
linux*) echo "LINUX" ;;
bsd*) echo "BSD" ;;
cygwin) echo "cygwin" ;;
*) echo "unknown: $OSTYPE" ;;
esac
@ChunMinChang
ChunMinChang / HardwareKeyboardSimulator.sh
Last active January 13, 2016 08:33
Simulate hardware keyboard input
#!/bin/bash
# Get the simulated key
KEY=$1
#print variable on a screen
echo "Send heardware key '$KEY'"
case "$OSTYPE" in
darwin*)
echo "OSX"
# osascript -e 'tell application System Events" to key code 0'
#!/bin/bash -n
array=($(adb shell ls | tr -d '\r'))
target_dir=~/Work/adb-files
for i in ${array[*]}; do
#echo "adb pull $i $target_dir"
adb pull $i $target_dir
done
@ChunMinChang
ChunMinChang / rolling_two_dice.c
Last active March 23, 2017 14:24
Week 1 Homework of C++ for C Programmers
#include <stdlib.h> // For generating random value:
// rand()
#include <stdio.h> // For basic input and output:
// printf
// scanf
#include <time.h> // For getting the time in seconds since the Epoch
// time()
// Label the sides of the dice.
#define SIDES 6
@ChunMinChang
ChunMinChang / html-markup-remover.py
Created July 24, 2016 08:39
Lesson 1 - Software Debugging
# -*- coding: utf-8 -*-
# Utils
# =======================================
# printTable
# ----------------
# @table:
# [
# (1-1, 1-2, ..., 1-m),
# (2-1, 2-2, ..., 2-m),
@ChunMinChang
ChunMinChang / short_path.cpp
Last active May 3, 2017 06:16
Calculation of short path for graph
// Compile: $ g++ -Wall -std=c++14 short_path.cpp
#include <cassert> // For standard debugging tool:
// assert
#include <cstdint> // For using fixed width integer types and part of
// C numeric limits interface:
// std::uint8_t
#include <iomanip> // For facilities to manipulate output formatting:
// std::setw
#include <iostream> // For input and output fundamentals:
// std::cout
@ChunMinChang
ChunMinChang / README.md
Last active January 31, 2018 14:20
Sorting algorithms #sorting

How to build it

Clone it and cd into the repo's folder, then run:

$ make
...
...
g++ -Wall --std=c++11 test.o selection_sort.o insertion_sort.o bubble_sort.o merge_sort.o quick_sort.o -o run_test
$ ./run_test
Source:                 13 13 12 4 13 2 6 10 1 6 18 15 20 0
Selection sort:         0 1 2 4 6 6 10 12 13 13 13 15 18 20
@ChunMinChang
ChunMinChang / day.cpp
Created October 2, 2016 06:29
Week 2 of C++ for C Programmers
/*
* Compile this file by C++11, e.g., g++ --std=c++11 <filename.cpp>
*/
#include <cstdint> // For using fixed width integer types and part of
// C numeric limits interface:
// std::int8_t
#include <iostream> // For input and output fundamentals:
// std::cout
// endl
// ostream
@ChunMinChang
ChunMinChang / common.h
Last active February 13, 2023 08:12
Audio mixer: Downmix 5.1 to stereo or remap the channels
#ifndef COMMON
#define COMMON
#include <iostream>
#include <unistd.h>
#define DEBUG false // Set true to log the debugging messages.
#define LOG(...) DEBUG && fprintf(stdout, __VA_ARGS__)
template<typename T, size_t N>
@ChunMinChang
ChunMinChang / ChannelLayout.cpp
Last active June 5, 2020 09:52
CoreAudio Playground #coreaudio #multichannel_audio
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <AudioUnit/AudioUnit.h>
#include <CoreAudio/CoreAudio.h>
#define kAudioUnitOutputBus 0
#define kAudioUnitInputBus 1