Skip to content

Instantly share code, notes, and snippets.

View gipi's full-sized avatar
😎
code for food

Gianluca Pacchiella gipi

😎
code for food
View GitHub Profile
@gipi
gipi / gist:1267311
Created October 6, 2011 12:46
To launch a web page in a browser from an activity
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
@gipi
gipi / gist:1267393
Created October 6, 2011 13:29
Retrieve an identification ID from an android device
// http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id
final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice, tmSerial, tmPhone, androidId;
tmDevice = "" + tm.getDeviceId();
tmSerial = "" + tm.getSimSerialNumber();
androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
String deviceId = deviceUuid.toString();
@gipi
gipi / SegmentedButton.java
Created October 7, 2011 09:13
Customized Segmented button
/**
* Customization of the RadioButton in order to allow behaviour
* and appearance like the iOS ones.
*
* Inspired from http://blog.bookworm.at/2010/10/segmented-controls-in-android.html
*/
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.GradientDrawable;
import android.graphics.Canvas;
@gipi
gipi / gist:1289605
Created October 15, 2011 14:03
Simple shell routine to calculate dpi
function calcdpi() {
echo "sqrt($1^2+$2^2)/$3" | bc
}
@gipi
gipi / gist:1292237
Created October 17, 2011 09:02
Install an APK in all running emulators/devices
# ant clean && ant debug && adbInstallAll
adbInstallAll() {
adb devices | \
sed '1d;/^$/d;' | \
awk '{print $1}' | \
while read device;
do
adb -s $device install -r bin/*-debug.apk
done
@gipi
gipi / gist:1292453
Created October 17, 2011 11:49
Set term title
set_console_title() {
PROMPT_COMMAND='echo -ne "\033]0;"'$1'"\007"';
}
@gipi
gipi / gist:1292623
Created October 17, 2011 13:38
Add a documentation target to Android ant build file
<target name="docs">
<javadoc
sourcepath="src/"
destdir="docs/"
/>
</target>
@gipi
gipi / progress.xml
Created October 18, 2011 14:26
Customize progress bar colors in Android
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Horizontal"
android:progressDrawable="@drawable/progress_horizontal"
/>
@gipi
gipi / gist:1298537
Created October 19, 2011 14:57
Pass paremeters between Activity
// calling activity
Intent i= new Intent(context, QRActivity.class);
i.putExtra("url", url);
startActivity(i);
// callee activity
Bundle extras = getIntent().getExtras();
if (extras != null) {
mUrl = extras.getString("url");
@gipi
gipi / singleton.py
Created October 19, 2011 20:25
Implementation of Singleton design pattern in Python (inspired from Alex Martelli talk)
# python -m doctest singleton.py
class Singleton(object):
"""
>>> s = Singleton()
>>> s #doctest: +ELLIPSIS
<hidden.Singleton object at 0x...>
>>> p = Singleton()
>>> p == s
True
"""