About neohope

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

CPP类型转换

1、static_cast

这是应该首先选用的转换方式,一般用于在相关类型间进行转换或在继承链中进行转换。
其运作方式类似于隐式转换 (比如int转为float,或指针转换为 void*), 而且它可以调用显示转换(当然包括隐式转换)。

在很多情况下, 显示声明static_cast是不必要的,
但有一点需要指出的是应当尽量避免type(XXX) 与(type)XXX 语法(详情见下文)。
然而type(XXX,YYY) 是安全的,而且一定会去调用构造函数。

static_cast也可以在父类及子类之间进行。 当子类向父类转换时是可以顺利进行的。但父类向子类转换时,只要子类没有继承virtual父类,就可以一直进行。但是它从父类转为子类时,不会做任何检查,即使类型不完全匹配。

2、const_cast

用来向一个变量增加或删除const属性。 其他任何C++ casts都无法完成此任务。
需要指出的是,当变量为const,该操作符是未定义的。

用它来声明一个非const类型的const引用是安全的。
当重载const类型的类成员变量时,该转换十分有用。
它也可以用来把一个对象增加const属性,比如调用重载的方法。

const_cast也适用于volatile,但很少见。

3、dynamic_cast

一般用来解决多态问题。你可以把指针或参考转换为任何继承链上的类型。
(一个多态类型至少用一个虚函数,无论是声明还是继承的)。
当从子类转换为父类时,dynamic_cast一定会成功。但从父类转换为子类,dynamic_cast会确保对象为子类的一个完全实现。

dynamic_cast将返回其是否可能。如果无法转换,他将返回NULL(对指针),或抛出std::bad_cast异常(对参考)。

dynamic_cast有一些限制:
如果在继承链中,同一类型有多个对象(dreaded diamond)同时你没有使用虚接口,转换不会进行。
他也只能应用于public继承,当protect或private继承时,会失败。

注意:
dynamic_cast需要编译器支持RTTI(运行时类型识别)。

4、reinterpret_cast

这是最危险的转换方式,慎用。 它直接把一种类型转换为另一种
(比如把值从一种指针转换为另一种指针,或把指针储存在int中, 或其他让人讨厌的事情)

使用reinterpret_cast,唯一能保证的是,当你从结构转回为原类型时,你能得到相同的结果。
当然,reinterpret_cast也有一些转换无法进行。

他通常用于比较奇怪的转换,或bit操作,比图把raw数据流转换为实际数据,或把数据储存在对齐指针的低字节。
当其他转换无法使用时,可以尝试reinterpret_cast

5、C-style cast
C-style cast 是使用(type)object 或 type(object)的转换方式。
C-style cast 被定义为下列转换中第一个成功返回的:
const_cast
static_cast
static_cast, then const_cast
reinterpret_cast
reinterpret_cast, then const_cast

在一些时候,他可以被用来替代其他casts,但用于他最后可能会调用reinterpret_cast(应显示调用),因此C-style cast是十分危险的。
除非你能保证,不会调用reinterpret_cast,或者reinterpret_cast一定会失败,否则不要轻易使用。即使如此,也应该考虑显示调用上面的转换。

当使用static_cast时,C-style casts 也可以忽略权限控制,这意味着他可以进行其他cast无法进行的操作。
这是避免C-style casts的一个不错的理由。

(翻译自Stack Overflow的一个帖子,水平有限,哈哈)

参考资料:
http://stackoverflow.com/questions/332030/when-should-static-cast-dynamic-cast-and-reinterpret-cast-be-used
http://www.cplusplus.com/doc/tutorial/typecasting/
http://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming_Languages/C%2B%2B/Code/Statements/Variables/Type_Casting

统计Excel工时的VBA脚本

很久很久以前,用于统计公司工时的一个VBA脚本,只使用了一小段时间。
代码写的有些傻傻的,哈哈哈。

