Archive

Archive for the ‘Beyond’ Category

Built-in web server python 3.x

December 11, 2017 Leave a comment

python -m http.server [portNo]
Advertisements

re-clone git

December 7, 2017 Leave a comment

GIT=$(git rev-parse --show-toplevel)
cd $GIT/..
rm -rf $GIT
git clone ...

Categories: Beyond, git

Built-in web server python 2.7

October 18, 2017 Leave a comment

The next command helps you to create a simple http server to test anything fast, or use that location and their resources with a different port.
Just navigate in the command line to the location and type the next:

python -m SimpleHTTPServer [port]
Categories: Beyond, Mini-tips, Python, Tips

Fixing: Error: Couldn’t find preset “latest” relative to directory

July 22, 2017 Leave a comment

Add the babel-preset-latest to the node_modules of the project directory with –save-dev option, in example:
npm install –save-dev babel-preset-latest

PD. This issue came up when configuring webpack on a project recently created from scratch, and configured the babel-loader with the latest as preset.

Command npm to check for installed packages

July 22, 2017 Leave a comment

npm list -g –depth=0

CodeFights MZbot AllianceVsMonster – Ruby

June 7, 2017 Leave a comment
def allianceVersusMonster hp, ad
    mHp = hp[0]
    mAd = ad[0]
    turns = []
    size = hp.size - 1
    (1...ad.size).each do |x|
        turns <= mAd && cHp >= mHp
        timesToDie = ( mHp / cAd.to_f).ceil
        timesIDie = ( cHp / mAd.to_f).ceil
        return size if timesIDie >= timesToDie
        mHp -= (timesIDie - 1) * cAd 
        w[1] = cHp % mAd + 1
    end
    
    #fight until dead
    turns.each do |w|
        cAd, cHp = w
        return size if cAd >= mAd && cHp >= mHp       
        while cHp > 0 && mHp > 0
            mHp -= cAd
            return size if mHp <= 0
            cHp -= mAd
        end
        size -= 1
    end
    0
end

Total Hamming Distance – Leetcode #Golang #Go

January 3, 2017 Leave a comment
func totalHammingDistance(nums []int) int {
    res := 0
    for i, len := uint(0), len(nums); i < 32; i++ {
         ones := 0
         for _,val := range nums {
             if val >> i & 1 == 1 {
                ones++
            }
        }
        if ones > 0 {
            res += ones * (len - ones)
        }
    }
    return res
}
Categories: Beyond, Golang, leetcode