Skip to content

Instantly share code, notes, and snippets.

View ipereziriarte's full-sized avatar
🦄
Building Unicorns

Imanol Pérez Iriarte ipereziriarte

🦄
Building Unicorns
View GitHub Profile
@ipereziriarte
ipereziriarte / gist:4202772
Created December 4, 2012 11:14
Android Restart Activity
private void restartFirstActivity() {
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
@ipereziriarte
ipereziriarte / barcodeScanner.py
Created January 9, 2013 10:57
Read Barcode and Isbn with android and Python
import android
droid = android.Android()
(id, result, error) = droid.scanBarcode()
isbn = int(result['SCAN_RESULT'])
url = "http://books.google.com?q=%d" % isbn
@ipereziriarte
ipereziriarte / reversegeoAndroid.java
Last active December 11, 2015 07:19
Get an address using a location object
/**
* Gets a reverse address from a location
*/
private void getAddress() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD
&& Geocoder.isPresent()) {
(new ReverseGeocodingTask(getSherlockActivity())).execute(new Location[] {
mLocation
});
@ipereziriarte
ipereziriarte / findbugs-exclude.xml
Created April 4, 2013 07:11
Suppress FindBugs specific warnings
<Match>
<Class name="com.mycompany.Foo" />
<Method name="bar" />
<Bug pattern="DLS_DEAD_STORE_OF_CLASS_LITERAL" />
</Match>
@ipereziriarte
ipereziriarte / build.gradle
Created May 22, 2013 15:19
Build Gradle fest dependecies
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
@ipereziriarte
ipereziriarte / FragmentBestPractice
Created May 24, 2013 09:12
Fragment initialization, best practices recommendations from Google IO/13
class Name extends Fragment {
// Key to find our state in a bundle
private static String ARG_STATE = "arg-state";
private Parcelable state;
/**
* Empty constructor
*
* **/
public Name() {
<!DOCTYPE html>
<html lang="${lang}">
<head>
<title>&{'admin.register.html.politician.page.title.text'}</title>
</head>
<body>
<script src="http://code.jquery.com/jquery.js"></script>
<form enctype="multipart/form-data">
<input type="file" id="photo" name="photo">
</form>
@ipereziriarte
ipereziriarte / build.gradle
Created September 13, 2013 13:08
This is a build gradle file for android that includes robolectric, checkstyle, sonar, findbugs and pmd.
buildscript {
dependencies {
repositories {
mavenCentral()
mavenLocal()
}
classpath 'com.android.tools.build:gradle:0.5.+'
classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.+'
@ipereziriarte
ipereziriarte / French and cyrilic regex
Created October 16, 2013 08:45
French and cyrilic regex
/^[\w\sáéíóäëiöúàèììùaaâêîôûа-яА-ЯёЁ]+$ /i French and cyrilic
@ipereziriarte
ipereziriarte / GetHash.java
Created October 17, 2013 10:54
I had some trouble login in Facebook with the skd 3.4. Finally the problem was that the hash generated by the keytool was different from the hash that the app was using. If you write this snipped of code in the onCreate method of your main activity you'll get the correct hash and then you can write it down in your facebook app control panel
try {
PackageInfo info = getPackageManager().getPackageInfo(
getPackageName(),
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("TAG", "Hash to copy ==> " + Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {