(轉)rvm安裝與常用命令

rvm是一個命令行工具,可以提供一個便捷的多版本ruby環境的管理和切換。

https://rvm.io/

如果你打算學習ruby/rails, rvm是必不可少的工具之一。

這里所有的命令都是再用戶權限下操作的,任何命令最好都不要用sudo.

rvm安裝

$ curl -L get.rvm.io | bash -s stable
$ source ~/.bashrc
$ source ~/.bash_profile

修改 RVM 的 Ruby 安裝源到國內的?淘寶鏡像服務器,這樣能提高安裝速度

$ sed -i -e 's/ftp\.ruby-lang\.org\/pub\/ruby/ruby\.taobao\.org\/mirrors\/ruby/g' ~/.rvm/config/db

ruby的安裝與切換

  • 列出已知的ruby版本
rvm list known
  • 安裝一個ruby版本
rvm install 1.9.3

這里安裝了最新的1.9.3,?rvm list known列表里面的都可以拿來安裝。

  • 使用一個ruby版本
rvm use 1.9.3

如果想設置為默認版本,可以這樣

rvm use 1.9.3 --default?
  • 查詢已經安裝的ruby
rvm list
  • 卸載一個已安裝版本
rvm remove 1.9.2

gemset的使用

rvm不僅可以提供一個多ruby版本共存的環境,還可以根據項目管理不同的gemset.

gemset可以理解為是一個獨立的虛擬gem環境,每一個gemset都是相互獨立的。

比如你有兩個項目,一個是rails 2.3 一個是 rails 3. gemset可以幫你便捷的建立兩套gem開發環境,并且方便的切換。

gemset是附加在ruby語言版本下面的,例如你用了1.9.2, 建立了一個叫rails3的gemset,當切換到1.8.7的時候,rails3這個gemset并不存在。

  • 建立gemset
rvm use 1.8.7
rvm gemset create rails23
  • 然后可以設定已建立的gemset做為當前環境

use 可以用來切換語言,或者gemset,前提是他們已經被安裝(或者建立)。并可以在list命令中看到。

rvm use 1.8.7
rvm use 1.8.7@rails23

然后所有安裝的gem都是安裝在這個gemset之下。

  • 列出當前ruby的gemset
rvm gemset list
  • 清空gemset中的gem

如果你想清空一個gemset的所有gem,想重新安裝所有gem,可以這樣

rvm gemset empty 1.8.7@rails23
  • 刪除一個gemset
rvm gemset delete rails2-3

項目自動加載gemset

rvm還可以自動加載gemset.

例如我們有一個rails3.1.3項目,需要1.9.3版本ruby.整個流程可以這樣。

rvm install 1.9.3
rvm use 1.9.3
rvm gemset create rails313
rvm use 1.9.3@rails313

下面進入到項目目錄,建立一個.rvmrc文件。

在這個文件里可以很簡單的加一個命令:

rvm use 1.9.3@rails313

然后無論你當前ruby設置是什么,cd到這個項目的時候,rvm會幫你加載 ruby 1.9.3和rails313 gemset.

使用rvm來快速部署nginx+passenger

*首先安裝passenger

gem install passenger

然后使用passenger-install-nginx-module 來安裝nginx和部署。

因為這一步需要root權限(因為要編譯nginx)可以用rvmsudo這個東西。(這個東西真是個好東西)

rvmsudo passenger-install-nginx-module

然后會讓你選擇是下載nginx源碼自動編譯安裝,還是自己選擇nginx源碼位置。

選擇nginx手動安裝的可以添加別的編譯參數,方便自定義編譯nginx。

然后一路下載安裝。默認的安裝位置為/opt/nginx.

然后看看nginx.conf,都給你配置好了,只需要加上root位置(yourapp/public)就可以了。

當我第一次安裝完成了,就驚呼,這也太爽了吧。

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

?

RubyGems 鏡像 - 淘寶網

為什么有這個?

由于國內網絡原因(你懂的),導致?rubygems.org?存放在 Amazon S3 上面的資源文件間歇性連接失敗。所以你會與遇到?gem install rack?或?bundle install?的時候半天沒有響應,具體可以用?gem install rails -V來查看執行過程。

