Skip to content

Instantly share code, notes, and snippets.

@ph1ee
ph1ee / boost-info.cc
Last active October 8, 2015 07:27
Sample code on Boost preprocessor macros
#include <boost/current_function.hpp> // BOOST_CURRENT_FUNCTION
#include <boost/predef.h> // checkXXX
#include <boost/config.hpp> // buildEnvInfo
#include <boost/version.hpp> // buildEnvInfo
#include <iostream>
struct App {
void checkOs() {
std::cout << BOOST_CURRENT_FUNCTION << std::endl;
@ph1ee
ph1ee / unordered.cc
Created October 23, 2015 01:26
Understanding the New Set and Map Containers in the C++11 Standard Library
/**
* Understanding the New Set and Map Containers in the C++11 Standard Library
* http://www.oracle.com/technetwork/articles/servers-storage-dev/new-set-and-map-containers-cpp11-2187367.html
*/
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
int test_unordered_map() {
@ph1ee
ph1ee / inotify.c
Created October 30, 2015 07:11
inotify sample code
/**
* gcc -std=gnu99 inotify.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdarg.h>
#include <limits.h>
@ph1ee
ph1ee / Makefile
Created November 25, 2015 01:39
Various echo daemons in C
CC = gcc
CFLAGS = -Wall
CCLD = $(CC)
define COMPILE_C
$(CC) $(CFLAGS) -o $@ -c $<
endef
define LINK_EXECUTABLE
$(CCLD) $(CFLAGS) $(LDFLAGS) -o $@ $(filter %.o,$^)
@ph1ee
ph1ee / CMakeLists.txt
Created November 25, 2015 02:02
insertion sort and merge sort
PROJECT(sort)
ADD_LIBRARY (pystring pystring.cpp)
ADD_LIBRARY (sort sort.cpp ins.cpp merge.cpp)
ADD_EXECUTABLE(test main.cpp)
TARGET_LINK_LIBRARIES (test pystring sort)
@ph1ee
ph1ee / MainActivity.java
Last active November 26, 2015 08:58
running command in android
package s.runcommand;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ph1ee
ph1ee / sort2count.cc
Created December 7, 2015 11:25
convert sorted numbers to counted numbers
#include <iostream>
#include <limits>
#include <sstream>
#include <string>
using namespace std;
/**
* This program helps to convert sorted numbers to counted numbers.
*
@ph1ee
ph1ee / tlvid.sh
Last active December 17, 2015 08:05
creating a video from time-lapse images
#!/bin/bash
infile="mylist.txt"
verbose="warning"
true > ${infile}
for photo in *.JPG; do
tag=$(exiv2 -K Exif.Image.ImageDescription pr "${photo}" 2>/dev/null | cut -b60-)
case "${tag}" in
@ph1ee
ph1ee / matrix.cc
Created January 13, 2016 03:04
2-dimensional array using std::array and std::vector
#include <iostream>
#include <array>
#include <vector>
template <size_t M, size_t N, class T>
using Matrix = std::array<std::array<T, N>, M>;
template <size_t M, size_t N, class T>
std::ostream& operator<<(std::ostream& os, Matrix<M, N, T>& matrix) {
for (auto row = matrix.begin(); row != matrix.end(); row++) {
@ph1ee
ph1ee / RateStatistics.java
Created January 30, 2016 07:13
WebRTC's RateStatistics in Java
package com.simplo.netapp;
public class RateStatistics {
private int num_buckets_;
private long[] buckets_;
private long accumulated_count_;
private long oldest_time_;
private int oldest_index_;