Java.util.Timer and java.util.TimerTask abomination

grrr. okay so your writing an Android app and you want some bit of code to run on a semi-regular basis. So, you create a Task, something like…

private TimerTask refreshTask = new TimerTask() {
public void run() {
//do something...
};
};

…looks like a familiar design pattern, right. So in my onResume I new a Task and schedule the bloody thing and in my onPause I call Task.cancel().

…and then you run the app and it doesn’t crash right away noooooo it waits until you have to present to your boss and then it pukes all over itself, ehhem why? Well this is just one of the many unintuitive &^%*$^ that come up all the time in Java. You spend the next couple hours borking with different ways to stop and start the timer, then you spend a bit more making sure onPause and onResume are really called when they’re supposed to, and then… You figure out that not only do you have to new a Timer every time you want to restart you also have to new a TimerTask. Why!, I don’t know why, I guess they store some state in the timer task.

I’m A Curmudgeon

I admit it, not only do I use vi (vim), but I use the terminal version. Here’s is screen shot of some Braille Buzz source, notice I use clang complete (Intelligent code completion), and tagbar for navigation. Please don’t get too hung up on the code remember this was hacked together as a proof of concept, the production code will still be C but not so messy.vim colourized with ClangComplete

My .vimrc

execute pathogen#infect()
nmap :TagbarToggle

source ~/.vim/vimrcs/basic.vim
source ~/.vim/vimrcs/filetypes.vim
source ~/.vim/vimrcs/plugins_config.vim
source ~/.vim/vimrcs/extended.vim

try
source ~/.vim/my_configs.vim
catch
endtry

” Highlight all instances of word under cursor, when idle.
” Useful when studying strange source code.
” Type z/ to toggle highlighting on/off.
nnoremap z/ :if AutoHighlightToggle()set hlsendif
function! AutoHighlightToggle()
let @/ = ”
if exists(‘#auto_highlight’)
au! auto_highlight
augroup! auto_highlight
setl updatetime=4000
echo ‘Highlight current word: off’
return 0
else
augroup auto_highlight
au!
au CursorHold * let @/ = ‘\V\<'.escape(expand('‘), ‘\’).’\>’
augroup end
setl updatetime=500
echo ‘Highlight current word: ON’
return 1
endif
endfunction

.ycm_extra_conf.py


flags = [
'-I./STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc',
'-I./STM32_USB-FS-Device_Lib_V4.0.0/Libraries/CMSIS/Include',
'-I./STM32_USB-FS-Device_Lib_V4.0.0/Libraries/CMSIS/Device/ST/STM32F10x/Include',
'-DSTM32F10X_XL',
'-DUSE_STDPERIPH_DRIVER'
]