Thursday, 25 February 2016
Vim tip: autocommands
The basic structure is pretty simple: "autocmd Event FileType Action". So, for example, "autocmd BufEnter *.txt call Rot13()" would tell vim to set a callback on BufEnter, that is whenever you change buffers, for all *.txt files, which will rot13 your text. Feel free to use this for actually useful things, like spell checking or auto indenting.
Tuesday, 23 February 2016
Bash tip: idiom to get the first error code from a pipe
real_command | filter_stuff | prettify | do_something_else
The problem arises when you try to figure out if your command succeeded or not. If you `echo $?` you'll get the return code for the last chain in the pipe. You don't really care about the output value of do_something_else, do you?
I haven't found a solution I really like to this problem, but this idiom is handy:
out=`real_command` && echo $out | filter_stuff | prettify | do_something_else
echo $?
Now $? will hold the value of real_command, and you can actually use it to diagnose the real problem.
Thursday, 18 February 2016
smaps: A quick memory analysis
There's a quick tip in Linux that can help you track down a lib gone haywire:
cat /proc/<pid>/smaps
smaps will report every mapped section of memory for a certain process, how big the memory allocation is and which binary created the allocation.
Tuesday, 16 February 2016
Some new set operations in C++11 stl
The std header has a few cool additions that make life easier in C++11:
void f() {
vector<int> v = {1, 2, 3, 4, 5, 60, 70, 80, 90};
auto less_than_10 = [](int x){ return x < 10; };
if (all_of(v.begin(), v.end(), less_than_10)) {
cout << "Yay!";
}
}
Besides all_of, in you can also find any_of and none_of.
Bonus: do you find that initializer list hideous? Just use std::iota, from stl too:
vector<int> v(100, 0);
iota(v.begin(), v.end(), 0);
Friday, 12 February 2016
Goto hell
Thursday, 11 February 2016
PSA: OEM unlocks may result in wiped filesystems
If this happens, go back to recovery mode, then adb shell and run 'mount /data'. This will give you an error like "Can't mount /dev/block/mmcblk0p23". Write down the /dev/block id and run 'mke2fs -t ext4 /dev/block/mmcblk0p30'. That should fix it.
In some systems you may be missing libext2_quota.so. If this happens, just look for libext2_quota.so in the interwebs, then adb push this file into /sbin.
Tuesday, 9 February 2016
KDE: Lock screen from CLI
qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock
"qdbus" is a broadcasting service for KDE (Qt, actually). This command basically tells the screen saver service to lock the screen. Works every time, and with an alias in my bashrc, I don't need to remember that horribly long command. Now I only need to determine if my computer detecting when I'm in a hurry is a sign of sentience, and whether this is a threat to mankind. Will report soon.
Thursday, 4 February 2016
VLCFreemote: no need to leave the couch
How many times have you been comfortably watching a movie from the couch only to find out you forgot the subtitles? How about being snugly tucked under a blanket, only to find out you need to brave the cold of winter just to add a new episode of your latest binge-watching series? Yeah, that can easily ruin your day.
Worry no more: with VlcFreemote you can now install a tiny Android app to control your VLC server.
FAQ:
- Another VLC remote? Why?There are a few VLC remote controls out there. I think this is the only once that's open source (not 100% sure). It has some nice extra features I haven't found in other remote controls too: bookmarks, automagic movie-skip (jump forward by a percentage of the file length, much more useful than it sounds!) a compact layout and other small things probably not even worth mentioning. In the future, whenever I get some free time, I'd like to add the ability to start VLC automatically from SSH, a feature I would use a lot and I have seen nowhere else.
- Why isn't this in Google play?Mostly cause I'm lazy and cheap. Getting a Google Play account costs 10 dollars or so, and I'm too lazy and too cheap to get one. Want me to upload it to Google Play? Feel free to buy me a beer. If not you can just get the APK from Github, or download the source code and build it yourself.
Tuesday, 2 February 2016
Don't exit gdb just to run make!
Turns out you don't even need to drop from gdb to a shell: just type make (using the parameters you'd usually call make with) and watch gdb take care of building your binary again.
Rebuilding your project like this is not only useful to save time: you can also keep your breakpoints and they should still make sense, assuming you didn't refactor your code too much.