This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <random> | |
int randomInRange(int min, int max, std::mt19937 &eng) { | |
std::uniform_int_distribution<> distr(min, max); // define the range | |
return distr(eng); | |
} | |
int main() { | |
std::random_device rd; // obtain a random number from hardware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo mount -o remount,rw /your/device/here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TYPE DATABASE USER ADDRESS METHOD | |
# "local" is for Unix domain socket connections only | |
local all postgres peer | |
local all all md5 | |
# IPv4 local connections: | |
host all all 127.0.0.1/32 md5 | |
# IPv6 local connections: | |
host all all ::1/128 md5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rpad(string text, length int [, fill text]) | |
fill is space by default | |
select rpad('hello', 10, 'w') -- hellowwwww | |
select lpad('hello', 10, 'p') -- ppppphello | |
select lpad('hello', 10) -- ' hello' | |
select rpad('hello', 4) -- hell | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select date_part('month', '2011-10-22'); -- 10 | |
select extract(month from '2011-12-22'); -- 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select count(case when some_col>10 then 1 end) as some_alias; | |
select count(*) filter(where some_col>10) as some_alias; | |
-- same can be applied to any aggregation function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select coalesce(col1, col2); -- return first col, which is not null | |
select nullif(val1, val2); -- return null if val1==val2, otherwise return val1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select generate_series('2016-12-31'::date, '2017-02-03'::date, '2 days'); -- series of days with interval of 2 days | |
select generate_series(1, 5, 2); -- 1, 3, 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select date_trunc('month', '2011-12-12'); -- '2011-12-01 00:00:00.000000' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select generate_subscripts(array[array[1,2,3], array[4,5,6]], 2); -- 1,2,3 | |
select generate_subscripts(array[array[1,2,3], array[4,5,6]], 1); -- 1,2 |
OlderNewer