|
在使用CCSpriteFrameCache 初始化的情况下更换sprite图片的方法。 p.s : 如果使用spriteWithFile 则使用setTexture. CCSpriteFrameCache* cache = [CCSpriteFrameCache sharedSpriteFrameCache]; CCSpriteFrame* frame = [cache spriteFrameByName:name]; [sprite setDisplayFrame:frame];
1,到 http://www.redmine.org 官网上下载最新的redmine。目前是1.1.0。将其解压至/opt/redmine 下 2,到 http://www.redmine.org/projects/redmine/wiki/RedmineInstall 查看需要的安装环境。 一般需要rails 和rack :gem install rails -v=2.3.5 :gem install rack -v=1.0.1 3,安装mysql 数据库 :sudo apt-get install mysql-server
。 安装好后 进入mysql进行配置: mysql -u root (以后有密码了需要 输入 mysql -u root -p 按回车,再输入密码) mysql>grant all privileges on *.* to root@localhost identified by '123456';
//先设置root密码 mysql>create database redmine character set utf8;
//必须要设置编码为utf8否则redmine所有汉字会显示成?? mysql>create user redmine@localhost identified by '123456'; //建立一个新用户redmine ,密码是123456 mysql>grant all privileges on redmine.* to redmine@localhost; 这样mysql就配置好了。 4, 进入/opt/redmine 找到刚才解压的文件夹redmine-1.1.0 ,进入 config 目录下 将database.example.yml 复制为database.yml sudo cp database.example.yml database.yml sudo gedit database.yml 按照如下修改 production: adapter: mysql socket: /var/run/mysqld/mysqld.sock database: redmine host: localhost username: redmine password: '123456' encoding: utf8 5, 进入 /opt/redmine/redmine-1.1.0 将redmine数据库导入到mysql数据库中 : sudo rake generate session_store sudo rake db:migrate RAILS_ENV =production 如果导入顺利,就可以启动redmine了: sudo ruby script/server -e production 6,打开ie浏览器,输入 : http://localhost:3000 进入redmine 。默认用户名和密码是admin。在配置里面可以设置每个用户的语言,改成中文即可。
用到了select,对select的了解更加深入了一些。 由于使用到了tcp链接,所以在发送的时候一定要关闭socket以使对端能收到EOF。
#include <sys/types.h> #include <ctype.h> #include <unistd.h> #include <stdarg.h> #include <stdlib.h> #include <stdio.h> #include <fcntl.h> #include <sys/ioctl.h> #include <errno.h> #include <string.h> #include <assert.h> #include <pthread.h> #include <sys/socket.h> #include <netinet/in.h> #include <netinet/ip.h> #include <netinet/udp.h> #include <netinet/tcp.h> #include <arpa/inet.h> #include <netdb.h> #include <net/if.h> #include <net/route.h> #include <sys/stat.h> #include <sys/epoll.h> #include <sys/resource.h> #include <sys/wait.h> #include <dlfcn.h> #define LISTEN_PORT 25000 #define BUFFLEN 128 typedef struct Recv_Info { FILE * fconnectin; char filepath[50]; }Recv_Info; typedef struct Send_Info { char ip[50]; char filepath[50]; }Send_Info;
int listen_fd,connect_fd; void handle_int ( int signo ) { fprintf ( stderr, "Interrupt catched!!\n" ); exit(0); } static void* recieve_file(void * arg) { Recv_Info *recv_info = (Recv_Info*)arg; FILE * p; p=fopen(recv_info->filepath,"w+"); if(p==NULL) fprintf(stdout,"Fopen failed in recieve file! make sure your filepath is right!\n"); char buff[BUFFLEN]; int count=0; int amount=0; while(fgets(buff,BUFFLEN,recv_info->fconnectin)!=NULL) { count=strlen(buff); amount+=count; fputs(buff,p); } fprintf(stdout,"Recieve %d Bytes !\n",amount); fclose(p); close(connect_fd); } static void* send_file(void * arg) { Send_Info * send_info=(Send_Info *)arg; char buff[BUFFLEN]; int remote_fd; int remote_len; struct sockaddr_in remote; FILE * p; p=fopen(send_info->filepath,"r+"); if(p==NULL) { fprintf(stdout,"fopen failed!\n"); return NULL; } remote_fd = socket(AF_INET, SOCK_STREAM, 0); if (remote_fd == -1) { fprintf(stderr, "socket() apply failed!\n"); return NULL; } memset(&remote, 0, sizeof(remote)); remote.sin_family = AF_INET; remote.sin_port = htons(LISTEN_PORT); remote.sin_addr.s_addr = inet_addr(send_info->ip); int count = 0; int amount = 0; if(connect(remote_fd,(sockaddr*)&remote,sizeof(sockaddr_in))==0) { send(remote_fd,"s",1,0); while(fgets(buff,BUFFLEN,p)!=NULL) { count=send(remote_fd,buff,strlen(buff),0); amount+=count; } fprintf(stdout,"Send %d Bytes !\n",amount); } else { fprintf(stderr,"errno:%d",errno); } fclose(p); close(remote_fd); } int main(int argc, char *argv[]) { //init socket struct sockaddr_in local; int remote_len; struct sockaddr_in remote; int ret; pthread_t tid; listen_fd = socket(AF_INET, SOCK_STREAM, 0); if (listen_fd == -1) { fprintf(stderr, "socket() apply failed!\n"); return NULL ; } memset(&local, 0, sizeof(local)); local.sin_family = AF_INET; local.sin_port = htons(LISTEN_PORT); local.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(listen_fd, (struct sockaddr *)&local, sizeof(local)) == -1) { fprintf(stderr, "bind failed!\n"); close(listen_fd); return NULL; } if (listen(listen_fd, 5) == -1) { fprintf(stderr, "listen wrong!\n"); close(listen_fd); return -1; } //init signal struct sigaction act; act.sa_handler = handle_int; sigemptyset ( &act.sa_mask ); act.sa_flags = 0; sigaction ( SIGINT, &act, NULL ); ////////////////// //message loop fprintf(stdout,"-Welcome to FeiGe! q to quit ,s filename ip to send ,p to input path-\n"); //init select fd_set rfds; int retval;
FD_ZERO(&rfds); FD_SET(0, &rfds); FD_SET(listen_fd, &rfds); char buffstdin[100]; char * token; FILE * fstdin; Recv_Info recv_info; //used for recv thread Send_Info send_info; //used for send thread fstdin=fdopen(0,"r+"); while ((retval = select(4, &rfds, NULL, NULL, NULL)) > 0)//begin the select loop { if(FD_ISSET(0,&rfds))//stdin is ready { fgets(buffstdin,100,fstdin); //get input switch(buffstdin[0]) //check the first charactor { case 'q': { exit(0); break; } case 's': //s means send { memset(&send_info,0,sizeof(Send_Info)); token = strtok(buffstdin," "); // s token = strtok(NULL," "); // filename memcpy(send_info.filepath,token,strlen(token)); token = strtok(NULL,"\n"); // ip memcpy(send_info.ip,token,strlen(token)); if ((ret = pthread_create(&tid, NULL, send_file, (void *)&send_info)) != 0) { fprintf(stderr, "pthread_create() failed!\n"); close(connect_fd); } break; } case 'p': //p means path { token = strtok(buffstdin," "); // get a p token = strtok(NULL,"\n"); // get path memcpy(recv_info.filepath,token,strlen(token)); if ((ret = pthread_create(&tid, NULL, recieve_file, (void *)&recv_info)) != 0) { fprintf(stderr, "pthread_create() failed!\n"); close(connect_fd); } break; } default: break; } } if(FD_ISSET(listen_fd,&rfds))//listen fd is ready { remote_len = sizeof(remote); memset(&remote, 0, sizeof(remote)); connect_fd = accept(listen_fd, (struct sockaddr *)&remote, (socklen_t *)&remote_len); if (connect_fd == -1) { if (errno == EINTR) continue; fprintf(stderr, "accept failed!\n"); close(listen_fd); return -1; } memset(&recv_info,0,sizeof(Recv_Info)); recv_info.fconnectin=fdopen(connect_fd,"r+"); if(fgetc(recv_info.fconnectin)!='s') { close(connect_fd); fprintf(stdout,"wrong format file incoming!\n"); } else fprintf(stdout,"A new file ,input a full path with p \n"); } FD_ZERO(&rfds); FD_SET(0, &rfds); FD_SET(listen_fd, &rfds); } return 0; }
如果想在程序里查看磁盘空间,就要用到statfs()函数。
查看指定路径下硬盘总空间和剩余空间大小的方法:
struct statfs diskInfo; statfs("/",&diskInfo); unsigned long long blocksize = diskInfo.f_bsize;// 每个block里面包含的字节数 unsigned long long totalsize = blocksize * diskInfo.f_blocks;//总的字节数 printf("TOTAL_SIZE == %lu MB\n",totalsize>>20); // 1024*1024 =1MB 换算成MB单位
unsigned long long freeDisk = diskInfo.f_bfree*blocksize; //再计算下剩余的空间大小 printf("DISK_FREE == %ld MB\n",freeDisk>>20);
char * p="wow";
最基本的 :
printf(“hello %s”,p)
可以定向的:
fprintf(stdout,“hello %s \n”,p) //行缓冲 fprintf(stderr,“hello %s \n”,p) //不缓冲
可以输出到buf里的:
char buf[100];
snprintf(buf,“hello %s \n”,p);
字符格式:
%s :字符串 %x:十六进制 0x%.2x :按照类似0xFF的格式显示十六进制 %lu: long unsigned %llu: long long unsigned
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> //decode const char Base64IdxTab[128] = {
255,255,255,255, 255,255,255,255, 255,255,255,255, 255,255,255,255,
255,255,255,255, 255,255,255,255, 255,255,255,255, 255,255,255,255,
255,255,255,255, 255,255,255,255, 255,255,255,62, 255,255,255,63,
52,53,54,55, 56,57,58,59, 60,61,255,255, 255,255,255,255,
255,0,1,2, 3,4,5,6, 7,8,9,10, 11,12,13,14,
15,16,17,18, 19,20,21,22, 23,24,25,255, 255,255,255,255,
255,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
41,42,43,44, 45,46,47,48, 49,50,51,255, 255,255,255,255 }; #define BVal(x) Base64IdxTab[x] int DecodeBase64(char * pInput, char * pOutput) {
int i = 0;
int iCnt = 0;
int iSrcLen = (int)strlen(pInput);
char * p = pOutput;
for (i=0; i < iSrcLen; i++)
{
if (pInput[i] > 127) continue;
if (pInput[i] == '=') return p-pOutput+1;
char a = BVal(pInput[i]);
if (a == 255) continue;
switch (iCnt)
{
case 0:
{
*p = a << 2;
iCnt++;
}
break;
case 1:
{
*p++ |= a >> 4;
*p = a << 4;
iCnt++;
}
break;
case 2:
{
*p++ |= a >> 2;
*p = a << 6;
iCnt++;
}
break;
case 3:
{
*p++ |= a;
iCnt = 0;
}
break;
}
}
*p = 0x00;
return p-pOutput; } //encode const char Base64ValTab[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; #define AVal(x) Base64ValTab[x] int EncodeBase64(char * pInput, char * pOutput) { int i = 0; int loop = 0; int remain = 0; int iDstLen = 0; int iSrcLen = (int)strlen(pInput);
loop = iSrcLen/3; remain = iSrcLen%3;
// also can encode native char one by one as decode method // but because all of char in native string is to be encoded so encode 3-chars one time is easier.
for (i=0; i < loop; i++) { char a1 = (pInput[i*3] >> 2); char a2 = ( ((pInput[i*3] & 0x03) << 4) | (pInput[i*3+1] >> 4) ); char a3 = ( ((pInput[i*3+1] & 0x0F) << 2) | ((pInput[i*3+2] & 0xC0) >> 6) ); char a4 = (pInput[i*3+2] & 0x3F);
pOutput[i*4] = AVal(a1); pOutput[i*4+1] = AVal(a2); pOutput[i*4+2] = AVal(a3); pOutput[i*4+3] = AVal(a4); }
iDstLen = i*4;
if (remain == 1) { // should pad two equal sign i = iSrcLen-1; char a1 = (pInput[i] >> 2); char a2 = ((pInput[i] & 0x03) << 4); pOutput[iDstLen++] = AVal(a1); pOutput[iDstLen++] = AVal(a2); pOutput[iDstLen++] = '='; pOutput[iDstLen++] = '='; pOutput[iDstLen] = 0x00; } else if (remain == 2) { // should pad one equal sign i = iSrcLen-2; char a1 = (pInput[i] >> 2); char a2 = ( ((pInput[i] & 0x03) << 4) | (pInput[i+1] >> 4)); char a3 = ( (pInput[i+1] & 0x0F) << 2);
pOutput[iDstLen++] = AVal(a1); pOutput[iDstLen++] = AVal(a2); pOutput[iDstLen++] = AVal(a3); pOutput[iDstLen++] = '='; pOutput[iDstLen] = 0x00; } else { // just division by 3 pOutput[iDstLen] = 0x00; }
return iDstLen; }
许多朋友开始使用Win7了,但是有个问题一直困扰着大家,就是如何添加网络中的打印机,我也曾经尝试过很多方法,比如:到HP网站下载64位的驱动等,都没有效果,今天终于解决了问题,在这里与大家分享:
接下来会快速显示出打印机选择列表,在里面选择你的网络打印机型号,确定后你的网络打印机就装上了
1,头文件: #include <fcntl.h> /* For O_* constants */ #include <sys/stat.h> /* For mode constants */ #include <mqueue.h>
2,mq_open 在指定 mqueue 的名字时,必须以 ”/" 开头,并且名字中只能有一个 “/"
3,对mqueue的队列位置进行重定向 $ mkdir /dev/mqueue
$ mount -t mqueue none /dev/mqueue 4,在编译时要加上 -lrt 选项。
文件IO使用文件描述符进行操作。 常用函数: open : 返回打开指定路径文件的描述符 read : 读取描述符指定的文件的内容,没有缓冲 write : 写描述符指定的文件,没有缓冲 lseek :为打开的文件设置偏移值(SEEK_SET; SEEK_CUR ;SEEK_END) 标准IO对流进行操作,即: FILE * (FILE 是个结构体,里面包含了文件描述符和缓冲区的信息) 我们常用的stdin,stdout,stderr 类型都是FILE * 常用函数: fopen :返回打开指定路径文件的标准IO流:即FILE* fdopen:将指定的文件描述符与标准IO流相关联。 setbuf: 设置IO流的缓冲大小,设置成NULL即没有缓冲 fgetc: 读一个char fputc: 写一个char fgets: 读一行 fputs: 写一行 fread: 读取指定个数的长度 fwrite: 写入指定个数的长度 fflush:强制冲洗一个流
我的硬盤為串口即SATA(也就是識別為sda)執行:
sudo dd if=/dev/sda of=/media/linux.lnx bs=512 count=1
如果你的硬盤為並口即IDE執行:
sudo dd if=/dev/hda of=/media/linux.lnx bs=512 count=1
然後到/media找到linux.lnx這個文件,這個文件就是linux的啟動文件,
然後將這個文件copy到你重裝後的Win的根目錄,一般是C盤.如果是xp这里修改啟動文件boot.ini在最後加入:
C:\linux.lnx=Ubuntu10.04 就行了。
但是win7已经取消了boot.ini,所以我们必须使用工具才行。下载EasyBCD,在界面添加linux 引导。但是这里没结束,因为path不对,
我们需要用管理员身份运行cmd ,然后到c:/Windows/System32下运行bcdedit,这里能找到刚才添加的linux的ID串,然后输入:
c:/Windows/System32/bcdedit /set {刚才添加的linux的ID串} path /linux.lnx
重啟就可以選擇進Ubuntu了,這個方法是比較簡單的方法了
|