Skip to content

Instantly share code, notes, and snippets.

View darwind's full-sized avatar

Kasper Rugård Thomsen darwind

  • rugaard.it
  • Copenhagen
View GitHub Profile
@darwind
darwind / date-to-string-and-string-to-date
Last active August 29, 2015 14:02
Formatting NSDate to NSString and vice versa...
---- NSDate -> NSString ----
NSDateFormatter *formatter;
NSString *dateString;
formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd-MM-yyyy HH:mm"]; // Change accordingly.
dateString = [formatter stringFromDate:[NSDate date]];
@darwind
darwind / AndroidVersionCode.java
Created August 7, 2014 13:19
Gets the versioncode of the current app.
public int getVersionCode() {
int versionCode = 0;
try {
versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
} catch (PackageManager.NameNotFoundException e) {
// Huh? Really?
}
return versionCode;
}
@darwind
darwind / gist:08241d74d01fef0dfb69
Last active August 29, 2015 14:05
Show/hide Navigation Bar in iOS
To hide the navigation bar:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
To show it:
[[self navigationController] setNavigationBarHidden:NO animated:YES];
See: http://stackoverflow.com/questions/2926914/navigation-bar-show-hide
@darwind
darwind / MainActivity.java
Last active August 29, 2015 14:14
Implementing the new ToolBar instead of the ActionBar
package com.example.toolbarexample;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
@darwind
darwind / snippet
Created February 24, 2015 20:59
Android - open Language settings directly from an app.
startActivity(new Intent(Settings.ACTION_LOCALE_SETTINGS));
@darwind
darwind / gist:5a6101667b5304d79b9a
Last active July 27, 2016 10:43
Get Android keyhash programatically...
// Add code to print out the key hash
try {
PackageInfo info = getPackageManager().getPackageInfo("my.app.packagename",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {
@darwind
darwind / gist:773f6abf703b5ec18583
Created March 14, 2015 20:16
Android: sharing photos to Facebook
Uri myImageContentUri; // A content Uri to the image you would like to share.
String myAppId = "<Your_Facebook_App_Id>";
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, myImageContentUri);
// Include your Facebook App Id for attribution
shareIntent.putExtra("com.facebook.platform.extra.APPLICATION_ID", myAppId);
@darwind
darwind / gist:02f5bea23338af53ab42
Created March 16, 2015 19:42
Android: load bitmap from Drawable
Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_resource);
@darwind
darwind / gist:32458409aeac7c945784
Created May 3, 2015 19:23
Android screenresolutions
List of good posts about Android screenresolutions:
http://stackoverflow.com/questions/6272384/most-popular-screen-sizes-resolutions-on-android-phones
http://petrnohejl.github.io/Android-Cheatsheet-For-Graphic-Designers/
More to come...
@darwind
darwind / FizzBuzz
Created November 4, 2015 23:36
I read about this test on Quora and just wanted to see if I was actually a real programmer... ;-)
public class FizzBuzz {
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
if ((i % 5 == 0) && (i % 3 == 0)) {
System.out.println("FizzBuzz");
} else if (i % 3 == 0) {
System.out.println("Fizz");
} else if (i % 5 == 0) {
System.out.println("Buzz");
} else {