Posts

GroupLayout for JavaFX 8: GroupLayoutPane

Image
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...

Quick scala experimenting in emacs

Sometimes it is very handy to do a quick coding session in some scripting language - when experimenting with new language feature, trying out some idea or just throwing together some math. Until recently, there was no way to use Scala for this. While it had script execution feature, it was very slow - could take several seconds on each script restart. This happened because you had to load and initialize scala compiler every time - and it's not a small beast. Somewhere between 2.9 and 2.11, situation changed to better - now, instead of tearing compiler up and down, "scala script.scala" silently starts a compile server in the background, and subsequent scripts are sent to it, cutting down script execution time to less than a second. It would get even better if there was a way to run the script directly from my emacs session, without going to terminal. Turns out, it's easy to do. Just place the following function in your init.el: (defun run-current-file () ...

Macros in Scala: moderately complex example

Image
I recently began to discover the power of newly-added macros in Scala. While they are still labeled as "experimental" , they already pack quite a punch. Most tutorials on the web usually use some simple examples - like assert macro , or debugging helper . In this post, I'll try to make a bit deeper dive into the subject, in hope that I will be able to explore darker corners of macro engineering. The use-case for today's macro is actually something I needed in one of my real projects - I had complex hierarchy of case classes, and I wanted a quick way to visualize it (without needing to read mile-long text files). So I created a macro, that takes case class, and creates a frame with JTree containing the hierarchy of case class members. Example use-case for the macro looks as follows: case class Author(name: String, birthYear: Int) case class Book(title: String, authors: List[Author]) val hobbit = Book("Hobbit: There And Back Again", List(Author(...

/dev/null for graphics

Have the following ever happened to you? You are trying to automate some data processing step. The step in question involves some complex, GUI-driven application, for which there is no source available or that source is a little to complex do dive in and extract the required functionality. As a happy coincidence, the application includes batch mode - but it still creates and displays the gui when running in batch mode (even when started with "nogui" option). (in my particular situation, the app in question was Brainstorm , a collection of Matlab scripts. The original author is using Windows exclusively, thus he probably couldn't even imagine this scenario) All of the above could be acceptable, but there is a slight problem - batch processing happens on a mainframe-style Linux server, without keyboard, display, or even X server running. Thus the application starts up, tries to create it's cosy GUI, obviously fails, and crashes hard. When applications...

Code highlighting in Blogger's dynamic templates

I decided to update the style of my blog recently, and immediately fell in love with new dynamic blog templates. Navigation is easy, and the look is quite slick. But, as usual, all shiny things have downsides. Since dynamic templates fetch content via ajax, long after the main page is loaded, "conventional" ways to highlight code snippets on page load don't work (and most code highlighting libs only use this method). And, to make things worse, developers of dynamic templates haven't provided us with hooks to detect the moment of page change. Some brave souls ventured into the depths of template javascript, and some even found the place where user's code can hook to get article change event - but since it's not documented and google developers change the code constantly, this workaround tends to break every several months or so. Currently, I use simple (as in "quick&dirty") workaround - I simply insert small piece of javascript code directl...