分类目录归档:日志

C# 连接数据库MySql并执行查询命令

首先,下载MySql.Data.dll,并将它放在你的工程目录下的Dubug下。

其次,右键点击你的项目名字,选择“添加引用”,将MySql.Data.dll添加到项目中。

最后,在代码页中输入using MySql.Data.MySqlClient;,然后就可以使用这个类库来建立连接了。

建立连接代码:

MySqlConnection sqlCon = new MySqlConnection("Database=数据库名字;Data Source=服务器的ip地址;User Id=用户名;Password=用户密码");

继续阅读

怎么解决linux解压zip出现的乱码

在windows上压缩的文件,是以系统默认编码中文来压缩文件。由于zip文件中没有声明其编码,所以linux上的unzip一般以默认编码解压,中文文件名会出现乱码。
虽然2005年就有人把这报告为bug,但是info-zip的官方网站没有把自动识别编码列入计划,可能他们不认为这是个问题。Sun对java中存在N年的zip编码问题,采用了同样的处理方式。

有2种方式解决问题:

1、 通过unzip行命令解压,指定字符集

unzip -O CP936 xxx.zip //用GBK, GB18030也可以

有趣的是unzip的manual中并无这个选项的说明, unzip –help对这个参数有一行简单的说明。

2、 在环境变量中,指定unzip参数,总是以指定的字符集显示和解压文件
/etc/environment 中加入2行

UNZIP="-O CP936"
ZIPINFO="-O CP936"

或者使用 unar ,例如:

unar xxx.zip

sqlmap 详细用法

基础用法:

sqlmap -u "注入地址" -v 1 -dbs // 列举数据库
sqlmap -u "注入地址" -v 1 -current-db // 当前数据库
sqlmap -u "注入地址" -v 1 -users  // 列数据库用户
sqlmap -u "注入地址" -v 1 -current-user // 当前用户
sqlmap -u "注入地址" -v 1 -tables -D "数据库" // 列举数据库的表名
sqlmap -u "注入地址" -v 1 -columns -T "表名" -D "数据库" // 获取表的列名
sqlmap -u "注入地址" -v 1 -dump -C "字段,字段" -T "表名" -D "数据库" // 获取表中的数据,包含列

已经开始拖库了,SQLMAP是非常人性化的,它会将获取的数据存储 sqlmap/output/ 中。
继续阅读

wordpress上传文件自动按日期更名

<?php
/*
Plugin Name: Uploaded Filename Sanitizer
Plugin URI: http://jerry.red/143.html
Description: 将所有上传的文件使用“日期_时间_三位随机数”方式重命名
Version: 1.0
Author: jerry
Author URI: http://jerry.red/
*/

function custom_upload_filter($name)
{
    $time = date('Ymd_His');
    $rand = sprintf('%03d', mt_rand(0, 999));
    $ext  = pathinfo($name, PATHINFO_EXTENSION);
    return "{$time}_{$rand}.{$ext}";
}

add_filter('sanitize_file_name', 'custom_upload_filter');

把这段代码另存为 uploaded-filename-sanitizer.php,上传到 wp-content/plugins 目录下,然后在后台启用这个插件即可。
如果不想以插件的形式使用,可以把这段代码粘贴到当前 WordPress 主题的 functions.php 中。请去掉本代码第一行的 <?php 和注释。

WordPress禁用自动更新邮件通知

将下面的代码添加到当前主题的 functions.php 中:

add_filter( 'auto_core_update_send_email', 'wpb_stop_auto_update_emails', 10, 4 );
function wpb_stop_update_emails( $send, $type, $core_update, $result ) {
if ( ! emptyempty( $type ) && $type == 'success' ) {
return false;
}
return true;
}

以上代码通过添加一个过滤器禁用自动更新邮件通知功能。

使用 anyexec 在 linux 上运行.NET程序

这是一种不使用 mono-runtime 的特殊方法,ubuntu 控制台程序测试通过,理论上 linux 控制台程序都可以运行,但 GUI 未测试。

1、下载 anyexec(不支持32位)anyexec-1.2-linux_x64.tar
2、解压得到一个目录,改成自己想要的名字,例如叫:myanyexec
3、运行 myanyexec/any ,如果看到如下信息,说明 anyexec 能正常工作:

4、将编译好的 .net 程序整体移动到 myanyexec/app/ 目录下
5、将 myanyexec/any 改名为 .net 主程序名,注意不要含 .exe 后缀
6、运行改名后的最终程序,测试是否可以运行
7、压缩,交付!

继续阅读

wordpress 注册/反注册 样式/脚本

function enqueue_scripts()
{
    // 反注册
    wp_deregister_style('font-awesome');
    wp_deregister_script('jquery');

    // 注册
    wp_enqueue_style('bootstrap', get_template_directory_uri() . '/bootstrap/css/bootstrap.min.css');
    wp_enqueue_script('jquery', get_template_directory_uri() . '/js/jquery.min.js');
    wp_enqueue_script('bootstrap', get_template_directory_uri() . '/bootstrap/js/bootstrap.min.js', ['jquery']);
    wp_enqueue_script('main', get_template_directory_uri() . '/js/main.js', false, false, true);
}

add_action('wp_enqueue_scripts', 'enqueue_scripts');

linux 安装 mono 开发环境

1 Add the Mono repository to your system

The package repository hosts the packages you need, add it with the following commands.

Ubuntu 18.04

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update

Ubuntu 16.04

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/mono-official.list
sudo apt-get update

继续阅读

wordpress 删除多余代码,加速前端加载

function clean_head()
{
    // remove the links to the extra feeds such as category feeds
    remove_action('wp_head', 'feed_links_extra', 3);
    // remove REST API link tag
    remove_action('wp_head', 'rest_output_link_wp_head');
    // remove the link to the Really Simple Discovery service endpoint
    remove_action('wp_head', 'rsd_link');
    // remove the link to the Windows Live Writer manifest file
    remove_action('wp_head', 'wlwmanifest_link');
    // remove rel=canonical for singular queries
    remove_action('wp_head', 'rel_canonical');
    // remove relational links for the posts adjacent to the current post for single post pages
    remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
    // remove shortlink
    remove_action('wp_head', 'wp_shortlink_wp_head');
    // remove oEmbed
    remove_action('wp_head', 'wp_oembed_add_discovery_links');
    remove_action('wp_head', 'wp_oembed_add_host_js');
    // 移除 wordpress 信息,防止被恶意扫描
    remove_action('wp_head', 'wp_generator');
    // 移除cdn预读
    remove_action('wp_head', 'wp_resource_hints', 2);
    // 移除emoji
    remove_action('wp_head', 'print_emoji_detection_script', 7);
    remove_action('wp_print_styles', 'print_emoji_styles');
}

add_action('after_setup_theme', 'clean_head');