Skip to content

Instantly share code, notes, and snippets.

SELECT setval('tbl_tbl_id_seq', max(tbl_id)) FROM tbl;
@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
@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: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:1dd7bdf7c2b7c05afb32f62348f3484f
Created March 29, 2017 20:43
Android, Java: Connect to WiFi network
WifiConfiguration wifiConfig = new WifiConfiguration();
wifiConfig.SSID = String.format("\"%s\"", ssid);
wifiConfig.preSharedKey = String.format("\"%s\"", key);
WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);
//remember id
int netId = wifiManager.addNetwork(wifiConfig);
wifiManager.disconnect();
wifiManager.enableNetwork(netId, true);
wifiManager.reconnect();
@mpuz
mpuz / gist:1ca81ecfbbe39379f81db6a93ba0b8b5
Created March 29, 2017 20:16
Android, Java: Encrypt and decrypt strings using AES128
//Simple helper class to encrypt and decrypt strings using AES128.
//The result is Ascii-encoded (actually hex, no base64), so no byte[] has to be stored.
//A SEED value is used as a shared secret (“Master-Password”).
//Only with the same SEED the stored values can be decrypted.
package net.sf.andhsli.hotspotlogin;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
@mpuz
mpuz / gist:78e9e875df646698243affe1870dda58
Created March 29, 2017 20:14
Android, Java: mix 2 PCM audio files
private void mixSound() throws IOException {
AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, 44100, AudioTrack.MODE_STREAM);
InputStream in1=getResources().openRawResource(R.raw.track1);
InputStream in2=getResources().openRawResource(R.raw.track2);
byte[] music1 = null;
music1= new byte[in1.available()];
music1=convertStreamToByteArray(in1);
in1.close();
@mpuz
mpuz / gist:6a2fc5ce8d88a0a53a1766d66c493413
Created March 29, 2017 20:11
Android, Java: Multicast check
/** 
* Ensures that the caller receives an usable multicast socket. 
* In case the network configuration does not have a default gateway 
* set, the multicast socket might not work. This is the case when 
* the device is connected to a Wireless Direct printer. In that 
* cases, force a network interface into the socket. 
* @return A ready-to-use multicast socket. 
*/ 
public static MulticastSocket createMulticastSocket(Context context)
@mpuz
mpuz / gist:3d946ae784ed485476171b3e1b1467dd
Created March 29, 2017 20:09
Android, xml: Roboto type family
// From android 4.1 / 4.2, the following Roboto font families are available:
android:fontFamily="sans-serif" // roboto regular
android:fontFamily="sans-serif-light" // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-thin" // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium" // roboto medium (android 5.0)
// in combination with this
android:textStyle="normal|bold|italic"
@mpuz
mpuz / gist:4df99c57528725dbc8604bb67f4b2929
Created March 29, 2017 20:07
Android, Java: Gradients, banding
//Add the following override to your activity,
//This ought to fix the color banding issue you are seeing
//by setting the window format to support more colors.
@Override
public void onAttachedToWindow() {
getWindow().setFormat(PixelFormat.RGBA_8888);
}
//More info : http://developer.android.com/reference/android/view/Window.html#setFormat(int)