Worst Financial year ever

Everything I touch turned to dust this year. I’m still on my anti-depressant medication because otherwise I would have killed myself by now. Seriously. Let’s count the ways.

-in Jan, Korea had the crypto premium at 40%. I didn’t make use of the crypto account my gf made for me, and the premium is now completely gone.
-In Jan, I had a gain of 50k on my crypto. I didn’t sell or take profits. Now I’m down 170k. That’s a swing of 220k. +50 to -170.
-In Feb, the only ICO I invested in last year at $1.10 each debuted at $4 each. I could have sold right then and there and took $30k profit but of course I didn’t. I kept holding, and now this month I sold it at $0.90 each. Yup, I lost $2k when I could have been up $30k.
-In Jan/Feb I invested in a lot of stupid risky ICOs – over 20 of them. I thought if even ONE of them did a 10x I could make up for the other ones. Nope, turned out ALL of them except two went down 80-90% and the two that made me money only went up 50%. That hardly makes up for my losses. I’m down 37 ETH on that.
-In Jan/Feb I took out 3 loans to average down for a total of 85k + 5k in origination fees/interest. And… the market went down 70% since then. So yeah, that was stupid as well.
-I sold off all my stocks at the beginning of the year to put all into crypto. The AMZN/TSLA/NVDA stocks I sold subsequently went up 50%+ and crypto went down 70%. FML.
-In Apr/May I got scammed 1.5ETH by people pretending to be admins on telegram.
-In Apr I lost $2300 shipping a package because I didn’t use the USPS Priority mail and it didn’t have tracking to Canada. Buyer complained, I had to pay it back since I had no way of proving it was delivered.
-Worst timing ever. I sell EOS and ETC, a few days later it goes up 20%. I sell BITG literally the next day it jumps up by 50%. Why? why does this happen to me?
-In June I put a lot of my money into masternode coins to try and stabilize. I sold off a lot of coins at the bottom because I wanted to make some stable income. Well guess what, those coins are up 30-40% now, and my masternode coins are down 70%. Of course. One of them even went down 90%. I lost over 2 BTC on those. Even when I am trying to stabilize I end up losing money.
-In June when I was trying to get my place renovated, the movers lost my $1000 camera. Seriously, wtf? I can’t even get something as simple as moving my items done without losing money???

So yeah (and don’t forget my gf broke up with me early in the year, my job gets more and more tedious and I’m on meds now) this is easily the most horrible year I’ve had in recent memory. Please, please let this year end soon. Last year was boring but I was at least steadily gaining money. This year, 1/3rd of my net worth is gone, and everything I try to do to get it back only loses me more money. What is happening to me? I must be the anti-Midas touch. I even lost my friends money as I got them into the same masternode coins. My only saving grace is I really hope my apartment sells for above market value to at least make back for some of my losses…


XML entity escaping in Freemarker and Looping issues

Thanks to my friend Chris Brelski for this trick. There are two ways to escape XML entities in Freemarker.


<#assign xmlEscape="freemarker.template.utility.XmlEscape"?new()>
<#-- Use a custom directive: -->
<@xmlEscape> ${variable} 


<#-- escape XML entities in output: -->
<#assign c="${category}">
<#escape c as c?xml>

In both these cases, there’s no need to modify Java files, and will convert & to


with proper encoding, etc.

Issues with Freemarker looping

I’ve been having lots of issues with looping in freemarker. Freemarker only has one basic loop, the collection loop which uses [#list] to iterate.
The List API reference only gives you two variables with this loop: list_index and list_has_next.
The problem is that if this were a true iterator, it should provide a next() method to provide the next iteration.
Say, you have some markup like this:

[#list data.outerInputContainer as inputContainers]
[#list inputContainers as innerInputContainer] [some freemarker macro that generates some markup here] [/#list]

So the backing Java object is a list of lists (the outer one called outerInputContainer and the inner one called innerInputContainer), and each inner list contains some input (radio input, select input, text input etc). In this situation, I want to bundle these inputs together into a group, so the List can be generic like


, where BaseInput is the superclass of radio, select, text input. So the list of lists look like this:


We know, the order is always going to be Radio, Select, Text because the Java method always inserts the BaseInputs into the list in that order. However in Freemarker, since there’s no next() method, each iteration cannot be controlled. That means there’s no way to customize specific markup for radio, select or text. Instead, I have to put a generic container outside of those inputs. What I want to have is a way to customize:

[#list data.outerInputContainer as inputContainers] [#list inputContainers as innerInputContainer] [#if innerInputContainer.type = radio input] [some freemarker macro that generates some radio specific markup here] [/#if] [#if innerInputContainer.type = select input] [some freemarker macro that generates some select specific markup here] [/#if] [#if innerInputContainer.type = text input] [some freemarker macro that generates some text specific markup here] [/#if] [/#list] [/#list]

So I can either use conditionals here to get the type of input specific markup I want, if the iterator provides that. I don’t think Freemarker will like equals operator with custom objects, so I’ll probably have to create a method and delegate that to Java to return true or false. If Freemarker provided a next() method for list like iterator interfaces are supposed to do, then I can do all this logic in Freemarker, not Java. Or I have to put a generic container over all these inputs.

Anyways, there’s no way to modify the index like in a for loop with Freemarker, and so accessing a specific element of the list at List[i] is not really possible. I don’t like this inflexibility and I’m sure there’s a better way to do this. Feel free to comment if you’re a freemarker guru.

You can access specific elements of a freemarker list using array index access instead of using an iterator:


Issues with HTTP Referrer and Redirection

You learn something new everyday, and of course I’ve learned many new things during the course of my work. One of them involves the HTTP referrer. So the HTTP referrer is the url of the page that linked to webpage. You can get the HTTP referrer by using document.referer in JavaScript. This is useful if you are conditionally handling people who come from different sites differently. For example, if I wanted to redirect people who come via Google search results to a Google page, and people who come via Yahoo search results to a Yahoo page.

The main issues with using the referer address is that its not reliable, and using document.referer, cgi.http_referer, and the browser you are using can all yield different results, especially when combined with redirection.
1) When you open up a new tab, or go to a website using a bookmark, the HTTP referer is blank.
2) When you use the back button on a browser, the HTTP referer does not catch the url of the website you were just on.
3) If you use JavaScript’s


to redirect to a page, IE 7 and 8 will not get the HTTP referer. This has to due with how Internet Explorer gets its referers, which is defined as the origin of the page. If you use IE 9 emulating IE 7/8, you will not find this issue.
4) If you use coldfusion or meta refresh


to redirect to a page, Browsers other than Google Chrome will not catch the HTTP referer.

As you can imagine, this was a nightmare to test, and I had to get around this, especially the IE7/8 issue, by creating a form dynamically using JS, and setting hidden input fields to the param values you want, then submit it in order for IE 7/8 to catch the proper referrer. It’s a little bit digusting, but that’s what happens when you have to make something work on all browsers (don’t get me started on IE6). In the future, a more preferred way of redirection is to have the server send an HTTP 302 error code instead which can be caught in most browsers without issue, avoiding domain specific language to do the redirection. This might be a more reliable way of getting the HTTP header and referrer too.