Skip to content

Instantly share code, notes, and snippets.

View xkikeg's full-sized avatar

kikeg xkikeg

  • Zürich, Switzerland
  • 00:41 (UTC +01:00)
View GitHub Profile
@xkikeg
xkikeg / evaluation-order.cpp
Created December 10, 2011 10:21
演算子の評価順序が不定であることを示している例?
#include <iostream>
using namespace std;
int main(){
int i,j;
i = 3;
j = 5;
// compiled with g++
@xkikeg
xkikeg / ring_buffer.cpp
Created February 6, 2012 05:48
Sequentialized Multithreaded Ring Buffer Implementation
#include <ostream>
#include <array>
#include <mutex>
#include <condition_variable>
#define DEBUG_PRINT
#ifdef DEBUG_PRINT
#include <iostream>
#endif
@xkikeg
xkikeg / from_lambda_to_std_function.cpp
Created February 19, 2012 02:39
C++ std::function<>におけるmemory allocationの疑問
#include <cassert>
#include <iostream>
#include <functional>
std::function<int (int)> make_g(int x)
{
std::cout << "Stack var: " << &x << std::endl;
return [x] (int y) {
std::cout << "Lambda var: " << &x << std::endl;
return x + y;
@xkikeg
xkikeg / boost_pp_valued_enum.cpp
Created March 26, 2012 17:37
Example of Definition of Value Specified ENUM with Boost.PP
#include <iostream>
#include <boost/preprocessor.hpp>
#define VALUED_ENUM(unused, index, seq) \
BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_SEQ_ELEM(index, seq)) \
= BOOST_PP_TUPLE_ELEM(2, 1, BOOST_PP_SEQ_ELEM(index, seq))
#define INSERT_TUPLE_HEAD(s, state, elem) \
BOOST_PP_SEQ_PUSH_BACK(state, \
BOOST_PP_TUPLE_ELEM(2, 0, elem))
@xkikeg
xkikeg / ffmpeg_configure.sh
Created October 11, 2012 07:36
ffmpeg configure script
#!/bin/sh
#version 1.0
#CPU=corei7
CPU=core2
./configure\
--prefix=${HOME}/local\
--enable-shared\
--enable-gpl\
--enable-version3\
@xkikeg
xkikeg / zshhist.py
Last active May 21, 2024 02:02
Convert ZSH history file (.zsh_history file) between original weird encoding and proper UTF-8.
#!/usr/bin/env python3
"""
ZSH history convert script.
When you mistakenly type your password or quite bad command into ZSH,
you may want to remove the entry from the history.
The problem is, the .zsh_history is encoded in a weird format!
If you want to find a command with non-ASCII character, it'll be problematic.
@xkikeg
xkikeg / ddrescue_chart.py
Last active April 30, 2019 08:54
This script visualize the logfile of GNU ddrescue.
#!/usr/bin/python
import argparse
import sys
import math
import operator
import itertools
import Image, ImageDraw
# http://stackoverflow.com/questions/14423794/equivalent-of-haskell-scanl-in-python
@xkikeg
xkikeg / sparsefile.c
Last active July 13, 2022 08:36
Find data positions of sparse file with SEEK_DATA & SEEK_HOLE, this does not work in Ubuntu 12.04.
#define _FILE_OFFSET_BITS 64
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#ifndef SEEK_DATA
@xkikeg
xkikeg / ddnonzero.cpp
Created January 27, 2013 00:04
Copy from source to destination only if position is recorded in input & source is nonzero and destination is zero.
#define _FILE_OFFSET_BITS 64
#include <vector>
#include <fstream>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <sys/types.h>
@xkikeg
xkikeg / hardlinkimage.py
Last active December 11, 2015 20:08
Search specified directory and convert the adjacent images equal to each other into hardlink.
#!/usr/bin/python
import os
import os.path
import sys
import Image
class ImageFile(object):