Skip to content

Instantly share code, notes, and snippets.

@dannyroa
dannyroa / TextResource.kt
Last active May 2, 2022 18:34
TextResource
import android.content.res.Resources
import androidx.annotation.PluralsRes
import androidx.annotation.StringRes
// from https://hannesdorfmann.com/abstraction-text-resource/
sealed class TextResource {
companion object {
// Just needed for static method factory so that we can keep concrete implementations file private
fun fromText(text: String): TextResource = SimpleTextResource(text)
[{"name" : "Washington, DC",
"country" : "USA"},
{"name" : "Berlin",
"country" : "Germany"},
{"name" : "Frankfurt",
"country" : "Germany"},
{"name" : "London",
"country" : "United Kingdom"},
{"name" : "Shanghai",
"country" : "China"},
@app.route('/hello/')
@app.route('/hello/<name>')
def hello(name=None):
if not name:
return "Please type a name"
#open shelve
filename = 'names.db'
d = shelve.open(filename)
@dannyroa
dannyroa / gist:5744412
Created June 9, 2013 17:28
ActionBat PullToRefresh Error Log
E/AndroidRuntime(21307): java.lang.RuntimeException: Unable to start activity ComponentInfo{uk.co.senab.actionbarpulltorefresh.sample/uk.co.senab.actionbarpulltorefresh.sample.ListViewActivity}: java.lang.RuntimeException: Unknown animation name: LinearLayout
E/AndroidRuntime(21307): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
E/AndroidRuntime(21307): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E/AndroidRuntime(21307): at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime(21307): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime(21307): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(21307): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(21307): at android.app.ActivityThread.main(ActivityThread.java:5041)
@dannyroa
dannyroa / access_token.py
Last active December 18, 2015 01:28
google oauth2 login
def get_access_token(request):
token = request.GET.get('token', None)
if not token:
return HttpResponse('error')
users = GlassUser.Query.all().eq(token=token)
@dannyroa
dannyroa / gist:5528998
Created May 6, 2013 23:08
fake camera & gallery for android
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
def get_val():
words = { 1 : 'one', 2 : 'two', 3 : 'three', 4 : 'four', 5 : 'five', 6 : 'six', 7 : 'seven'
, 8 : 'eight', 9 : 'nine', 10 : 'ten', 11 : 'eleven', 12 : 'twelve', 13 : 'thirteen'
, 14 : 'fourteen', 15 : 'fifteen', 16 : 'sixteen', 17 : 'seventeen', 18 : 'eighteen'
, 19 : 'nineteen', 20 : 'twenty', 30 : 'thirty', 40 : 'forty', 50 : 'fifty', 60 : 'sixty'
, 70 : 'seventy', 80 : 'eighty', 90 : 'ninety', 100 : 'hundred', 1000 : 'thousand' }
# Sorting a List using Mergesort in Python
# 2011-05-16
def mergeSort(toSort):
if len(toSort) <= 1:
return toSort
mIndex = len(toSort) / 2
left = mergeSort(toSort[:mIndex])
right = mergeSort(toSort[mIndex:])
class FacebookBackend:
"""
Authenticates against django.contrib.auth.models.User.
"""
@ staticmethod
def authenticate(request):
if 'access_token' in request.session:
@dannyroa
dannyroa / backends.py
Last active December 11, 2015 11:58
'code' should only be used once. Once the 'code' is used to obtain the 'access_token', store the 'access_token' to the session. Use 'access_token' if available in the session.
from django.contrib.auth.models import User
from facebookconnect.models import FacebookProfile
from django.conf import settings
from django.core.urlresolvers import reverse
import facebook
from facebookconnect.utils import facebook_login_check, get_access_token
class FacebookConnectBackend:
"""