Skip to content

Instantly share code, notes, and snippets.

View mladenp's full-sized avatar

Mladen Petrović mladenp

View GitHub Profile
@mladenp
mladenp / componentDidMount.test.js
Created May 30, 2018 16:41
Test componentDidMount jest
it('componentDidMount should dispatch loadHomeAction', () => {
const wrapper = shallow(<Home dispatch={jest.fn()} />);
wrapper.instance().componentDidMount();
expect(wrapper.instance().props.dispatch).toBeCalledWith(loadHomeAction());
});
@mladenp
mladenp / psql-drop-db
Created January 18, 2018 01:16
Postgres DROP db - right way
/* Disable connection to Database */
UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'mydb';
/* Get postgres process id */
SELECT pg_backend_pid();
/* Force Disconnect all clients ( use pid from previous step) */
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'mydb';
/* Finaly Drop database */
@mladenp
mladenp / postgres-commands
Last active January 15, 2018 15:18
Postgres commands list
Start Postgres without background service:
pg_ctl -D /usr/local/var/postgres start
Login to postgresql:
psql -d mydb -U myuser -W
psql -h myhost -d mydb -U myuser -W
psql -U myuser -h myhost "dbname=mydb sslmode=require" # ssl connection
Default Admin Login:
sudo -u postgres psql -U postgres
@mladenp
mladenp / postgres cheatsheet.md
Created October 5, 2017 14:51 — forked from apolloclark/postgres cheatsheet.md
postgres cheatsheet

Postgres Cheatsheet

This is a collection of the most common commands I run while administering Postgres databases. The variables shown between the open and closed tags, "<" and ">", should be replaced with a name you choose. Postgres has multiple shortcut functions, starting with a forward slash, "". Any SQL command that is not a shortcut, must end with a semicolon, ";". You can use the keyboard UP and DOWN keys to scroll the history of previous commands you've run.

Setup

installation, Ubuntu

http://www.postgresql.org/download/linux/ubuntu/ https://help.ubuntu.com/community/PostgreSQL

@mladenp
mladenp / esritogeo.js
Created June 13, 2017 10:27 — forked from odoe/esritogeo.js
Convert ESRI-JSON to GeoJSON
var stripJSON = function(str) {
return str.replace(/\\n/g, "\\n")
.replace(/\\t/g, "\\t");
};
var jsonToObject = function(stringIn) {
var data;
try {
data = JSON.parse(stripJSON(stringIn));
console.log("json converted to object");
@mladenp
mladenp / postgres-cheatsheet.md
Created June 4, 2017 02:11 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

If run with -E flag, it will describe the underlaying queries of the \ commands (cool for learning!).

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*

@mladenp
mladenp / bash_find_all_files.sh
Created June 1, 2017 07:31
Bash script - list recursively with find
find . -print0 | while IFS= read -r -d '' file
do
echo "$file"
done
@mladenp
mladenp / tail_rm_first_line
Created June 1, 2017 05:14
Remove First line of the file
tail -n +2 "$FILE" > "$FILE.tmp" && mv "$FILE.tmp" "$FILE"
var degrees2meters = function(lon,lat) {
var x = lon * 20037508.34 / 180;
var y = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180);
y = y * 20037508.34 / 180;
return [x, y]
}
lon= -77.035974
lat = 38.898717
@mladenp
mladenp / gist:3d908e2dae9a27179246018ca103130f
Created May 16, 2017 15:31 — forked from khakimov/gist:3558086
Matrix Effect in you terminal
echo -e "\e[1;40m" ; clear ; while :; do echo $LINES $COLUMNS $(( $RANDOM % $COLUMNS)) $(( $RANDOM % 72 )) ;sleep 0.05; done|awk '{ letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()"; c=$4; letter=substr(letters,c,1);a[$3]=0;for (x in a) {o=a[x];a[x]=a[x]+1; printf "\033[%s;%sH\033[2;32m%s",o,x,letter; printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,letter;if (a[x] >= $1) { a[x]=0; } }}'