mac快捷键

mac快捷键

快捷键 功能
cmd + space 输入法切换
cmd + f3 显示桌面
cmd + 上下箭头 上级/下级目录
enter 重命名文件
cmd + c 复制文件
cmd +s 保存

end

图片缩略图动态生成

旧博文备份http://blog.uedao.com/blog/?p=85

整理下网站缩略图水印图动态生成的方法:

会员上传图片后,调用图片的各地方需要的尺寸不全一样,需要生成大小不同的等比例缩略图。
实现方法是nginx判断,请求的缩略图规则url中,如果图片不存在则调用php程序以原始图片生成对应的缩略图,然后显示出来,并且图片第一次生成后下次直接调用即可。

一、基本原则:
只保留原始图片,其它尺寸由原图生成。
缩略图按需生成,大小体现在固定的url。

二、图片文件:
原始图路径:/home/htdocs/app/upfiles/house/年/月/日/src图片名
生成图路径:/home/htdocs/app/upfiles/house/active/年/月/日/图片名
图片生成大小
生成图路径:/home/htdocs/app/upfiles/house/active/年/月/日/图片名_图片生成大小及会员编号
原始图url:

http://p2.uedao.com/house/2011/02/12/src_130037359579225801.jpg

缩略图url(不存在则自动生成):

http://p1.uedao.com/house/active/2011/02/12/130037359579225801_128x92.jpg

水印图url(不存在则自动生成):

http://p1.uedao.com/house/active/2011/02/12/130037359579225801_128x92x1001.jpg

三、nginx配置(nginx.conf)

#p1.uedao.com p2.uedao.com
server {
    # listen port
    listen       80;
    server_name  p1.uedao.com p2.uedao.com;
    charset utf-8;

    # root
    root   /home/htdocs/app/upfiles;
    index  index.php index.html;

    # blocked
    location ~ .*\.(gif|jpg|png|jpeg|bmp|swf|cur|ico)$ {
        valid_referers none blocked *.uedao.com *.facebook.com;
        if ($invalid_referer) {
           #return 404;
        }
        location ~* /house/active/(.+)$ {
            if (!-f $request_filename) {
                proxy_pass http://localhost:8000/app/action/createimg.php?s=$1&$args;
                break;
            }
        }
        expires max;
        access_log off;
    }
}
#注:$1,为location匹配的正则结果;$args, 请求中的参数。

四、php程序(createimg.php)

$src = $GET ['s']; //图片路径
if ($src) {
    //省略数据验证(如请求来源判断、只响应指定尺寸等)
    $src_array = explode ( '/', $src );
    $src_array_len = count ( $src_array );
    $file_path = $src_array [0] . '/' . $src_array [1] . '/' . $src_array [2] . '/';
    $file_name = $src_array [3];
    //生成大小
    $size_ext_str = strrchr ( trim ( $file_name ), '_' );
    $size_str = substr ( str_replace ( strrchr ( $size_ext_str, '.' ), '', $size_ext_str ), 1 );
    $size_array = explode ( 'x', $size_str );

    $des_file_name = getSourceImgSrc ( $file_path, $file_name ); //会员原始图片
    if (! file_exists ( $des_file_name )) {
        $width = $size_array [0];
        $heigh = $size_array [1];
        $src_file_name = getDestImgSrc ( $file_path, $file_name ); //生成目标图片
        $obj_image = new Tool_Image ();
        if (2 == count ( $size_array )) {
            //生成缩略图
            $result = $obj_image->make_thumb ( $src_file_name, $width, $heigh, $des_file_name );
        } else if (3 == count ( $size_array ) && 0 != intval ( $size_array [2] )) {
            //生成水印图
            $user_id = $size_array [2];
            $water_img = FILE_PATH . 'images/index/public/global/logo.png';
            $result = $obj_image->make_watermark ( $src_file_name, $width, $heigh, $des_file_name, $water_img, $user_id );
        }
    }
    loadImgFile ( $des_file_name ); //读取图片并显示
}
//更快的读取图片并显示
function loadImgFile($file_name) {
    $fp = fopen ( $file_name, 'r' );
    header ( "Content-type:image/jpeg" );
    fpassthru ( $fp );
    return true;
}

注:生成缩略图后需要程序读取显示出来。

五、相关文章
如果你感兴趣阅读到此,下面的文章你可能也想看。
Nginx做动态生成缩略图

http://cnctblog.com/?p=633

Abusing Amazon images

http://aaugh.com/imageabuse.html

基于MongoDB GridFS的图片存储

http://liut.cc/blog/2010/12/about-imsto_my-first-open-source-project.html


end

mysql视图表创建与修改

旧博文备份http://blog.uedao.com/blog/?p=20

1、创建

CREATE [OR REPLACE] [<algorithm attributes>] VIEW [database.]< name> [(<columns>)]
AS <SELECT statement> [<check options>]

例子:

CREATE VIEW `view_articles`
AS
SELECT
    a.id AS id,
    a.title AS title,
    a.content AS content,
    t.name AS tagname,
    u.firstname AS "username"
FROM `articles` a
    LEFT JOIN `tags` t
        ON a.tag_id = t.id
    LEFT JOIN `users` u
        ON a.user_id = u.id
ORDER BY a.posttime DESC;

2、修改

ALTER [<algorithm attributes>] VIEW [<database>.]< name> [(<columns>)]
AS<SELECT statement> [<check options>]

例子:

ALTER VIEW `view_articles`
AS
SELECT
    a.id AS id,
    a.title AS title,
    a.content AS content,
    a.posttime AS posttime,
    t.name AS tagname,
    CONCAT(u.firstname,' ',u.lastname) AS "username"
