c语言中,用函数实现sizeof操作

大家都知道,c语言中sizeof是个操作符,在编译阶段已经变成了数值
要用函数实现sizeof的话,和sizeof操作符是会有一定区别的
这里,我只给出了一个很简单的例子,
用指针操作实现sizeof(double)的功能

double a=0.0;
int sz=(int)&((&a)[1])-(int)&a;

Java Cheat List

1.控制台读入字符串

String pair ="";
try
{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    pair = br.readLine(); 
}
catch(IOException ex)
{
    ex.printStackTrace();
}

2.控制台读入整数

int a=0;
try{
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    a=Integer.parseInt(br.readLine());
    b=Integer.parseInt(br.readLine());
    c=Integer.parseInt(br.readLine());
}catch(IOException ex){
    ex.printStackTrace();
}

3.计算某年某月为星期几

int y=2000,m=1,d=1;
Calendar aCalendar=Calendar.getInstance();
aCalendar.set(Calendar.YEAR,y);
aCalendar.set(Calendar.MONTH, m-1);
aCalendar.set(Calendar.DAY_OF_MONTH, d);
//注意,x为1-7,默认1为星期日
int x=aCalendar.get(Calendar.DAY_OF_WEEK);

IOS Cheat List

1.页面切换

//页面切换
MyViewController *controller = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentModalViewController:controller animated:YES];
//页面返回
[self dismissModalViewControllerAnimated:YES];

2.获取AppDelegate

MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

3.获取配置信息

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *MyTextValue = [defaults objectForKey:TEXT_VALUE_KEY];

BOOL MyBoolValue = [defaults boolForKey:BOOL_VALUE_KEY];

4.读取plist

//本地
NSString *path = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
//远程
NSStrng * strURL = [[NSString alloc] initWithFormat:@"FORMAT",.....];
NSLog(@"%@",strURL);
NSURL *plistURL = [NSURL URLWithString:strURL];
NSDictionary *myDict = [[NSDictionary alloc] initWithContentsOfURL:plistURL];

5.关闭键盘

[myControl resignFirstResponder];

6.内置功能调用

//网站
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://网址"]];
//打电话
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://电话号码"]];
//发送邮件
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://邮箱地址"]];
//发送短信
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://电话号码"]];

7.导航

//左按钮
UIBarButtonItem *lBtn = [[UIBarButtonItem alloc] initWithTitle:@"名称" style:UIBarButtonItemStylePlain target:self action:@selector(lBtnPressed:)];
self.navigationItem.leftBarButtonItem = lBtn;
 [lBtn release];

//入栈
MyViewController *nextController = [[MyViewController alloc] init];
nextController.title = @"MyViewControllerName";
[self.navigationController pushViewController:nextController animated:YES];

//出栈
[self.navigationController popViewControllerAnimated:YES];

8.返回一个TableViewCell

static NSString *tableViewCellIdentifier = @"MyCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableViewCellIdentifier];
if(cell==nil)
{
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableViewCellIdentifier] autorelease];
}
cell.textLabel.text = @"TEXT"
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;

9.UIAlertView异步的哟

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"HI" message:@"Hello" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alert show];
[alert release];

10.注册推送通知

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert |UIRemoteNotificationTypeSound];

11.注册网络状态

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: KEY_ATS_NETWORK_CHANGE_NOTIFICATION object: nil];

NSString* token = [deviceToken description];
deviceTokenId = [[[token stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]] stringByReplacingOccurrencesOfString:@" "withString:@""] retain];

PushedMsg *newMsg = [[PushedMsg alloc] init];
newMsg.msgContent = [[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] copy];

12.本地通知

//增加
UILocalNotification *notification=[[UILocalNotification alloc] init];
NSDate *now1=[NSDate date];
notification.timeZone=[NSTimeZone defaultTimeZone];
notification.repeatInterval=NSDayCalendarUnit;
notification.applicationIconBadgeNumber = 1;
notification.alertAction = NSLocalizedString(@"显示", nil);

notification.fireDate=[now1 dateByAddingTimeInterval:10];
notification.alertBody=@"通知";

[notification setSoundName:UILocalNotificationDefaultSoundName];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"%d",myswitch.tag],KEY_ATS_LOCAL_NOTIFICATION, nil];
[notification setUserInfo:dict];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
//取消
UILocalNotification *myUILocalNotification=[myArray objectAtIndex:i];
if ([[[myUILocalNotification userInfo] objectForKey:KEY_ATS_LOCAL_NOTIFICATION] intValue]==myswitch.tag)
{
[[UIApplication sharedApplication] cancelLocalNotification:myUILocalNotification];
}