這是一個完整 rubygems.org 鏡像,你可以用此代替官方版本,同步頻率目前為15分鐘一次以保證盡量與官方服務同步。
如何使用?
$ gem sources --remove https://rubygems.org/
$ gem sources -a http://ruby.taobao.org/
$ gem sources -l
*** CURRENT SOURCES ***http://ruby.taobao.org
# 請確保只有 ruby.taobao.org
$ gem install rails
如果你是用 Bundle (Rails 項目)
source 'http://ruby.taobao.org/'
gem 'rails', '3.2.12' ...
Ruby 源代碼下載
  • ruby-2.0.0-p247.tar.gz
  • ruby-1.9.3-p448.tar.gz
  • ruby-1.9.2-p320.tar.gz
  • ruby-1.8.7-p358.tar.gz
RVM 改用本站作為下載源, 提高 Ruby 安裝速度
For Mac
$ sed -i .bak 's!ftp.ruby-lang.org/pub/ruby!ruby.taobao.org/mirrors/ruby!' $rvm_path/config/db
For Linux
$ sed -i 's!ftp.ruby-lang.org/pub/ruby!ruby.taobao.org/mirrors/ruby!' $rvm_path/config/db

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

?

https://github.com/saberma/vimfiles

?

介紹

?

這是經典的vim on rails開發工具

安裝

請確保您已經安裝了git-core,vim-7.2,ruby,rvm

sudo apt-get install exuberant-ctags ncurses-term vim-noxgit clone git://github.com/saberma/vimfiles.git ~/.vim#初始化插件
cd ~/.vim
git submodule init
git submodule update
ln -s ~/.vim/vimrc ~/.vimrccd ~/.vim/bundle/Command-T/ruby/command-t
#一定要先切換回ruby1.8.7,否則vim會報錯:Vim: Caught deadly signal SEGV
rvm system
ruby extconf.rb
make
rvm default

注意

最新版本的rails vimfiles已經不再使用fuzzy_finder實現快速打開文件的功能,而改用CommandT
其快捷鍵也由原來的ctrl + t 改為 leader + t,leader鍵即\鍵

外部新增文件后,CommandT列表中看不到時,需要手動輸入:CommandTFlush,刷新緩存

升級

2011.08.19已升級至最新版本,手動升級方法如下:

cd ~/.vim
git remote add akitaonrails git://github.com/akitaonrails/vimfiles.git
git pull akitaonrails master
git submodule foreach git pull

參考資源

使用說明參考這里

以下為akitaonrails原版詳細說明:

Vim

It is recommended that you use gVim in either Windows or Linux and MacVim for
Mac. Download from:

  • (Windows)?http://www.vim.org/download.php#pc?(gvim73_46.exe)
  • (Mac)?https://github.com/b4winckler/macvim/downloads?(snapshot-56)

