鳕鱼天空

This is Mr Wang's Tech Blog.

解决Python-pip安装缓慢的问题

首先,推荐使用 -i https://pypi.tuna.tsinghua.edu.cn/simple

对于Python开发用户来讲,PIP安装软件包是家常便饭。但国外的源下载速度实在太慢,浪费时间。而且经常出现下载后安装出错问题。所以把PIP安装源替换成国内镜像,可以大幅提升下载速度,还可以提高安装成功率。

国内源:

新版ubuntu要求使用https源,要注意。

清华:https://pypi.tuna.tsinghua.edu.cn/simple

阿里云:http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

华中理工大学:http://pypi.hustunique.com/

山东理工大学:http://pypi.sdutlinux.org/ 

豆瓣:http://pypi.douban.com/simple/

临时使用:

可以在使用pip的时候加参数-i https://pypi.tuna.tsinghua.edu.cn/simple

例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider,这样就会从清华这边的镜像去安装pyspider库。
 

永久修改,一劳永逸:

Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)

内容如下:


 
  1. [global]

  2. index-url = https://pypi.tuna.tsinghua.edu.cn/simple


 
  1. [install]

  2. trusted-host=mirrors.aliyun.com

windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini。内容同上。

Js中 Math ceil()、floor()、round()的用法

原文转载自:http://blog.csdn.net/xiaxiaorui2003/article/details/6481034
 

Math.floor()

功能: 对一个数进行下取整。

语法: Math.floor(x)

参数:

  • x:一个数值。

返回值: 返回小于或等于 x ,并且与之最接近的整数。

注: 如果 x 是正数,则把小数 “ 舍 ” ;如果 x 是负数,则把小数 “ 入 ” 。

例:

<script type="text/javascript">
document.write( Math.floor(1.2)+", "+Math.floor(1.8)+", "+Math.floor(-1.2)+", "+Math.floor(-1.8) );
</script>

输出结果为:

document.write( Math.floor(1.2)+", "+Math.floor(1.8)+", "+Math.floor(-1.2)+", "+Math.floor(-1.8) ); 1, 1, -2, -2

Math.round()

功能: 四舍五入取整。

语法: Math.round(x)

参数:

  • x:一个数值。

返回值: 与 x 最接近的整数。

例:

<script type="text/javascript">
document.write( Math.round(1.2)+", "+Math.round(1.8)+", "+Math.round(-1.2)+", "+Math.round(-1.8) );
</script>

输出结果为:

document.write( Math.round(1.2)+", "+Math.round(1.8)+", "+Math.round(-1.2)+", "+Math.round(-1.8) );  1, 2, -1, -2

Math.ceil()

功能: 对一个数进行上取整。

语法: Math.ceil(x)

参数:

  • x:一个数值。

返回值: 返回大于或等于 x ,并且与之最接近的整数。

注: 如果 x 是正数,则把小数 “ 入 ” ;如果 x 是负数,则把小数 “ 舍 ” 。

例:

<script type="text/javascript">
document.write( Math.ceil(1.2)+", "+Math.ceil(1.8)+", "+Math.ceil(-1.2)+", "+Math.ceil(-1.8) );
</script>

输出结果为:

document.write( Math.ceil(1.2)+", "+Math.ceil(1.8)+", "+Math.ceil(-1.2)+", "+Math.ceil(-1.8) );  2, 2, -1, -1

c# 图片围绕圆心旋转

public Image RotateImg(Image b, int angle)
        {
            //原图的宽和高
            int w = b.Width;
            int h = b.Height;
 
            int squartWidth = Math.Max(w, h) * 3;//目标图边长
            int radius = (squartWidth - 1) / 2;//圆半径
            //目标位图
            Bitmap dsImage = new Bitmap(squartWidth, squartWidth);
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            Pen pen = new Pen(Color.Black,1)   ;
            g.DrawEllipse(pen, 0, 0, squartWidth - 1, squartWidth - 1);//画个圆圈用于确认功能是否正确
            
            angle = angle % 360;
            g.TranslateTransform(radius, radius);
            g.RotateTransform(360 - angle);
            g.TranslateTransform(-radius, -radius);
            g.DrawImage(b, radius - w / 2, radius - h * 2);//平面几何这个算不来了,所以直接写死了
 
            ////重至绘图的所有变换
            g.ResetTransform();
            g.Save();
            g.Dispose();
 
            ////保存旋转后的图片
            b.Dispose();
            return dsImage;
 
        }
 
        int number = 0;
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            var img = this.RotateImg(Resources._1, 10 * (number++));
            this.pictureBox1.Image = img;
        }

asp.net 网站调用python执行返回信息Demo

首先需要引入IronPython,可以通过NuGet搜索获得,基于4.5以上框架集

using System;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
public partial class python : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        RunPythonShell();
    }
    /// <summary>
    /// 调用Python
    /// </summary>
    private void RunPythonShell()
    {
        ScriptRuntime pyRuntime = Python.CreateRuntime();
        //python文件绝对路径
        string path = string.Format(@"{0}1.py", Server.MapPath("./"));
        dynamic py = pyRuntime.UseFile(path);
        //调用Python 的函数run()
        Response.Write(py.show());
    }

}

 

cocos 通过碰撞边缘判断非常规多边形按钮

     // 不规则形状通过碰撞边缘检测是否在有效区域内
            let target = this.node;
            let pos = target.convertToNodeSpaceAR(e.getLocation())
            var polygonCollider = target.getComponent(cc.PolygonCollider);
            //pos.x -= target.getContentSize().width / 2;   // 原始示例中由减去宽度和高度的设定,实测不需要
            //pos.y -= target.getContentSize().height / 2;
            if (!cc.Intersection.pointInPolygon(pos, polygonCollider.points)) {
                return;
            }

以上是多边形按钮


var Global = require("Global");

cc.Class({
    extends: cc.Component,

    properties: {
        touched: false,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.node.on(cc.Node.EventType.TOUCH_START, this.touchStart.bind(this));
        this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd.bind(this));
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove.bind(this));
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd.bind(this));
    },

    onDestory() {

    },

    touchStart(e) {

        // 不规则形状通过碰撞边缘检测是否在有效区域内
        let target = this.node;
        let pos = target.convertToNodeSpaceAR(e.getLocation())
        var polygonCollider = target.getComponent(cc.PolygonCollider);
        //pos.x -= target.getContentSize().width / 2;   // 原始示例中由减去宽度和高度的设定,实测不需要
        //pos.y -= target.getContentSize().height / 2;
        if (!cc.Intersection.pointInPolygon(pos, polygonCollider.points)) {
            return;
        }
        this.touched = true;
        // 切换选中状态
        if (Global.selectedBoard != undefined && this.node != Global.selectedBoard) {
            Global.selectedBoard.opacity = 255;
        }
        Global.selectedBoard = this.node;
        this.node.opacity = 180;    // 选中状态半透明
        this.node.zIndex = 1;   // 最前
    },
    touchMove(e) {
        if (this.touched) {
            // 开始移动
            let delta = e.getDelta();
            this.node.x += delta.x;
            this.node.y += delta.y;
        }
    },
    touchEnd(e) {
        this.touched = false;
        this.node.zIndex = 0;
    },
});

以上是不规则图形按住拖动