分类目录归档:其它

sqlserver收缩数据库日志脚本

因为需要迁移数据库,但是发现日志文件非常大,所以需要收缩数据库后再迁移,但是一个服务器有几个数据库,每个都点一次感觉太累了。在没有sqlserver编程基础的情况下,在百度搜了一下相关资料,写出了这个脚本,用起来感觉还好。所以在这里分享

use master
go 
declare mydbs cursor scroll
for Select Name FROM Master..SysDatabases
open mydbs
Declare @dbname nvarchar(255)
fetch next from mydbs into @dbname

while(@@FETCH_STATUS=0)
begin
	if @dbname!='master' and @dbname !='model' and @dbname!='msdb' and @dbname!='tempdb'
	begin

	declare @sqlquery nvarchar(1024)
		set @sqlquery='USE master
--GO
ALTER DATABASE '+@dbname+' SET RECOVERY SIMPLE WITH NO_WAIT
--GO
ALTER DATABASE '+@dbname+' SET RECOVERY SIMPLE   
--GO
USE '+@dbname+'
--GO
DBCC SHRINKFILE (N'''+@dbname+'_Log'', 100, TRUNCATEONLY)
--GO
USE master
--GO
ALTER DATABASE '+@dbname+' SET RECOVERY FULL WITH no_wait
--GO
ALTER DATABASE '+@dbname+' SET RECOVERY FULL   
--GO'
		EXEC SP_EXECUTESQL @sqlquery
		--print @sqlquery

	end
	fetch next from mydbs into @dbname
end
close mydbs
deallocate mydbs
go

 

svn 递归添加所有新文件

有时候添加了很多文件,但是提交的时候又忘记了添加哪些文件和目录,那么可以用这个命令

svn add * –force

如果添加了你不想要的目录,在提交前执行下面的命令

svn revert sessions/*

这样就可以把session 里的文件排除了

Resize an image with OpenCV cvResize function[转]

This is a small code to resize an image to a desired percentage from an original. New size of width and height are calculated from a percentage supplied as a 3th argument. Supplying 100% will simply copy the original image to new image.

cvResize also accepts an interpolation argument, however in case of this small program we use the default linear interpolation.

#include <iostream>
#include "cv.h"
#include "highgui.h"

using namespace std;

int main( int argc, char** argv )

{
// Create an IplImage object *image 
IplImage *source = cvLoadImage( argv[1]);
// Here we retrieve a percentage value to a integer
int percent = atoi(argv[3]);

// declare a destination IplImage object with correct size, depth and channels
      IplImage *destination = cvCreateImage
( cvSize((int)((source->width*percent)/100) , (int)((source->height*percent)/100) ),
                                     source->depth, source->nChannels );

//use cvResize to resize source to a destination image
cvResize(source, destination);

// save image with a name supplied with a second argument
      cvSaveImage( argv[2], destination );


return 0;

}

Compile:

g++ `pkg-config opencv --cflags --libs` resize_image.cpp -o resize_image


Usage:

./resize_image dsc00056.jpg new_dsc00056.jpg 65%

https://linuxconfig.org/resize-an-image-with-opencv-cvresize-function

一个快速获取/更新 Let’s encrypt 证书的 shell script

一个快速获取/更新 Let’s encrypt 证书的 shell script

调用 acme_tiny.py 认证、获取、更新证书,不需要额外的依赖。

下载到本地

wget https://raw.githubusercontent.com/xdtianyu/scripts/master/lets-encrypt/letsencrypt.conf
wget https://raw.githubusercontent.com/xdtianyu/scripts/master/lets-encrypt/letsencrypt.sh
chmod +x letsencrypt.sh

配置文件

只需要修改 DOMAIN_KEY DOMAIN_DIR DOMAINS 为你自己的信息

ACCOUNT_KEY="letsencrypt-account.key"
DOMAIN_KEY="example.com.key"
DOMAIN_DIR="/var/www/example.com"
DOMAINS="DNS:example.com,DNS:whatever.example.com"
#ECC=TRUE
#LIGHTTPD=TRUE

执行过程中会自动生成需要的 key 文件。其中 ACCOUNT_KEY 为账户密钥, DOMAIN_KEY 为域名私钥, DOMAIN_DIR 为域名指向的目录,DOMAINS 为要签的域名列表, 需要 ECC 证书时取消 #ECC=TRUE 的注释,需要为 lighttpd 生成 pem 文件时,取消#LIGHTTPD=TRUE 的注释。

运行

./letsencrypt.sh letsencrypt.conf

注意

需要已经绑定域名到 /var/www/example.com 目录,即通过 http://example.com http://whatever.example.com 可以访问到/var/www/example.com 目录,用于域名的验证

将会生成如下几个文件

lets-encrypt-x1-cross-signed.pem
example.chained.crt          # 即网上搜索教程里常见的 fullchain.pem
example.com.key              # 即网上搜索教程里常见的 privkey.pem 
example.crt
example.csr

在 nginx 里添加 ssl 相关的配置

ssl_certificate     /path/to/cert/example.chained.crt;
ssl_certificate_key /path/to/cert/example.key;

cron 定时任务

每个月自动更新一次证书,可以在脚本最后加入 service nginx reload等重新加载服务。

0 0 1 * * /etc/nginx/certs/letsencrypt.sh /etc/nginx/certs/letsencrypt.conf >> /var/log/lets-encrypt.log 2>&1

discuz去掉手机版只保留触屏版

1、修改source\class\discuz\discuz_application.php 大约在 177行,改为如下

'mobiletpl' => array('1' => 'touch', '2' => 'touch', '3' => 'wml', 'yes' => 'touch'),

2、修改static\js\mobile\common.js  第二行,将后面 forum.php?mobile=1 改为forum.php?mobile=2,如下

var supporttouch = "ontouchend" in document;
!supporttouch && (window.location.href = 'forum.php?mobile=2');

版权www.yiyou.org

Let’s Encrypt试用

Let’s Encrypt项目意在让每个网站都能使用HTTPS加密的连接,有空之余测试一下免费ssl

1、安装git

apt-get install git

2、下载代码

git clone https://github.com/letsencrypt/letsencrypt.git

3、生成证书,nginx用  –standalone   apache 用 –apache 参数

./letsencrypt-auto –standalone -d www.maildir.cn

如果你收到下面的信息,说明安装成功了

IMPORTANT NOTES:
– Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/www.maildir.cn/fullchain.pem. Your cert will
expire on 2016-03-24. To obtain a new version of the certificate in
the future, simply run Let’s Encrypt again.
– If you like Let’s Encrypt, please consider supporting our work by:

Donating to ISRG / Let’s Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

4、nginx 配置

server {
listen 80;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/www.maildir.cn/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.maildir.cn/privkey.pem;

…..

}

大功告成,另外证书有效期90天,过期了还得去重新申请QQ图片20151225094132

微信转发好友,分享标题,链接,图片,描述修改方法

在页面<head>,与 </head>这间加入下面js代码即可

<script>
var imgUrl = 'http://basd.com/Public/web/home//images/header.jpg';
var lineLink = 'http://basd.com/weixin.php';
var descContent = "maildir.cn 邮件免费中继描述";
var shareTitle = 'maildir.cn邮件免费中继标题';
var appid = 'wx397fa4dffe0aaaa';

function shareFriend() {
    WeixinJSBridge.invoke('sendAppMessage',{
                            "appid": appid,
                            "img_url": imgUrl,
                            "img_width": "640",
                            "img_height": "640",
                            "link": lineLink,
                            "desc": descContent,
                            "title": shareTitle
                            }, function(res) {
                            _report('send_msg', res.err_msg);
                            })
}
function shareTimeline() {
    WeixinJSBridge.invoke('shareTimeline',{
                            "img_url": imgUrl,
                            "img_width": "640",
                            "img_height": "640",
                            "link": lineLink,
                            "desc": descContent,
                            "title": shareTitle
                            }, function(res) {
                            _report('timeline', res.err_msg);
                            });
}
function shareWeibo() {
    WeixinJSBridge.invoke('shareWeibo',{
                            "content": descContent,
                            "url": lineLink,
                            }, function(res) {
                            _report('weibo', res.err_msg);
                            });
}
// 当微信内置浏览器完成内部初始化后会触发WeixinJSBridgeReady事件。
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {

        // 发送给好友
        WeixinJSBridge.on('menu:share:appmessage', function(argv){
            shareFriend();
            });

        // 分享到朋友圈
        WeixinJSBridge.on('menu:share:timeline', function(argv){
            shareTimeline();
            });

        // 分享到微博
        WeixinJSBridge.on('menu:share:weibo', function(argv){
            shareWeibo();
            });
        }, false);
</script>