Tweepy User object structure

I’m working on a Python app that uses the Tweepy API.  The docs aren’t entirely thorough so I thought I’d put this out there for anyone who needed it like I did.

So for example, you have the below

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)
other_user = api.get_user(user_name)
my_info = api.me()

other_user now has this structure…

Continue Reading →

Programmatically screenshot from the parent’s View

The first necessary step is to add the appropriate permission to your AndroidManifest.xml.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

The code, in one lump:

View rootView = childView.getRootView();
rootView.setDrawingCacheEnabled(true);
Bitmap bitmap = rootView.getDrawingCache();

ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, baos);
File file = new File(Environment.getExternalStoreDirectory() + "/my_cap.jpg");

try {
    file.createNewFile();
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(baos.toByteArray());
    fos.close();
} catch(Exception e) {
    e.printStackTrace();
}

Where childView is or inherits from the View class.

Hopefully you can extrapolate from line 6 and the usage of an enum that formats other than JPEG exist and this is merely what I chose for this example code.  Likewise 80 is a value I decided on and is the desired quality of the output image; Only values from 0-100 are accepted.  (Even though png files ignore this value it is still necessary to include one and that its value falls within the 0-100 range)

Verifying Fragments With Espresso

I’ve done some searching to see how I can use Espresso to validate the navigation throughout my app. My typical set-up is one activity encompassing whichever fragments make sense to be managed by that activity (adding additional activities with their own fragments as necessary). In my searching, however, all I was finding were people suggesting I select a View that is displayed within that fragment, and check for its existence.

onView(withId(R.id.some_button)).check(matches(isDisplayed()));

But that seems a little too fragile to me, layouts can change fairly easily as projects progress and so I figured, since there seems to be no way to actually check that the fragment itself is displayed, just give the master layout an id and look for that instead.  I see less chance for that to change than I do a view within it.

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/parent_layout" >

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/timer"
        android:id="@+id/some_button"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>
onView(withId(R.id.parent_layout)).check(matches(isDisplayed()));

It’s such a minuscule alteration but I think, how it’s performed currently, this is less likely to fail throughout an app’s evolution.

And if that hasn’t convinced you here’s a picture — 9000 seconds in Paint.

layout-2016-02-04-164407

error: ‘;’ expected

I just had a frustrating configuration hunt. I was creating an Espresso test-file for a new app I’m making, and after writing just the tiniest bit of boilerplate I wanted to verify everything was working properly, ran the Gradle connectedAndroidTest configuration and got the below…

error: type annotations are not supported in -source 1.7
(use -source 8 or higher to enable type annotations)

Continue Reading →

Recursively search Bash command history

I love the history recall features in Bash. I recently was searching for a short perl script I wrote a couple days ago but !:p was only giving me the first hit in the command history (IE the most recently used match) so a quick google search resulted in me stumbling across this beautiful history feature.

Pressing ctrl+r will allow you to recursively search through matching commands in your terminal history

1

2

If you pass the command you want to run, pressing ctrl+s will move you forward in the same manner.

3

Ctrl+s didn’t work for me at first (and realize you have to hit it twice to go forward one – first time switches you into the forward-search mode with the currently displayed result shown), if you find yourself in the same situation add this to your ~/.bash_profile or ~/.bashrc (whichever is sourced when a new term is started)

stty -ixon