Scam Warning: Take care when pasting things you don't understand. This could allow attackers to steal your identity or take control of your computer.
That's some really good advice coming from your browser's console.
Scam Warning: Take care when pasting things you don't understand. This could allow attackers to steal your identity or take control of your computer.
If you don't want to read many pages on file transfer standards (Samba? What's that?) you can try this little snippet:
python -m SimpleHTTPServer $PORT
This will create an http server sharing the current directory. HTTP, luckily, is one of those things that tend to work everywhere, always.
Bonus: some other ways of doing the same thing at https://gist.github.com/willurd/5720255
Do you know the quickest way to create a constructor that initializes the elements in this struct?
#include <string>
struct MyStruct {
int x;
std::string y;
const char *z;
};
If you answered "by typing really fast", you may be interested in knowing that the fastest way to create this constructor is to not write it at all!
MyStruct a = {42, "Hello", "World"};
Yes, the line above works and it's perfectly legal C++. It's event C++ 98! This language feature is called aggregate initialization and it says the compiler should be smart enough to initialize MyStruct using each value successively. Of course C++11 has made this syntax somewhat simpler and a lot more uniform:
MyStruct a{42, "Hello", "World"};
There are some caveats when using this initialization, namely that the initialized type must be an aggregate. An aggregate, in standard lingo, is a type that has some restrictions. No virtuals, no privates, etc. You can say it's a POD and in most cases you'd be right.
Now, is this also legal?
MyStruct a = {42, "Hello"};
You'd be tempted to say that's a syntax error. It's not, now z will just be default-initialized. What about this, then?
MyStruct a = {42, "Hello", "World", "Extra!"};
According to the standard, that's an error. Or... is it? Let's try out this example:
struct A {
int x;
};
struct B {
A a;
std::string y;
};
struct C {
B b;
const char *z;
};
C o = {42, "Hello", "World"};
Yes. Believe it or not, the object o will now contain three members: o.b.a.x, o.b.y and o.z. All three will be properly initialized with their respective value.
Aggregate initializations should, according to the standard, be smart enough to initialize aggregate objects and use any "spill over" to continue initializing other values/aggregate objects recursively.
Aggregate initialization is also what makes this idiom valid:
char x[] = {1, 2, 3}
In this case, x will be of length 3 because that's the length of its aggregate initializer.
I'm sure anyone trying to get up to date with C++11 will have played around with variadic templates. One of the first exercises I'd recommend for this would be a compile-time list of different types. Knowing about aggregate initializations now, how would you write a constructor for this type?
template <typename H, typename... T>
struct Multilist<H, T...> {
H x;
Multilist<T...> next;
};
Multilist<int, string, float> foo{42, "XXX", 1.23};
# The include "throw.h" the extern "the C" {void seppuku () {throw statement the Exception () ; }}
Another one I liked:
the struct the Exception {};
#ifdef __cplusplus
the extern "the C" {
#endif
void seppuku ();
# Ifdef __cplusplus
}
# endif
Now you know it. Next time you're looking at some incomprehensible c++ code, run it through Google translate. It may improve it.
I have been using Ubuntu for a while now. From the time when Canonical actually mailed real, physical CDs of the distro. So get of my lawn.
In all of my Linux years I have never, ever, had such a horrible installation experience as I did this weekend with Ubuntu 15.10. I may go as far as saying not even Windows ME was this horrible to install. I hit dozens of critical show-stopper bugs, from poor UEFI support to an installer that crashed when clicking "Go back". And that's only the installation, don't get me started on the new KDE Plasma 5 desktop... (hint: my big desktop screen is NOT a phone. Swiping to login? Bad idea for a mouse).
A few hints for any other poor souls that made the fatal mistake of installing Ubuntu ME:
2016? Still not the year of the Linux desktop.
Update: XFCE is great... except it doesn't really support moving the mouse. Seems Ubuntu is having a nostalgic release and decided to introduce old bugs from 2012!
Luckily, there's an easy way to replace built in commands with custom ones: cabbrev. cabbrev will do a textual replacement, so if you add "cabbrev tabnew TabNew" to your vimrc, eachtime you type "tabnew" it will be translated to TabNew.
Bonus tip: The command is actually, "abbrev", not "cabbrev". The "c" stands for command: it's telling Vim that you want the abbrev command applied in command mode. You can also use it as "nabbrev" to have it applied in normal mode. "abbrev" it's a nice way to correct common typos!
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.
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.
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);
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.
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.
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:
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.
I hacked together IMGeotagger, a Geotagger for Linux (though it should work in Windows too) that uses Google maps.
Recently, after coming back from a trip, I tried to geotag (*) my pictures. I don't have a fancy GPS device for my camera but I do have a fairly good memory. There are applications that will let you drop your pics to a map, then get the GPS coordinates out of that. Unfortunately, the current state of geotagging applications in Linux is just sad.
Gotten Geography mostly works. I don't find it very nice to use, though. Pictag doesn't even work anymore, although I have hacked a version which at least manages to start in modern Ubuntu setups. That puts it more or less at the same level as Gotten Geography. Both suffer from a fatal problem: there is no latin charset maps for places that don't use a latin alfabet. Now, this is clearly not a fault in either program.
Both Gotten and Pictag use the (incredibly awesome) Open Street Map project. OSM provides some default map rendered tiles, and those are in the "local" language. Transliterating the local written name of a street is not an easy task. The rules in each place are completely different, some places have a completely different name in latin chars than they do in the local alphabet and a million other problems that can't be solved as a general case.
What to do when there are no readily available OSM tiles with latin chars? There is a fairly good product that does provide latin names for most (all?) places in the world: Google maps. Now, there is a reason neither Gotten nor Pictag use Google maps for geotagging: Google maps has no (free?) API to get tiles which you can embed in an application. It does let users view their maps in a browser, though. And the map URI is a nice and easy way to translate from map-tiles to map-coordinates.
I'm not 100% sure if IMGeotagger falls under Google maps terms of use, so I may have to take it down in the future. What it does is pretty simple: you use a browser to select a place, then IMGeotagger retrieves the location from the URI of the browser. This will break when Google maps changes their URI structure; until then, IMGeotagger works pretty well and it uses a really nice map (sorry OSM, G. Maps are pretty good).
You can grab the IMGeotagger (and its source code, as it's open source) from https://github.com/nicolasbrailo/IMGeotagger.
(*) What's geotagging? That's adding GPS coordinates on the exif metadata of your pictures. This is only useful to nerds and very pedantic people who enjoy analyzing photo albums to get GPS plots and other nerdy things like that.
To debug a native Android application, a binary called gdbserver and its associated gdb.setup must be included in the generated APK file. Including this into the APK can be very painful in Gradle, so here's a workaround I found:
Edit: remember you may need to chmod +777 your gdbserver.