作者归档:ning

WSL 服务自启动脚本

支持在Windows启动时启动WSL中的Linux服务.

安装

  • 使用 git clone 到任意目录 (e.g C:\wsl-autostart)
git clone https://github.com/troytse/wsl-autostart
  • 在注册表中加入启动项
    run-regedit
  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run下新增字符串项目 (e.g WSLAutostart)
    regedit-new-item
  • 设定脚本的路径 (e.g C:\wsl-autostart\start.vbs)
    regedit-set-path

使用

  • 修改在WSL中/etc/sudoers文件,为需要自启动的服务指定为免密码. 如:
%sudo ALL=NOPASSWD: /etc/init.d/cron
%sudo ALL=NOPASSWD: /etc/init.d/ssh
%sudo ALL=NOPASSWD: /etc/init.d/nginx
%sudo ALL=NOPASSWD: /etc/init.d/postgresql
%sudo ALL=NOPASSWD: /etc/init.d/mysql
%sudo ALL=NOPASSWD: /etc/init.d/redis-server
%sudo ALL=NOPASSWD: /etc/init.d/php7.2-fpm
%sudo ALL=NOPASSWD: /etc/init.d/mongodb
  • 修改commands.txt文件指定需要自启动的服务. 如:
/etc/init.d/mysql
/etc/init.d/postgresql
/etc/init.d/redis-server
/etc/init.d/php7.2-fpm
/etc/init.d/nginx
/etc/init.d/ssh
/etc/init.d/cron
/etc/init.d/mongodb

来源:WSL服务自启动脚本

yii gridview 使用target=”_blank”无效

解决办法是设置format为raw:

        [
            'attribute' => 'attribute',
            'format' => 'raw',
            'value' => function ($model, $key, $index, $column) {
                return  Html::a($model->title, ['view', 'id' => $model->id], ['target' => '_blank']);
            },
        ],

Yii2设置变量到布局layout

通过全局params配置

Yii::$app->params['myVar']

通过session

Yii::app()->session['myvar']

或者通过Flash Message

通过控制器传递变量方式

首先,需要再控制器添加参数

class SiteController extends CController {

    public $myvar;
//...

然后在layout/main.php获取控制器变量

$this->context->myvar
Yii::$app->controller->myvar

精品数据库(省市区县带拼音行政区划、大学、IP地址、农历、等)

行政区划-数据库

全国行政区划,省市区镇四级,包含名称、完整名称、经纬度、区号、邮编、行政区划代码、拼音。

使用说明

area.xlsx Excel文件数据
area.sql MySQL脚本
area.psc Navicat for MySQL备份文件
area.nb3 Navicat Premium备份文件

数据来源

高德API
民政部官网
中国邮政官网

C#实现自动打印PDF

采用PDFRender4NET

//打印机设置
PrinterSettings settings = new PrinterSettings();
settings.PrinterName = printername;
settings.PrintToFile = false;
settings.Copies = 1;
settings.PrintRange = PrintRange.AllPages;
//设置纸张大小(可以不设置取,取默认设置)
PaperSize ps = new PaperSize("Your Paper Name",595,842);
ps.RawKind = 9; //如果是自定义纸张,就要大于118

//打印设置
PDFRender.Printing.PDFPrintSettings pdfPrintSettings = new PDFRender.Printing.PDFPrintSettings(settings);
pdfPrintSettings.AutoRotate = false;            //自动旋转
pdfPrintSettings.BitmapPrintResolution = 560;   //图片打印精度                    
pdfPrintSettings.PaperSize = ps;                //纸张尺寸
pdfPrintSettings.PageScaling = PDFRender.Printing.PageScaling.FitToPrinterMarginsProportional;

pdfFile.Print(pdfPrintSettings);

代码详见: https://github.com/HiRaygo/DocumentPrint/blob/master/PdfPrint.cs

采用SumatraPDF或Acrobat Reader方案