FROM `articles` a
    LEFT JOIN `tags` t
        ON a.tag_id = t.id
    LEFT JOIN `users` u
        ON a.user_id = u.id
ORDER BY a.posttime DESC;

修改已经建立好的视图表,最简单的方法就是在phpMyAdmin导出视图表的SQL,然后修改开头的“CREATE”(后面的

ALGORITHM=UNDEFINED DEFINER=root@localhost SQL SECURITY DEFINER
等不用管,保留它)为ALTER,运行语句即可。

参考文章:

http://database.51cto.com/art/201005/200526.htm
http://www.sqlinfo.net/mysql/mysql_VIEWS_the_basics.php
http://www.java2s.com/Tutorial/MySQL/0180View/Catalog0180View.htm


end

mysql经常使用的10个技巧

旧博文备份http://blog.uedao.com/blog/?p=5

1、shell执行sql语句

/usr/local/mysql/bin/mysql -h192.168.1.36 -uaddcn -p'password' -e "use  dev; SELECT * FROM config LIMIT 0,10;"

2、查看执行线程

/usr/local/mysql/bin/mysqladmin -uaddcn -p'password'  pr
/usr/local/mysql/bin/mysqladmin -uaddcn -p'password' processlist | wc -l  #连接数

3、kill锁表线程

/usr/local/mysql/bin/mysql -h192.168.1.36 -uaddcn -p'password'
mysql> show processlist;
mysql> kill 102609;

4、主从同步

从机执行


/usr/local/mysql/bin/mysql -h192.168.1.36 -uaddcn -p'password'
mysql> show slave status\G;
mysql> stop slave;
mysql> start slave;

5、数据库备份还原

备份

/usr/local/mysql/bin/mysqldump -h192.168.1.36 -uaddcn -p'password' --opt  dev article > /home/addcn/backup/sql/dev_article_20110625.sql;
/usr/local/mysql/bin/mysqldump -h192.168.1.36 -uaddcn -p'password' --opt  -l --default-character-set=latin1 --skip-set-charset dev >  /home/addcn/backup/sql/dev_`date +%d`.sql;
/usr/local/mysql/bin/mysqldump -h192.168.1.36 -uaddcn -p'password' --opt  -l --default-character-set=latin1 --skip-set-charset dev article >  /home/addcn/backup/sql/dev_article_`date +%d`.sql;

还原

/usr/local/mysql/bin/mysql -h192.168.1.36 -uaddcn -p'password'
mysql> show databases;
mysql> create database dev;
mysql> drop database dev;
mysql> use dev;
mysql> SET NAMES utf8;
mysql> source /home/addcn/backup/sql/dev_article_20110625.sql;

6、用户管理

GRANT ALL PRIVILEGES ON *.* TO 'addcn'@'localhost' IDENTIFIED BY  'password' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON dev.* TO 'addcn'@'%' IDENTIFIED BY 'password'  WITH GRANT OPTION;
SET PASSWORD FOR 'addcn'@'localhost' = password('password');
SET PASSWORD FOR 'addcn'@'%' = password('password');
FLUSH PRIVILEGES;

7、sql复制记录

INSERT INTO `table` SELECT * FROM `table1` WHERE id=1; #无主键
INSERT INTO `table`(`a`,`b`,`c`) SELECT `a`,`b`,`c` FROM `table1` WHERE  id=1 AND posttime<=unix_timestamp('2001-03-26 00:00:00');="" #有主键写列="" <="" code="">

8、根据两关联表更新其中一表某字段

UPDATE `table` SET a = !a WHERE id = 1; #布尔值取反
UPDATE `table1`,`table2` SET `table1`.id = `table2`.id WHERE  `table1`.id=`table2`.id; #更新

9、if函数

UPDATE `users` SET money=IF(money>=$monty,money-{$monty},money) WHERE user_id=1001;

扣费结合 if(mysql_affected_rows()) do_success_action(); 可防止INT字段超最大值而变很大数

10、其它

EXPLAIN SELECT * FROM `article` FORCE INDEX (user_id) WHERE 1; #分析语句
SELECT * FROM `article` FORCE INDEX (user_id) WHERE 1; #强制索引
UPDATE LOW_PRIORITY `article` SET browsenum=browsenum+1 WHERE id='1001'; #滞后更新

end

Windows下搭建Android开发环境

旧博文备份http://addcn.blogbus.com/logs/119738531.html

一、安装

1、jdk(非jre)下载

http://java.sun.com/javase/downloads/index.jsp

默认安装在C:\Program Files\Java\jdk1.6.0_24

2、eclipse下载

(1)http://www.oyksoft.com/soft/1250.html

下载解压在D:\Program Files\eclipse

(2)添加环境变量

JAVA_HOME C:\Program Files\Java\jdk1.6.0_24

CLASSPATH .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar

PATH %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;D:\Program Files\Android\android-sdk-windows\tools

3、Android SDK

http://dl.google.com/android/android-sdk_r08-windows.zip

解压在D:\Program Files\Android\android-sdk-windows

(1)安装android开发插件(ADT)

help->Install New SoftWare
Add
Name:Android
Location:https://dl-ssl.google.com/android/eclipse/

点击Yes按钮,最后重启Eclipse

(2)配置Android SDK

点击菜单window->preferences

选择android SDK解压后的目录

我这里只选了SDK 2.1 和samples for api 7 , 自己可以任意自定义,确定后,选择install按钮

(3)新建AVD(android vitural device)

android sdk and avd manager,选中Vitural Devices 在点击New按钮

AVD2.2

(4)HelloAndroid项目

HelloAndroid
com.helloandroid
HelloAndroid
8
Run as -> Run Configuration 选择AVD2.2

二、参考文章

jdk环境变量配置

Android开发环境搭建


end