Archive

Archive for the ‘Beyond’ Category

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]
Advertisements
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

Configuration Errors on Spring + Wicket

October 11, 2016 Leave a comment

When facing error:
The matching wildcard is strict, but no declaration can be found for element ‘context:component-scan’.

Remember, is a typo somewhere!

If you face error:
No WebApplicationContext found: no ContextLoaderListener registered?

You need to set manually the applicationContext on the setUp() of your test.


public ServletContext getServletContext() {
                ServletContext sc = super.getServletContext();
                XmlWebApplicationContext appCont = new XmlWebApplicationContext();

                appCont.setConfigLocation("classpath:applicationContext.xml");
                appCont.setServletContext(sc);
                appCont.refresh();
                sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCont);

                return sc;
            }

When error BeanDefinitionStoreException Failed to read candidate component class you got a pom.xml with spring dependencies in conflict.

Categories: Beyond, typo

Split string in sql query – oracle

October 3, 2016 Leave a comment

select regexp_substr('MyString,otherString,lastOneStr','[^,]+', 1, level) from dual
connect by regexp_substr('MyString,otherString,lastOneStr', '[^,]+', 1, level) is not null;

–Result :
———-
–MyString
–otherString
–lastOneStr

Categories: Beyond, Mini-tips, Oracle, SQL