Sub Summary()

    '统计行数
    Dim TotalLine As Integer
    TotalLine = 1
    
    Dim i, j As Integer
    i = 1
    j = 1
    
    Dim name As String
    
    '清空上次统计信息
    Sheet32.Range("A2:F301").ClearContents
    
    '计算人名
    name = Sheet1.Cells(2, 2)
    name = Right(name, Len(name) - 3)

    '遍历所有sheets
    For i = 1 To 31
    
        '每个sheets中有效行数
        For j = 4 To 12
        
            '判断一行是否为空
            If (Worksheets(i).Cells(j, 1) = "" And Worksheets(i).Cells(j, 2) = "" And Worksheets(i).Cells(j, 3) = "" And Worksheets(i).Cells(j, 4) = "" And Worksheets(i).Cells(j, 5) = "") Then
                '空行,不做处理
            Else
                '非空行,进行统计
                TotalLine = TotalLine + 1
                Sheet32.Cells(TotalLine, 1) = Worksheets(i).Cells(j, 4)
                Sheet32.Cells(TotalLine, 2) = Worksheets(i).Cells(j, 5)
                Sheet32.Cells(TotalLine, 3) = name
                
                If (Worksheets(i).Cells(j, 2) = "/") Then
                    Sheet32.Cells(TotalLine, 4) = "0"
                Else
                    Sheet32.Cells(TotalLine, 4) = Worksheets(i).Cells(j, 2)
                End If
                
                If (Worksheets(i).Cells(j, 3) = "/") Then
                    Sheet32.Cells(TotalLine, 5) = "0"
                Else
                    Sheet32.Cells(TotalLine, 5) = Worksheets(i).Cells(j, 3)
                End If

                Sheet32.Cells(TotalLine, 6) = Sheet32.Cells(TotalLine, 4) + Sheet32.Cells(TotalLine, 5)
            End If
        Next j
    Next i
    
    '清空上次统计信息
    Sheet33.Range("A2:F301").ClearContents
    
    '任务行数
    Dim TaskLine As Integer
    TaskLine = 1
    
    '本条记录是否添加
    Dim bFind As Boolean
    
    '效率低下的循环
    For i = 2 To TotalLine
        bFind = False
        For j = 2 To TaskLine
            If (Sheet32.Cells(i, 1) = Sheet33.Cells(j, 1) And Sheet32.Cells(i, 2) = Sheet33.Cells(j, 2)) Then
                Sheet33.Cells(j, 4) = Sheet33.Cells(j, 4) + Sheet32.Cells(i, 4)
                Sheet33.Cells(j, 5) = Sheet33.Cells(j, 5) + Sheet32.Cells(i, 5)
                Sheet33.Cells(j, 6) = Sheet33.Cells(j, 6) + Sheet32.Cells(i, 6)
                bFind = True
                Exit For
            End If
        Next j
        
        If (Not bFind) Then
                TaskLine = TaskLine + 1
                Sheet33.Cells(TaskLine, 1) = Sheet32.Cells(i, 1)
                Sheet33.Cells(TaskLine, 2) = Sheet32.Cells(i, 2)
                Sheet33.Cells(TaskLine, 3) = Sheet32.Cells(i, 3)
                Sheet33.Cells(TaskLine, 4) = Sheet32.Cells(i, 4)
                Sheet33.Cells(TaskLine, 5) = Sheet32.Cells(i, 5)
                Sheet33.Cells(TaskLine, 6) = Sheet32.Cells(i, 6)
        End If
        
    Next i
    
    MsgBox ("任务完成咯 :)")
    
End Sub

Linux及BSD包管理系统

大家都知道,
Linux发行版=Linux内核+包管理系统

当下,Linux的主要包管理系统分为两大阵营,RPM和DEB,
(其主要原因是,子发行版多沿用了父发行版的包管理系统)
但每种有特色的发行版,又都会开发自己独特的包管理系统。
主要Linux发行版的管理统系统计如下:

