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/

Tuesday, September 20, 2016

Remove iptables rule

I recently had to fool around with IP tables in one of our web instances, and I found this SO link useful. So here it is for everyone (read: myself).

 This happened because Ubuntu had updated some packages and there was a message telling me to restart the instance when I logged in last week. So I foolishly did. As a result, PostgreSQL was broken (/var/run/something was deleted and it took my colleague a good 30 minutes to find that out). And suddenly our Tomcat application wasn't working.


  1. https://my.application.com was timing out.
  2. so was http://my.application.com
  3. But the our direct IP http://123.12.123.12:8080 was working. 
  4. BUT the direct IP http://123.12.123.12:80 wasn't!
  5. Nginx logs were not logging anything at all.
  6. Checking Amazon AWS, I confirmed that both 80 and 8080 were "allowed".

So there's got to be something between AWS and nginx that was blocking port 80, and allowing port 8080. Which was something no human would do.

So I did something I've never had to do before: check iptables. And sure enough I found the below:


So here's the steps I took to wipe out all those rules.
iptables -L INPUT --line-numbers
iptables -D INPUT 5
iptables-save > /etc/iptables/rules.v4

The 2nd line was done a couple of times to remove all the iptables lines.
The last line was so that each time the instance was restarted, the rules would be the same. The rules might be stored in a different file. Check your local distro for details.



Wednesday, September 23, 2015

Resistance Avalon role "assigner"

First select number of players:

  • Merlin
  • Percival
  • Mordred
  • Oberon
  • Morgana (requires Percival)

Number of players

Next shuffle the deck

Then reveal the secret role to 1 player at a time.









Percival - good
Percival's special power is knowledge of Merlin at the start of the game. Using Percival's knowledge wisely is key to protecting Merlin's identity. Adding Percival into the game will make the Good side more powerful.

Mordred - Evil
Mordred's special power is that identity is not revealed to Merlin at the start of the game. Adding Mordred will make the Evil side more powerful.

Oberon - Evil
Oberon's power is that he does not reveal himself to other evil players, and he doesn't know of the other evil players. Merlin does know who Oberon is. Adding Oberon will make the Good side more powerful.

Morgana - Evil
Morgana's special power is she appears to be Merlin. She reveals herself to Percival as Merlin (Percival must be in play). Adding Morgana will make the Evil side more powerful.

Friday, September 11, 2015

The Resistance Reference card

The Resistance board game voting application

The Resistance board game can be played without buying the actual game itself. You just need some cards, and you specify which cards are the resistance and which are the traitors. I wrote a little Javascript here to keep a secret count of the votes. Everyone just goes around voting. And after everyone votes, you just click Show Results, and you see if the mission passes or fails.
Number of votes =