mari
a
a
a
a
a
chi >
[ Page 1 of 5 ]
From: Simon Wistow Date: 22:37 on 04 Apr 2008 Subject: Java's anonymous inner classes So Jav allows you to have anonymous inner classes. For example this is a really easy (if ugly) way to run something asynchronously new Thread(new Runnable() { public void run() { // do some stuff } }).start(); All well and good. But there is one down side. Say you want to, let's say, increment a counter; int counter = 0; new Thread(new Runnable() { public void run() { counter++; } }).start(); Perfectly reasonable, right? BZZZZZZZZZZZZZZZZZZZT! Wrong! You can't access anything other than final variables from within an anonymous class. Which means that final int counter = 0; new Thread(new Runnable() { public void run() { counter++; } }).start(); doesn't work because, well, counter is final. So how do you get around this? final int[] counter = { 0 }; new Thread(new Runnable() { public void run() { counter[0]++; } }).start(); I mean. Seriously. What The Fuck? Of course this gets extra special fun if you want to do something with exceptions. Let's say you want to do try { final Foo foo = FooFactory.getFoo(); Bar.doSomething(new BarRunner() { public void quux() { foo.execute(); } }); } catch (SomeCommonException e) { System.err.println("Got an exception: "+e); } finally { FooFactory.release(foo); } Well you can't because the finally clause won't see the foo object but you can't do final Foo foo; try { foo = FooFactory.getFoo(); Bar.doSomething(new BarRunner() { public void quux() { foo.execute(); } }); } catch (SomeCommonException e) { System.err.println("Got an exception: "+e); } finally { FooFactory.release(foo); } because that doesn't make sense. So what you have to do is Foo foo; try { foo = FooFactory.getFoo(); runBar(foo); } catch (SomeCommonException e) { System.err.println("Got an exception: "+e); } finally { FooFactory.release(foo); } public void runBar(final Foo foo) { Bar.doSomething(new BarRunner() { public void quux() { foo.execute(); } }); } And people wonder why Java has a reputation as being verbose? *sigh*
From: Simon Wistow Date: 08:43 on 29 Apr 2007 Subject: uTorrent I was recommended uTorrent last year and have been using it since. I was generally pleased with it - my two issues being that when it was on then I couldn't open new sockets - no new SSH connections, no reading web pages, no starting up the daemon that's part of my current project. I accepted this. I presumed it was because, somehow, it used up MAX_SOCKETS or whatever. Either way there seemed to be nothing in the FAQs about it so either it was unreproducible (whihc seemed unlikely) or it just was. But it was fine. I'd just run it at night. However, what was more annoying was the fact that someitmes it would run for hours. I could leave it running Friday night, get back Sunday evening and it would still be running. Other times however, and this was far more frequent than running for hours, suddenly all download pseed would drop to zero. And stay that way. Restarting it usually helped but often it would get itno a spiral. The 'uptime' would get less and less and less until it was unusable and I'd tend to reboot my machine and also cycle the router because, well, voodoo sometimes works. Again, nothing in the FAQ. I guessed it was a Windows issue - maybe resource starvation or something. Sockets not being freed. Annoying but plausible. Then someone reccomended Azeureus to me. They'd never heard of these problems they said. So I gave it a try. Oh my! First off - I can surf the web and open new connections when it's on. Hurrah! Ok, so someitmes it can be a bit laggy but I dpn't mind because ... It seems to be about twice as fast. I don't know if that's me ascribing all kinds of wonderful to it but I swear it seems to be getting the same torrents I was downloading with uTorrent at double the download rate. Which is good because I need that, err, iso of Debian right now. *cough* And it hasn't stopped downloading at all. Rarrrr! So, in summary uTorrent == the suck Azeureus == t3h w1N!!!!1111
From: Simon Wistow Date: 18:51 on 23 Jan 2007 Subject: Possibly PuTTY, possibly something else. It's still hate. Given that PuTTY is generally pretty damn nifty I'm willing to possibly lay the blame on something else (for example, XP itself. Or a a peice of Virtual Desktop software I'm running called Virtual Dimension) hwoever the hate still stands with ... with SOMETHING DAMMIT. And it smells like this. The only way you can close a Putty session is by exiting the shell or by killing the process in the Task Manager. This is retarded. If I lose my network connection then when I regain it to close all the inactive windows I have to go to each of them, restart the session then type exit. GRAAAGAGGAGAGAGH. This is especially irritating when I've still got my connections open to other machines on the same LAN or the Xen instance I'm running on my machine because my shortcut of firing up the Task Manager and hitting kill process is nigh on impossible because the process name doesn't have the host I'm connected to in it. KILL! MURDER! DEATH!
From: Simon Wistow Date: 12:54 on 03 Oct 2006 Subject: iTunes on Windows I have no idea whether these are Windows specific iTunes hate or whether they span the platforms but I only have experience with iTunes on Windows so I'll restrict it to that. Feel free to chip in and complain about the Mac version later. I'm not entirely sure why people rave about iTunes - I suspect it'shte iPod and ITMS integration but people raved about it before then. Maybe they were blinded by the shiny metal. Either way, I have no iPod (HERECY!) nor the inclination to by DRM encrusted tat from iTMS so I miss out on those benefits. Ooh - I can organise my podCasts . Which would be great. If I listened to any. Aren't we supposed to call them soundBlogs or something now anyway? However, the single biggest hate I have so far is why the auto complete in the ID3 field editor. Here's how to replicate the hate ... 1) Obtain mp3 from somewhere 2) Realise that ID3 tag, whilst technically correct, is lowercased 3) Try and edit that 4) Have iTunes know better than you do and autocomplete the field back to the lowercase version 5) Try again 6) Have same experience 7) Scream. Curse. Rant. 8) Edit the field to say "Foo" 9) Rename it back to Properly Capsed Version of Name 10) Repeat with other MP3s 11) See 7
From: Simon Wistow Date: 02:32 on 13 Sep 2006 Subject: Lucene's Index opening modes I don't know about you, dear hates-software reader, but, in general, when wanting to write something like an index for a search engine I have two major uses cases. The first is - open the index and start using it. The second is - open the index, if it doesn't exists then create it, then use it. The number of times I want to open the index and nuke any existing comments is small. Even whilst developing a search engine. Still, I can imagine it being useful to, you know, someone. Lucene, the Java based search engine with the hateful documentation, seems to think that it is important. Very important. Because it doesn't have a "Create if it doesn't exist mode". I know not why. Sure it's emulatable in my own code. But so would throwing an error if it didn't exist. Or deleting all the documents if it did exist. When you've had 3 hours sleep these things can trip you up and suddenly all your indexed data is gone. All of it. I hate you Lucene. I'm giving you cancer with my thumbs.
From: Simon Wistow Date: 17:42 on 19 Jul 2006 Subject: tcsh's conditionals Oh tcsh - so much to despise about you my little hate dumpling stuffed with loathsomeness. How we could while away the evenings talking about your little pecadillos. I can picture it now - you'd be on the floor cowering and I'd be standing over you, repeatedly hitting you using a bat with a rusty nail through it, cackling whilst your screams for forgiveness became slowly muffled by your own sobbing. Good times. Good times. But, such pleasurable evenings will have to wait because we need to have a talk about your conditional statements, you and I. No, no, there's no need to be modest. Don't be shy. I merely want to ask you which of these is the correct syntax ... if ($foo) then echo "foo" elsif ($bar) then echo "bar" endif or if ($foo) then echo "foo" else if ($bar) then echo "bar" endif Hmm. The second choice you say? My, my, my. That *is* interesting because, you see, the first choice doesn't provoke a compile error. No, no, no such niceties are for weak minded, lily livered, frankly pinko, leftie WIMP programmers. So gauche. So ... recherche. A real man's language would compile the first syntax fine and then ... oh, do excuse me, I'm chuckling just thinking about it ... and then silently ignore it. Unless of course there's a 'else' statement which will, in that case, *always* get run. Since it's the default case it will probably go undetected for YEARS until some poor schmoe is asked to find why a certain option isn't working on some script left lying around. Oh how he'll clutch his sides with mirth, wipe a tear of glee from his eyes and then sink back in his chair, plotty gruesome revenge on you. Tssk, I ramble. So indulgent of me to take up your precious time when it could be more productively spent making someone else's life a misery. Accept my apologies, please. Until we meet again, dear tcsh. I'm sure you'll recognise me - I'll be the one skull fucking you to death with the severed arms of your creators. I may be covered in blood and crying bloody murder. Yours, Simon
From: Simon Wistow Date: 19:52 on 11 Jul 2006 Subject: putty - please to be remembering what I told you
From: Simon Wistow Date: 14:35 on 23 Jun 2006 Subject: YAML and its parsers I have an app. It stores some data (in this case CVS commits) as YAML. Don't ask. Then something else consumes the YAML and turns it into RSS. Again, don't ask. So YAML.pm (for these are in Perl) creates a YAML file for me. Then, int eh RSS generator it reads it back in. And throws an epi claiming it's not valid YAML. Some diagnostics indicates that it may be a problem with new lines. I try upgrading YAML (which imports half of CPAN in a scary way that makes me nervous) and it still doesn't work. I try YAML::Syck and that only parses out the first record. I try YAML::Tiny but that claims not to support 'partial-line comments'. WT and might I also add F?
From: Simon Wistow Date: 17:24 on 26 May 2006 Subject: Adobe Acrobat and its font non handling Or, more succinctly, acroread since I have no idea if this is the same on Windows. I have a PDF. Acroread tries to load and then bitches that it doesn't have the right font. Not a particularly exotic font - just Times New Roman. I *know* I have TNR installed somewhere because The Gimp and Star Office and Firefox can use them but we shall ignore that. In fact we better ignore that because there's no way to tell Acrobat "try looking here as well". Now, I know the PDF might not render exactly as was designed and since PDF is a print layout format I can see why that's more important than in HTML but, you know, just this one time I'm willing to let you substitute Helvetica or Garamond or Arial because, crazy kook that I am, actually care about the content rather than the presentation. I know, I know. Shun me! I am an aesthetic pariah. Will it let me do this. No. It displays square boxes for every character instead. Ghostview, btw, handled it with aplomb.
From: Simon Wistow Date: 14:25 on 21 Feb 2006 Subject: mplayer's frame extraction I want to extract some frames from a movie and mplayer has the necessary codec chops to cover it. Handily it provides a video out codec of 'png' which writes each frame as a png. Kudos to mplayer. Kudos. Enjoy it though, you weasley bit of software sputum, it's the last you'll get. In my handy dandy wrapper to extract movies into frames I want to provide the ability to extract only a range of frames. So we have five options 1) $start-$end (i.e 1-$end) 2) $start-$m 3) $n-$n (i.e a single frame) 4) $n-$end 5) $n-$m The first one is easy - we just extract everything. This, hwoever is where it stops being straight forward. mplayer provides two relevant options: -frames which takes an integer and only extracts that many frames. And -ss. Which takes a floating point number of seconds offset. *sigh* That's no problem though - we can just get the FPS of the movie subtract 1 from our start frame and then divide by the FPS to get the start second of the frame we want. Easy. Right? No. Let's try it shall we ---------------------------------------------- o Case 1 - $start-$end (i.e 1-$end) ---------------------------------------------- Do nothing. ---------------------------------------------- o Case 2 - $start-$m ---------------------------------------------- % mplayer -frames 1 -vo png test.mov ... % ls *.png 00000001.png 00000002.png % WTF? I asked you for one frame. You gave me two. % mplayer -frames 2 -vo png test.mov ... % ls *.png 00000001.png 00000002.png 00000003.png % *breathe* No, it's ok. We can deal with this. We just delete the extra one. Right that takes care of cases 1 and 2. Let's try with an offset and extracting only 1 frame (i.e case 3). ---------------------------------------------- o Case 3 - $n-$n (i.e a single frame) ---------------------------------------------- Well, in the case of $start=1 and $end=1 - frame 1 is time offset 0 so that's just the case above. Let's try $start=2 and $end=2.Frame 2 should be at (assuming 24 FPS) at time offset 0.04166666667. % mplayer -ss 0.04166666667 -frames 1 -vo png test.mov ... % ls *.png 00000001.png 00000002.png % ok, well it's generated that extra frame again so all we have to do is delete the last one and ... Oh. Wait. No. the first image is actually frame 1. So we delete that, right? If only it was that simple. 00000002.png is actually ... frame, err, 4. Well, what happens if try and get frame 3 % mplayer -ss 0.08333333334 -frames 1 -vo png test.mov ^^^^^^^^^^^^^ (3-1/24) Again we get 2 frames but this time 00000002.png is actually frame 5. And 00000001.png is *still* frame 1. Fortunately this progresses linearly so we can deal fairly sanely with case 3 with just 2 special cases for when $n is 1 or 2. ---------------------------------------------- o Case 4 - $n-$end ---------------------------------------------- 'Fortunately' enough we have the same issues that we do with case 3 i.e the spurious frame 1 always being there and weird jump at the start of the frame offset but no matter - we can deal with this. Again 'just' 2 special cases for frames 1 and 2. Running tally so far 4 cases + 4 special cases. ---------------------------------------------- o Case 5 - $n-$m ---------------------------------------------- Let's break this down shall we. ============================================= * 5a) $n == 1 ============================================= Same as Case 1 ============================================= * 5b) $m == $end ============================================= Same as Case 4 ============================================= * 5b) $n=2 $m=3 ============================================= Almost the same as Case 3 but with another special case because mplayer can't seek to frame 2 because ... .... .... and this goes on with an ever increasing number of special cases. I think I'm up to about 10 at the moment. And my logic, written in tcsh (don't ask) is getting ever more complicated. And basically I can't be arsed. Weirdly it turns out to usually be quicker to just dump everything out and then nuke the stuff you don't want because see because seeking is so slow. So fuck it.
mari
a
a
a
a
a
chi >
[ Page 1 of 5 ]
Generated at 10:27 on 16 Apr 2008 by mariachi