RPM:
RHEL;Fedora;CentOS;
openSUSE;SUSE Linux Enterprise;
PCLinuxOS;
Mageia;
Fuduntu;
Mandriva Linux;
Scientific Linux;
Oracle Linux;

DEB:
Debian;
Ubuntu;Kubuntu;Xubuntu;Ubuntu Studio;
Lubuntu;
Linux Mint;
Ultimate Edition;
Bodhi Linux;
Pinguy OS;
Zorin OS;
MEPIS Linux;
KNOPPIX;
BackTrack;

Pacman:
Arch Linux;
Chakra GNU/Linux;

Portage:
Gentoo

PET:
Puppy

TCE:
Tiny Core Linux

Entropy:
Sabayon Linux

TXZ:
Slackware Linux

TBZ:
FreeBSD;
DragonFly BSD;

TGZ:
OpenBSD

PBI/TGZ:
PC-BSD

IPS, pkgadm:
Oracle Solaris

pkgin:
MINIX

【转载】弹性分布式数据集:内存集群计算的容错抽象(Resilient Distributed Datasets: A Fault-Tolerant Abstraction for In-Memory Cluster Computing)

弹性分布式数据集:内存集群计算的容错抽象

Resilient Distributed Datasets: A Fault-Tolerant Abstraction for In-Memory Cluster Computing

贡献:提出RDD,促使Spark生态取代MapReduce成为大数据计算的事实标准

作者:Matei Zaharia, Mosharaf Chowdhury, Tathagata Das, Ankur Dave, Justin Ma, Murphy McCauley, Michael J. Franklin, Scott Shenker, Ion Stoica
单位:University of California, Berkeley


摘要

我们提出了弹性分布式数据集(Resilient Distributed Datasets,简称RDD),这是一种分布式内存抽象,能够让程序员在大型集群上以容错的方式执行内存计算。RDD的提出,旨在解决两类现有计算框架处理效率低下的应用场景:迭代算法与交互式数据挖掘工具。在这两类场景中,将数据保存在内存中可以将性能提升一个数量级。为了高效实现容错,RDD提供了一种受限制的共享内存形式:它是只读数据集,只能通过对其他RDD执行批量操作来构建。但我们的研究表明,RDD的表达能力足以覆盖广泛的计算类型,包括MapReduce,以及Pregel等面向迭代任务的专用编程模型,还能支持这些模型无法覆盖的新型应用。我们在名为Spark的系统中实现了RDD,并通过多种用户应用和基准测试对其进行了评估。

Continue reading 【转载】弹性分布式数据集:内存集群计算的容错抽象(Resilient Distributed Datasets: A Fault-Tolerant Abstraction for In-Memory Cluster Computing)→

Jar包签名

1、生成keystore及key

#生成私钥
keytool -validity 10000 -genkey -alias xxxxxx -keypass xxxxxx -storepass xxxxxx -keystore xxxxxx.jks -dname "CN=(R&D),O=(ATS),C=(CN)" -keyalg RSA

导出证书

#证书DER格式
keytool -exportcert -alias xxxxxx -keypass xxxxxx -keystore xxxxxx.jks -storepass xxxxxx -file xxxxxx.der
#证书PEM格式
keytool -exportcert -alias xxxxxx -keypass xxxxxx -keystore xxxxxx.jks -storepass xxxxxx -rfc -file xxxxxx.pem

枚举证书

keytool -list -keystore xxxxxx.jks 

2、签名

jarsigner -keystore xxxxxx.jks -storepass xxxxxx -keypass xxxxxx xxxxxx.jar xxxxxx

3、验证

JARsigner -verbose -verify  xxxxxx.jar

C#调用cdll指针参数处理

1、API声明(包括**参数)

int GetTheLastErrorA(char **pcError);
int GetTheLastErrorW(wchar_t **pwError);

2、C#代码

using System.Runtime.InteropServices;

