Skip to content

Instantly share code, notes, and snippets.

View mladenp's full-sized avatar

Mladen Petrović mladenp

View GitHub Profile
@mladenp
mladenp / git_ls-files
Created December 22, 2016 10:22
Count lines of code in git repo
git ls-files | xargs wc -l
@mladenp
mladenp / redux-thunk-examples.js
Created January 16, 2017 13:45 — forked from markerikson/redux-thunk-examples.js
Redux-Thunk examples
// The classic AJAX call - dispatch before the request, and after it comes back
function myThunkActionCreator(someValue) {
return (dispatch, getState) => {
dispatch({type : "REQUEST_STARTED"});
myAjaxLib.post("/someEndpoint", {data : someValue})
.then(response => dispatch({type : "REQUEST_SUCCEEDED", payload : response})
.catch(error => dispatch({type : "REQUEST_FAILED", error : error});
};
}
@mladenp
mladenp / .eslintrc
Created January 31, 2017 13:03 — forked from cletusw/.eslintrc
ESLint Reset - A starter .eslintrc file that resets all rules to off and includes a description of what each rule does. From here, enable the rules that you care about by changing the 0 to a 1 or 2. 1 means warning (will not affect exit code) and 2 means error (will affect exit code).
{
// http://eslint.org/docs/rules/
"ecmaFeatures": {
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"defaultParams": false, // enable default function parameters
"forOf": false, // enable for-of loops
"generators": false, // enable generators
"objectLiteralComputedProperties": false, // enable computed object literal property names
@mladenp
mladenp / mac-sierra-tweaks
Created March 15, 2017 16:20
MacOS Sierra Tweaks
Speed Up Mission Control Animations in MacOS Sierra:
defaults write com.apple.dock expose-animation-duration -float 0.1
// and restart Dock with "killall Dock"
// Go back to default speed:
defaults delete com.apple.dock expose-animation-duration; killall Dock
Set Key Repeat:
defaults write -g InitialKeyRepeat -int 10 # normal minimum is 15 (225 ms)
defaults write -g KeyRepeat -int 1 # normal minimum is 2 (30 ms)
// login/logoff is neded
@mladenp
mladenp / GPScalculateDistance.js
Created May 16, 2017 12:10
Calulate Distance between lat lng points
/* Calculate Distance between two latitute & longitude points */
function GPScalculateDistance(lat1, lng1, lat2, lng2)
{
//radians
lat1 = (lat1 * 2.0 * Math.PI) / 60.0 / 360.0;
lng1 = (lng1 * 2.0 * Math.PI) / 60.0 / 360.0;
lat2 = (lat2 * 2.0 * Math.PI) / 60.0 / 360.0;
lng2 = (lng2 * 2.0 * Math.PI) / 60.0 / 360.0;
@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; } }}'
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 / 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"
@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 / 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 *.*