Skip to content

Instantly share code, notes, and snippets.

@mpuz
mpuz / gist:953c4d503bcf2a338f8e48d279a3c838
Created March 29, 2017 20:44
IP Traffic Class specs
For Internet Protocol v4 the value consists of an integer, the least significant 8 bits of which represent the value of the TOS octet in IP packets sent by the socket. RFC 1349 defines the TOS values as follows:
IPTOS_LOWCOST (0x02)
IPTOS_RELIABILITY (0x04)
IPTOS_THROUGHPUT (0x08)
IPTOS_LOWDELAY (0x10)
The last low order bit is always ignored as this corresponds to the MBZ (must be zero) bit.
24 is 0x18 i.e. 0x10 | 0x08, which corresponds to IPTOS_THROUGHPUT and IPTOS_LOWDELAY being set.
@mpuz
mpuz / gist:81fbda3d0b9a6796dddbdd7a1da66e39
Created March 31, 2017 17:11
Android, Java: pass method as argument to dialog
//You can use a Runnable to wrap your method:
Runnable r = new Runnable() {
public void run() {
Sesija.forceNalog(reg.getText().toString(), num);
}
}
//Then pass it to your method and call r.run(); where you need it:
@mpuz
mpuz / gist:bedae3038ec7bef3a046398ec74ff377
Created April 4, 2017 10:46
Raspberry Pi - get serial
//BASH
cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2
//BASH PERL
cat /proc/cpuinfo | perl -n -e '/^Serial[ ]*: ([0-9a-f]{16})$/ && print "$1\n"'
//Python
SELECT setval('tbl_tbl_id_seq', max(tbl_id)) FROM tbl;
The for–in loop is for looping over object properties.
The for–of loop is for looping over data—like the values in an array.
@mpuz
mpuz / hashcode.js
Created March 18, 2020 14:50
JavaScript implementation of hashcode
/**
* Returns a hash code for a string.
* (Compatible to Java's String.hashCode())
*
* The hash code for a string object is computed as
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
* using number arithmetic, where s[i] is the i th character
* of the given string, n is the length of the string,
* and ^ indicates exponentiation.
* (The hash value of the empty string is zero.)
@mpuz
mpuz / copysshkeys.sh
Created April 1, 2020 20:45
copying SSH keys to server
cat ~/.ssh/id_rsa.pub | ssh user@222.22.22.2 "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"
@mpuz
mpuz / checkinternetspeedfromcli.txt
Last active April 3, 2021 18:50
check internet speed from cli
curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -
@mpuz
mpuz / moveup.sh
Created September 30, 2021 17:08
moves files from subfolders up
find . -mindepth 2 -type f -print -exec mv --backup=numbered {} . \;
@mpuz
mpuz / fixnode.txt
Created October 12, 2021 11:19
fix node js permissions
sudo chown -R $USER ~/.npm
sudo chown -R $USER /usr/lib/node_modules
sudo chown -R $USER /usr/local/lib/node_modules