27
2013
01

[转载]linux学习curses(3) 学习输入

code:

//字符输入
#include <curses.h>
main()
{
    int ch;
    int x=5,y=5;
    initscr();
    keypad(stdscr,TRUE);
    curs_set(0);
    noecho();
    mvaddch(y,x,'A');
    while(1)
    {
        ch=getch();
        //mvaddch(y,x,' ');
        //clrtoeol();
        erase();
        //clear();
        switch(ch)
        {
        case KEY_UP:
            y--;
            break;
        case KEY_DOWN:
            y++;
            break;
        case KEY_LEFT:
            x--;
            break;
        case KEY_RIGHT:
            x++;
            break;
        }
        mvaddch(y,x,'A');
        refresh();
    }        
    endwin();
}
//字符串输入
#include <curses.h> 
main()
{
    char name[9]={0};
    int r;
    initscr();
    //绘制UI
    mvaddstr(4,10,"用户:[        ]");
    //输入
    r=mvgetnstr(4,16,name,8);
    //name[r]=0;
    //打印输入
    mvprintw(7,10,"你输入的是:%s",name);
    refresh();
    //输入字符    
    getch();
    endwin();
}
 //格式输入
#include <curses.h>
void init();
void drawUi();
void dealInput();
void destroy();
main()
{
init();
drawUi();
dealInput(); 
destroy();
}
void dealInput()
{
int a,b;
while(1)
{
mvaddstr(2,3,"     ");
mvscanw(2,3,"%d",&a);
mvaddstr(2,11,"     ");
mvscanw(2,11,"%d",&b);
mvaddstr(2,19,"      ");
mvprintw(2,19,"%d",a+b);
refresh();
}
}
void drawUi()
{
mvaddstr(2,2,"[     ]+[     ]=[      ]");
refresh();
}
void destroy()
{
endwin();
}
void init()
{
initscr();
}


27
2013
01

[转载]linux学习curses(2) 时间显示器

code:

#include <curses.h>
#include <time.h>
#include <unistd.h>
void init();
void drawui();
void business();
void destroy();
main()
{
init();
drawui();
business();
destroy();
}
void business()
{
time_t tt;
struct tm *t;
while(1)
{
//取时间
tt=time(0);
t=localtime(&tt);
//显示时间
mvprintw(LINES/2,(COLS-8)/2,
"%02d:%02d:%02d",
t->tm_hour,t->tm_min,t->tm_sec);
//刷新屏幕
refresh();
sleep(1);
}
}
void drawui()
{
box(stdscr,0,0);
}
void destroy()
{
endwin();
}
void init()
{
initscr();
}


27
2013
01

[转载]linux学习curses(1)

code:

#include<curses.h>
/*
在initscr();后调用。
终端是否支持颜色:bool has_colors();
初始化颜色:int start_colors();
定义颜色对:int init_pair(short pair,short fore,short back);
使用颜色对:COLOR_PAIR(short pair);
*/
int main()
{
    WINDOW *w=initscr();
    if(has_colors()==TRUE)
    {
        start_color();
        init_pair(1,COLOR_RED,COLOR_WHITE);
        init_pair(2,COLOR_RED,COLOR_GREEN);
        bkgd(COLOR_PAIR(2));//整体颜色
    }
    border(0,0,0,0,0,0,0,0);
    box(stdscr,0,0);//画边框,0都代表系统默认格式
    mvhline(2,10,'=',20);//第几行第几列输出多少个字符
    //mvhline(2,10,'|',20);
    mvaddch(3,10,'A'|A_BOLD|A_UNDERLINE|COLOR_PAIR(1));//指定位置输出字符//man attron
    attron(COLOR_PAIR(1));//开启属性
    mvaddstr(5,10,"hello");//输出字符串
    attroff(COLOR_PAIR(1));//关闭属性
    mvprintw(9,10,"行:%d,列:%d",LINES,COLS);//格式字符输出到窗口
    refresh();//刷屏,显示效果
    //wrefresh(WINDOW *w);
    getch();
    endwin();
    return 0;
}


25
2013
01

linux c定位读取数据pread

code:

#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
int a=6666;
main()
{
char filename[100];
int fd;
int data;
sprintf(filename,"/proc/%d/mem",getpid());//本程序虚拟内存文件
fd=open(filename,O_RDWR);
if(fd==-1) printf("open error:%m\n"),exit(-1);
pread(fd,&data,4,(off_t)&a);//从虚拟内存的相同地址中,读取实际地址位置相同的数据到data中
//pread() = lseek()+read()
//lseek(fd,(off_t)&a,SEEK_SET);
//read(fd,&data,4);   
printf("%d\n",data);
close(fd);
}


25
2013
01

asp.net调用飞信免费发短信

