Skip to content

Instantly share code, notes, and snippets.

View gnuton's full-sized avatar
:shipit:

Antonio Aloisio gnuton

:shipit:
View GitHub Profile
@gnuton
gnuton / gist:513c67283bc4458dd3bd
Created December 2, 2014 15:01
Hijack STDERR and STDOUT stream - useful in tests
import sys
class MyStream(object):
S = property(lambda self: self._S)
def __init__(self):
self._S = ""
def write(self, s):
self._S += s
@gnuton
gnuton / gist:99f128f7587832f6a9b9
Created July 15, 2015 18:50
calculate logarithm in python
# complexity: logarihmic! :D
def log2(n):
result=0
while n > 1:
n//=2
result +=1
return result
import unittest
import math
@gnuton
gnuton / BoilerPipeTask.java
Created May 21, 2013 23:04
Generic Android Async Task with internal interface
package com.example.toniotest.utils;
import android.os.AsyncTask;
/**
* Created by gnuton on 5/22/13.
*/
public class BoilerPipeTask extends AsyncTask<String, Void, String> {
private static final String TAG = "BOILER PIPE TASK";
@gnuton
gnuton / gist:5748980
Created June 10, 2013 14:09
Printing in utf8 unicode escaped strings in Python
t = 'R\\u00f3is\\u00edn'
print(t.decode('unicode_escape'))
output => Róisín
private TextView htmlTextView;
private SpannableStringBuilder htmlSpannable;
@Override
public void onCreate(Bundle savedInstanceState) {
// ...
// first parse the html
// replace getHtmlCode() with whatever generates/fetches your html
@gnuton
gnuton / DiskLruImageCache.java
Created June 18, 2013 06:42
Using Log on Android
if ( BuildConfig.DEBUG ) {
Log.d(TAG, "getBitmap " + key);
}
@gnuton
gnuton / ImageAdapter.java
Last active December 18, 2015 16:09
Image adapter for viewPager. It works with mViewPager.setOffscreenPageLimit(1);
/**
*
* Created by gnuton on 6/18/13.
*/
public class ImageAdapter extends PagerAdapter {
Context mContext;
public List<Drawable> mImages = new ArrayList<Drawable>();
private List<ImageView> mImageViews = new ArrayList<ImageView>();
@gnuton
gnuton / MainActivity.java
Created June 21, 2013 06:34
Get orientation on Android
/*Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();
Log.d(TAG, "Orientation " + rotation);
If in portrait mode
if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_0 )*/
@gnuton
gnuton / FragmentUtils.java
Created June 22, 2013 06:20
Fuck you Fragments IDs/TAGs! Here is the way to map dynamic fragments in your app!
public class FragmentUtils {
private static Map mMap = new HashMap<String, Fragment>();
public static Fragment getFragment(FragmentManager fm, String className, String tag){
if (tag == null)
tag = className;
Fragment f = (Fragment) mMap.get(tag);
if (f != null)
return f;

IDs

  • user_id - user/:uid
  • feed_id - feed/:feed_uri
  • category_id - :user_id/category/:category (special category: global.all, global.uncategorized)
  • tag_id - :user_id/tag/:tag (special tag: global.saved)

APIs

http://cloud.feedly.com/:version/:api