Skip to content

Instantly share code, notes, and snippets.

@speto
speto / bashBraceExpansion
Last active May 2, 2016 14:08
How to make your command line life easier with bash brace expansion
chimney@chimney.local:~/workspace$ echo a{0..3}b
a0b a1b a2b a3b
chimney@chimney.local:~/workspace$ echo a{0..3}
a0 a1 a2 a3
chimney@chimney.local:~/workspace$ echo a{0,3}
a0 a3
chimney@chimney.local:~/workspace$ echo {a,b{1..3},c}
@speto
speto / scp.sh
Last active May 2, 2016 14:04
Simple scp command example
scp -r user@example.com:/remote/path/to/foo /local/home/user/Desktop/
scp -r user@example.com:~/dummies .
@speto
speto / dummies.sh
Last active May 2, 2016 14:03
How to generate dummy text files e.g. for benchmarking purpose
#vygenerovat 7tisic riadkovy txt
yes "AAA|1241525678|Zleteli orly z Tatry, tiahnu na podolia, ponad vysoké hory, ponad rovné polia|0|0" | head -$((1000*7)) > dummy7000.txt
C=5 && yes "AAA|1241525678|Zleteli orly z Tatry, tiahnu na podolia, ponad vysoké hory, ponad rovné polia|0|0" | head -$((1000*$C)) > "dummy$C.txt"
C=5 && yes "AAA|1241525678|Zleteli orly z Tatry, tiahnu na podolia, ponad vysoké hory, ponad rovné polia|0|0" | head -$[1000*$C] > "dummy$C.txt"
for i in {1..6}; do yes "AAA|1241525678|Zleteli orly z Tatry, tiahnu na podolia, ponad vysoké hory, ponad rovné polia|0|0" | head -$((100*$i)) > "dummy$i.txt"; done
dd if=/dev/urandom bs=1024 count=5 of=dummy.txt
The Python 2.7 documentation recommends the use of cProfile to profile Python code with reasonnably low overhead: https://docs.python.org/release/2.7/library/profile.html
If you use virtualenv, dont forget to activate it:
$ . bin/activate
How do you launch your script with cProfile enabled ?
$ python -m cProfile -o run.profile myscript.py
The output file (run.profile) will be generated when the execution terminates (including CTRL-C).
@speto
speto / hashCode.js
Last active May 2, 2016 14:20
Simple hashing function for JS string
//http://stackoverflow.com/a/22429679
String.prototype.hashCode = function(){
var FNV1_32A_INIT = 0x811c9dc5;
var hval = FNV1_32A_INIT;
for ( var i = 0; i < this.length; ++i )
{
hval ^= this.charCodeAt(i);
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
}
return hval >>> 0;
@speto
speto / grep.sh
Last active August 29, 2015 14:17 — forked from NapoleonWils0n/grep.sh
pbpaste | grep -o 'http://[^"]*'
@speto
speto / webserver.sh
Last active May 3, 2016 08:54
Simple shell script for starting PHP built-in web server on specific port with port use checking
#!/usr/bin/env bash
if [ -z $1 ]; then
echo "Usage: $0 port [dir]"
exit
fi
#kontola ci sa port nahodou nepouziva
CHECK=`lsof -i:$1`
if [[ $CHECK != "" ]]; then
@speto
speto / uri.js
Last active August 29, 2015 14:20 — forked from jlong/uri.js
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@speto
speto / current-dir.sh
Last active July 19, 2016 13:17
How to get directory of currently running script in bash
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo $DIR
@speto
speto / refreshDockIcon.md
Last active May 2, 2016 14:13
How to refresh OS X dock icon for specific application

If you only want to update one Application icon, ie, in App.app/Contents/Resources/App.icns just touch the App.app folder. (I've read you need to do the Info.plist as well sometimes, although I've never needed to.)

Close the finder windows and:

touch /Applications/App.app
touch /Applications/App.app/Contents/Info.plist

You can refresh the dock icon cache using the commands above, also do a killall Dock to restart it. Personally I would just drag the application in question, off the dock and re-start / keep in dock, because this is generally a one off thing. As always, script it if possible / and you're doing it a lot.

source: https://gist.github.com/fabiofl/5873100#gistcomment-1320553