之前用过一段时间,已经证实不能再用!

        #region 免费发送飞们接口(2014-01-06 16:20测试有效)
        /// <summary>
        /// 免费发送飞们接口(要开通飞信把对方加为好友才能发,也可以给自己发做测试)
        /// </summary>
        /// <param name="sendNumber">登陆飞信手机号</param>
        /// <param name="sendPassword">登陆密码</param>
        /// <param name="receiveNumber">接收手机</param>
        /// <param name="Content">短信内容</param>
        /// <returns></returns>
        public bool sendfetion(string sendNumber, string sendPassword, string receiveNumber, string Content)
        {
            string url = string.Format("https://quanapi.sinaapp.com/fetion.php?u={0}&p={1}&to={2}&m={3}", sendNumber, sendPassword, receiveNumber, HttpUtility.UrlEncode(Content));
            string strRet = "";
            try
            {
                HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(url);
                hr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
                hr.Method = "GET";
                hr.Timeout = 30 * 60 * 1000;
                WebResponse hs = hr.GetResponse();
                Stream sr = hs.GetResponseStream();
                StreamReader ser = new StreamReader(sr, Encoding.Default);
                strRet = ser.ReadToEnd();
            }
            catch (Exception er)
            {
                strRet = "";
            }
            if (!strRet.Contains(":0")) return false;//成功时返回数据:{"result":0,"message":"\u53d1\u9001\u6210\u529f"}
            return true;
        } 
        #endregion


25
2013
01

asp.net两种方式的短信接口使用(提供接口的都是收费的)

一种是http请求的方式,另一种就是提供WebService接口供调用的。


25
2013
01

asp.net中缓存类DataCache(依赖文件缓存和时间缓存,或两者)


更新:2013-12-29

24
2013
01

linux下c通过虚拟地址映射读写文件

code:

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<string.h>
#include<sys/mman.h>
struct stu
{
char name[20];
int age;
float score;
};
//1 打开文件,2 映射到虚拟地址,3 写入数据,4 卸载虚拟地址,5关闭文件
main()
{
int fd;
struct stu *s;
struct stat st;
int size;
int count;
struct stu record;
memset(&record,0,sizeof(struct stu));
fd=open("newstu.dat",O_RDWR|O_CREAT|O_EXCL,0666);
if(fd==-1)
{
fd=open("newstu.dat",O_RDWR);
if(fd==-1) printf("::%m\n"),exit(-1);
}
fstat(fd,&st);
size=st.st_size;//原大小 
count=size/sizeof(struct stu);
ftruncate(fd,size+sizeof(struct stu));;//改变文件大小,在munmap前调用就行,+ 就是增大,-就是减小
s=mmap(0,size+sizeof(struct stu),
PROT_READ|PROT_WRITE,
MAP_SHARED,fd,0);
//*
printf("输入姓名:");
scanf("%s",s[count].name);
printf("输入年龄:");
scanf("%s",&(s[count].age)); 
printf("输入分数:");
scanf("%f",&(s[count].score));
//*/
int i;
for(i=0;i<count-1;i++)
{
printf("%s,%d,%.2f\n",s[i].name,s[i].age,s[i].score);
}
munmap(s,size+sizeof(struct stu));
close(fd);
}


24
2013
01

网站权限问题要重视-维护服务器后的看法

今天维护了一台某公司的网站服务器,就是访问文件突然不存在了,花了些时间看了一下,原因如下:

Global.asax 被改,变成了系统文件,还隐藏了。。

18
2013
01

SQLiteHelper类,操作SQLite数据库

操作类:

using System;
using System.Data;
using System.Text.RegularExpressions;
using System.Xml;
using System.IO;
using System.Collections;
using System.Data.SQLite;
using System.Configuration;//添加.net引用
namespace Tools.Common
{
    /// <summary>
    /// 对SQLite操作的类
    /// 引用:System.Data.SQLite.dll【版本:3.6.23.1(原始文件名:SQlite3.DLL)】
    /// </summary>
    public class SQLiteHelper
    {
        /// <summary>
        /// 所有成员函数都是静态的,构造函数定义为私有
        /// </summary>
        private SQLiteHelper()
        {
        }
        /// <summary>
        /// 连接字符串
        /// </summary>
        public static string ConnectionString
        {//"Data Source=Test.db3;Pooling=true;FailIfMissing=false";
            get
            {
                ////(AppSettings节点下的"SQLiteConnectionString")
                string text = ConfigurationManager.AppSettings["SQLiteConnectionString"];
                string str2 = ConfigurationManager.AppSettings["IsEncrypt"];
                if (str2 == "true")
                {
                    text = DesEncrypt.Decrypt(text);
                }
                return text;
            }
        }
        private static SQLiteConnection _Conn = null;