13.计算MD5

#import <CommonCrypto/CommonDigest.h>

//生成指定字符串的MD5
+ (NSString*)CalcMD5:(NSString *)InString
{
    //生成MD5
    const char *ptr = [InString UTF8String];
    unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];
    CC_MD5(ptr, strlen(ptr), md5Buffer);
   
    //转为NSString
    NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
    {
        &#91;output appendFormat:@"%02x",md5Buffer&#91;i&#93;&#93;;
    }
    return output;
}
&#91;/code&#93;

<strong>14.获取位置</strong>
[code lang="objc"]
CLLocationManager* locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];

15.本地化

NSLocalizedString(@"KEY",@"DEFAULT");

16.获取图片

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
[picker release];

17.加速器

UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
accel.delegate =self;
accel.updateInterval = UPDATE_INTERVAL;

18.声音

NSString *path=[[NSBundle mainBundle] pathForResource:@"文件名" ofType:@"wav"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);

AudioServicesPlaySystemSound(soundID);

汉化.net程序

1.首先是反编译

ildasm11.exe /ALL /VISIBILITY=PUB+PRI+FAM+ASM+FAA+FOA+PSC /UNICODE Target.dll /OUT=Target.il

2.打开Target.il
搜索ldstr,后面就是你所需要汉化的字符串

同时会遇到bytearray类型的字符串,这些字符串是以UNICODE的HEX方式存储的,将汉化后内容,同样转成UNICODE的HEX字符串存回去,同时记住要修改字体

3.去掉StrongName
将Target.il中publickkey字段删除

4.生成snk

sn.exe -k Target.snk

5.重新编译并增加StrongName

ILASM11.exe Target.il /dll /key:Target.snk /resource:Target.res /out:Target_cn.dll

6.验证

sn -v Target_cn.dll

第一次汉化游戏

上大学时,有款游戏叫“是男人就下100层”
无聊的时候玩玩还不错

但是看到上面的日文,我就不爽,干脆,汉化掉算了
查看后,没加壳,哈哈哈哈哈哈哈哈
掏出eXeScope,找出资源,我改。。。
很快菜单等资源都改好了

运行试试,感觉不错,但旁边怎么还有这么大的日文?
继续找,发现,居然是图片
算你狠,掏出PS,改了几张,换上去
啊~~~
好难看,字体好难看啊
我这个没审美观的人都觉得好难看啊

算了,这个汉化版就算了吧,还是不拿出去丢人了。

过了几个月,
一哥们跟我说,来,我有中文版,
我很想看看PS高人怎么换掉图片的,
结果,
结果,他只换了菜单,
还没我汉化的多。。。
心情大好,原来我不是最差的那个啦

其实,换掉菜单后,的确就容易入手一些了,
后来看到过比较好的版本,但加壳了,
也没空细细研究,高手还是普遍存在的

MyEclipse不更新JSP

为了测试系统中的一个小功能,我很开心的修改了系统时间
然后,我发现,无论我怎么修改JSP,在Tomcat中浏览就是没有任何效果,整个一大悲剧啊

于是,我纠结了整整一下午,最后,想起来修改了系统时间
文件修改时间比修改前的还要早,当然不会去刷新啦,唉,悲剧。

将系统时间调好,删掉Tomcat下编译好的JSP目录
系统就正常啦

面壁去了~~

CMD常用命令05Cluster切换时丢失网关

公司在一家医院做实施,将Tomcat,存储,Oracle都做好了Cluster

但好景不长:
切换几次后,总会有一台服务器连不上,ping都ping不通,只好再手工切回去

后来发现,切换后把网关给丢掉了
在cmd下ipconfig -all,网关为空,但在连接属性的TCP/IP设置里,网关仍健在

唉,在google未果的情况下,只好做了件很无奈的事情,
写了个脚本,去设置网关

Rem Hansen
set myinterface=本地连接
set mygateway=192.168.100.1
netsh interface ip set address name="%myinterface%" gateway="%mygateway%" gwmetric=1
pause

居然还算管用,将就一下吧,唉

CDatabase中Open与OpenEx

昨天帮同事调试一段Windows服务代码,
其实很简单,但诡异的是,在服务中一直无法Catch到数据库无法连接的错误。

一开始,我以为他没有加载资源,少了:

AfxSetResourceHandle(GetModuleHandle(NULL));

这句话

后来发现,错误根本无法catch到,运行后直接向死了一样,等了几分钟还是这样
后来仔细看了下代码

db.OpenEx(szConnect);

天啊
直接换成

db.Open(szConnect);

问题解决。

Service里弹什么对话框啊,晕。