Python2 在windows控制台运行会出现乱码,改用IronPython解析就好了。
Python2 在windows控制台运行会出现乱码。
一个彻底的解决 办法是改成python3,但工作量太大。
今晚试了下IronPython,,非常好用,直接支持中文了,而且不用改一行代码!!!
因为这个事情浪费了好多时间。把一个QQ机器人的代码改成了py3
注意在Py文件第一行写上: # -*- coding: utf-8 -*-
Python2 在windows控制台运行会出现乱码,改用IronPython解析就好了。
Python2 在windows控制台运行会出现乱码。
一个彻底的解决 办法是改成python3,但工作量太大。
今晚试了下IronPython,,非常好用,直接支持中文了,而且不用改一行代码!!!
因为这个事情浪费了好多时间。把一个QQ机器人的代码改成了py3
注意在Py文件第一行写上: # -*- coding: utf-8 -*-
在现代软件开发中,随机生成手机号码是一项常见的需求,无论是用于测试、数据填充还是其他应用场景。本文将介绍如何使用 C# 编写一个简单而有效的方法来随机生成符合中国大陆规范的手机号码。
private string [] telStarts = "134,135,136,137,138,139,150,151,152,157,158,159,130,131,132,155,156,133,153,180,181,182,183,185,186,176,187,188,189,177,178" .Split(',' );
/// <summary>
/// 随机生成电话号码
/// </summary>
/// <returns></returns>
public string getRandomTel()
{
Random ran = new Random();
int index = ran.Next(0, telStarts.Length - 1);
string first = telStarts[index];
string second = (ran.Next(100, 888) + 10000).ToString().Substring(1);
string thrid = (ran.Next(1, 9100) + 10000).ToString().Substring(1);
return first + second + thrid;
}
telStarts 数组包含了当前中国大陆主要的手机号码段,每三个数字代表一个运营商和号段的组合,例如 134、135 等。这些前缀确保生成的号码符合运营商的分配规则。Random 类从 telStarts 数组中随机选择一个号码前缀,保证了号码前3位的合法性和多样性。ran.Next(100, 888) + 10000 生成一个五位数,通过 Substring(1) 获取后四位。为了进一步提高号码的随机性和有效性,可以调整生成范围,避免生成不常用的数字组合。ran.Next(1, 9100) + 10000 生成一个五位数,通过 Substring(1) 获取后四位。不折腾,多年走弯路的经验告诉我,不遵守以下原则必将浪费生命和时间。
没有问题就不要折腾,遇到问题或需求再去研究并解决。
用成熟的技术,不要做技术小白鼠。
不要追求完美 ,世界本来就是不完美的,好和坏是一半一半的。任何事物都有两面性。要接受不完美。
追求简单、 实用、快速、高效。
在Codeigniter中使用Blade模板引擎:
使用compoer引入blade库
composer require "philo/laravel-blade": "3.*"
在helpers目录下创建 view_helper.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once 'vendor/autoload.php';
use Philo\Blade\Blade;
if (!function_exists('view')) {
function view($name = NULL, $data = [], $mergeData = [])
{
$CI = &get_instance();
if (!isset($CI->blade)) {
$views = __DIR__ . '/../views';
$cache = __DIR__ . '/../cache';
$CI->blade = new Blade($views, $cache);
$elapsed_time = $CI->benchmark->elapsed_time('total_execution_time_start', 'total_execution_time_end');
$CI->blade->view()->share('elapsed_time', $elapsed_time);
}
echo $CI->blade->view()->make($name, $data, $mergeData)->render();
}
}
在config/autoload.php中,引入
$autoload['helper'] = array('view', 'url');
controller中:
<?php defined('BASEPATH') or exit('No direct script access allowed');
class Welcome extends CI_Controller
{
public function index()
{
return view('index', ['name' => 'haha']);
}
public function test()
{
echo 'this is a test';
}
}
还是喜欢codeigniter的简洁和可扩展性,用来做中小项目还是很爽的。
在万网虚拟主机上,发现laravel无法加载.env中配置的信息,然后一路跟踪发现,问题出在PHPDotEnv这个库上
在Loader.php里有一个函数如下:
public function setEnvironmentVariable($name, $value = null)
{
list($name, $value) = $this->normaliseEnvironmentVariable($name, $value);
// Don't overwrite existing environment variables if we're immutable
// Ruby's dotenv does this with `ENV[key] ||= value`.
if ($this->immutable && $this->getEnvironmentVariable($name) !== null) {
return;
}
putenv("$name=$value");
$_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
里面使用了putenv函数,这个函数是用于设置或修改环境变量的,目的是把.env里面的配置放到环境变量里面。通过var_dump查看返回值发现都是NULL, 可以猜测万网虚拟主机应该是禁用了putenv这个函数。
解决办法就是放弃使用.env文件,把里面的一些配置信息放到config/app.php里面去。
C#文件重命名
DirectoryInfo dir = new DirectoryInfo(img); // 创建DirectoryInfo类的实例
var path = Path .GetDirectoryName(img); // 获取原图片文件的路径
dir.MoveTo(path + $"\\{ret.id}.jpg" ); // 进行改名
C# 每两位插入一个空格
string txt = "12345678" ;
string result = Regex .Replace(txt, @"(\d{2}(?!$))", "$1 " );
每N位插入一个就把2改成N
上面只分操作全是数字的,如果是适应所有的,可以把\d换成.号
string txt = "ABCD1E2F4G" ;
string result = Regex .Replace(txt, @"(.{2}(?!$))", "$1 " );
PHP验证码类
<?php
/**
* 验证码
*/
class Code{
// 1. 定义各个成员 有宽、高、画布、字数、类型、画类型
private $width; //宽度
private $height; //高度
private $num; //验证码字数
private $imgType; //生成图片类型
private $Type; //字串类型 1,2,3 三个选项 1 纯数字 2 纯小写字母 3 大小写数字混合
private $hb; //画布
public $codestr; // 验证码字串
public function __construct($height=20,$num=4,$imgType="jpeg",$Type=1){
$this->width = $num*20;
$this->height = $height;
$this->num = $num;
$this->imgType = $imgType;
$this->Type = $Type;
$this->codestr = $this->codestr();
$this->zuhe();
}
// 2. 定义随机获取字符串函数
private function codestr(){
switch($this->Type){
case 1: // 类型为1 获取1-9随机数
$str = implode("",array_rand(range(0,9),$this->num));
break;
case 2: // 类型为2 获取a-z随机小写字母
$str = implode("",array_rand(array_flip(range(a,z)),$this->num));
break;
case 3: // 类型为3 获取数字,小写字母,大写字母 混合
for($i=0;$i<$this->num;$i++){
$m = rand(0,2);
switch($m){
case 0:
$o = rand(48,57);
break;
case 1:
$o = rand(65,90);
break;
case 2:
$o = rand(97,122);
break;
}
$str .= sprintf("%c",$o);
}
break;
}
return $str;
}
// 3. 初始化画布图像资源
private function Hb(){
$this->hb = imagecreatetruecolor($this->width,$this->height);
}
// 4. 生成背景颜色
private function Bg(){
return imagecolorallocate($this->hb,rand(130,250),rand(130,250),rand(130,250));
}
// 5. 生成字体颜色
private function Font(){
return imagecolorallocate($this->hb,rand(0,100),rand(0,100),rand(0,100));
}
// 6. 填充背景颜色
private function BgColor(){
imagefilledrectangle($this->hb,0,0,$this->width,$this->height,$this->Bg());
}
// 7. 干扰点
private function ganrao(){
$sum=floor(($this->width)*($this->height)/3);
for($i=0;$i<$sum;$i++){
imagesetpixel($this->hb,rand(0,$this->width),rand(0,$this->height),$this->Bg());
}
}
// 8. 随机直线 弧线
private function huxian(){
for($i=0;$i<$this->num;$i++){
imageArc($this->hb,rand(0,$this->width),rand(0,$this->height),rand(0,$this->width),rand(0,$this->height),rand(0,360),rand(0,360),$this->Bg());
}
}
// 9. 写字
private function xiezi(){
for($i=0;$i<$this->num;$i++){
$x=ceil($this->width/$this->num)*$i;
$y=rand(1,$this->height-15);
imagechar($this->hb,5,$x+4,$y,$this->codestr[$i],$this->Font());
}
}
// 10. 输出
private function OutImg(){
$shuchu="image".$this->imgType;
$header="Content-type:image/".$this->imgType;
if(function_exists($shuchu)){
header($header);
$shuchu($this->hb);
}else{
exit("GD库没有此类图像");
}
}
// 11. 拼装
private function zuhe(){
$this->Hb();
$this->BgColor();
$this->ganrao();
$this->huxian();
$this->xiezi();
$this->OutImg();
}
public function getCodeStr(){
return $this->codestr;
}
}
?>
使用composer添加第三方库jenssegers/agent
// language: bash
composer require jenssegers/agent
然后在app/config/app.php 里的服务提供者数组里添加该库, 并添加别名
// language: php
'providers' => [
Jenssegers\Agent\AgentServiceProvider::class,
]
'aliases' => [
'Agent' => Jenssegers\Agent\Facades\Agent::class,
]
使用artisan创建一个服务提供者类php artisan make:provider ResponseMacroServiceProvider
同样要在app.php里面配置
// language: php
'providers' => [
App\Providers\ResponseMacroServiceProvider::class,
]
// 别名用不到,不用配置了
修改app/Providers/ResponseMacroServiceProvider.php的boot方法
// language: php
public function boot(ResponseFactory $factory)
{
$factory->macro('ress', function ($viewname) use ($factory) {
if ( Agent::isMobile() ) {
return view()->make($viewname . "_mobile");
} else {
return view()->make($viewname . "_web");
}
});
}
在Controller中可以这样使用
// language: php
class HomeController extends Controller
{
public function index()
{
return response()->ress('home.index');
//return view('home.index');
}
public function article()
{
return response()->ress('home.article');
}
}
最后就是把视图名改为 _web.blade.php 和 _mobile.blade.php
ubuntu 14.04运行asp.net core程序所需要的一些运行库支持
apt-get install -y libunwind8 libunwind8-dev gettext libicu-dev liblttng-ust-dev libcurl4-openssl-dev libssl-dev uuid-dev