Tuesday, August 29, 2017

I created a NodeJS project in GitHub so I wouldn't have to keep writing boiler plate code. It uses

  • Node
  • Express
  • Webpack
  • Angular 1.x
  • Angular UI Router
No unit tests were included in this seed project (yet).

Hope it helps. 

Monday, July 24, 2017

Sparse Numbers

I just completed my Codility test, and one of my solutions ran slowly. Unfortunately, I am unable to find out where the bottleneck might be (its hard to cover all possible test cases within a limited time).

But I think it might be the way I get the next sparse number. My Java implementation is below.



    /**
     *
     * @param i assume i to be sparse.
     * @return
     */
    private int getNextSparse(int i) {

        int mask = 0b11;
        int shift = 0;
        while ((i & (mask << shift)) != 0) {
            shift++;
        }

        return (i & (0b11111111_11111111_11111111_11111111 << shift)) | (1 << shift);
    }


I hope to have a YouTube video out to explain all the above soon. (edit: the YouTube vide is here)

Codility Lessons

Recently I've had to do a Codility (www.codility.com/programmers/) test while applying for a job. It seems to be a pretty popular website (I just been told to do another test today!).

So before I did the test, I tried some of the Tasks in their Lessons, and they were pretty fun. So I'm going to try some of the more interesting looking tasks. I've posted my solutions to GitHub (here) and YouTube (here).

Obviously this is a work in progress, but I'll try to post as many of my solutions as possible.




Monday, May 22, 2017

Spring MVC's ArgumentResolver


Recently a colleague introduced to me the concept of an ArgumentResolver.

In theory, with an ArgumentResolver, one can inject anything into a Spring MVC Controller. They are usually injected as arguments (aka parameters) in the Controller's methods.



So first in the XML configuration we do the below:


    <mvc:annotation-driven>
        <mvc:argument-resolvers>
            <bean class="com.mycompany.ArgumentResolver"></bean>
        </mvc:argument-resolvers>
    </mvc:annotation-driven>



Then we implement the class itself:

import org.springframework.core.MethodParameter;
import org.springframework.web.method.support.ModelAndViewContainer;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;

public class ArgumentResolver implements HandlerMethodArgumentResolver {
    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return parameter.getParameterType().equals(MyClass.class);
    }

    @Override
    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

        // do what you need to return the Argument
        
    }
}




Friday, February 10, 2017

An OpenSSL helper

And by that I mean an 'openssl' command line helper. I normally use openssl to create my CSRs and I always have to look up the command line options. Here is a tool that helps me (especially with my very limited use case).

https://www.digicert.com/easy-csr/openssl.htm

It creates the command command to use with 'openssl' so I don't have to keep checking. Thanks Digicert! If I had my way, I'd use your services, just for this one tool alone.

And after I create the CSR, I usually just check that its done correctly (I don't know why, just obsessive I guess). And I normally have to check that too. So here is the command line.

openssl req -in xxxxxxxxxxxxxxx.csr -noout - text

Tuesday, February 7, 2017

Change the screenshots folder in Mac

This actually works!!
http://www.cultofmac.com/419083/how-to-change-where-mac-screenshots-get-saved/