Bundled Plugins

  • Ack?– type :Ack [search pattern] to search your entire project
  • Align?– align blocks of text using equal sign, make comment boxes and more
  • bufexplorer?– manage your file buffers
  • Command-T?– the fastest and most intuitive way for opening files in your project
  • cucumber?– support for cucumber features such as syntax highlight, indentation, etc
  • endwise?– support to close Ruby blocks such as ‘if’, ‘do’ with ‘end’
  • fugitive?– support for Git, adding convenient commands such as :Gstatus, :Gread, :Gmove
  • haml?– syntax highlight for HAML
  • html5.vim?– omnicomplete function and syntax for HTML5
  • markdown?– syntax highlight for Markdown
  • NERD_commenter?– support to comment lines of code
  • NERD_tree?– project pane that you can open with [leader] p
  • ragtag?– easier way to create tags for html, erb, etc
  • rails?– lot’s of tools to make it easier to manage your Rails projects
  • snipmate?– support for textmate-like snippets for several languages
  • supertab?– pseudo auto-complete with tab
  • surround?– add, change, remove surrounding parentheses, brackets, quotes, etc
  • syntastic?– checks for syntax errors in many languages
  • textile?– syntax highlight for Textile
  • vim-coffee-script?– syntax highlight for Coffee Script
  • vim-jade?– Vim syntax highlighting for the Jade templating engine
  • vim-jquery?– Vim syntax file to add some colorations for jQuery keywords and css selectors
  • vim-preview?– [leader] P previews Markdown, Rdoc, Textile, html. Requires Ruby and other gems.
  • vim-ruby-sinatra?– syntax highlight for Sinatra
  • vim-ruby?– syntax highlight, smart identation, auto-complete for Ruby
  • vim-textobj-rubyblock?– smart block selection in Ruby code
  • vividchalk?– color scheme inspired by the classic Vibrant for Textmate
  • Zencoding?– powerful way for HTML abbreviations (learn here:?http://code.google.com/p/zen-coding/). Type abbreviation and press Ctrl+Y+comma (c-y ,)

Usage

Troubleshoot: Because of the large amount of submodules, if you ever have any
trouble after pulling from the repository, it will be easier to just back up
your old .vim folder and just git clone a new version.

Clone this repo into your home directory either as .vim (linux/mac) or
vimfiles (Windows). Such as:


git clone git://github.com/akitaonrails/vimfiles.git ~/.vim

Then ‘cd’ into the repo and run this to get the snippets submodule:


git submodule update --init

Now you should create a new?.vimrc?file in your home directory that
loads the pre-configured one that comes bundled in this package. You can do it
on Linux/Mac like this:


echo "source ~/.vim/vimrc" > ~/.vimrc

On Windows you should create a?_vimrc?(underline instead of dot) and add
the following line inside:


source ~/vimfiles/vimrc

This way you can override the default configuration by adding your own inside
this file.

You should also create a new?.gvimrc?file in your home directory. You can do
it on Linux/Mac like this:


echo "source ~/.vim/gvimrc" > ~/.gvimrc

On Windows you should create a?_gvimrc?(underline instead of dot) and add
the following line inside:


source ~/vimfiles/gvimrc

This way you can override the default GUI configuration by adding your own inside
this file.

Help Tags

At first usage of vim, type “:” while in command mode and execute:

call pathogen#helptags()

This will make the plugins documentations available upon :help

Dependencies

You will need these dependencies figured out:

  • Ruby (for the fuzzy finder plugin)
  • Exuberant Ctags (http://ctags.sourceforge.net/)
  • Ncurses-term (in Linux only)

In Ubuntu, for example, you will have to do:


apt-get install exuberant-ctags ncurses-term

In OS X, you can install ctags with homebrew


brew install ctags

On Windows you have to download Ctags and add ctags.exe in your PATH.

Mac OS X and most Linux distros come with Ruby already. If you’re in Windows
look for Luis Lavena’s latest Ruby Installer (http://rubyforge.org/projects/rubyinstaller/)

IMPORTANT: Command-T

The latest version replaces the old Fuzzy Finder with a new one called
“Command-T” form wincent.com. I’ve replaced the old “Command-T” key
binding that used to open new tabs and assigned it to this new plugin
so it behaves the same as Textmate.

You may have problems in Mac/Linux because this plugin requires a native
extension, so you will have to do this:


rvm use system # use this line if using rvm
cd ~/.vim/bundle/Command-T/ruby/command-t
ruby extconf.rb
make

This means that you need to have your Ruby source files and GCC also
installed. A binary for Windows is already bundled so it should just
work. I’ve also included a binary compiled for Ruby Enterprise Edition,
but if you are using other Ruby distros, you will need to recompile.

There are binaries for Mac and Windows. The Mac version is compiled
against the default system Ruby for Mac OS X 10.6.5. The Windows version
is compiled against Ruby Installer 1.8.7-p330.

Ubuntu 11.04 and/or Vim 7.3.35

Ubuntu 11.04 comes bundled with Vim 7.3.35, which has “flaky” Ruby support.
Even if you do everything right, you might see the following crashes when
trying to use Command-T:


Vim: Caught deadly signal SEGV
Vim: Finished.Segmentation fault

If this happens to you, update Vim to 7.3.154:


hg clone https://vim.googlecode.com/hg/ ~/vim
cd ~/vim
hg update -C v7-3-154
./configure --enable-rubyinterp
make
sudo make install

More details can be found?here

Learn Vim

Visit the following sites to learn more about Vim:

  • http://vimcasts.org

There are many sites teaching Vim, if you know of any other that are easy
to follow for newcomers, let me know.

Credits

  • Original project and most of the heavy lifting: @scrooloose
  • All the cool plugins for Rails, Cucumber and more: @timpope
  • Great Command-T plugin by: Wincent
  • Hacks and some snippets: @akitaonrails

--------------------------------------------------------------------------------------------

Installing Prebuilt Binaries with RVM

Originally posted 2012-12-21.

I've been working with a lot of virtual machines lately, and using RVM to install the version of ruby I need took longer than installing the base system. If you go through the motions of?rvm install {VERSION}, you might just gloss over this message:

No binary rubies available for: ubuntu/12.04/x86_64/{VERSION}.

Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.

Not reading the documentation for?rvm mount?might end up costing you a lot of time.

RVM Prepare

RVM has a list of premade binaries that it will download if it gets the chance - you can see the list in/usr/local/rvm/config/remote?or?on github?(I used a system-wide RVM install for this. Your path may be ~/.rvm/config/remote). For binaries that don't exist in that list, there's the option of packaging your own.

I'll be assuming that we're building a 2.0.0-preview2 binary, using a server you can scp files to, which is also accessable at?http://artifacts.corp/binaries/

rvm install 2.0.0-preview2 rvm prepare 2.0.0-preview2 --install -r artifacts.corp:/var/www/binaries/

The?rvm prepare?command should have made a file called?ruby-2.0.0-preview2.tar.bz2?in your current directory, and output something like the following.

--- upload:
ssh "artifacts.corp" "mkdir -p /var/www/binaries//ubuntu/12.04/x86_64/" scp "ruby-2.0.0-preview2.tar.bz2" "artifacts.corp:/var/www/binaries//ubuntu/12.04/x86_64/ruby-2.0.0-preview2.tar.bz2"

RVM rightly cares quite a bit about the OS that the build will be installed on, and?strongly?recommends that you follow the naming convention seen in that output as a way to organize and name your builds. Once those commands are run and the file is uploaded, we'll be ready for the next time that we need to install 2.0.0-preview2 on this OS.

RVM Mount

There are two ways to download premade binaries -?rvm install {name}, which uses the list of prebuilt binaries if possible, or?rvm mount -r {URI}. The former works with data from configuration files, while the latter works using just command line parameters. Let's install our Ruby using mount first, since it takes fewer steps:

rvm mount -r http://artifacts.corp/binaries//ubuntu/12.04/x86_64/ruby-2.0.0-preview2.tar.bz2 --verify-downloads 1

On the VM I tested this with,?rvm mount?takes 12 seconds, while?rvm install?takes 4 minutes. Of course, there's that?verify-downloads?flag and the lists of prebuilt binaries left to explain..

RVM Remote

As mentioned above, RVM has a list of prebuilt binaries for different platforms that it can download. In addition to the file (on ubuntu) at?/usr/local/rvm/config/remote, RVM will also use/usr/local/rvm/users/remote, if present. You can see the rubies that RVM can download as binaries for your system with?rvm list remote

# Rubies available for 'ubuntu/12.04/x86_64':rbx-2.0.0-rc1 ruby-1.9.3-p194 ruby-1.9.3-p286 ruby-1.9.3-p327

If we add the URL to our precompiled 2.0.0-preview2 binary to?/usr/local/rvm/users/remote, it will show up in that list.

root$ echo "http://artifacts.corp/binaries//ubuntu/12.04/x86_64/ruby-2.0.0-preview2.tar.bz2" >> /usr/local/rvm/user/remote root$ rvm list remote # Rubies available for 'ubuntu/12.04/x86_64': rbx-2.0.0-rc1 ruby-1.9.3-p194 ruby-1.9.3-p286 ruby-1.9.3-p327 ruby-2.0.0-preview2

For this bit, there is every chance that I am missing, or misunderstanding, something. This may not be the best or right way to do things

Even though it shows up in the remote list, we still have to tell RVM that our server is an acceptable place to download rubies from. We do this by adding it to another textfile.

echo "rvm_remote_server_url=http://artifacts.corp/" >> /usr/local/rvm/user/db

Checksums

At this point, if you try?rvm install 2.0.0-preview2?you would get an error message about checksums not matchng. With RVM's mount we used the?--verify-downloads?flag, which saves checksums of the file we download after the fact. Using that same flag,?rvm install 2.0.0-preview2 --verify-downloads 1, will download and install the package correctly.

If however, you want to have RVM to use checksums to verify the download was successful, we can refer way back to the rest of the output from our?rvm prepare?command:

--- rvm/config/md5: http://artifacts.corp/binaries/ruby-2.0.0-preview2.tar.bz2=fdb22cbad861616f5e3b56f0e3d976be --- rvm/config/sha512: http://artifacts.corp/binaries/ruby-2.0.0-preview2.tar.bz2=eb1972575cee09b0de59f39815b2f9992366cd6aaf3e32ab214d39b054029cf904260933e8b2fa101c7b5eb548d013e0e05c09d3e93dbc97a1ae55789d6a046b

And add those lines to our?user/*?files

echo "http://artifacts.corp/binaries/ubuntu/12.04/x86_64/ruby-2.0.0-preview2.tar.bz2=eb1972575cee09b0de59f39815b2f9992366cd6aaf3e32ab214d39b054029cf904260933e8b2fa101c7b5eb548d013e0e05c09d3e93dbc97a1ae55789d6a046b" >> /usr/local/rvm/user/sha512 echo "http://artifacts.corp/binaries/ubuntu/12.04/x86_64/ruby-2.0.0-preview2.tar.bz2=fdb22cbad861616f5e3b56f0e3d976be" >> /usr/local/rvm/user/md5

Now,?rvm install 2.0.0-preview2?will download a prebuilt binary from a server of your choosing, as well as verify that the checksum is the same as the package you built at the very beginning.

Phew.

轉載于:https://www.cnblogs.com/code-changeworld/p/4775899.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/375574.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/375574.shtml
英文地址,請注明出處:http://en.pswp.cn/news/375574.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Symfony2 EventDispatcher組件

一個插件系統中,A插件在不影響其它插件的前提下,添加新的方法,或者在一個方法運行前做一些準備工作,通過繼承來實現擴展是很不容易的,由于插件之間的關聯關系,A插件的改變也會使得關聯的插件被動的修改。Sy…

【轉】漫談ANN(2):BP神經網絡

上一次我們講了M-P模型,它實際上就是對單個神經元的一種建模,還不足以模擬人腦神經系統的功能。由這些人工神經元構建出來的網絡,才能夠具有學習、聯想、記憶和模式識別的能力。BP網絡就是一種簡單的人工神經網絡。我們的第二話就從BP神經網絡…

給定一個值S,在有序數組中找出兩個元素A和B,使 A+B = S.

在網上看到過一個面試題,感覺挺有意思,看別人的代碼寫的邏輯不夠謹慎,重寫了一個,較真了又。。。 package com.array7.algorithm;public class AlgorithmTest {public static void main(String[] args) {int[] arr {2 ,4 ,5 ,8 ,…

二叉樹的最小深度

給定一個二叉樹,找出其最小深度。 最小深度是從根節點到最近葉子節點的最短路徑上的節點數量。 說明: 葉子節點是指沒有子節點的節點。 示例: 給定二叉樹[3,9,20,null,null,15,7] 3/ \9 20/ \15 7返回它的最小深度 2. c 廣度優先 /*** Definition for a b…

(轉)會議期刊論文發表介紹(計算機科學領域)

轉自:http://blog.csdn.net/babyfacer/archive/2009/07/25/4377552.aspx 一、計算機科學期刊介紹計算機科學的publication最大特點在于:極度重視會議,而期刊則通常只用來做re- publication。大部分期刊文章都是會議論文的擴展版,首…

笑男手札:SharePoint 2013 單一服務器場環境恢復數據庫內容

SharePoint 2013 單一服務器場環境恢復數據庫內容 笑男的公司服務很多客戶,當然,這些客戶都很挑剔,所以一般情況下生產(Prod)環境的服務是不能停的。 當然,如果你將包含相同網站集的數據庫連接到同一個服務…

數組中數字出現的次數

一個整型數組 nums 里除兩個數字之外,其他數字都出現了兩次。請寫程序找出這兩個只出現一次的數字。要求時間復雜度是O(n),空間復雜度是O(1)。 示例 1: 輸入:nums [4,1,4,6] 輸出:[1,6] 或 [6,1]示例 2:…

【轉】String Date Calendar之間的轉換

1.Calendar 轉化 String Calendar calendat Calendar.getInstance(); SimpleDateFormat sdf new SimpleDateFormat("yyyy-MM-dd"); String dateStr sdf.format(calendar.getTime()); 2.String 轉化Calendar String str"2012-5-27"; SimpleDateFormat sd…

圖解 深入淺出 JavaWeb:Servlet 再說幾句

Writer :BYSocket(泥沙磚瓦漿木匠) 微 博:BYSocket 豆 瓣:BYSocket FaceBook:BYSocket Twitter :BYSocket 上一篇的《 Servlet必會必知 》受到大家一致好評 — (感謝 讀…

react.js 從零開始(五)React 中事件的用法

事件系統 虛擬事件對象 事件處理器將會傳入虛擬事件對象的實例,一個對瀏覽器本地事件的跨瀏覽器封裝。它有和瀏覽器本地事件相同的屬性和方法,包括 stopPropagation() 和 preventDefault(),但是沒有瀏覽器兼容問題。 如果因為一些因素&#x…

乘積的最大子數組

給你一個整數數組 nums ,請你找出數組中乘積最大的連續子數組(該子數組中至少包含一個數字),并返回該子數組所對應的乘積。 示例 1: 輸入: [2,3,-2,4] 輸出: 6 解釋: 子數組 [2,3] 有最大乘積 6。示例 2: 輸入: [-2,0,-1] 輸出…

javascript new

1. 僅function可以使用new 2. function使用new時,會拷貝function中this的內容給新對象,并將function的prototype指向新對象(如果該function沒有prototype,則指向Object的prototype) 注:function本身不是Obj…

!+\v1 用來“判斷瀏覽器類型”還是用來“IE判斷版本”的問題!

這種寫法是利用各瀏覽器對轉義字符"\v"的理解不同來判斷瀏覽器類型。在IE中,"\v"沒有轉義,得到的結果為"v"。而在其他瀏覽器中"\v"表示一個垂直制表符,所以ie解析的"\v1" 為 "v1&quo…

三個數的最大乘積

給定一個整型數組,在數組中找出由三個數組成的最大乘積,并輸出這個乘積。 示例 1: 輸入: [1,2,3] 輸出: 6示例 2: 輸入: [1,2,3,4] 輸出: 24注意: 給定的整型數組長度范圍是[3,104],數組中所有的元素范圍是[-1000, 1000]。 輸入的數組中任…

VB.NET 數組的定義 動態使用 多維數組

我們都知道在全部程序設計語言中數組都是一個非常重要的概念,數組的作用是同意程序猿用同一個名稱來引用多個變量,因此採用數組索引來區分這些變量。非常多情況下利用數組索引來設置一個循環,這樣就能夠高效地處理復雜的情況,因此…

web.xml 中的listener、 filter、servlet 加載順序

1:首先是context-param節點 2:接著配置和調用listeners 并開始監聽 3:然后配置和調用filters filters開始起作用 4:最后加載和初始化配置在load on startup的servlets轉載于:https://www.cnblogs.com/dwchenxj/p/4787717.html

這么多個月,我頭一次體驗用類的概念來寫驅動

原來感覺一樣是那么爽阿。。。快樂得不得了。。。轉載于:https://www.cnblogs.com/suanguade/p/4038190.html

設置Chrome忽略網站證書錯誤

本人在XP下使用Chrome。總是莫名其妙的提示整數錯誤,一部分https網站無法直接訪問。網上找了下,把解決思路記錄下來。 解決這個問題很簡單,只需要修改你平時用來啟動Chrome的快捷方式就可以忽略掉證書錯誤. 具體的操作方法是這樣的: 找到你的Chrome快捷方…

Android開發之合并文件的幾種方式

以下介紹合并文件的幾種方式,并通過合并amr文件來舉例介紹合并文件的詳細流程。amr格式的文件頭是6字節,所以在進行文件合并的時候要減去除第一個文件以外的其它文件的文件頭。 注意:不同文件的文件頭是不一樣的,所以在合并的時候…

數組中出現次數超過一半的數

數組中有一個數字出現的次數超過數組長度的一半&#xff0c;請找出這個數字。 你可以假設數組是非空的&#xff0c;并且給定的數組總是存在多數元素。 示例 1: 輸入: [1, 2, 3, 2, 2, 2, 5, 4, 2] 輸出: 2限制&#xff1a; 1 < 數組長度 < 50000class Solution { pub…