2017-04-18

Fallacy: Process as Proxy

https://www.sec.gov/Archives/edgar/data/1018724/000119312517120198/d373368dex991.htm

Resist Proxies

As companies get larger and more complex, there’s a tendency to manage to proxies. This comes in many shapes and sizes, and it’s dangerous, subtle, and very Day 2.

A common example is process as proxy. Good process serves you so you can serve customers. But if you’re not watchful, the process can become the thing. This can happen very easily in large organizations. The process becomes the proxy for the result you want. You stop looking at outcomes and just make sure you’re doing the process right. Gulp. It’s not that rare to hear a junior leader defend a bad outcome with something like, “Well, we followed the process.” A more experienced leader will use it as an opportunity to investigate and improve the process. The process is not the thing. It’s always worth asking, do we own the process or does the process own us?

2017-03-23

Java: Silence Eclipse's Null Type Safety Warnings Where It Shouldn't

So you just enabled "Null analysis" in Eclipse, and set a reasonable NonNull annotation to confom (ie. javax.validation.constraints.NotNull), also started annotating the relevant methods with it.

But.
When using the new Java 8 Streams API, Eclipse warns inside the functions you toss in, even if you've filtered out the null ones.

I'll give you an example:
// ...inside the Foo class...
public Foo(@NotNull final Bar bar) {
        this.bar = Objects.requireNonNull(bar, "Shame...");
}
// ...inside somewhere completely unrelated...
public Optional<Foo> getFoobarizedBarBaz() {
        return Optional.ofNullable(
                fooService.getBar()
                        .stream()
                                .filter(Objects::nonNull) // yeah, so no nulls, plz
                                .map(bar -> new Foo(bar /* Oh no, yellow underline*/, someLocalValue)
                                .findAny());
}

But oh, the "bar" is underlined, stating "Null type safety: The expression of type 'Bar' needs unchecked conversion to conform to '@NotNull Bar'"...

If only there were a way to resolve that...wait, there is! We can set the type of the formal parameters inside the lambda expression!
// ...inside somewhere completely unrelated...
public Optional<Foo> getFoobarizedBarBaz() {
        return Optional.ofNullable(
                fooService.getBar()
                        .stream()
                                .filter(Objects::nonNull)
                                .map((@NotNull Bar bar) -> new Foo(bar, someLocalValue)
                                .findAny());
}

Formal parameters. PARAMETERS.
@NotNull's @Target annotation includes PARAMETER.
Even it's comment states: "Formal parameter declaration".

Win.

2017-03-17

hosts: Blocking noxious sites effectively

Years ago I found this cool website: http://someonewhocares.org/hosts/

It blocks a lot of sites you don't normally want to visit :)

Also, I have a Hungary-specific compilation of anti-science / russian propaganda / simply dumb sites (and a few USA-specific ones) you don't want to stumble upon:

#<hu-russian-propaganda>
127.0.0.1 888.hu
127.0.0.1 adatlistazo.hu
127.0.0.1 aktiv-blog.net
127.0.0.1 aktivblog.net
127.0.0.1 atomenergiainfo.hu # powered by rosatom :)
127.0.0.1 balrad.com
127.0.0.1 bejegyzes.com
127.0.0.1 civilkontroll.com
127.0.0.1 debmedia.hu
127.0.0.1 elkepeszto.net
127.0.0.1 hidfo.net
127.0.0.1 hidfo.ru
127.0.0.1 hir.club
127.0.0.1 hirado.top
127.0.0.1 hirarena.eu
127.0.0.1 hircentrum.top
127.0.0.1 hirek.in
127.0.0.1 hirek.top
127.0.0.1 hirekonline.net
127.0.0.1 hirexpressz.top
127.0.0.1 hirhatar.hu
127.0.0.1 hirkert.info
127.0.0.1 hirkozpont.eu
127.0.0.1 hirlistazo.com
127.0.0.1 hirma.info
127.0.0.1 hirmagazin.eu
127.0.0.1 hironline.club
127.0.0.1 hirportal.info
127.0.0.1 hirtop.in
127.0.0.1 hirtrafik.top
127.0.0.1 hirvilag.eu
127.0.0.1 hungarian.ruvr.ru
127.0.0.1 hunhir.hu
127.0.0.1 hunhir.info
127.0.0.1 hunhonlap.hu
127.0.0.1 hunsor.se
127.0.0.1 huntv.info
127.0.0.1 impulzus.net
127.0.0.1 internetfigyelo.wordpress.com
127.0.0.1 jovonk.info
127.0.0.1 kho.jobbikhosting.com
127.0.0.1 kitartas.net
127.0.0.1 kulfoldiapro.com
127.0.0.1 kuruc.info
127.0.0.1 legfrissebb.info
127.0.0.1 lovasistvan.hu
127.0.0.1 ma.hu
127.0.0.1 magyarifjak.org
127.0.0.1 magyarmegmaradasert.hu
127.0.0.1 magyarno.com
127.0.0.1 magyartudat.com
127.0.0.1 maivalosag.com
127.0.0.1 meteon.org
127.0.0.1 mindenegyben-blog.net
127.0.0.1 mindenegyben.net
127.0.0.1 mindenegybenblog.com
127.0.0.1 mokazona.eu
127.0.0.1 napihirozon.eu
127.0.0.1 napimigrans.com
127.0.0.1 nemadomahazamat.hu
127.0.0.1 nemzeti.net
127.0.0.1 nemzetiarcvonal.net
127.0.0.1 nemzetibulvar.hu
127.0.0.1 nemzetihirhalo.hu
127.0.0.1 netbulvar.com
127.0.0.1 netbulvar.eu
127.0.0.1 netceleb.eu
127.0.0.1 netceleb.hu
127.0.0.1 nethir.com
127.0.0.1 orientalista.hu
127.0.0.1 oroszhirek.hu
127.0.0.1 paxhungarica.org
127.0.0.1 rapidpress.info
127.0.0.1 realzoldek.hu
127.0.0.1 simsim.eu
127.0.0.1 sokkaljobb.hu
127.0.0.1 szabadriport.wordpress.com
127.0.0.1 szentkoronaradio.hu
127.0.0.1 thenews.hu
127.0.0.1 titkolthirek.hu
127.0.0.1 totalcar.top
127.0.0.1 tvhir.com
127.0.0.1 videohirek.com
127.0.0.1 vilaghalo.info
127.0.0.1 vilagom.hu
127.0.0.1 adatlistazo.hu
127.0.0.1 hidfo.net
127.0.0.1 xcore.in
#</hu-russian-propaganda>
 
#<hu-conteo-sites>
## These are Hungarian sites spreading bullshit (typical antivaxxer, anti-science, and/or fake news sites).
127.0.0.1 2perc.info
127.0.0.1 aktiv-hir.net
127.0.0.1 aktivhir.net
127.0.0.1 atomenergiainfo.hu
127.0.0.1 avilagtitkai.com
127.0.0.1 best-hir.com
127.0.0.1 bizony.eu
127.0.0.1 csucshatas.eu
127.0.0.1 csumida.com
127.0.0.1 dekutya.com
127.0.0.1 egeszsegmindenkinek.hu
127.0.0.1 epic-info.com
127.0.0.1 ez-zsir.net
127.0.0.1 ezt-figyeld.com
127.0.0.1 filmtar.in
127.0.0.1 frenetikus.com
127.0.0.1 hirado-online.net
127.0.0.1 hirexpressz.top
127.0.0.1 hirkert.info
127.0.0.1 hirnap.info
127.0.0.1 hirtop.in
127.0.0.1 husospizza.com
127.0.0.1 impulzus.net
127.0.0.1 index-video.com
127.0.0.1 magyarkozosseg.net
127.0.0.1 mindenegyben-blog.net
127.0.0.1 mindenegybenblog.hu
127.0.0.1 mindenegyhelyen.info
127.0.0.1 napi-hir.net
127.0.0.1 napiszarka.com
127.0.0.1 nemkutya.com
127.0.0.1 netextra.hu
127.0.0.1 nyaralok.net
127.0.0.1 origo-hir.net
127.0.0.1 origo-hirek.net
127.0.0.1 origo-online.info
127.0.0.1 origo-online.net
127.0.0.1 origoblog.net
127.0.0.1 origohir.net
127.0.0.1 origoonline.net
127.0.0.1 szupcsi.eu
127.0.0.1 tudnodkel.blogspot.com
127.0.0.1 tudnodkell.blogspot.com
127.0.0.1 tutihirek.com
127.0.0.1 vakarek.info
127.0.0.1 valoshirek.top
127.0.0.1 vattacukor.net
127.0.0.1 video-perc.net
127.0.0.1 hirnap.info
127.0.0.1 video-perc.net
#</hu-conteo-sites>
 
#<us-fake-news-sites>
127.0.0.1 100percentfedup.com
127.0.0.1 21stcenturywire.com
127.0.0.1 70news.wordpress.com
127.0.0.1 abcnews.com.co
127.0.0.1 activistpost.com
127.0.0.1 addictinginfo.org
127.0.0.1 americannewsx.com
127.0.0.1 americannews.com
127.0.0.1 anonnews.co
127.0.0.1 associatedmediacoverage.com
127.0.0.1 thebostontribune.com
127.0.0.1 beforeitsnews.com
127.0.0.1 beingliberal.org
127.0.0.1 bigamericannews.com
127.0.0.1 bigpzone.com
127.0.0.1 bipartisanreport.com
127.0.0.1 bizpacreview.com
127.0.0.1 bluenationreview.com
127.0.0.1 breitbart.com
127.0.0.1 cap-news.com
127.0.0.1 christwire.org
127.0.0.1 chronicle.su
127.0.0.1 civictribune.com
127.0.0.1 clickhole.com
127.0.0.1 coasttocoastam.com
127.0.0.1 collective-evolution.com
127.0.0.1 consciouslifenews.com
127.0.0.1 conservativeoutfitters.com
127.0.0.1 wideawakeamerica.com
127.0.0.1 countdowntozerotime.com
127.0.0.1 counterpsyops.com
127.0.0.1 creambmp.com
127.0.0.1 crooksandliars.com
127.0.0.1 dcclothesline.com
127.0.0.1 dcgazette.com
127.0.0.1 dailywire.com
127.0.0.1 dailybuzzlive.com
127.0.0.1 dailycurrant.com
127.0.0.1 derfmagazine.com
127.0.0.1 disclose.tv
127.0.0.1 drudgereport.com.co
127.0.0.1 duffleblog.com
127.0.0.1 duhprogressive.com
127.0.0.1 embols.com
127.0.0.1 empireherald.com
127.0.0.1 empirenews.net
127.0.0.1 empirenews.com
127.0.0.1 endingthefed.com
127.0.0.1 enduringvision.com
127.0.0.1 fprnradio.com
127.0.0.1 geoengineeringwatch.org
127.0.0.1 globalresearch.ca
127.0.0.1 govtslaves.info
127.0.0.1 gulagbound.com
127.0.0.1 hangthebankers.com
127.0.0.1 humansarefree.com
127.0.0.1 huzlers.com
127.0.0.1 ijr.com
127.0.0.1 ifyouonlynews.com
127.0.0.1 indecisionforever.com
127.0.0.1 infowars.com
127.0.0.1 inquisitr.com
127.0.0.1 intellihub.com
127.0.0.1 jonesreport.com
127.0.0.1 lewrockwell.com
127.0.0.1 liberalamerica.org
127.0.0.1 libertymovementradio.com
127.0.0.1 libertytalk.fm
127.0.0.1 libertyunyielding.com
127.0.0.1 libertyvideos.org
127.0.0.1 msnbc.com.co
127.0.0.1 msnbc.website
127.0.0.1 mediamass.net
127.0.0.1 megynkelly.us
127.0.0.1 ncscooper.com
127.0.0.1 nahadaily.com
127.0.0.1 nationalreport.net
127.0.0.1 naturalnews.com
127.0.0.1 newcenturytimes.com
127.0.0.1 newsexaminer.com
127.0.0.1 news-hound.com
127.0.0.1 newsbiscuit.com
127.0.0.1 newsbuzzdaily.com
127.0.0.1 newsmutiny.com
127.0.0.1 newswire-24.com
127.0.0.1 newslo.com
127.0.0.1 newswatch28.com
127.0.0.1 newswatch33.com
127.0.0.1 nodisinfo.com
127.0.0.1 now8news.com
127.0.0.1 nowtheendbegins.com
127.0.0.1 occupydemocrats.com
127.0.0.1 pakalertpress.com
127.0.0.1 politicalblindspot.com
127.0.0.1 politicalears.com
127.0.0.1 politicususa.com
127.0.0.1 prisonplanet.com
127.0.0.1 prisonplanet.tv
127.0.0.1 private-eye.co.uk
127.0.0.1 projectveritas.com
127.0.0.1 react365.com
127.0.0.1 realfarmacy.com
127.0.0.1 realnewsrightnow.com
127.0.0.1 redstate.com
127.0.0.1 redflagnews.com
127.0.0.1 reductress.com
127.0.0.1 rilenews.com
127.0.0.1 satiratribune.com
127.0.0.1 sprotspickle.com
127.0.0.1 theblaze.com
127.0.0.1 thefreethoughtproject.com
127.0.0.1 other98.com
127.0.0.1 thereporter.com
127.0.0.1 thedailysheeple.com
127.0.0.1 thenewsnerd.com
127.0.0.1 therundownlive.com
127.0.0.1 theuspatriot.com
127.0.0.1 truthfrequencyradio.com
127.0.0.1 twitchy.com
127.0.0.1 usuncut.com
127.0.0.1 usasupreme.com
127.0.0.1 unconfirmedsources.com
127.0.0.1 veteranstoday.com
127.0.0.1 wakingupwisconsin.com
127.0.0.1 wakingtimes.com
127.0.0.1 wideawakeamerica.com
127.0.0.1 winningdemocrats.com
127.0.0.1 witscience.org
127.0.0.1 wnd.com
127.0.0.1 worldnewsdailyreport.com
127.0.0.1 worldtruth.tv
127.0.0.1 zerohedge.com
#</us-fake-news-sites>

Do not forget to regularly update :)

2017-01-10

Java: About returning Optional and Collections

Copy-paste post follows.
Of course, people will do what they want. But we did have a clear intention when adding this feature, and it was not to be a general purpose Maybe or Some type, as much as many people would have liked us to do so. Our intention was to provide a limited mechanism for library method return types where there needed to be a clear way to represent "no result", and using null for such was overwhelmingly likely to cause errors.

For example, you probably should never use it for something that returns an array of results, or a list of results; instead return an empty array or list. You should almost never use it as a field of something or a method parameter.

I think routinely using it as a return value for getters would definitely be over-use.

There's nothing wrong with Optional that it should be avoided, it's just not what many people wish it were, and accordingly we were fairly concerned about the risk of zealous over-use.

(Public service announcement: NEVER call Optional.get unless you can prove it will never be null; instead use one of the safe methods like orElse or ifPresent. In retrospect, we should have called get something like getOrElseThrowNoSuchElementException or something that made it far clearer that this was a highly dangerous method that undermined the whole purpose of Optional in the first place. Lesson learned.)

Source: http://stackoverflow.com/a/26328555/357403

The Lord has been spoken.

2016-12-15

Issue in Eclipse with Generated Sources

So I had a maven project in eclipse, which has a few grammars, generated by ANTLR. Once in a while, eclipse goes nuts, it fails to recognize the classes in the target/generated-sources directory.

What happened to me is that it somehow reinstated a filter in the Java Build Path. Something "reverts" the .classpath file in the project root...
  1. Right click on your project,
  2. click Properties,
  3. click on Java Build Path,
  4. find your source folder with the generated sources, and you will see Excluded: ** [means exclude all]
  5. click on it,
  6. click Edit,
  7. click on the Exclusion pattern stating **,
  8. click Remove,
  9. click Finish,
  10. now you should see Excluded: (None),
  11. click Apply,
  12. click OK,
  13. rebuild :)

