Skip to content

Instantly share code, notes, and snippets.

View mcatta's full-sized avatar
📚
Learning

Marco Cattaneo mcatta

📚
Learning
View GitHub Profile
@mcatta
mcatta / pre-match-example
Created May 8, 2013 10:02
Ricerca per pattern in PHP
$to_search = '{pippo}';
preg_match("/{(.*)}/", $to_search, $result_array);
$result_array; // Array with results, string {string}
@mcatta
mcatta / convert-pass-md5
Created May 8, 2013 14:08
Android/Java convert String to MD5
public static String convertPassMd5(String pass) {
String password = null;
MessageDigest mdEnc;
try {
mdEnc = MessageDigest.getInstance("MD5");
mdEnc.update(pass.getBytes(), 0, pass.length());
pass = new BigInteger(1, mdEnc.digest()).toString(16);
while (pass.length() < 32) {
pass = "0" + pass;
}
@mcatta
mcatta / AndroidManfiest
Created May 8, 2013 14:09
Android check connectivity
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
@mcatta
mcatta / AndroidManifest
Created May 8, 2013 14:12
Java recursive delete dir
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@mcatta
mcatta / AndroidManifest
Created May 8, 2013 14:15
Android getMacAddress
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
@mcatta
mcatta / sdcard-access
Created May 8, 2013 15:47
Android File system snippet
Environment.getExternalStorageDirectory(); // something like /sdcard/
@mcatta
mcatta / array-adapter
Created May 10, 2013 15:40
Simple android adapters
String[] items = { "this", "is", "a", "really" };
ArrayAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, items));
@mcatta
mcatta / override-back-press
Created May 12, 2013 16:05
Override backPress android
@Override
public void onBackPressed() {
if(close_count==1) {
Toast.makeText(getApplicationContext(), "Press back again to close application...", Toast.LENGTH_SHORT).show();
close_count--;
return;
}
super.onBackPressed();
@mcatta
mcatta / intent-mail-send
Created May 13, 2013 07:33
Email intent send
Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
Uri.fromParts("mailto","[email protected]", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "EXTRA_SUBJECT");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
@mcatta
mcatta / DownloadThread
Created May 13, 2013 10:15
Download thread
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
public class DownloadThread extends Thread {