Install Octave with Image processing package on MAC OS X

Using homebrew to install octave

brew update

brew upgrade

brew install octave

Install image processing package (running octave), first download the package from http://octave.sourceforge.net/image/ into home folder ~/octave

octave>pkg list

octave>pkg install image-2.4.1.tar.gz

Octave is using graphicsmagick for handling the image files. In order to read TIFF image, please make sure the graphicsmagick is compiled with tiff enabled:

gm version (tiff should be enabled)

Otherwise, reinstall gm with tiff enabled

brew install libtiff

brew uninstall –force graphicsmagick

brew install graphicsmagick –with-libtiff

Gnuplot with X11

brew install Caskroom/cask/xquartz

brew install gnuplot –with-x11

export GNUTERM=x11

 

Posted in Software | Tagged , , , | Leave a comment

Openssl RSA+AES 128bit

Create a random AES key (128bit)

openssl rand 16 > key.bin

encrypt AES key with RSA public key

openssl rsautl -encrypt -inkey public.key -pubin -in key.bin -out key.bin.enc

Encrypt data with AES key

openssl enc -aes-128-cbc -nosalt -nopad -in text.txt -out encrypted.txt -pass file:./key.bin

Decrypt AES key with RSA private key

openssl rsautl -decrypt -inkey private.key -in key.bin.enc -out key.bin.dec

Decrypt data with AES key

openssl enc -d -aes-128-cbc -nosalt -nopad  -in encrypted.txt -out decrypted.txt -pass file:./key.bin.dec

Posted in Uncategorized | Tagged , , | Leave a comment

Openssl RSA test

generate a RSA private key:

openssl genrsa -out private.key 1024

extract public key from private key:

openssl rsa -in private.key -pubout -out public.key

Encryption:

openssl rsautl -encrypt -pubin -inkey public.key -in text.txt -out encrypted.txt

Decryption:

openssl rsautl -decrypt -inkey private.key -in encrypted.txt -out decrypted.txt

There is a data limit for text.txt: 117 bytes

Posted in Software | Tagged , | Leave a comment

Using MySQL connection under Wildfly

adding modules:

$JBOSS_HOME/modules/com/mysql/main/module.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<module xmlns=”urn:jboss:module:1.0″ name=”com.mysql”>
<resources>
<resource-root path=”mysql-connector-java-5.1.36.jar”/>
</resources>
<dependencies>
<module name=”javax.api”/>
<module name=”javax.transaction.api”/>
</dependencies>
</module>

and mysql-connector-java-5.1.36.jar file

Posted in Uncategorized | Tagged | Leave a comment

PHP Laravel DB phpunit test

Write unit test for Laravel DB: if a class has a static method:

public static function read($id, $field, $lang)
{
    $line = DB::table('tablename')->where('id', '=', $id)->where('field', '=', $field)->where('lang', '=', $lang)->first();
    if (empty($line)) {
        return "";
    } else {
        return $line->value;
    }
}

To mock this DB statement:

DB::shouldReceive('table')->once()->andReturn(
    \Mockery::mock('Illuminate\Database\Query\Builder', function ($mock) {
    // @var \Mockery\Mock $mock
    $mock->makePartial();
    $mock->shouldReceive('where')->once()->andReturn(
        \Mockery::mock('Illuminate\Database\Query\Builder', function ($mock) {
            $mock->makePartial();
            $mock->shouldReceive('where')->once()->andReturn(
                \Mockery::mock('Illuminate\Database\Query\Builder', function ($mock) {
                    $mock->makePartial();
                    $mock->shouldReceive('where')->once()->andReturn(
                        \Mockery::mock('Illuminate\Database\Query\Builder', function ($mock) {
                            $mock->makePartial();
                            $mock->shouldReceive('first')->once()->andReturn('');
                        })
                    );
                })
            );
        })
    );
}));

 

or

$mock = \Mockery::mock('Illuminate\Database\Query\Builder');
$mock->shouldReceive('where')->zeroOrMoreTimes()->andReturn($mock);
$mock->shouldReceive('first')->zeroOrMoreTimes()->andReturn('');
DB::shouldReceive('table')->zeroOrMoreTimes()->andReturn($mock);

 

Posted in Computer und Internet | Tagged , , , | Leave a comment

Apple Passbook pkpass generating with PHP

PHP + ZIP + OPENSSL+COMPOSER

 

Init a new project (adding dependence passbook https://github.com/eymengunay/php-passbook/):

composer init

composer install

p12 file generated for Pass Type IDs

WWDRCA.pem

$factory = new PassFactory(‘PassTypeIDs’, ‘TeamIDs’, ‘customer name’, ‘cert/pass.p12’, ‘123456’, ‘cert/AppleWWDRCA.pem’);

git: https://github.com/paipeng/PHP-Passbook-test

Posted in Computer und Internet | Tagged | Leave a comment

Virtualbox 扩展硬盘容量

当之前定义的虚拟硬盘容量不够的时候,可以扩容硬盘的大小。

设置过程:

VBoxManage modifyhd Windows\ 7.vdi –resize 40960

(使用VBoxManage命令修改虚拟硬盘文件的大小到4GB)

0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%

启动Win7虚拟系统。开机后,打开Control Panel 》System and Security》Administrative Tools》Create and Format HD partitions

选择硬盘右键鼠标》Extend Volumen

Posted in Computer und Internet | Tagged , | Leave a comment

Deploy war on Wildfly via jboss-cli

Command:

/path/wildfly/bin/jboss-cli.sh –connect –command=”deploy –force /path/test-javaee7.war”

Posted in Uncategorized, Computer und Internet | Tagged , , | Leave a comment

Using adb copy files from devices to MAC

command line copy files:

adb push path/ ~/local

 

Posted in Computer und Internet | Tagged , | Leave a comment

c pointer to pointer

int** mat = malloc(10 * sizeof(int*));
for (int i=0; i<10; ++i) {
  mat[i] = malloc(10 * sizeof(int));
}

http://computer.howstuffworks.com/c32.htm

for (i=0; i<10; ++i) {
  free(mat[i]);
}


Posted in Computer und Internet | Tagged , | Leave a comment