[DllImport("StringAW.dll", CallingConvention = CallingConvention.Winapi, 
CharSet = CharSet.Ansi, EntryPoint = "GetTheLastErrorA")]
extern static int GetTheLastErrorA(ref IntPtr a);

[DllImport("StringAW.dll", CallingConvention = CallingConvention.Winapi, 
CharSet = CharSet.Auto, EntryPoint = "GetTheLastErrorW")]
extern static int GetTheLastErrorW(ref IntPtr w);

IntPtr a = IntPtr.Zero;
GetTheLastErrorA(ref a);
String sa = Marshal.PtrToStringAnsi(a);
MessageBox.Show(sa);

IntPtr w = IntPtr.Zero;
GetTheLastErrorW(ref w);
String sw = Marshal.PtrToStringUni(w);
MessageBox.Show(sw);

Maven常用参数

1.常用命令参数
进行编译

mvn compile

进行打包

#测试并打包
mvn package
#直接打包,不进行测试
mvn package -DskipTests=true
#打Jar包
mvn jar:jar
#打War包
mvn war:war
#打War包但不执行最后的压缩
mvn war:exploded

进行测试

#编译单元测试
mvn test-compile
#编译并允许单元测试
mvn test

安装到本地repository

mvn install
mvn install -DskipTests=true
mvn install -DskipTests=true --fail-at-end
#安装jar包到本地仓库
mvn install:install-file -DgroupId=groupId -DartifactId=artifactId -Dversion=1.0.0 -Dpackaging=jar -Dfile=xxx.jar

安装到远程repository

mvn deploy

进行清理

mvn clean

生成网站

#生成网站
mvn site
#生成网站并发布
mvn site-deploy

打包源码包

#打包源码
mvn source:jar
#下载项目源码
mvn dependency:sources -DdownloadSources=true -DdownloadJavadocs=true

打包测试源码包

mvn source:test-jar

拷贝依赖到target目录

#拷贝依赖
mvn dependency:copy-dependencies
#依赖分析
mvn dependency:analyze
mvn dependency:tree

生成ecplise项目

mvn eclipse:eclipse

生成ecplise项目

mvn idea:idea

生成文档

#单模块项目生成文档
mvn javadoc:javadoc
#多模块项目生成文档
mvn javadoc:aggregate

创建Jar项目

mvn archetype:create -DgroupId=gourpid -DartifactId=artifactId

创建War项目

mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=gourpid  -DartifactId=artifactId

2.settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"]

<localRepository>X:/Maven/repository</localRepository>

<servers>
<server>
<id>neo-public</id>
<username>username</username>
<password>password</password>
</server>
<server>
<id>neo-releases</id>
<username>username</username>
<password>password</password>
</server>
<server>
<id>neo-snapshots</id>
<username>username</username>
<password>password</password>
</server>
</servers>

<mirrors>
<mirror>
<id>neo-public</id>
<name>Neohope Nexux Public Mirror</name>
<url>http://192.168.xxx.xxx:8081/nexus/content/groups/public</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>

<profiles>
<profile>
<id>myprofile</id>
<repositories>
<repository>
<id>neo-public</id>
<name>Neohope Nexux Public Mirror</name>
<url>http://192.168.xxx.xxx:8081/nexus/content/groups/public</url>
</repository>
</repositories>
</profile>
</profiles>

<activeProfiles>
<activeProfile>myprofile</activeProfile>
</activeProfiles>

</settings>

3.pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"]
<modelVersion>4.0.0</modelVersion>

<groupId>com.neohope.xxx</groupId>
<artifactId>xxx-xxx</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>xxx-xxx</name>
<url>http://neohope.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<nexus.url>http://192.168.xxx.xxx:8081</nexus.url>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>neo-releases</id>
<name>Internal Releases</name>
<url>${nexus.url}/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>neo-snapshots</id>
<name>Internal Snapshots</name>
<url>${nexus.url}/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>