About neohope

一直在努力,还没想过要放弃...

Io自学笔记01

//animal
animal := Object clone
animal name := "name"

//dog
dog := animal clone
dog name := "dog"
dog isSit := false
dog bark := method(writeln("woof"))
dog sit := method(
	if(isSit==true,writeln("sitting now");bark;return;)
	isSit=true
	writeln("sit ok")
	bark
)

//fido
fido := dog clone
fido name := "fido"
fido bark := method(
	writeln("ruf")
)

//test
writeln("dog bark>>")
dog bark
writeln("dog sit>>")
dog sit
writeln("dog sit>>")
dog sit

writeln("fido bark>>")
fido bark
writeln("fido sit>>")
fido sit
writeln("fido sit>>")
fido sit

关闭和打开Oralce10g自动收集COB信息

前几天,发现平台的一支程序突然运行的很慢,经分析后,发现是数据库查询变得超级慢。
用OB9分析后,发现索引正常,没办法最后重启了数据库后,速度直接飚上来了。
但好景不长,第二天早上4点后,又变成龟速,只好找公司DBA帮忙分析问题。

最后发现是Oracle的自动统计分析Job,每天自动进行统计,然后优化器就不走索引,而走统计分析的结果。
而我们的表有较多的删除操作,很快统计分析的结果就不可靠了,结果速度很快就下来了。

最后,禁用之,搞定:)

--状态查询
select * from Dba_Scheduler_Jobs where JOB_NAME ='GATHER_STATS_JOB'

--sysdba
--关闭
exec dbms_scheduler.disable('SYS.GATHER_STATS_JOB');

--sysdba
--启用
exec dbms_scheduler.enable('SYS.GATHER_STATS_JOB');

JNI简单例子2

最近又用jni写了一个编码工具,从中抽出了最简单的代码,如下:

1、Compress4j.java

package com.neohope.test.compress.jni;

/**
 *
 * @author Hansen
 */
public class Compress4j {
    private native int encodeR(String inFilePath,String outFilePaht);
    private native int decodeR(String inFilePath,String outFilePaht);
    
