• <tbody id="baor6"></tbody>

  • <em id="baor6"><acronym id="baor6"><input id="baor6"></input></acronym></em>
    <strike id="baor6"></strike><li id="baor6"></li>
    <rp id="baor6"></rp>
    1. <em id="baor6"></em>
      <form id="baor6"></form>
      <nobr id="baor6"></nobr>

      <em id="baor6"><acronym id="baor6"><u id="baor6"></u></acronym></em>

          葵花寶典教程,一個自學編程平臺

          葵花寶典教程,一個自學編程平臺

          sudo go 提示找不到命令:sudo: go: command not found

          環境變量配置:

          # ~/.bash_profile

          export GOROOT=/usr/local/go

          export GOPATH=/usr/local/GO

          export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

          錯誤描述:

          使用非root用戶,執行 go version 獲得正確輸出。

          使用root用戶,執行 go verison 獲得正確輸出。

          使用非root用戶,執行 sudo go version 獲得輸出 sudo: go: command not found。

          解決辦法:

          根據 Some programs not found when used with sudo 中的回答。


          我們使用 sudo 時,使用的配置文件是 /etc/sudoers。


          配置 /etc/sudoers 文件中的 Defaults secure_path 這一項。將 $GOROOT/bin 目錄加入進去。(請使用絕對目錄,如:/usr/local/go/bin/)


          Defaults secure_path 這一行:

          Defaults    secure_path = /usr/local/go/bin/:/sbin:/bin:/usr/sbin:/usr/bin

          go mod tidy 報錯:XXXX found,but does not contain package XXXX

          舉個例子:

          gitee.com/atix/utils/logger: module gitee.com/atix/utils@latest found (v0.1.0), but does not contain package gitee.com/atix/utils/logger

          來看上文這個報錯,由于我們 import 時未指定特定版本號,故 golang 默認使用最新版本(即能夠通過 git checkout 將其檢出的版本號),我們去查看該 module,發現有一個 tag 號為:v0.1.0,檢查該 tag 代碼發現確實沒有我們要用的 logger 包,由此判斷是我們 import 了一個尚未發布的 package,碰到這種情況只需要將該 module 重新打個 tag,將我們用到的 package 發布,然后本地執行:

          go get gitee.com/atix/utils@v0.1.1 把新的版本下載、安裝到本地,之后就正常了。

          go get  github.com/aaa/lotus@latest    [最新版]

          Lotus

          Lotus 是 Filecoin 分布式存儲網絡的實現。

          基本構建說明

          構建 Lotus 需要一些系統依賴項,這些依賴項通常由您的發行版提供。

          Ubuntu/Debian:


          sudo apt install mesa-opencl-icd ocl-icd-opencl-dev gcc git bzr jq pkg-config curl clang build-essential hwloc libhwloc-dev wget -y && sudo apt upgrade -y


          要構建 Lotus,您需要安裝Go 1.16.4 或更高版本

          wget -c https://golang.org/dl/go1.16.4.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local

          提示:您需要添加/usr/local/go/bin到您的路徑。對于大多數 Linux 發行版,您可以運行以下命令:


          echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc && source ~/.bashrc

          構建和安裝 Lotus

          一旦安裝了所有依賴項,您就可以構建和安裝 Lotus 套件(lotus、lotus-minerlotus-worker)。

          1克隆存儲庫:

          git clone https://github.com/filecoin-project/lotus.git

          cd lotus/

          注意:默認分支master是最新的新功能

          2要加入主網

          git checkout < tag_or_branch > #例如: 
          git checkout < vX.XX >  #發布標簽
          
          目前master分支上的最新代碼對應主網。
          
          3如果您在中國
          4此構建指令使用預構建的證明二進制文件[請注意,如果您從源代碼構建證明二進制文件,則還需要安裝 rustup 。]
          5構建和安裝 Lotus
          
          make clean all #mainnet
          
          # Or to join a testnet or devnet:
          make clean calibnet # Calibration with min 32GiB sectors
          
          sudo make install
          
          lotus將$HOME/.lotus默認使用該文件夾進行存儲(配置、鏈數據、錢包等)。


          6您現在應該已經安裝了 Lotus。


          [

          https://github.com/filecoin-project/lotus

          ]

          filecoin安裝條件

          最低要求

          要運行 Lotus 節點,您的計算機必須具備:


          已安裝 macOS 或 Linux。尚不支持 Windows。

          8 核 CPU 和 32 GiB RAM。支持英特爾 SHA 擴展(自 Zen 微架構以來的 AMD 或自 Ice Lake 以來的英特爾)的模型將顯著加快速度。

          足夠的空間來存儲當前的 Lotus 鏈(最好在 SSD 存儲介質上)。該鏈以每天大約 38 GiB 的速度增長。該鏈可以從受信任的狀態快照同步,并壓縮或修剪到最小大小約為 33Gib。2021 年 6 月的完整歷史記錄約為 10TiB。

          中國節點加速

          運行 Lotus 需要下載鏈的證明參數,這些文件是大文件,默認托管在中國境外,在那里下載非常慢。為了解決這個問題,用戶應該在運行 和 時設置以下lotus環境lotus-miner變量lotus-worker

          export IPFS_GATEWAY=https://proof-parameters.s3.cn-south-1.jdcloud-oss.com/ipfs/


          構建 Lotus 需要下載一些 Go 模塊。這些通常托管在 Github 上,來自中國的帶寬非常低。要解決此問題,請在運行 Lotus之前通過設置以下變量來使用本地代理:

          export GOPROXY=https://goproxy.cn


          在 Linux 上安裝 Lotus 有幾種方法:


          • Snap package manager

          • AppImages

          • Building from source.





          go面試題

          Go學習-make和new的區別

          https://blog.csdn.net/ouyangyiwen/article/details/111548053

          [

          new和make的區別,我們從下圖便可看出:

                   1)new是為值類型分配內存(可以任意類型的數據),其返回的是指針,指向分配類型的內存地址。         

                   2)make為引用類型分配內存并初始化,如:chan、map和slice,其返回值為這個類型(引用)本身。   

                   3)new 分配的空間被清零。make 分配空間后,會進行初始化;

          ]

          golang切片和數組的區別


          數組是值拷貝而切片是引用

          https://www.cnblogs.com/blog-196/p/11141356.html

          Go語言切片詳解 

          https://www.cnblogs.com/lvnux/p/12907356.html


          goland使用go mod模式

          使用go mod之后,想要在goland中有代碼提示,有兩種方式,一種是使用gopath下的goimport工具,另一種是使用gomod自身的管理工具

          我是用的是非gopath的方式,每次新建項目后總是報錯

          go list -m: can‘t compute ‘all‘ using the vendor directory
          (Use -mod=mod or -mod=readonly to bypass.),

          得不到想要的效果,最后終于發現是步驟不對

          第一步:創建空文件夾

          第二步:goland以項目方式打開文件夾

          第三步:設置goland中的配置,goroot,gomodule


          1-1.png

          第四步:執行go mod init + 項目名,這個截圖的地方多一個go modules,用于存放下載的包的


          2-2.png

          第五步:創建.go文件,然后寫上代碼

          第六步:執行go mod tidy,下載所需的包,也會刪除多余的包


          Laravel DB::table update record

          I have this query

           DB::table('product_options')
                  ->where('product_id', $id)
                  ->where('size', $selected_size)
                  ->update(array('stock' => WHAT TO PUT HERE));

          In the update part where I've put WHAT TO UPDATE, what should I put here to decrease the number by 1?

          DB::table('product_options')
                  ->where('product_id', $id)
                  ->where('size', $selected_size)
                  ->decrement('stock');


          當 Target 類 [Controller] 不存在時怎么辦. 出現在 Laravel

          在最近的 Laravel(可能是 v8 或更高版本)中,如果你在初始狀態下在 routes/web.php 中編寫以下代碼,你將無法找到應該在那里的 Controller Class,并且會出現錯誤。

          Route::get('/hoge', 'Controller@index');
          Illuminate\Contracts\Container\BindingResolutionException Target class [Controller] does not exist.  http://laravel.internal/hoge  Illuminate\Container\Container::build htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php:811

          顯然,我開始忘記了 Contoller 的初始位置。

          一致

          $namespace取消注釋App / Providers / RouteServiceProvider.php

              /**      
              * The controller namespace for the application.      *      
              * When present, controller route declarations will automatically be prefixed with this namespace.           
              * @var string|null      
              */     
              protected $namespace = 'App\\Http\\Controllers'; //


          python字符串連接的幾種方法

          python字符串連接的方法,一般有以下三種:

          方法1:直接通過加號(+)操作符連接

          1
          website = 'python' + 'tab' + '.com'

          方法2:join方法

          1
          2
          listStr = ['python''tab''.com'
          website = ''.join(listStr)

          方法3:替換

          1
          website = '%s%s%s' % ('python''tab''.com')

          下面再來說一下三種方法的不同

          方法1,使用簡單直接,但是網上不少人說這種方法效率低

          之所以說python 中使用 + 進行字符串連接的操作效率低下,是因為python中字符串是不可變的類型,使用 + 連接兩個字符串時會生成一個新的字符串,生成新的字符串就需要重新申請內存,當連續相加的字符串很多時(a+b+c+d+e+f+...) ,效率低下就是必然的了

           

          方法2,使用略復雜,但對多個字符進行連接時效率高,只會有一次內存的申請。而且如果是對list的字符進行連接的時候,這種方法必須是首選

           

          方法3:字符串格式化,這種方法非常常用,本人也推薦使用該方法


          Python爬蟲常用庫總結之“Requests”

          Requests模塊介紹:

          發送http請求,獲取響應數據

          requests模塊是一個第三方模塊,需要在你的python(虛擬)環境中額外安裝: 

          pip/pip3 install requests

          requests基礎:

          requests模塊發送get請求


          • import requests

          • # 目標url

          • url = 'https://www.baidu.com'

          • # 向目標url發送get請求

          • response = requests.get(url)

          • # 打印響應內容

          • print(response.text)


          Response響應對象:

          觀察上邊代碼運行結果發現,有好多亂碼;這是因為編解碼使用的字符集不同造成的;我們嘗試使用下邊的辦法來解決中文亂碼問題


          • import requests

          • url = 'https://www.baidu.com'

          • # 向目標url發送get請求

          • response = requests.get(url)

          • # 打印響應內容

          • # print(response.text)

          • print(response.content.decode()) # 注意這里!


          1、response.text是requests模塊按照chardet模塊推測出的編碼字符集進行解碼的結果

          2、網絡傳輸的字符串都是bytes類型的,所以response.text = response.content.decode(‘推測出的編碼字符集’)

          3、我們可以在網頁源碼中搜索charset,嘗試參考該編碼字符集,注意存在不準確的情況。


          Response.text 和Response.content的區別:

          1、Response.text


          • 類型:str

          • 解碼類型: requests模塊自動根據HTTP 頭部對響應的編碼作出有根據的推測,推測的文本編碼


          2、Response.content


          • 類型:bytes

          • 解碼類型: 沒有指定



          解決中文亂碼:

          通過對response.content進行decode,來解決中文亂碼


          1、Response.content.decode() 默認utf-8

          2、Response.content.decode("GBK")

          3、常見的編碼字符集

          • utf-8

          • gbk

          • gb2312

          • ascii (讀音:阿斯克碼)

          • iso-8859-1



          Response響應對象的其它常用屬性或方法:


          • #https://beishan.blog.csdn.net/

          • # 1.2.3-response其它常用屬性

          • import requests


          • # 目標url

          • url = 'https://www.baidu.com'


          • # 向目標url發送get請求

          • response = requests.get(url)


          • # 打印響應內容

          • # print(response.text)

          • # print(response.content.decode()) # 注意這里!

          • print(response.url)# 打印響應的url

          • print(response.status_code)# 打印響應的狀態碼

          • print(response.request.headers)# 打印響應對象的請求頭

          • print(response.headers)# 打印響應頭

          • print(response.request._cookies)# 打印請求攜帶的cookies

          • print(response.cookies)# 打印響應中攜帶的cookies



          Requests實操:

          requests模塊發送請求

          發送帶header的請求

          我們先寫一個獲取百度首頁的代碼



          • import requests

          • url = 'http://www.voyageurimaginaire.com'

          • response = requests.get(url)

          • print(response.content.decode())

          • # 打印響應對應請求的請求頭信息

          • print(response.request.headers)


          從瀏覽器中復制User-Agent,構造Headers字典;完成下面的代碼后,運行代碼查看結果


          • import requests


          • url = 'http://www.voyageurimaginaire.com'


          • headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"}


          • # 在請求頭中帶上User-Agent,模擬瀏覽器發送請求

          • response = requests.get(url, headers=headers)


          • print(response.content)


          • # 打印請求頭信息

          • print(response.request.headers)


          發送帶參數的請求:

          我們在使用百度搜索的時候經常發現url地址中會有一個 ?,那么該問號后邊的就是請求參數,又叫做查詢字符串


          在url攜帶參數,直接對含有參數的url發起請求


          • import requests


          • headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"}


          • url = 'https://www.baidu.com/s?wd=python'


          • response = requests.get(url, headers=headers)



          通過Params攜帶參數字典:

          1.構建請求參數字典

          2.向接口發送請求的時候帶上參數字典,參數字典設置給params


          • import requests


          • headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"}


          • # 這是目標url

          • # url = 'https://www.baidu.com/s?wd=python'


          • # 最后有沒有問號結果都一樣

          • url = 'https://www.baidu.com/s?'


          • # 請求參數是一個字典 即wd=python

          • kw = {'wd': 'python'}


          • # 帶上請求參數發起請求,獲取響應

          • response = requests.get(url, headers=headers, params=kw)


          • print(response.content)

          • 從瀏覽器中復制User-Agent和Cookie

          • 瀏覽器中的請求頭字段和值與headers參數中必須一致

          • headers請求參數字典中的Cookie鍵對應的值是字符串

          • import requests


          • url = 'https://github.com/USER_NAME'


          • # 構造請求頭字典

          • headers = {

          • # 從瀏覽器中復制過來的User-Agent

          • 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36',

          • # 從瀏覽器中復制過來的Cookie

          • 'Cookie': 'xxx這里是復制過來的cookie字符串'

          • }


          • # 請求頭參數字典中攜帶cookie字符串

          • resp = requests.get(url, headers=headers)


          • print(resp.text)




          超時參數timeout的使用:

          在平時網上沖浪的過程中,我們經常會遇到網絡波動,這個時候,一個請求等了很久可能仍然沒有結果。

          在爬蟲中,一個請求很久沒有結果,就會讓整個項目的效率變得非常低,這個時候我們就需要對請求進行強制要求,讓他必須在特定的時間內返回結果,否則就報錯。


          1、超時參數timeout的使用方法

          response = requests.get(url, timeout=3)

          2、timeout=3表示:發送請求后,3秒鐘內返回響應,否則就拋出異常


          • import requests



          • url = 'https://twitter.com'

          • response = requests.get(url, timeout=3) # 設置超時時間



          Requests發送post請求的方法:


          • response = requests.post(url, data)

          • data參數接收一個字典

          • requests模塊發送post請求函數的其它參數和發送get請求的參數完全一致


          注意運行的時候開梯子就會報錯



          << 1 2 3 4 5 6 7 8 9 10 > >>

          Copyright www.voyageurimaginaire.com Rights Reserved葵花寶典教程.鄂icp2022001145號-1

          分享:

          支付寶

          微信

          精品一区二区三区无码毛片 午夜性色福利影院 国产一级黄片大全 97免费看少妇高潮A片 肉肉爱AV无码 av看片
        1. <tbody id="baor6"></tbody>

        2. <em id="baor6"><acronym id="baor6"><input id="baor6"></input></acronym></em>
          <strike id="baor6"></strike><li id="baor6"></li>
          <rp id="baor6"></rp>
          1. <em id="baor6"></em>
            <form id="baor6"></form>
            <nobr id="baor6"></nobr>

            <em id="baor6"><acronym id="baor6"><u id="baor6"></u></acronym></em>