• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Onway

            我是一只菜菜菜菜鳥...
            posts - 61, comments - 56, trackbacks - 0, articles - 34

            2017年2月11日

            一,matplotlib是什么

            python中用于數據庫可視化的2D繪圖庫。


            二,安裝

            http://matplotlib.org/users/installing.html


            三,交互模式與非交互模式

            1,非交互模式

            python shell里面執行

            import matplotlib.pyplot as plt
            plt.plot([12])
            plt.show()

            執行show之后會打開一個GUI窗口顯示,同時交互命令會阻塞。



            2,交互模式

            matplotlib.is_interactive()可以查看當前是否在交互模式;

            matplotlib.pyplot.ion()用于打開交互模式;

            matplotlib.pyplot.ioff()用于關閉交互模式;

            import matplotlib.pyplot as plt
            plt.ion()
            plt.plot([12])

            執行plot之后打開了一個GUI窗口,交互命令沒有阻塞,繼續執行:

            plt.plot([23])

            可以看到在窗口里面再畫了一條線。

            也就是在非交互模式,需要一次畫好再調用show顯示;而交互模式在每次繪制后都能實時看到效果。


            3,ipython的magic command 

            在ipython的%matplotlib也可以打開交互模式。

            在交互模式中如果某些修改沒有自動刷新,可以調用matplotlib.pyplot.draw()刷新。


            四,在jupyter notebook中使用matplotlib

            1,%matplotlib

            以交互模式打開獨立的GUI窗口,對同一個figure的繪制都自動刷新到對應的GUI窗口。


            2,%matplotlib notebook

            同%matplotlib,只是會將GUI窗口嵌入到cell的輸出。



            3,%matplotlib inline

            將繪制的圖轉換為靜態圖片嵌入到cell的輸出。在不同的cell進行繪制效果不會疊加。




            五,figure的各個組成部分

            http://matplotlib.org/faq/usage_faq.html#parts-of-a-figure


            六,matplotlib的兩種繪圖接口

            1,matlab風格接口

            所有的plt命令都會應用到自動創建的當前figureaxes對象。使用plt.gcfplt.gca獲取當前figureaxes

            調用plt.plot([1, 2])即繪制到自動創建的figureaxes

            plt.plot([12])
            plt.plot([21])


            2,面向對象接口

            顯式獲得繪制對象,在特定對象執行相應操作。

            fig, ax = plt.subplots()
            ax.plot([12])
            ax.plot([21])


            3,差別

            對于簡單繪制兩種接口的差別不大,復雜情況面向對象接口會更合適。

            另外plt的很多函數都可以直接轉為ax的函數,例如plt.plot() -> ax.plot(),但某些會有差別,例如plt.xlabel() -> ax.set_xlabel()。


            七,各類圖形demo

            http://matplotlib.org/gallery.html


            八,API

            http://matplotlib.org/api/index.html



            參考:

            1,http://matplotlib.org/index.html#

            2http://matplotlib.org/faq/usage_faq.html#what-is-interactive-mode

            3http://jupyter.org

            4http://www.labri.fr/perso/nrougier/teaching/matplotlib/#introduction

            5,http://nbviewer.jupyter.org/github/jakevdp/PythonDataScienceHandbook/blob/master/notebooks/04.00-Introduction-To-Matplotlib.ipynb#Two-Interfaces-for-the-Price-of-One

            posted @ 2017-02-11 15:12 Onway 閱讀(1648) | 評論 (0)編輯 收藏

            2016年2月15日

            一晃N年過去了。

            windows的有道詞典都不知道升級到哪個版本了。
            linux的有道詞典官方版本也出來了。
            goldendict已經1.5版本了。

            博客上幾個月前居然還有一條關于這個東西的評論。
            將代碼找回來試了一下居然還能跑,有道的api和xml格式還是真是穩定啊。

            簡單修改了一下install腳本,重寫了README,收到github了:
            原1.3版本:

            posted @ 2016-02-15 19:57 Onway 閱讀(2109) | 評論 (2)編輯 收藏

            2016年2月12日

            背景
            前段時間在digitalocean租了vps搭建shadowsocks,簡單看了一下socks5協議,決定自己也造一個小輪子玩玩。
            春節在家整理了一下代碼,大神輕拍。
            功能
            代碼是c++,在linux基于perfork+select實現的,目前的功能有:
            • TCP代理
            • 遠程DNS
            • 用戶驗證
            • 數據加密

            過程
            開發調試的過程發現兩點比較有意思:
            1. 偶爾會收到RST的數據包,查看代碼日志,用tcpdump在兩端抓包并無發現異常
            2. 訪問某些網站總是會收到RST數據包造成無法訪問
            對上述第二點加入了非常簡單的數據加密后就解決了哈,shadowsocks的加密應該就是這么用的吧。

            缺陷
            功能上沒有支持UDP,ie和chrome瀏覽器似乎都不支持socks5,只能先用著firefox了。
            在windows也用c#做了一個客戶端,但無暇顧及已經好久沒更新了。

            其他
            可能跟所用寬帶有關,訪問digitalocean的時延超過300ms,網站只能打開首頁,登錄頁面都加載不全,慎用。
            前些天收到郵件說是vps出現流量異常被關閉了,還無法登錄管理頁面,用lantern也一直連不上。(T_T)

            posted @ 2016-02-12 17:50 Onway 閱讀(2170) | 評論 (0)編輯 收藏

            2015年12月8日

            1, 三個標準
            1.1, ISO C標準由ISO/IEC維護開發
            最新版本是C11,共有29個標準頭文件。

            1.2, POSIX是一系列由IEEE制定的標準
            POSIX包括ISO C標準庫函數。
            POSIX標準的1988版本是IEEE 1003.1-1988,經過修改后作為IEEE Std.1003.1-1990提交ISO,成為國際標準ISO/IEC 9945-1:1990,該標準通常稱為POSIX.1。
            當前最新版本是POSIX.1-2008,由IEEE和Open Group共同開發。

            1.3, SUS是POSIX的超集,其系統接口全集稱為XSI
            The core specifications of the SUS are developed and maintained by the Austin Group, which is a joint working group of IEEE, ISO JTC 1 SC22 and The Open Group.
            只有遵循XSI的實現才能稱為UNIX系統。
            當前的最新版本是SUSv4。

            1.4, 找到一些網址
            C11
            http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=57853

            POSIX.1-2008
            http://pubs.opengroup.org/onlinepubs/9699919799/
            https://standards.ieee.org/findstds/standard/1003.1-2008.html

            SUSv4
            https://www2.opengroup.org/ogsys/jsp/publications/PublicationDetails.jsp?publicationid=12310
            https://en.wikipedia.org/wiki/Single_UNIX_Specification#cite_note-11

            2, 限制
            2.1 兩種限制
            編譯時限制和運行時限制。
            編譯時限制通過頭文件獲?。?/span>
            不與文件或目錄相關的運行時限制通過sysconf函數獲??;
            與文件或目錄相關的運行時限制通過pathconf和fpathconf函數獲取。

            2.2 ISO C限制
            都是編譯時限制,主要定義在<limits.h>里面。
            http://en.cppreference.com/w/c/types/limits

            2.3 POSIX限制和XSI限制
            書中列出的都是實現中必須支持的各種最小值,特定系統實際支持的限制值需要通過頭文件或者三個函數函數獲取。
            三個函數的name參數是限制名前面加_SC_或者_PC_前綴得到。
            http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html

            2.4 書中代碼
            /*
             * If  name  is  invalid, -1 is returned, and errno is set to EINVAL.
             * Otherwise, the value returned is the value of the system resource and errno is not changed.
             * In the case of options, a positive value is returned if a queried option is available, and -1 if it is not.
             * In the case of limits, -1 means that there is no definite limit.
            */

            #include 
            "apue.h"
            #include 
            <errno.h>
            #include 
            <limits.h>

            #ifdef OPEN_MAX
            static long openmax = OPEN_MAX;
            #else
            static long openmax = 0;
            #endif

            /*
             * If OPEN_MAX is indeterminate, we're not
             * guaranteed that this is adequate
             
            */
            #define OPEN_MAX_GUESS 256

            long
            open_max(
            void)
            {
                
            if (openmax == 0) { /* first time through */
                    errno 
            = 0;
                    
            if ((openmax = sysconf(_SC_OPEN_MAX)) < 0) {
                        
            if (errno == 0)
                            openmax 
            = OPEN_MAX_GUESS; /* it's indeterminate */
                        
            else
                            err_sys(
            "sysconf error for _SC_OPEN_MAX";)
                    }
                }

                
            return(openmax);
            }

            3, 選項
            3.1, 選項確定方式
            編譯時選項定義在<unistd.h>中;
            與文件或目錄無關的選項用sysconf確定;
            與文件或目錄有關的選項用pathconf或者fpathconf確定;
            http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html

            3.2, 選項確定流程
            如果符號常量未定義,
            對_POSIX前綴的選項,將_POSIX前綴替換為_SC或_PC前綴,
            對_XOPEN前綴的選項,在_XOPEN前面加上_SC或_PC前綴,
            然后調用sysconf, pathconf或fpathconf函數。
            如果符號常量已經定義,則有三種可能:
            值為-1,不支持相應的選項;
            值大于0,支持相應的選項;
            值為0,需調用函數確定選項是否支持。
            注:某些系統可能出現定義了符號常量,但沒有定義值的情況。

            3.4, 代碼示例
            先占坑。

            4, 功能測試宏
            Feature test macros allow the programmer to control the definitions that are exposed by system header files when a program is compiled.
            NOTE:  In  order  to be effective, a feature test macro must be defined before including any header files.  This can be done either in the compilation command (cc -DMACRO=value) or by defining the macro within the source code before including any headers.
            see man page feature_test_macros(7).

            posted @ 2015-12-08 22:35 Onway 閱讀(435) | 評論 (0)編輯 收藏

            2015年12月6日

            1, shadowsocks home page
            https://shadowsocks.org/en/index.html

            2, install shadowsocks server
            $ sudo apt-get install python-pip
            $ sudo pip install shadowsocks
            https://shadowsocks.org/en/download/servers.html

            3, shadowsocks server config file
            $ vi /etc/shadowsocks.json
            {
                "server":"my_server_ip",
                "server_port":8388,
                "local_port":1080,
                "password":"barfoo!",
                "timeout":600,
                "method":"table"
            }
            https://shadowsocks.org/en/config/quick-guide.html

            4, shadowsocks server command
            $ ssserver -h // help message
            $ ssserver -c /etc/shadowsocks.json -d start // start in daemon mode
            $ ssserver -d stop // stop the server

            5, shadowsocks-qt5 client for ubuntu 14.04
            $ sudo add-apt-repository ppa:hzwhuang/ss-qt5
            $ sudo apt-get update
            $ sudo apt-get install shadowsocks-qt5
            https://github.com/shadowsocks/shadowsocks-qt5/wiki/Installation

            6, install genpac to generate PAC file from gfwlist
            $ sudo pip install genpac // install
            $ genpac --init // generate config.ini and user-rules.txt
            -- modify config.ini
            $ vi config.ini
            [config]
            proxy = SOCKS5 127.0.0.1:1080
            gfwlist-url = https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt
            user-rule-from = /path/to/user-rules.txt
            output = /path/to/proxy.pac
            $ genpac -c config.ini // generate pac file
            https://github.com/JinnLynn/genpac
            https://github.com/gfwlist/gfwlist

            7, using a PAC file in Firefox
            about:preferences#advanced -> Network -> Settings
            check 'Automatic proxy configuration URL:'
            file:///path/to/proxy.pac
            enable 'Remote DNS'
            https://www.youtube.com/watch?v=nKB4FoPw15k

            posted @ 2015-12-06 17:18 Onway 閱讀(247) | 評論 (0)編輯 收藏

            2015年8月1日

                 摘要: 1,最先學會的是,繼承了IEnumerable接口的類都可以使用foreach遍歷,但一直沒有多想。2,IEnumerable和IEnumerable<out T>的定義:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->  &nb...  閱讀全文

            posted @ 2015-08-01 14:00 Onway 閱讀(599) | 評論 (1)編輯 收藏

            2015年7月29日

            1,兩個鏈接里面已經解析完Dispose模式了,其他的只是自己的一些理解。

            2,如果自定義類型封裝了非托管資源,或者引用了一個封裝了非托管資源的對象時(比如引用了SqlConnection對象),應該實現Dispose模式。

            3,如果自定義類型繼承的基類需要Dispose,但該對象本身并沒有需要Dispose的資源時(比如只是附加了一些簡單類型),無需考慮Dispose模式。

            4,如果基類實現了Dispose,則其派生類只需重寫protected級別的Dispose方法,釋放本類型的使用到的資源。
            public級別的Dispose和Finalize方法都來自繼承。
            重寫的Dispose方法,記得最后調用基類帶參的Dispose。

            5,附加的Close方法都是直接調用public無參的Dispose方法。

            6,類型的析構函數會被編譯器改為Finalize方法,不要重載這個方法。
            基類的Finalize方法總是會被自動調用的。
            Finalize方法都不應該引用任何對象。

            7,不懂這段話,既然基類沒有需要釋放的資源,為何要實現Dispose模式,而為了性能考慮,又不寫析構函數?
            那我的派生類,還要先看一下基類,再決定要不要寫析構函數?
            Implement the dispose design pattern on a base type that commonly has derived types that hold onto resources, even if the base type does not. If the base type has a Close method, often this indicates the need to implement Dispose. In such cases, do not implement a Finalize method on the base type. Finalize should be implemented in any derived types that introduce resources that require cleanup.

            8,對象在調用Dispose之后,除了Dispose以外,都應該拋出ObjectDisposedException異常。

            9,實現了Finalize的對象,在第一次垃圾回收的時候,不會釋放對象,而只是調用其Finalize方法,第二次回收才會真正釋放對象。

            posted @ 2015-07-29 22:50 Onway 閱讀(717) | 評論 (0)編輯 收藏

            因為某些原因,一直用的都是.NET2,但渣也總得有些追求是不,說不定哪天就用上了呢?

            using System;
            using System.Collections.Generic;
            using System.Text;

            namespace ConsoleApplicationTest
            {
                /*
                 * 變體泛型
                 *
                 * .NET4,在泛型接口類型或者泛型委托類型里面,
                 * 被關鍵字in聲明的泛型參數,其類型可以從父類向子類逆變,只能用作輸入參數
                 * 被關鍵字out聲明的泛型參數,其類型可以從子類向父類協變,只能用于返回值
                 * 整個泛型類型是不限于用作輸入參數還是作為返回值
                 *
                 * interface IType_IN_OUT<in T1, out T2>
                 * IType_IN_OUT<Farmer, Person> farmerPersonType = null;
                 * IType_IN_OUT<Person, Farmer> personfarmerType = null;
                 * farmerPersonFinder = personFarmerFinder;
                 *
                 * 為什么不支持“變體”class呢?跟字段有關系么?
                 
            */

                class Program
                {
                    static void Main(string[] args)
                    {
                        IType_IN<Person> person_in = null;
                        IType_IN<Farmer> farmer_in = null;
                        farmer_in = person_in;
                        Greeting(person_in);
                        Console.WriteLine(GetTypeIn() == null);

                        IType_OUT<Person> person_out = null;
                        IType_OUT<Farmer> farmer_out = null;
                        person_out = farmer_out;
                        Greeting(farmer_out);
                        Console.WriteLine(GetTypeOut() == null);

                        Finder_IN<Person> personFinderIn = p => Console.WriteLine(p.GetType());
                        Finder_IN<Farmer> farmerFinderIn = f => Console.WriteLine(f.GetType());
                        farmerFinderIn = personFinderIn;
                        Greeting(personFinderIn);
                        Console.WriteLine(GetFarmerFinder().GetType());

                        Finder_OUT<Person> personFinderOut = () => new Person();
                        Finder_OUT<Farmer> farmerFinderOut = () => new Farmer();
                        personFinderOut = farmerFinderOut;
                        Greeting(personFinderOut);
                        Console.WriteLine(GetPersonFinder().GetType());

                        Finder_IN_OUT<Farmer, Person> farmerPersonFinder = f => new Person();
                        Finder_IN_OUT<Person, Farmer> personFarmerFinder = p => new Farmer();
                        farmerPersonFinder = personFarmerFinder;

                        // interface IType_IN_OUT<in T1, out T2>
                        IType_IN_OUT<Farmer, Person> farmerPersonType = null;
                        IType_IN_OUT<Person, Farmer> personfarmerType = null;
                        farmerPersonType = personfarmerType;

                        Console.ReadKey();
                    }

                    static void Greeting(IType_OUT<Person> person)
                    {
                        Console.WriteLine(person == null);
                    }

                    static void Greeting(IType_IN<Farmer> farmer)
                    {
                        Console.WriteLine(farmer == null);
                    }

                    static IType_OUT<Person> GetTypeOut()
                    {
                        IType_OUT<Farmer> farmer = null;
                        return farmer;
                    }

                    static IType_IN<Farmer> GetTypeIn()
                    {
                        IType_IN<Person> person_IN = null;
                        return person_IN;
                    }

                    static void Greeting(Finder_OUT<Person> personFinder)
                    {
                        Console.WriteLine(personFinder().GetType());
                    }

                    static void Greeting(Finder_IN<Farmer> farmerFinder)
                    {
                        Console.WriteLine(farmerFinder.GetType());
                    }

                    static Finder_OUT<Person> GetPersonFinder()
                    {
                        Finder_OUT<Farmer> farmerFinder = () => new Farmer();
                        return farmerFinder;
                    }

                    static Finder_IN<Farmer> GetFarmerFinder()
                    {
                        Finder_IN<Person> person = p => Console.WriteLine(p.GetType());
                        return person;
                    }
                }

                interface IType_OUT<out T>
                {
                }

                interface IType_IN<in T>
                {
                }

                interface IType_IN_OUT<in T1, out T2>
                {
                }

                delegate T Finder_OUT<out T>();

                delegate void Finder_IN<in T>(T t);

                delegate T2 Finder_IN_OUT<in T1, out T2>(T1 t1);

                class Person
                {
                }

                class Farmer : Person
                {
                }
            }

            posted @ 2015-07-29 20:23 Onway 閱讀(374) | 評論 (0)編輯 收藏

            2015年7月19日

            需求:
            地圖上Grid對象表示一個40*40的柵格,除了經緯度以外,還有一個指標值如信號強度,以及一個根據指標值確定的渲染顏色。
            Road對象是一條矢量道路,由多個經緯度點組成。
            如果道路穿過某個柵格,則將穿過柵格的那一小段道路按柵格的顏色值畫出來,沒有穿過柵格的其他道路部分,用黑色渲染。

            第一次做法:
            對道路進行預處理,將道路上的各個點歸類到其所屬的柵格內。
            然后將柵格內的點用線連起來。
            完成后一看地圖,掉坑里面了。
            1,一條道路穿過某個柵格,柵格內可能只有一個點,連不成線;
            2,一條直線道路,只記錄了開頭和結尾,中間穿過的柵格就沒點了
            后來想到用補點的方式,兩個點超過20米就補一個
            簡單試了一下,效果不好就開始用第二種方法

            第二次做法:
            先將道路在空白bitmap上畫出來,顏色用黑色;
            再將柵格在另一空白的bitmap上畫出來,顏色用原本的柵格顏色;
            對比兩張bitmap,像素同時不為0的就是相交像素,用柵格的像素顏色復制到道路的像素里面;
            效果杠杠的。

            其他方法:
            在討論組里面說了以后,發現另一種是預處理做法
            判斷兩點之間跟柵格的相交,將相交點記錄到所在柵格里面,這比較適合后臺。

            以后還是默默寫博客吧!

            posted @ 2015-07-19 13:31 Onway 閱讀(753) | 評論 (0)編輯 收藏

            2015年7月11日

            說明
            用于多人開發的項目且在不提交項目文件的情況下,自動將新增的源碼文件加入到項目中或者將刪除的文件從項目中移除。
            https://github.com/Onway/AutoProjectFiles

            使用
            安裝后在資源管理器中右鍵項目名稱節點,會看到“自動更新項目”和“創建快照...”兩個選項。  
            “創建快照”是對項目中指定的源碼目錄建立一份已有文件列表,以便后續知道新增或者刪除的文件。  
            “自動更新項目”之后,將會對新增或刪除文件更新至項目,同時刷新文件快照列表。

            效果圖


            posted @ 2015-07-11 19:39 Onway 閱讀(339) | 評論 (0)編輯 收藏

            亚洲国产精品18久久久久久| av无码久久久久不卡免费网站 | 久久精品国产亚洲av麻豆小说| 一本色道久久HEZYO无码| 久久狠狠高潮亚洲精品| 久久久久久亚洲精品不卡| 中文字幕无码免费久久| 国产午夜福利精品久久| 久久久久亚洲AV无码专区首JN| 9久久9久久精品| 亚洲愉拍99热成人精品热久久| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久精品国产99国产精品| 97久久国产露脸精品国产| 久久久精品免费国产四虎| 色综合久久夜色精品国产| 久久香综合精品久久伊人| 久久精品水蜜桃av综合天堂| 精品国产91久久久久久久a| 欧美喷潮久久久XXXXx| 久久久久久午夜精品| 成人国内精品久久久久影院VR| 色综合久久无码五十路人妻| 久久性生大片免费观看性| 久久久九九有精品国产| 蜜臀av性久久久久蜜臀aⅴ| 久久久这里只有精品加勒比| 久久久综合香蕉尹人综合网| 亚洲国产精品久久66| 色综合久久久久| 久久精品国产精品青草app| 99精品伊人久久久大香线蕉| 久久亚洲精精品中文字幕| 精品熟女少妇AV免费久久| 老男人久久青草av高清| 一本一本久久a久久精品综合麻豆| 亚洲国产成人久久精品动漫| 69久久精品无码一区二区| 99久久无码一区人妻a黑| 亚洲av成人无码久久精品| 久久人人爽人人爽人人片av高请|