phantom This application failed to start because it could not find or load the Qt platform plugin “xcb”.

If you encounter this issue, it’s a bug in phantomjs that prevents it from working properly when QT_QPA_PLATFORM environment variable is set.

The best way to solve this issue is to upgrade to the newest phantom, but if you cannot do it, you can unset the variable:
unset QT_QPA_PLATFORM
or give it an empty value, e.g.:
export QT_QPA_PLATFORM=""

If you don’t want to type the command every time, you can one of the above to .bashrc or .profile

Here’s one of the related issues on GitHub: https://github.com/ariya/phantomjs/issues/14061

Invoking angular stuff from console

To get an angular service in chrome console you can use:

angular.element(document.body).injector().get('serviceName')

This will get you a service object.

Source: http://stackoverflow.com/questions/15527832/how-can-i-test-an-angularjs-service-from-the-console

To get to angular scope, inspect an element, for which you want to get the scope and invoke: angular.element($0).scope()

(http://stackoverflow.com/questions/13743058/how-to-access-the-scope-variable-in-browsers-console-using-angularjs)

PostgreSQL on Fedora: psql: FATAL: Ident authentication failed for user “username”

Usually, to add a user to postgres, you have to run psql as user postgres and create user as such.

On Ubuntu it’s enough to let you log in as a newly created user to the DB, but it’s not enough on Fedora. Here psql responds with the error from the subject.

To fix it add the following line to pg_hba.conf (on F23: /var/lib/pgsql/data/pg_hba.conf):

local   all             all                           md5

Line above is for socket configuration. If you need IP access too, add:

host    all             all        127.0.0.1/32       md5

PostgreSQL faster dump & restore

For PostgreSQL it takes a lot of time to import a text-based dump.

It turns out that binary dumps are imported much faster.
To create a binary dump run:

pg_dump -Fc dbname > /tmp/database.bak

Creating a database upon dump import should work, but for me it didn’t on PostgreSQL 9.4, so I recommend first creating the database and then running:

pg_restore -Fc /tmp/database.bak -d dbname

Debugging C/C++ programs with GDB

Starting

Compiling

To add debugging info to an executable generated by gcc:

gcc -g source.c

Amount of debugging info added by gcc can be controlled.
For minimal debug info use: -g1, for maximal: -g3

Running

gdb a.out

To skip intro message add -q flag.

To attach gdb to a running process:

gdb a.out pid 

Debugging

breakpoints

Setting a breakpoint

Set a breakpoint at specific line:

break line_number

If you have multiple source files you can specify one:

break source.c:line_number

Set a breakpoint on a function call:

break function_name
break source.c:function_name

You can make a breakpoint conditional by adding if condition to breakpoint definition. E.g.:

break 12 if x > 5

Removing a breakpoint

clear line_number
clear function_name

Versions with source_file_name work as well.

running and traversing

To start debugging an app run:

run

If you have set breakpoints, the app will stop at first of them.

command description
n go to the next line of program
s make a single step in execution, i.e. go into the function if another function is called at our current line or go to the next line.
c continue execution (i.e. go to the next breakpoint or finish

printing out variables

To print value of a specific variable:

print variable_name

To print array:

print *array_name@length

To print all function arguments with their values:

info args

To print all local variables with their values:

info locals

To print all global and static variables with their values:

info variables

trace/frames

To print out function calls that lead to current place:

bt

To print frames: frame
To step into specific frame (e.g. to print out callers variables):

frame frame_number

To switch between frames one can also use: up and down

Extras

Quitting

q

calling a function

While debugging a program one can call a function. To do it use:

call function_name(function_params)

E.g.: call print("some text\n")

heap consistency checking

To enable controlling of mallocated memory one can call:

mcheck(0)

The function has to be called before the first malloc.
To call it from gdb use:

call mcheck(0)

More info about mcheck: http://www.gnu.org/software/libc/manual/html_node/Heap-Consistency-Checking.html

For more info about gdb visit: http://www.yolinux.com/TUTORIALS/GDB-Commands.html