This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
#!/usr/bin/python | |
# This code is original from jsmin by Douglas Crockford, it was translated to | |
# Python by Baruch Even. The original code had the following copyright and | |
# license. | |
# | |
# /* jsmin.c | |
# 2007-05-22 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 验证是否是一个数值型 | |
* 合法格式: 32位整型值 如1 52 5555 414 | |
*/ | |
String.prototype.isInt32 = function() { | |
var regex = new RegExp("^[\d]{1,32}$"); | |
return regex.exec(this); | |
} | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 开启在 script/console 里面显示SQL查询日志 | |
# Ruby on Rails script/server 的时候,你会看到所有查询的调用日志,SQL语句,是否用缓存,还有执行时间等 | |
# 如何在 script/console 里面也实现这样的功能呢? | |
# 我们只需要修改 ~/.irbrc 文件并加入下面的代码就好了(.irbrc 如果没有可直接创建一个) | |
# jason@ubuntu:/home/huacnlee/wwwroot/pasite$ cd ~ | |
# jason@ubuntu:~$ sudo vim .irbrc | |
if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER') | |
require 'logger' | |
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Linux 自动备份 MySQL与网站并发邮件到自已邮箱 1 | |
# 1.将刚才到处的MySQL文件压缩,以节省邮箱空间 | |
tar zcf $BACKUP_PATH/pasite_db_$DATE_NAME.tar.gz $DATE_NAME/pasite.sql | |
tar zcf $BACKUP_PATH/personlab_db_$DATE_NAME.tar.gz $DATE_NAME/personlab.sql | |
# 2.打包压缩网站 | |
tar zcf $BACKUP_PATH/pasite_src_$DATE_NAME.tar.gz ~home/huacnlee/wwwroot/pasite/ | |
tar zcf $BACKUP_PATH/personlab_src_$DATE_NAME.tar.gz ~home/huacnlee/wwwroot/personlab/ | |
# Linux 自动备份 MySQL与网站并发邮件到自已邮箱 2 | |
# 发送邮件 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mysql 完整备份数据库 | |
# -uroot(root是用户名 -u与root之间没空格) -p123123 (123123是密码 -p与123123之间没空格) | |
mysqldump -uroot -p123123 --databases pasite > $BACKUP_PATH/pasite.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 禁止在iframe里面打开窗口,自动跳出iframe | |
// 常用于浮动窗口(iframe方式的)验证登陆后跳转到登陆页面,这个时候登陆页面还在iframe里面,通过此方法就可以自动判断并跳出iframe | |
// 跳出iframe | |
if (top.location !== self.location) { | |
top.location.href = location.href | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails 扩展 Paperclip 加入hash目录参数:hashed_path | |
# 扩展 Paperclip 加入hash目录参数 :hashed_path | |
# 建立 config/initializers/paperclip_extensions.rb | |
Paperclip::Attachment.interpolations[:hashed_path] = lambda do |attachment, style| | |
hash = Digest::MD5.hexdigest(attachment.instance.id.to_s) | |
hash_path = '' | |
3.times { hash_path += '/' + hash.slice!(0..2) } | |
hash_path[1..12] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails 事务 | |
begin | |
Post.transaction do | |
# 删除旧数据 | |
Post.delete_all | |
# 例子 新数据 | |
datas [{:title => "title1", :slug => "title-1"},{:title => "Title 2", :slug => "Title 2"}] | |
counter = 0 | |
datas.each do |d| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nginx Linux 下面创建为系统服务脚本 | |
#!/bin/sh -e | |
### BEGIN INIT INFO | |
# Provides: nginx | |
# Required-Start: $all | |
# Required-Stop: $all | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: starts the nginx web server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import md5 | |
def md5_encode(str): | |
u""" | |
summary: | |
MD5 encode | |
author: | |
Jason Lee <huacnlee@gmail.com> | |
""" |