## Posts

### Solving quadruple dependency injection problem in Angular

Angular comes with built-in dependency injection and module management system, but it can get a bit tedious to use when your project grows. Especially if you use RequireJS alongside it (a must for almost any project) and also want to be minification-safe with all those dependency injections. Let's look at a simple example with one module that provides a value and another module that prints that value: // answer.js define(["angular"], function(angular) { angular.module("the.answer") .value("TheAnswer", 42); }); // main.js define(["angular", "the.answer" ], function(angular) { angular.module("main", [ "the.answer" ]) .run([ "TheAnswer" , function( TheAnswer ) { console.log(TheAnswer); }]); }); As you can see, to provide a single dependency to my code, I had to specify it in four places (highlighted in red) - first as RequireJS dependency, then as Angular module dependency,

### DIY control pedal on Linux

I use Emacs a lot, thus pressing and releasing Ctrl all the time is really a problem for me. Recently I even started experiencing pain in finger joints due to inefficient hand position. Remapping CapsLock as additional Ctrl didn't help much. So I embarked upon a quest to use foot pedal as additional Ctrl. My first attempt was to buy already assembled and working USB pedal, like this one . Long story short, I waited two months, it never arrived (I got a refund, though), so I had to work with whatever I had available. I am an amateur piano player, so I have Yamaha electronic piano with electronic suspension pedal at home. It looks like this: It's some generic Yamaha pedal, but I think that something like Yamaha FC5 model will work just as well. As you can see, it has TS 6.3 mm mono jack as it's output. But audio input on most sound cards is stereo and uses 3.5 mm jacks. Thus I had to find an adapter. I settled on using Proel AT100 adapter: It still doesn&

### How to create your own simple 3D render engine in pure Java

3D render engines that are nowdays used in games and multimedia production are breathtaking in complexity of mathematics and programming used. Results they produce are correspondingly stunning. Many developers may think that building even the simplest 3D application from scratch requires inhuman knowledge and effort, but thankfully that isn't always the case. Here I'd like to share with you how you can build your very own 3D render engine, fully capable of producing nice-looking 3D images. Why would you want to build a 3D engine? At the very least, it will really help understanding how real modern engines do their black magic. Also it is sometimes useful to add 3D rendering capabilities to your application without calling to huge external dependencies. In case of Java, that means that you can build 3D viewer app with zero dependencies (apart from Java

### Jinni is going away: export your ratings!

Jinni was an awesome movie recommendation service - actually, it was the only service that was able to accurately predict if movie will suit my taste or not. Alas, good things are not meant to last, and recently they announced that they will be shutting down the service and will be instead focusing on providing targeted ads for TV. They do promise that they will e-mail users their rating history once the site goes down, but I can't trust them about that - I care about my movie list too much. So I needed to export ratings myself, to be extra sure. Jinni doesn't provide any automated export service (at least, I failed to find one). Since copying several hundred ratings by hand would be tedious, I decided to throw together a simple script, that other Jinni users may find useful. First, we need to talk about authentication to Jinni server. In this case, when I say "authentication", I rather mean lack of it - because all you need is to add "auth=Username

### GroupLayout for JavaFX 8: GroupLayoutPane

I recently decided to do small gui application in JavaFX, and I'm very excited about it's capabilities and nice design. Compared to pure-Swing gui, JavaFX seems to be more consistent and extendable. But as usual, there's a fly in the oinment - default layouts are really horrible for anything except simplest setups. There are eight different layouts, all with incredible amount of hidden gotchas. Take VBox for example. By default, it doesn't expand children to fill all the provided width. There's an option for fixing that, of course. Okay, but now I want to spread VBox children vertically. Sure there is fillHeight property to give me that? Nope. Screw me. Maybe I can use GridPane for that? Yes, I can, but first I need to learn all the setValignment, setHgrow, and a bunch of other cryptic methods. And whatever I did, I was unable to place a canvas onto that grid and make it resize/redraw when the frame is resized. I really missed the old GroupLayout from Swing.

### FTP-backed filesystem with aggressive caching

I know, I know. It's 2015 and nobody uses FTP anymore. But by some unlucky coincidence, I found myself forced to use it - because the target machine couldn't have ssh for political reasons. After some googling around I found CurlFtpFS - which mounts remote directory as a FUSE filesystem. It works, but I find it to be horribly slow - it takes several seconds to save a file, and opening small text file in Emacs takes over a minute (as it turns out, in my configuration Emacs searches the neighborhood of the opened file all possible version control system files and autosave files from other editors - and with FTP, each stat() call gives 1 second delay). Since I didn't see any other way, I sat down to write my own FTP-backed filesystem with aggressive caching. The idea is that we don't expect that files on remote target will change often, so we can skip doing FTP calls for directory listings, file stats and the like if we have already cached them. I didn't implement

### DIY screenshot sharing service

I often find it useful to send someone a screenshot - to facilitate some explanation, to point out a bug in some app, or maybe even just brag about my awesome desktop. Obviously, I can open a terminal, start some screenshot app, save screenshot to file, upload a file somewhere, then figure out the link, etc - quite repetitive, I think. Or I could use some of the new-and-popular screenshot uploading services - like  Gyazo  for example. But all those services require you to install some package or application, which looks ridiculous for such a simple task. But we are Linux users, aren't we? We can always do better! Especially when we have some rusty bash skills, barely alive web-facing server somewhere in our closet, and half an hour of free time on our hands. #!/bin/bash f=$(mktemp -u screenshot_XXXXXX.png) import /tmp/$f scp /tmp/$f server:/some/webroot/ rm /tmp/$f url="http://your.server.hostname/$f" echo$url | xclip echo $url | xclip -sel c echo$url The abov