 public static PrintEngine SumatraPDF = new PrintEngine("Sumatra PDF Reader",
            ((printerName, filePath, documentName) => 
            {
                string app = Path.Combine(Program.localPath, "SumatraPDF.exe");
                string args = string.Format("-silent -exit-on-print -print-to \"{0}\" \"{1}\"", printerName, filePath);

                Process p = new Process();
                p.StartInfo = new ProcessStartInfo()
                {
                    CreateNoWindow = true,
                    WindowStyle = ProcessWindowStyle.Hidden,
                    FileName = app,
                    Arguments = args
                };
                //if (User.isNetworkService())
                //{
                //    p.StartInfo.UserName = Program.config.serviceLogin;
                //    p.StartInfo.Password = tools.secureString(tools.Decrypt(Program.config.servicePass));
                //    p.StartInfo.Domain = Program.config.serviceDomain;
                //    p.StartInfo.LoadUserProfile = true;
                //    p.StartInfo.UseShellExecute = false;
                //}
                p.Start();

            })){};

        /// <summary>
        /// Print via external programm Acrobat Reader
        /// </summary>
        public static PrintEngine AcrobatReader = new PrintEngine("Acrobat Reader",
            ((printerName, filePath, documentName) =>
            {                
                string app = Registry.LocalMachine.OpenSubKey(
                        @"SOFTWARE\Microsoft\Windows\CurrentVersion" +
                        @"\App Paths\AcroRd32.exe"
                    ).GetValue("").ToString()
                ;
                string args = string.Format("/h /t \"{0}\" \"{1}\"", filePath, printerName);

                Process p = new Process();
                p.StartInfo = new ProcessStartInfo()
                {
                    CreateNoWindow = true,
                    WindowStyle = ProcessWindowStyle.Hidden,
                    FileName = app,
                    Arguments = args
                };
                //if (User.isNetworkService())
                //{

                //    p.StartInfo.UserName = Program.config.serviceLogin;
                //    p.StartInfo.Password = tools.secureString(tools.Decrypt(Program.config.servicePass));
                //    p.StartInfo.Domain = Program.config.serviceDomain;
                //    p.StartInfo.LoadUserProfile = true;
                //    p.StartInfo.UseShellExecute = false;
                //}
                p.Start();

})){};

代码详见: https://github.com/RepairShopr/AutoPrintr-win/blob/master/AutoPrintr/modules/PrintEngines.cs

fedora如何从Nautilus/Files打开终端

使用Files(又名Nautilus)时,您是否想过快速打开终端以在当前位置运行命令?

Nautilus的gnome-terminal-nautilus附加组件提供了一个右键单击上下文菜单项, 可以在当前位置快速打开一个新的gnome-terminal窗口。

enter image description here

当您需要对图形文件浏览器中正在查看的某些文件运行快速命令时,对nautilus界面的这一小调整非常方便。

安装gnome-terminal-nautilus

sudo dnf install gnome-terminal-nautilus

安装后,“在终端中打开”选项应出现在“文件”中的右键单击上下文菜单中。如果安装后没有出现,请通过运行以下命令强制关闭Nautilus。然后重新打开文件

nautilus -q

Yii2 文件上传扩展

官方指南

aminkt/yii2-upload-manager

Upload manager system based and inspired from WordPress upload manager.

yii2-image-manager

A module/widget for upload, manage and cropping images

yii2-attachments

Extension for file uploading and attaching to the models

yii2-widget-fileinput

An enhanced FileInput widget for Bootstrap 3.x with file preview, multiple selection, and more features

yii2-file-input-widget

Jasny File Input Bootstrap Widget + Local and Remote storage

yii2-file-upload

PHP library for uploading files to your server or Amazon S3

yii2-upload-file

Yii2 tools for upload file

基于WePY的开源微信小程序汇总

WePY

仿vue小程序组件开发框架

wepy-mall

基于wepy 商城(微店)微信小程序

wepy_ios_top

一款可以切换国家查看不同国家iOS应用排行榜的小程序

x-mall-miniprogram-wepy

一个基于wepy+redux+eslint+sass的类Vue开发风格的商城微信小程序项目。

jiezhang

基于 wepy 开发的一款纯记账的微信小程序

Ufutx library

友福同享共享图书馆

Ufutx party

友福聚会

shanbay-mina

基于wepy框架的“扇贝阅读”微信小程序

wepy-books

微信小程序/wepy/图书商城

vant-weapp

轻量、可靠的小程序 UI 组件库

wepy-zanui-demo

基于zanui-weapp移植的一套wepy界面框架

wepy-weui-demo

WeUI 在 WePY 中的使用示例,同一份代码可以运行在小程序上和Web上

minui

基于规范的小程序 UI 组件库,自定义标签组件,简洁、易用、工具化