Programming

Normalize file names

Abstract Normalize file names on Ubuntu 12.04.The following script and command: Normalize unicode characters. E.g. image①.jpg -> image1.jpg. Make the extension of a basename lower case. E.g. image.JPG -> image.jpg Strip the root of a basen…

Call Python functions from C++ on Ubuntu 12.04

Code /home/shinya/py_example/mymain.py import sys def main(args): sys.stdout.write('Hello, world!\n'); if args: sys.stdout.write('{0}\n'.format(args)) /home/shinya/py_example/main.cc #include <Python.h> #include <cassert> #include <iostream> int main(int argc, char** </iostream></cassert></python.h>…

Call Java functions from C++ by using Java Native Interface (JNI) on Ubuntu 12.04

Code /home/shinya/jni_example/Main.java public class Main { public static void main(String[] args) { System.out.println("Hello, world!"); if (1 <= args.length) { System.out.println(args[0]); } } } /home/shinya/jni_example/main.cc #include <jni.h></jni.h>…

Tokenize c, c++ and objective-c files with clang

// tokenizer.cc // Copyright (c) 2013 Shinya // The MIT License (MIT) http://opensource.org/licenses/mit-license.php #include <iostream> #include <clang-c/Index.h> void DisplayTokens(const CXTranslationUnit& tu) { CXCursor cursor = clang_getTranslationUnitCursor(tu)</clang-c/index.h></iostream>…

Extending Python with C or C++

Wrapping a C library in Python. Environment Ubuntu 12.04 64bit Python 2.7 Install Python.h $ sudo apt-get install python2.7-dev Code // spammodule.c #include <Python.h> #ifdef __cplusplus extern "C" { #endif static PyObject* SpamError; static PyObje</python.h>…