Category Archives: programming

clang-format

local backup

This runs a local backup to a mounted file system (ext4 or btrfs). It does de-duplication at the file level; that is, the first backup copies everything, subsequent backups only copy the changed files and hard link to the unchanged files. RAID storage systems like NetApp de-duplicate at the block level but the snapshot paradigm is very similar.

remote backup

This runs a remote backup via ssh to a mounted file system (ext4 or btrfs). It does de-duplication at the file level; that is, the first backup copies everything, subsequent backups only copy the changed files and hard link to the unchanged files. RAID storage systems like NetApp de-duplicate at the block level but the snapshot paradigm is very similar.

Google Pixel as an Android development box

Recently I bought a Google Pixel (2015 samus). Chrome OS is really just a Linux variant running the Chrome browser so I figured I could just get it to boot Debian or Ubuntu and I’d have a nice laptop; indeed, there is much to like about the Pixel. Alas, I’ve tried booting an Ubuntu variant natively and Crouton; neither were good experiences.

Ubuntu
There are plenty of step by step instructions out there on how to do this and to Google’s credit they don’t try to stop you from owning your hardware. Getting Linux to boot is not the problem, living with it is. I suspect things will improve over time but here is my list of fails:

The keyboard layout is rather simple, I think I could have learned to live with this, but I found no mappings for this unique keyboard.
– The top row of keys are just F1 through F10, no combination of ctrl, alt, shift will make them adjust brightness etc; I could have lived with this.
– WiFi randomly stops working requiring a reboot; I can’t live with this.
– Every-time you wake from sleep there is a finite chance that you will have to do a cold reboot to get the track-pad to work again; this is another show-stopper, this is Linux, we don’t reboot.
– It didn’t seem to know if it was on AC or battery so things like folding down the screen didn’t work well; when I’m on AC, just keep running, but when I’m on battery, sleep.

On the other hand, no lockups and I could run Android Studio reliably, it was almost good enough. Yes, I did try the git-hub stuff with the special kernel version and the fixes for some of the hardware, no joy.

Crouton
I reinstalled Chrome OS and tried Crouton next… uh a little better and then I tried to run Android Studio… eh, not good. With Crouton one runs xorg et al. in a kind of sandbox. One switches between X and Chrome OS by holding down shift, ctrl, alt F1 or F2. In X, the keyboard problems noted above are still there but one can easily switch to Chrome OS and adjust the brightness etc. Sleeping seems to work better, the track-pad is reliable, and AC/battery detection and battery life seem to be better. …and then Android Studio took over eight minutes to build a small app and it is at this point I threw up my hands. [see update below]

Conclusion
I know many of these things are fixable –I could wait for the hardware fixes which I suspect will be here soon and I could remap the keyboard– but I don’t have the time. I need a Linux Laptop experience that works reasonably well out of the box. Really Google 1200 bucks for a Chromebook? Yes the hardware is nice, there really is a lot to like there, but I needed a better experience running a real OS.

I tried to buy a Dell ultrabook, they have a line that comes with Ubuntu out of the box but their moronic marketing department and broken business process caused me to have contact with sales support… epic fail! I should note that their tech support has become legendarily bad in recent years too.

Finding a good Linux laptop sucks, but I’m going to put the blame where it belongs… on the hardware vendors. The hardware market has gone from bad to really broken. Hey vendors, I need an ultrabook that runs Linux out of the box.

In closing I am writing this on the Pixel, when I finish I’m going to do a factory reset, box it up, send it back. I’m not happy about this, I really want like this thing, there
is a lot to like.

update 02/09: I got Android Studio to build/ The problem was with aapt, the fix, install lib32z1.

fun differences betwixt Java and C++ containers

…and for my next rant I wax poetic about the joys of writing code in the morning using C++ containers and in the afternoon switching to Java!

So I’ve got me an array of, I dunno uint32_t’s, and I’m just happy as a clam with my fun member functions and I’m callin’ ’em and I’m doing all sorts of cleverness, and then it comes time to do something with my amusingly arranged array. I need to call something that takes a pointer to an array of uint32_t’ or better yet I need to manipulate my fancy C++ array very quickly. No problem, this is still C isn’t it, bloated and strange but I can still get a pointer, why yes I can. A quick call to array::data() and I get me a pointer to an array of uint32_t’s…but not just any array of uint32_t’s _the_ array, not a copy (that the cpu had to do a shit load of work to make) the real thing… and I can do what I want with this array, may not be wise but I’m good to go!

…and later that day I’m writing some Java; and I got me a SortedSet… clever… arrange… member functions… But now I gotta call some Android crap and it wants an array because it’s going to display it somewhere. So I go to the documentation and I read, “toArray() Returns an array containing all elements contained in this set.” and I’m having flashbacks to this morning and I think jammin! I’ll just use these cutesy member functions to cleverly arrange my set and then I’ll call this refresh (update whatever) method and I already passed Android a reference to the underlying array and viol-la! …and it doesn’t bloody work. Well, it works the first time but I make my member calls on the set and I call refresh and I get the same display I got last time. So I reread the docs, it says, “toArray() Returns an array containing all elements contained in this set,” so what’s the problem… wait for it… Returns an array containing all elements contained in this set not the array. Effing Java decided to copy the whole bloody thing to a new array and then has the temerity to hand me a reference to this useless (and CPU intensive) pile of crap. Arrrgghh, I hate Java. Yeah, yeah, yeah, copy on write whatever, memset this pal!

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'
]