Skip to content

Instantly share code, notes, and snippets.

View hackjutsu's full-sized avatar

CosmoX hackjutsu

View GitHub Profile
@hackjutsu
hackjutsu / simplest_Android.mk
Last active February 12, 2017 23:45
The simplest Android.mk example for NDK
# An Android.mk file must begin with the definition of the LOCAL_PATH variable
LOCAL_PATH := $(call my-dir)
# The CLEAR_VARS variable is provided by the build system and points to a special
# GNU Makefile that will clear many LOCAL_XXX variables for you (e.g. LOCAL_MODULE),
# with the exception of LOCAL_PATH.
include $(CLEAR_VARS)
# The LOCAL_MODULE variable must be defined to identify each module you describe
# in your Android.mk. The name must be unique and not contain any spaces.
@hackjutsu
hackjutsu / simplest_Application.mk
Last active January 23, 2017 06:47
Simplest Application.mk for NDK
APP_PROJECT_PATH := <path to project>
@hackjutsu
hackjutsu / copying_files.java
Created September 16, 2016 22:25
Copying files in Java
// If you are using Java 7, Files (in the standard library) is the best approach:
/* You can get Path from file also: file.toPath() */
Files.copy(InputStream in, Path target)
Files.copy(Path source, OutputStream out)
@hackjutsu
hackjutsu / regex.sh
Last active January 23, 2017 06:48
[Example about doing regular expression match via Bash] Bash doesn't support non-greedy regex like (.*?)
str="asdkljfgaskdlgjkladsjfg123_abc_d4e5#asdfgerhgreg"
regex="[0-9]+_([a-z]+)_[0-9a-z]*"
if [[ $str =~ $regex ]]
then
name="${BASH_REMATCH[1]}"
echo "${name}.jpg" # 123_abc_d4e5.jpg
name="${name}.jpg" # same thing stored in a variable
else
echo "$str doesn't match" >&2
@hackjutsu
hackjutsu / json_string.js
Last active February 12, 2017 19:48
JSON object to string and vice versa
var json = '{"result":true,"count":1}';
var obj = JSON.parse(json);
console.log(JSON.stringify(obj));
@hackjutsu
hackjutsu / linebyline.js
Created September 22, 2016 00:42
Reading file line by line in NodeJS
var fs = require("fs");
// Sync
var array = fs.readFileSync(path).toString().split('\n');
// Async
fs.readFile(path, function(err, f){
var array = f.toString().split('\n');
// use the array
});
@hackjutsu
hackjutsu / java_main.java
Created October 4, 2016 18:26
Java main sample
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
@hackjutsu
hackjutsu / ArrBlockingQueue.java
Last active October 4, 2016 23:48
Sample code for thread safe blocking queue in Java
public class ArrBlockingQueue {
final private Lock _lock = new ReentrantLock();
final private Condition _notFull = _lock.newCondition();
final private Condition _notEmpty = _lock.newCondition();
final private Object[] _items;
private int _putptr, _takeptr, _count;
public ArrBlockingQueue(final int size) {
@hackjutsu
hackjutsu / print.mk
Created October 4, 2016 23:51
How to print message in makefile
$(info VAR="$(VAR)")
@hackjutsu
hackjutsu / open_xcode_from_terminal.sh
Last active February 21, 2017 03:06
[Env in Xcode] Open Xcode from terminal so that env defined in .bash_profile could be inherited.
# Xcode should be the default application for .xcodeproj files, so this should work:
open a.xcodeproj
# If that opens a different application, you can force it to use xcode:
open -a Xcode a.xcodeproj