Skip to content

Instantly share code, notes, and snippets.

@sheimi
sheimi / Singleton.java
Created Nov 9, 2014
code in blog.sheimi.me: 2012-06-20-software-architecture-review-5 (1)
View Singleton.java
import java.util.*;
public class Limiton {
private static int limit = 3;
private static Limiton[] instances = new Limiton[3];
private static Random r = new Random();
static {
for (int i = 0; i < limit; i++) {
instances[i] = new Limiton();
}
}
@sheimi
sheimi / Decorator.java
Created Nov 9, 2014
code in blog.sheimi.me: 2012-06-20-software-architecture-review-4 (3)
View Decorator.java
// Problem
abstract class VisualComponent {
void draw();
void resize();
}
class TextView extends VisualComponent {
void draw() {...}
void resize() {...}
}
@sheimi
sheimi / Proxy.java
Created Nov 9, 2014
code in blog.sheimi.me: 2012-06-20-software-architecture-review-4 (2)
View Proxy.java
import java.util.*;
public class Proxy {
public static void main(String[] args) {
}
}
class ThreeD<T, V, W> {
private T t;
@sheimi
sheimi / Iter.java
Created Nov 9, 2014
code in blog.sheimi.me: 2012-06-20-software-architecture-review-4 (1)
View Iter.java
import java.util.*;
public class Iter {
public static void main(String[] args) {
Aggregate<Integer, Integer, Integer> ag = new DataList<Integer, Integer, Integer>();
((DataList)ag).add(new ThreeD<Integer, Integer, Integer>(1, 2, 3));
((DataList)ag).add(new ThreeD<Integer, Integer, Integer>(1, 2, 3));
((DataList)ag).add(new ThreeD<Integer, Integer, Integer>(1, 2, 3));
Iterator<Integer> ia = ag.createIteratorA();
while (ia.next() != null) {
@sheimi
sheimi / test.java
Created Nov 9, 2014
code in blog.sheimi.me: 2012-09-05-a-summary-of-using-jni (5)
View test.java
jbyteArray result = env->NewByteArray(imageDesV.size());
@sheimi
sheimi / test.sh
Created Nov 9, 2014
code in blog.sheimi.me: 2012-09-05-a-summary-of-using-jni (4)
View test.sh
g++ -m64 -shared -fPIC cvjni.cpp /usr/local/lib/libopencv_core.so \
/usr/local/lib/libopencv_highgui.so -o libcvjni.so \
-I/usr/local/include -I/usr/lib/jvm/jdk1.6.0_35/include \
-I/usr/lib/jvm/jdk1.6.0_35/include/linux
@sheimi
sheimi / Makefile
Created Nov 9, 2014
code in blog.sheimi.me: 2012-09-05-a-summary-of-using-jni (3)
View Makefile
# Makefile
# FOR MAC
CC=g++
SEARCH_LIB=-lopencv_core -lopencv_highgui
INCLUDE=-I/usr/local/include -I$(JAVA_INCLUDE)
LIBRARY=-L/usr/local/lib
FLAGS= -m64 -dynamiclib -fPIC
OUT=libcvjni.jnilib
SRC=cvjni.cpp
@sheimi
sheimi / cvjni.cpp
Created Nov 9, 2014
code in blog.sheimi.me: 2012-09-05-a-summary-of-using-jni (2)
View cvjni.cpp
//cvjni.cpp
#include "cvjni.h"
#include <opencv2/opencv.hpp>
#include <vector>
#include <iostream>
using namespace std;
using namespace cv;
/*
@sheimi
sheimi / CVJNI.java
Created Nov 9, 2014
code in blog.sheimi.me: 2012-09-05-a-summary-of-using-jni (1)
View CVJNI.java
// CVJNI.java
import java.io.*;
public class CVJNI {
//Load jni library
static {
try {
System.loadLibrary("cvjni");
} catch (Exception e) {
e.printStackTrace();
@sheimi
sheimi / injector.java
Created Nov 9, 2014
code in blog.sheimi.me: 2012-05-17-source-code-02 (3) injector
View injector.java
public static void install(JobConf job, Path crawlDb) throws IOException {
Path newCrawlDb = FileOutputFormat.getOutputPath(job);
FileSystem fs = new JobClient(job).getFs();
Path old = new Path(crawlDb, "old");
Path current = new Path(crawlDb, CURRENT_NAME);
if (fs.exists(current)) {
if (fs.exists(old)) fs.delete(old, true);
fs.rename(current, old);
}
fs.mkdirs(crawlDb);
You can’t perform that action at this time.