2016-10-26

Mysql: MySQL Workbench 6.3 and the Options File editor

Yeah, today it wrote the query_cache_wlock_invalidate (boolean) parameter to the my.cnf file and forgot to give it some value.

You won't believe what happened next... MySQL did not woke up after the restart... FML

2016-10-25

Java: About invoke bytecode instructions

You can find the Java bytecode instruction here.
  1. invokestatic: This instruction is used to call static methods on a class. It is determined at compile time, which method will be called.
  2. invokevirtual: This calls public and protected instance methods. Of course, it needs the instance reference on the stack, and also does the runtime binding (which adds overhead compared to invokestatic, but this "overhead" is not something you want to micro-optimize by design) for method dispatching. In fact, invokevirtual is not a true instruction, the actual steps taken are determined at runtime (cf. invokestatic) by the JVM, and can even involve Reflection, maybe even prohibit JIT in-place optimizations. Note, that the method handles are determined compile time, just the call path and strategy is determined at runtime (see: polymorphism).
  3. invokeinterface: Similar to invokevirtual, just the method dispatch is based on an interface, not a class.
  4. invokespecial: Calls the constructors (as they have special names that can't be referenced from plain Java code directly [on purpose]), also private and super (class parent's) methods.
  5. invokedynamic: This was introduced to address the "performance issues" of invokevirtual in a way, that the first call is executed as an invokevirtual, and the selected call path is stored for that invocation for subsequent reuse. In fact, this dynamic method resolution works with method handles obtained runtime (see: java.lang.invoke.* methods), not at compile time.
How does this affect you? Make your methods static if possible, but don't be overzealous! That's never a good approach.

2016-10-14

Java 8: Glossary of a session

OCP
Open/Closed Principle
Open for extension, Closed for modification Principle
SAM / Function Object
Only one method in a class. See: @FunctionalInterface; eg. Callable or Runnable.
Covariant Overriding
During inheritance, an overridden method's return type can be changed to one of it's subtypes. Eg. when overriding clone().
Erasure
Type parameters are removed from the types in the class bytecode.

2016-10-13

Java: PMD AvoidStringBufferField resolution

Inside an inherited code, I got a warning from PMD, stating
StringBuffers can grow quite a lot, and so may become a source of memory leak (if the owning class has a long life time).

StringBuffers/StringBuilders can grow considerably, and so may become a source of memory leaks if held within objects with long lifetimes.
So I went ahead and replaced the StringBuilder with a StringWriter. It even has the same append method signature for strings :D

2016-09-29

Java 8: Find First Match

Oh, how I love chainable methods, especially over a stream...

// Return first match in this List, or null.
return contents.stream().filter(c -> c.name.equals(fieldName)).findFirst().orElse(null);

<3 lambda <3