    static{
        try{
            System.loadLibrary("compress4j");
        }catch(UnsatisfiedLinkError e){
            //nothing to do
            System.out.println("Error: Couldn't load compress4j");
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }
    
    public String encode(String inFilePath,String outFilePath)
    {
        encodeR(inFilePath, outFilePath);
        return "xxxxx";
    }
    
    public String decode(String inFilePath,String outFilePath)
    {
        decodeR(inFilePath, outFilePath);
        return "xxxxx";
    }
}

2、找到生成的classes文件夹,运行命令行:

javah -classpath . -jni com.neohope.test.compress.jni.Compress4j 

3、生成的.h文件如下

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_neohoe_test_compress_jni_Compress4j */

#ifndef _Included_com_neohoe_test_compress_jni_Compress4j
#define _Included_com_neohoe_test_compress_jni_Compress4j
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_neohoe_test_compress_jni_Compress4j
 * Method:    encodeR
 * Signature: (Ljava/lang/String;Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_com_neohoe_test_compress_jni_Compress4j_encodeR
  (JNIEnv *, jobject, jstring, jstring);

/*
 * Class:     com_neohoe_test_compress_jni_Compress4j
 * Method:    decodeR
 * Signature: (Ljava/lang/String;Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_com_neohoe_test_compress_jni_Compress4j_decodeR
  (JNIEnv *, jobject, jstring, jstring);

#ifdef __cplusplus
}
#endif
#endif

3、编写成的.cc文件如下

#include "com_neohoe_test_compress_jni_Compress4j.h"

JNIEXPORT jint JNICALL Java_com_neohoe_test_compress_jni_Compress4j_encodeR
  (JNIEnv *env, jobject, jstring inpathjs, jstring outpathjs)
{
    //first convert jstring to const char*
    const char* inpath = env->GetStringUTFChars( inpathjs, false);
    const char* outpath = env->GetStringUTFChars( outpathjs, false);

    //...

    return 0;
}

JNIEXPORT jint JNICALL Java_com_neohoe_test_compress_jni_Compress4j_decodeR
  (JNIEnv *env, jobject, jstring inpathjs, jstring outpathjs)
{
    //first convert jstring to const char*
    const char* inpath = env->GetStringUTFChars( inpathjs, false);
    const char* outpath = env->GetStringUTFChars( outpathjs, false);

    //...

    return 0;
}

4、在VS工程中,新增头文件目录
%JAVA_HOME%/include
%JAVA_HOME%/include/win32

5、编译为dll即可使用啦

6、关于mt和md的问题
编译为MT和MTd的话,用JNI是没有任何问题的
编译为MD的话,需要安装VC2010sp1可再发行包
编译为MDd的话,就比较麻烦了,手动复制依赖的dll后,我用c++调用dll可以成功,但用jni就一直提示:缺少依赖的dll

ipa包重签名

如果ipa打包时,签名文件不包括你的设备id,用itunes安装后是无法使用的,
这样,就要重新申请包含你设备id的证书,用下面的方法重签名:

1、把ipa和新证书放到同一目录下

2、新建文件resignipa.sh

IPA="xx.ipa"
IPAOUT="xxx.ipa"
PROVISION="xxxx.mobileprovision"
CERTIFICATE="xxxxx" # must be in keychain

# unzip the ipa
unzip -q "$IPA"

# remove the signature
rm -rf Payload/*.app/_CodeSignature Payload/*.app/CodeResources

# replace the provision
cp "$PROVISION" Payload/*.app/embedded.mobileprovision

# sign with the new certificate
/usr/bin/codesign -f -s "$CERTIFICATE" --resource-rules Payload/*.app/ResourceRules.plist Payload/*.app

# zip it back up
zip -qr "$IPAOUT" Payload

3、启动命令行

chmod 777 resignipa.sh
./resignipa.sh

生成IPA包

生成ipa包有以下几种方式:
1、自己手工打包
a、找到xcode生成app包
b、新建文件夹Payload,并把app包放进去
c、(可选)准备一张jpeg格式的图(<500*500px),用来显示在iTunes中 d、(可选)命名这张图为iTunesArtwork(无扩展名),并把它放在和Payload同一级目录中 e、将Payload和iTunesArtwork压缩,后缀名改为ipa即可 2、利用itunes a、找到xcode生成app包 b、直接拖到itunes中 c、在itunes的app目录下找到对应ipa即可(无图片) 3、利用xcode a、生成Archive b、在organizer的Archive界面选择share

VirtualBox从U盘启动

默认情况下,Virtualbox从无法从U盘启动的。

但可以用变通的方法,将宿主机的U盘,模拟为一个虚拟盘,从虚拟盘进行启动。

1、首先产看本地硬盘信息
运行diskmgmt.msc
查看U盘是第几个驱动器,比如我的是第2个驱动器(编号从0开始,0,1,2这样)

2、将U盘模拟为一个虚拟盘

VBoxManage internalcommands createrawvmdk -filename D:\VirtualMashines\VirtualBox\WinXP\usbdisk.vmdk -rawdisk \\.\PhysicalDrive2

3、虚拟机中,添加该虚拟盘

4、启动,按F12,选择虚拟盘启动。

VirtualBox扩展及压缩虚拟磁盘

1、首先定位各虚拟磁盘的UUID

C:\ProgramerTools\Oracle\VirtualBox>VBoxManage.exe list hdds
UUID:           b806ffa9-ea8e-4059-9dd8-2d246e850ab6
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       D:\VirtualMashines\VirtualBox\WinXP\WinXP.vdi
Storage format: VDI
Capacity:       10240 MBytes

UUID:           945de0c8-f928-44ad-ae39-9a12a71568ef
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       D:\VirtualMashines\VirtualBox\Debian8\Debian8.vdi
Storage format: VDI
Capacity:       20480 MBytes

UUID:           e49d8a88-d68b-43b8-954e-2be419933e08
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       D:\VirtualMashines\VirtualBox\Docker\Debian8Docker\Debian8Docker
.vdi
Storage format: VDI
Capacity:       20480 MBytes

UUID:           eab29989-ce9c-4491-8dd0-2190ed3029d6
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       D:\VirtualMashines\VirtualBox\FreeBSD10\FreeBSD10.vdi
Storage format: VDI
Capacity:       20480 MBytes

UUID:           74bcd43e-a315-437e-9b4f-895051ff8433
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       D:\VirtualMashines\VirtualBox\FreeBSD10\FreeBSD10A01.vdi
Storage format: VDI
Capacity:       20480 MBytes

2、扩展WinXP虚拟磁盘
2.1我的xp虚拟机一共只有10G,我需要扩展到20G(要关虚拟机)

C:\ProgramerTools\Oracle\VirtualBox>VBoxManage modifyhd b806ffa9-ea8e-4059-9dd8-
2d246e850ab6 --resize 20480
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

2.2扩展后,开启虚拟机,自己到磁盘管理器中分配空间即可。

3、扩展Debian虚拟磁盘
3.1我的Debian8Docker虚拟机一共只有20G,我需要扩展到30G(要关虚拟机)

C:\ProgramerTools\Oracle\VirtualBox>VBoxManage modifyhd e49d8a88-d68b-43b8-954e-
2be419933e08 --resize 30720
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

3.2扩展后,开启虚拟机,使用gparted等工具分配空间即可。
需要提前unmount分区,如果是调整扩展分区,需要umount该扩展分区下的所有挂载点。

4、压缩WinXP虚拟磁盘
4.1需要到微软官网下载sdelete工具,然后在虚拟机中运行:

sdelete -z

4.2关闭虚拟机,运行:

VBoxManage modifyhd b806ffa9-ea8e-4059-9dd8-2d246e850ab6 --compact

5、压缩Debian虚拟磁盘:
5.1A在虚拟机中运行zerofree命令,需要将分区挂载为只读模式

apt-get install zerofree
cd /
umount /home
zerofree /dev/sda6

5.1B在虚拟机中运行dd命令,需要将分区挂载为读写模式

dd if=/dev/zero of=/bigemptyfile
rm bigemptyfile 

5.2关闭虚拟机,运行:

VBoxManage modifyhd 945de0c8-f928-44ad-ae39-9a12a71568ef --compact

6、压缩FreeBSD虚拟磁盘:
6.1A在虚拟机中运行dd命令,需要将分区挂载为读写模式

dd if=/dev/zero of=bigemptyfile bs=1m
rm bigemptyfile

6.1B在虚拟机中运行dd命令,需要将分区挂载为读写模式(适用于影片空闲空间较小)

cat /dev/zero > bigemptyfile;sync;sleep 1;sync;
rm -f bigemptyfile

6.2关闭虚拟机,运行:

VBoxManage modifyhd eab29989-ce9c-4491-8dd0-2190ed3029d6 --compact
VBoxManage modifyhd 74bcd43e-a315-437e-9b4f-895051ff8433 --compact

go语言channel测试

go语言channel测试,请注意空格

package main
import "fmt"

const num_go_routine = 10000

func channeltest(left,right chan int){
	left<-1+<-right;
}

func main(){
	leftmost := make(chan int);

	var left,right chan int = nil,leftmost;
	for i:=0; i<num_go_routine; i++ {
		left, right = right, make(chan int);
		go channeltest(left,right);
	}

	right<-0;
	x := <-leftmost;
	fmt.Println(x);
}

注:本示例程序来自于《代码的未来》,松本行弘