<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>nosemaj.org</title>
	<atom:link href="http://nosemaj.org/feed" rel="self" type="application/rss+xml" />
	<link>http://nosemaj.org</link>
	<description></description>
	<lastBuildDate>Wed, 04 Apr 2012 01:25:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Getting Android Sensor Events While The Screen is Off</title>
		<link>http://nosemaj.org/android-persistent-sensors?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=android-persistent-sensors</link>
		<comments>http://nosemaj.org/android-persistent-sensors#comments</comments>
		<pubDate>Wed, 04 Apr 2012 00:28:13 +0000</pubDate>
		<dc:creator>Jameson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nosemaj.org/?p=225</guid>
		<description><![CDATA[So you want to continue to get sensor events in your Android service, even after the screen turns off? Well that&#8217;s too damn bad, kid, cause you can&#8217;t. No, I&#8217;m just kidding. But you&#8217;ll probably need a work-around for Android Issue 3708. In this document I describe what I had to do to get it [...]]]></description>
			<content:encoded><![CDATA[<p>So you want to continue to get sensor events in your Android service, even after the screen turns off? Well that&#8217;s <em>too damn bad</em>, kid, cause you can&#8217;t. No, I&#8217;m just kidding.</p>
<p>But you&#8217;ll probably need a work-around for <a href="http://code.google.com/p/android/issues/detail?id=3708">Android Issue 3708</a>. In this document I describe what I had to do to get it working on my platform. My assumption is you&#8217;ve already been Googling around, and so have a little background on this, but are still scratching your head as to why it&#8217;s not working. Hopefully, you won&#8217;t be in that position after reading this!</p>
<h3>Hold a PARTIAL_WAKE_LOCK</h3>
<p>Some relic platforms of the past might have skated by holding just a <code><a href="http://developer.android.com/reference/android/os/PowerManager.html#PARTIAL_WAKE_LOCK">PARTIAL_WAKE_LOCK</a></code>. For me this was necessary, but not sufficient. Even while holding the lock, my service ceased to receive notifications via <code><a href="http://developer.android.com/reference/android/hardware/SensorListener.html#onSensorChanged(int, float[])">onSensorChanged()</a></code> nor <code><a href="http://developer.android.com/reference/android/hardware/SensorListener.html#onAccuracyChanged(int, int)">onAccuracyChanged()</a></code>. </p>
<h3>Re-register Your Listeners When The Screen Goes Off</h3>
<p>Some then propose to take action when the screen turns off. In <a href="http://stackoverflow.com/a/2167311/695787">this post on StackOverflow</a>, for example, the author proposes un-registering and re-registering to receive sensor events at that time.</p>
<h3>Use a Delayed Thread, for the Above</h3>
<p>The above two techniques are ultimately what I&#8217;ve used to solve the problem, except I had to make one additional modification. When the <code>BroadcastReceiver</code> receives an <code>ACTION_SCREEN_OFF</code> Intent, I queue a thread to run 500ms in the future, instead of running immediately. This ensures that most other activities surrounding the screen off will have completed. So at that time, 500ms later, we un-register and re-register our service as a sensor event listener.</p>
<p>This is how I&#8217;ve implemented the <code>BroadcastReceiver</code>:</p>
<pre class="brush: java; title: ; notranslate">    public BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.i(TAG, &quot;onReceive(&quot;+intent+&quot;)&quot;);

            if (!intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
                return;
            }

            Runnable runnable = new Runnable() {
                public void run() {
                    Log.i(TAG, &quot;Runnable executing.&quot;);
                    unregisterListener();
                    registerListener();
                }
            };

            new Handler().postDelayed(runnable, SCREEN_OFF_RECEIVER_DELAY);
        }
    };</pre>
<p>You may have to play with the value of <code>SCREEN_OFF_RECEIVER_DELAY</code> &#8212; for me, 500 (milliseconds) was the minimal value that would get it working.</p>
<h3>See the Code In An Example App</h3>
<p>I&#8217;ve posted an example app which includes the above code. It shows a foreground service holding a <code>PARTIAL_WAKE_LOCK</code>, doing the re-registration business mentioned above. The result is a service which continues to receive sensor events even after the screen goes off (for whatever reason.)</p>
<p><a href="https://github.com/jamesonwilliams/AndroidPersistentSensors">https://github.com/jamesonwilliams/AndroidPersistentSensors</a></p>
<p>Well, it worked for me at least. Does it work for you? (Please comment below.)</p>
<h3>References</h3>
<ul>
<li><a href="http://mylifewithandroid.blogspot.com/2010/04/monitoring-sensors-in-background.html">http://mylifewithandroid.blogspot.com/2010/04/monitoring-sensors-in-background.html</a></li>
<li><a href="http://code.google.com/p/android/issues/detail?id=3708">http://code.google.com/p/android/issues/detail?id=3708</a></li>
<li><a href="http://stackoverflow.com/a/2167311/695787">http://stackoverflow.com/a/2167311/695787</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://nosemaj.org/android-persistent-sensors/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Building GCC 4.7.0 on Debian Squeeze (Stable)</title>
		<link>http://nosemaj.org/debian-gcc-4-7?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=debian-gcc-4-7</link>
		<comments>http://nosemaj.org/debian-gcc-4-7#comments</comments>
		<pubDate>Thu, 29 Mar 2012 01:29:09 +0000</pubDate>
		<dc:creator>Jameson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nosemaj.org/?p=213</guid>
		<description><![CDATA[GCC 4.4 is the default compiler on Squeeze, and there&#8217;s nothing newer in the Backports. So, you can dirty up your system by installing some packages from sid or testing, of you can build your own compiler. Since 4.4 wasn&#8217;t sufficient for my needs, I decided to do the latter. I killed a day on [...]]]></description>
			<content:encoded><![CDATA[<p>GCC 4.4 is the default compiler on Squeeze, and there&#8217;s nothing newer in the Backports. So, you can dirty up your system by installing some packages from sid or testing, of you can build your own compiler. Since 4.4 wasn&#8217;t sufficient for my needs, I decided to do the latter. I killed a day on this, but finally have something that works decently.</p>
<p>To start, create a directory like <code>~/gcc-4.7</code>, and export it&#8217;s <em>absolute</em> path into an environment variable.</p>
<p>Note: this isn&#8217;t necessary, but it cleans up our configuration options. Depending on your use case, you might just choose to install to the <code>/usr/local</code> prefix, or even something more serious like <code>/usr</code>.</p>
<pre class="brush: bash; title: ; notranslate">mkdir ~/gcc-4.7
export PROJECT_DIR=$(cd ~/gcc-4.7 &amp;&amp; pwd &amp;&amp; cd - &amp;&gt;/dev/null)</pre>
<h3>Get the Source Packages</h3>
<p>Firstly, you&#8217;ll want to download all of the necessary packages. I created a directory for these in <code>$PROJECT_DIR/sources</code>:</p>
<pre class="brush: bash; title: ; notranslate">mkdir $PROJECT_DIR/sources &amp;&amp; cd !$</pre>
<ol>
<li>PPL latest (0.12):
<pre class="brush: bash; title: ; notranslate">wget http://bugseng.com/products/ppl/download/ftp/releases/LATEST/ppl-0.12.tar.gz</pre>
</li>
<li>CLooG 0.16.1:
<pre class="brush: bash; title: ; notranslate">wget http://www.bastoul.net/cloog/pages/download/count.php3?url=./cloog-0.16.1.tar.gz</pre>
</li>
<li>MPC latest (0.9):
<pre class="brush: bash; title: ; notranslate">wget http://www.multiprecision.org/mpc/download/mpc-0.9.tar.gz</pre>
</li>
<li>GMP latest (5.0.4):
<pre class="brush: bash; title: ; notranslate">wget ftp://ftp.gmplib.org/pub/gmp-5.0.4/gmp-5.0.4.tar.bz2</pre>
</li>
<li>MPFR latest (3.1.0):
<pre class="brush: bash; title: ; notranslate">wget http://www.mpfr.org/mpfr-current/mpfr-3.1.0.tar.bz2</pre>
</li>
<li>GCC 4.7.0:
<pre class="brush: bash; title: ; notranslate">wget http://www.netgull.com/gcc/releases/gcc-4.7.0/gcc-4.7.0.tar.bz2</pre>
</li>
</ol>
<p>Okay, now unpack them. This should do the trick:</p>
<pre class="brush: bash; title: ; notranslate">for file in *.tar.gz; do tar xzvf $file; done
for file in *.tar.bz2; do tar xjvf $file; done</pre>
<h3>Building the Pre-requisites</h3>
<p>From here, you can mostly follow this documentation on <a href="http://solarianprogrammer.com/2012/02/20/living-on-the-edge-building-gcc-4-7-on-mac-osx-lion/">building 4.7 for Mac OS X Lion</a>. A couple of notable differences, though.</p>
<p>It&#8217;s good practice to build in a separate directory from the source. So I create a directory <code>$PROJECT_DIR/build</code>. Also at this time I create directory <code>$PROJECT_DIR/output</code>, which will be the install target for everything we build.</p>
<p>So let&#8217;s get right down to it.</p>
<p>Build GMP:</p>
<pre class="brush: bash; title: ; notranslate">mkdir $PROJECT_DIR/build/gmp
cd !$
../../sources/gmp-5.0.4/configure --prefix=$PROJECT_DIR/output/
make &amp;&amp; make install
cd -
</pre>
<p>Build MPFR:</p>
<pre class="brush: bash; title: ; notranslate">
mkdir $PROJECT_DIR/build/mpfr
cd !$
../../sources/mpfr-3.1.0/configure \
    --prefix=$PROJECT_DIR/output/  \
    --with-gmp=$PROJECT_DIR/output/
make &amp;&amp; make install
cd -
</pre>
<p>Build MPC:</p>
<pre class="brush: bash; title: ; notranslate">mkdir $PROJECT_DIR/build/mpc
cd !$
../../sources/mpc-0.9/configure     \
    --prefix=$PROJECT_DIR/output/   \
    --with-gmp=$PROJECT_DIR/output/ \
    --with-mpfr=$PROJECT_DIR/output/
make &amp;&amp; make install
cd -
</pre>
<p>Build PPL:</p>
<pre class="brush: bash; title: ; notranslate">
mkdir $PROJECT_DIR/build/ppl
cd !$
../../sources/ppl-0.12/configure  \
    --prefix=$PROJECT_DIR/output/ \
    --with-gmp=$PROJECT_DIR/output/
make &amp;&amp; make install
cd -
</pre>
<p>Build CLooG:</p>
<pre class="brush: bash; title: ; notranslate">
mkdir $PROJECT_DIR/build/cloog
cd !$
../../sources/cloog-0.16.1/configure \
    --prefix=$PROJECT_DIR/output/
    --with-gmp=$PROJECT_DIR/output/
make &amp;&amp; make install
cd -
</pre>
<p>And that&#8217;s that!</p>
<h3>Build GCC 4.70</h3>
<p>Okay, so now it&#8217;s time for the main attraction, the compiler suite itself.</p>
<pre class="brush: bash; title: ; notranslate">mkdir $PROJECT_DIR/build/gcc
cd !$
../../sources/gcc/configure          \
    --prefix=$PROJECT_DIR/output/    \
    --with-gmp=$PROJECT_DIR/output/  \
    --with-mpfr=$PROJECT_DIR/output/ \
    --with-mpc=$PROJECT_DIR/output/  \
    --program-suffix=-4.7            \
    --enable-cloog-backend=isl       \
    --with-ppl=$PROJECT_DIR/output/  \
    --with-cloog=$PROJECT_DIR/output/

export LD_LIBRARY_PATH=$PROJECT_DIR/output/lib/
make &amp;&amp; make install
cd -
</pre>
<p>Note the <code>LD_LIBRARY_PATH</code> line. That&#8217;s crucial if you&#8217;re not installing to the default location, <code>/usr/local</code>, because your libraries won&#8217;t be in the <code>PATH</code> specified in the <code>ld.so.conf</code> files.</p>
<p>The <code>--program-suffix=-4.7</code> flag is of course a matter of personal taste, and can be omitted if you like. </p>
<p>It may be possible to use a value for <code>--enable-cloog-backend</code> other than <code>isl</code>, but that seemed to work.</p>
<p>Also, there are of course hundreds of other reasonable GCC configurations possible. Your mileage may vary, but this is pretty vanilla, and it produces a working toolchain. (Which is a nice quality to it.)</p>
<p>Thanks for reading!</p>
<h3>References</h3>
<ul>
<li><a href="http://samritmaity.wordpress.com/2010/06/20/cannot-compute-suffix-of-object-files-gcc-4-4-3-installation-problem-solved/">Cannot compute suffix of object files : gcc 4.4.x and $gt;</a></li>
<li><a href="http://solarianprogrammer.com/2012/02/20/living-on-the-edge-building-gcc-4-7-on-mac-osx-lion/">Living on the edge building gcc-4.7 on Mac OSX Lion</a></li>
<li><a href="http://www.linuxfromscratch.org/lfs/view/development/chapter06/gcc.html">LFS Chapter 6.17. GCC 4.7.0</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://nosemaj.org/debian-gcc-4-7/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Android Permissions-on-Demand System</title>
		<link>http://nosemaj.org/android-permissions-on-demand?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=android-permissions-on-demand</link>
		<comments>http://nosemaj.org/android-permissions-on-demand#comments</comments>
		<pubDate>Tue, 20 Mar 2012 06:25:53 +0000</pubDate>
		<dc:creator>Jameson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nosemaj.org/?p=203</guid>
		<description><![CDATA[Today’s Android permissions system has many short-comings. While perhaps a decent starting place for development of a more robust solution, the existing implementation is minimally effective at fostering good security practices. Consider the last time you installed an app — did you look closely at the permissions? I sometimes look out of curiosity, or to [...]]]></description>
			<content:encoded><![CDATA[<p>Today’s Android permissions system has many short-comings. While perhaps a decent starting place for development of a more robust solution, the existing implementation is minimally effective at fostering good security practices.</p>
<p>Consider the last time you installed an app — did you look closely at the permissions? I sometimes look out of curiosity, or to make sure they are not blatantly egregious. But, even then I often assume someone else has scrutinized the application for me.</p>
<p>A revised system might foster a “Permission on Demand” model, as implemented in most modern Web Browsers. As non-core features are needed, the user is able to allow or disallow the permission — optionally, to always or never allow. Some more elevated permissions &#8212; those sensitive to the user&#8217;s data and identity &#8212; might always require explicit consent.</p>
<p>The new permissions system would extend the existing infrastructure beyond the all-declarative <code>uses-permission</code> element, to include a new <code>requests-permission</code> element. Required permissions would then only be those necessary for basic operation of the application. All other permissions would be declared with <code>requests-permission</code>. At install, these could be set to “Never,” “Always”, or “Ask me.” The default would be “Ask me.”</p>
<p>Much later, when the user has forgotten the particulars of this interaction, the application might try to request an optional permission. At this time, the user would make a decision appropriate to the context: “Not now,” “Never,” “Yes,” or “Yes, always.” In the event that the User decided to deny the permission, the application would display an error message stating that the functionality was not available &#8212; or degrade gracefully. Up until then, however, the application would have been entirely functional as expected, operating perfectly happily without the permission.</p>
<p>Now this all sounds like the Web. In many ways, as horrifying as Web programming and security has been throughout its lifetime, the infrastructure seems to have gained a certain degree of maturity. Here, for example, we either evangelize a mass movement to HTML5, or make a request to “forward-port” a better permissions model to Android.</p>
<p>So who&#8217;d like to code this up?</p>
]]></content:encoded>
			<wfw:commentRss>http://nosemaj.org/android-permissions-on-demand/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding the Android Application Lifecycle with a Hands-on Example</title>
		<link>http://nosemaj.org/android-application-lifecycle?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=android-application-lifecycle</link>
		<comments>http://nosemaj.org/android-application-lifecycle#comments</comments>
		<pubDate>Tue, 20 Mar 2012 03:30:33 +0000</pubDate>
		<dc:creator>Jameson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nosemaj.org/?p=189</guid>
		<description><![CDATA[The Android documentation is really pretty good. And you can whine about how things are put together &#8212; the nature of the APIs, or the Frameworks implementation, but really, it could be a lot worse. And for platforms come and gone, I think it was a lot worse, way-back-when. That&#8217;s part of why you&#8217;re bothering [...]]]></description>
			<content:encoded><![CDATA[<p>The Android documentation is really pretty good. And you can whine about how things are put together &#8212; the nature of the APIs, or the Frameworks implementation, but really, it could be a lot worse. And for platforms come and gone, I think it was a lot worse, way-back-when. That&#8217;s part of why you&#8217;re bothering to read this right now, right!</p>
<p>Anyway, here&#8217;s a blog about the Android Application Lifecycle, viewed from the eye of some simple get-started-already code.</p>
<h3>Setup Our Test Code</h3>
<pre class="brush: bash; title: ; notranslate">mkdir LifecycleTest
cd LifecycleTest

android create project \
    --target &quot;Google Inc.:Google APIs:10&quot; \
    --path . \
    --package org.nosemaj.lifecycle_test \
    --activity LifecycleTest \
    --name LifecycleTest</pre>
<p>Okay, fine. Now let&#8217;s create a simple Activity which will show us whenever a new lifecycle change occurs:</p>
<p>In <code>src/org/nosemaj/lifecycle_test/LifecycleTest.java</code>, I have:</p>
<pre class="brush: java; title: ; notranslate">package org.nosemaj.lifecycle_test;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class LifecycleTest extends Activity {
    public static final String TAG = LifecycleTest.class.getName();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG, &quot;onCreate()&quot;);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.i(TAG, &quot;onStart()&quot;);
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i(TAG, &quot;onRestart()&quot;);
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.i(TAG, &quot;onResume()&quot;);
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.i(TAG, &quot;onPause()&quot;);
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.i(TAG, &quot;onStop()&quot;);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i(TAG, &quot;onDestroy()&quot;);
    }
}</pre>
<p>Boom. Wham, bam; presto.</p>
<p>Moving right along, then, let&#8217;s build the thing and start seeing what gets called when:</p>
<pre class="brush: bash; title: ; notranslate">ant clean; # out of habit
ant debug
adb install bin/LifecycleTest-debug.apk</pre>
<h3>Some Common Activity Change Scenarios</h3>
<p>Let&#8217;s consider a few scenarios we might want to test, which occur frequently to an Application in the wild:</p>
<ol>
<li>The app is started from the launcher.</li>
<li>The user hits the &#8220;Back&#8221; button while in the app.</li>
<li>The user hits the &#8220;Home&#8221; key while in the app.</li>
<li>The user does nothing, and the screen goes to sleep.</li>
<li>The user wakes up the phone to resume the app.</li>
<li>The user launches a new application, whilst the one we&#8217;re testing is running.</li>
<li>The screen orientation changes</li>
</ol>
<p>There might be some other important things, but that seems like a good start to get our feet wet.</p>
<p>So let&#8217;s start observing messages:</p>
<pre class="brush: bash; title: ; notranslate">adb logcat | grep LifecycleTest</pre>
<h3>The app is started</h3>
<pre>I/ActivityManager(   61): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=org.nosemaj.lifecycle_test/.LifecycleTest } from pid 126
I/org.nosemaj.lifecycle_test.LifecycleTest(  371): onRestart()
I/org.nosemaj.lifecycle_test.LifecycleTest(  371): onStart()
I/org.nosemaj.lifecycle_test.LifecycleTest(  371): onResume()</pre>
<p>Look like the documentation.</p>
<h3>The user hits the &#8220;Back&#8221; button:</h3>
<pre>I/org.nosemaj.lifecycle_test.LifecycleTest(  371): onPause()
I/org.nosemaj.lifecycle_test.LifecycleTest(  371): onStop()
I/org.nosemaj.lifecycle_test.LifecycleTest(  371): onDestroy()</pre>
<p>The Back key destroys the app.</p>
<h3>The user hits the &#8220;Home&#8221; key:</h3>
<pre>I/org.nosemaj.lifecycle_test.LifecycleTest(  371): onPause()
I/org.nosemaj.lifecycle_test.LifecycleTest(  371): onStop()
</pre>
<p>Aha, no <code>onDestroy()</code>, this time.</p>
<h3>The screen falls asleep</h3>
<pre>I/org.nosemaj.lifecycle_test.LifecycleTest(  371): onPause()</pre>
<p>Just only <code>onPause()</code> gets called this time.</p>
<h3>The screen wakes up to the app</h3>
<pre>I/org.nosemaj.lifecycle_test.LifecycleTest(  371): onResume()</pre>
<h3>Something gets launched over this app</h3>
<pre>I/org.nosemaj.lifecycle_test.LifecycleTest(  371): onPause()
I/org.nosemaj.lifecycle_test.LifecycleTest(  371): onStop()</pre>
<h3>Screen orientation changes</h3>
<pre>I/org.nosemaj.lifecycle_test.LifecycleTest(23872): onPause()
I/org.nosemaj.lifecycle_test.LifecycleTest(23872): onStop()
I/org.nosemaj.lifecycle_test.LifecycleTest(23872): onDestroy()
I/org.nosemaj.lifecycle_test.LifecycleTest(23872): onCreate()
I/org.nosemaj.lifecycle_test.LifecycleTest(23872): onStart()
I/org.nosemaj.lifecycle_test.LifecycleTest(23872): onResume()</pre>
<p>Wow, a slew of stuff. The application gets destroyed &#8212; only to be recreated again in new skin a moment later. Baller.</p>
<h3>Conclusion</h3>
<p>Well, so that&#8217;s probably enough of that for now wouldn&#8217;t you say?</p>
<p>Anyway, I think the point is that <code>onPause()</code> and <code>onResume()</code> are the only really reliable ones. You might save a little gas by putting a select few lines in <code>onCreate()</code>, but probably better to put the volatile stuff in <code>onResume()</code>.</p>
<p>If you want to play around with this code, I&#8217;ve posted it to <a href="https://github.com/jamesonwilliams/LifecycleTest">Github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nosemaj.org/android-application-lifecycle/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating Twitter Into Your Android App</title>
		<link>http://nosemaj.org/android-twitter?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=android-twitter</link>
		<comments>http://nosemaj.org/android-twitter#comments</comments>
		<pubDate>Wed, 07 Mar 2012 10:01:10 +0000</pubDate>
		<dc:creator>Jameson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nosemaj.org/wordpress/?p=13</guid>
		<description><![CDATA[Foreword Consider that you might want to just actually use the real Twitter instead of reinventing the wheel. That said, sometimes it can be useful to get assets from Twitter.com to display in your app, as they pertain to your app. In Android, you can launch Twitter with one line of Code: You can also [...]]]></description>
			<content:encoded><![CDATA[<h3>Foreword</h3>
<p>Consider that you might want to just actually use the real Twitter instead of reinventing the wheel. That said, sometimes it can be useful to get assets from Twitter.com to display in your app, as they pertain to your app.</p>
<p>In Android, you can launch Twitter with one line of Code:</p>
<pre class="brush: java; title: ; notranslate">startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(&quot;http://www.twitter.com&quot;));</pre>
<p>You can also share content with about just as many lines, by using an <code>ACTION_SEND</code>. Anyway, if you need to do something deeper, you have to leverage the Twitter API directly.</p>
<h3>Get the Twitter4J Jar</h3>
<p>Download this: <a href="http://twitter4j.org/en/twitter4j-android-2.2.5.zip">http://twitter4j.org/en/twitter4j-android-2.2.5.zip</a>. Extract the core jar, and put it in the <code>libs</code> directory of your android project.</p>
<h3>Register Your App with Twitter</h3>
<p>You need to do this to placate their OAuth nonsense. Visit <a href="https://dev.twitter.com/apps/new">https://dev.twitter.com/apps/new</a>.</p>
<h3>Add the OAuth Keys to Your App</h3>
<p>In <code>res/values/strings.xml</code>, add the lines:</p>
<pre class="brush: xml; title: ; notranslate">&lt;string name=&quot;twitter_oauth_key&quot;&gt;PUT YOUR CONSUMER KEY HERE&lt;/string&gt;
&lt;string name=&quot;twitter_oauth_secret&quot;&gt;PUT YOUR CONSUMER SECRET HERE&lt;/string&gt;</pre>
<p>Note: Here we take a No-BS approach to the OAuth stuff. (In figuring out how to do this, there are a lot of posts on the internet you have to sort through that don&#8217;t.) One solution for hiding your OAuth secret is to keep it on a server and proxy your requests to Twitter through that host. Needless to say, that&#8217;s not covered here.</p>
<h3>Get a Handle to the Twitter obejct in Java</h3>
<pre class="brush: java; title: ; notranslate">ConfigurationBuilder cb = new ConfigurationBuilder();
String key = getApplicationContext().getString(R.string.twitter_oauth_key);
String secret = getApplicationContext().getString(R.string.twitter_oauth_secret);
cb.setOAuthConsumerKey(key);
cb.setOAuthConsumerSecret(secret);
Twitter twitter = TwitterFactory(cb.build()).getInstance();</pre>
<h3>Example Use</h3>
<p>And that&#8217;s basically it. Now you you can get info from twitter using the Twitter object. For example, here&#8217;s how to get a list of tweets about Potatos.</p>
<pre class="brush: java; title: ; notranslate">List&lt;Tweet&gt; tweets = twitter.search(new Query(&quot;Potatos&quot;)).getTweets();</pre>
<h3>See Code in an Example App</h3>
<p>I have created an example app that shows the above. Check it out on Github: <a href="https://github.com/jamesonwilliams/AndroidTwitterExample">https://github.com/jamesonwilliams/AndroidTwitterExample</a></p>
<h3>References</h3>
<ol>
<li><a href="http://stackoverflow.com/questions/3528458/android-twitter-xauth-example-using-twitter4j">Stack Overflow &#8211; Android Twitter xAuth example using twitter4j</a></li>
<li><a href="http://twitter4j.org/en/javadoc/twitter4j/Twitter.html">Twitter4J Twitter Class Documentation</a></li>
<li><a href="http://twitter4j.org/en/code-examples.html">Twitter4J Example Code</a></li>
<li><a href="https://dev.twitter.com/docs/twitter-libraries">Twitter Endorsed Client Libraries</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://nosemaj.org/android-twitter/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Workqueues in Recent Linux 2.6.31</title>
		<link>http://nosemaj.org/workqueues-linux-2-6?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=workqueues-linux-2-6</link>
		<comments>http://nosemaj.org/workqueues-linux-2-6#comments</comments>
		<pubDate>Mon, 22 Aug 2011 07:57:23 +0000</pubDate>
		<dc:creator>Jameson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jamesonwilliams.com/?p=2957</guid>
		<description><![CDATA[While I was working on an interrupt service for a(n embedded) driver, I found some useful posts: Howto write a driver for an i2c client device Overview of Workqueues in 2.6 Anyway, I&#8217;d never explicitly tried it before, so I was a bit unsure of how to use a workqueue for a bottom-half for my [...]]]></description>
			<content:encoded><![CDATA[<p>While I was working on an interrupt service for a(n embedded) driver, I found some useful posts:</p>
<ul>
<li><a href="http://www.embedded-bits.co.uk/2009/i2c-in-the-2632-linux-kernel/">Howto write a driver for an i2c client device</a></li>
<li><a href="http://www.linuxjournal.com/article/6916">Overview of Workqueues in 2.6</a></li>
</ul>
<p>Anyway, I&#8217;d never explicitly tried it before, so I was a bit unsure of how to use a workqueue for a bottom-half for my ISR. Anyway, it <i>is</i> really that easy. Here are the key components (this is for Android Froyo, 2.6.31 I think.)</p>
<p>In what follows, remember: &#8220;<code>work</code>&#8221; is a <code>work_struct</code>, and &#8220;<code>worker_function</code>&#8221; is a function pointer.</p>
<h3>Setup the WorkQueue</h3>
<p>First, include the header:</p>
<pre class="brush: cpp; title: ; notranslate">#include &lt;linux/workqueue.h&gt;</pre>
<p>Somewhere near the top, declare a <code>work_struct</code>:</p>
<pre class="brush: cpp; title: ; notranslate">static struct work_struct work;</pre>
<p>Somewhere in your init routine, initialize that structure:</p>
<pre class="brush: cpp; title: ; notranslate">static int __init module_init(void)
{
...
        INIT_WORK(&amp;work, (void *)worker_function);
...
}</pre>
<p><code>worker_function</code> is a function pointer to the task to be done. It can be as simple as:</p>
<pre class="brush: cpp; title: ; notranslate">static void worker_function(void)
{
    /* Do some work! */
}</pre>
<h3>Use it in an ISR</h3>
<p>So, nothing will ever happen unless you schedule the thing somewhere. You might probably like to use the workqueue as a bottom-half for an interrupt service routine (be sure to register that separately via <code>request_irq()</code>):</p>
<pre class="brush: cpp; title: ; notranslate">static irqreturn_t isr(int irq, void *data)
{
        /* schedule_work() returns 0 on failure. */
        if (0 == schedule_work(&amp;work)) {
                return IRQ_NONE;
        }

        return IRQ_HANDLED;
}</pre>
<h3>Notes</h3>
<p>One interesting note: in a number of places on the web, <code>INIT_WORK</code> is documented as taking a third argument &#8212; the <code>(void *)</code> argument to the function pointer (argument 2). However, this was not the case in my kernel tree. <code>INIT_WORK</code> for me simply took the <code>work_struct</code> and the <code>worker_function</code>.</p>
<p><q>Wait&#8230; are there bells and whistles that you&#8217;re not mentioning?</q></p>
<p>Yea, probably, sure &#8212; but this was all it took for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://nosemaj.org/workqueues-linux-2-6/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solution to a Putnam Exam Problem (Algebra)</title>
		<link>http://nosemaj.org/putnam-exam-problem?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=putnam-exam-problem</link>
		<comments>http://nosemaj.org/putnam-exam-problem#comments</comments>
		<pubDate>Wed, 28 Jan 2009 10:02:28 +0000</pubDate>
		<dc:creator>Jameson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[december]]></category>
		<category><![CDATA[mathematics]]></category>

		<guid isPermaLink="false">http://www.jamesonwilliams.com/?p=1479</guid>
		<description><![CDATA[The Putnam Exam is a test administered by the Mathematics Association of America that is given to undergraduate students each year on the first Saturday in December. I came across an exam problem from 1995 which I found interesting and for which I was able to find a solution &#8212; although it took me quite [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://math.scu.edu/putnam/">Putnam Exam</a> is a test administered by the <a href="http://www.maa.org/">Mathematics Association of America</a> that is given to undergraduate students each year on the first Saturday in December. I came across an exam problem from 1995 which I found interesting and for which I was able to find a solution &#8212; although it took me quite a bit of time to do so, considering the brevity of the proof.</p>
<h3>Putnam 1995</h3>
<blockquote><p>Let <var>S</var> be a set of real numbers such that <var>S</var> is closed under multiplication (that is, if <var>a</var> and <var>b</var> are in <var>S</var>, then so is <var>ab</var>). Let <var>T</var> and <var>U</var> be disjoint subsets of <var>S</var> whose union is <var>S</var>. Given that the product of any <em>three</em> (not necessarily distinct) elements of <var>T</var> is in <var>T</var> and that the product of any three elements of <var>U</var> is in <var>U</var>, show that at least one of the two subsets <var>T</var>, <var>U</var> is closed under multiplication.</p></blockquote>
<p><strong>Proof (by contradiction).</strong><br />
Suppose neither <var>U</var> nor <var>T</var> is closed under multiplication.</p>
<p>Then there exist <var>u</var>, <var>w</var> &isin; <var>U</var> s.t. <var>uw</var> &notin; <var>U</var>. So <var>uw</var> &isin; <var>T</var>.</p>
<p>Similarly, there exist <var>s</var>, <var>t</var> s.t. <var>st</var> &notin; <var>T</var>. So <var>st</var> &isin; <var>U</var>.</p>
<p>So the product <var>uw(st)</var> &isin; <var>U</var>, and <var>st(uw)</var> &isin; <var>T</var>, which has that <var>U</var>&cap;<var>T</var> &ne; &empty;. This is a contradiction of the assumption that <var>U</var>, <var>T</var> are disjoint.</p>
<p>Therefore, at least one of <var>U</var>, <var>T</var> is closed under multiplication.</p>
<h3>Extension</h3>
<p>Note that the problem statement can be generalized from &#8220;S, a set of real numbers,&#8221; to G, any Abelian group. In particular, the mechanics of my solution are general enough to show the following result:</p>
<p>Let <var>G</var> be an Abelian group and let <var>A</var>, <var>B</var> be two disjoint subsets of <var>G</var> s.t. <var>A</var>&cap;<var>B</var> = &empty;, and <var>A</var>&cup;<var>B</var> = <var>G</var>. Given that the product of any three elements in <var>A</var> is in <var>A</var>, and that the product of any three elements in <var>B</var> is in <var>B</var>, show that at least one of <var>A</var>, <var>B</var> is a subgroup of <var>G</var>.</p>
<p>Well, yes, that <em>is</em> a more general proposition as it is not limited to the real numbers and it&#8217;s usual &#8220;multiplication,&#8221; but mostly, it&#8217;s just a hell of a lot snootier. The word &#8220;Abelian&#8221; just means that multiplication is commutative. It <em>sounds</em> a lot more sophisticated, though, doesn&#8217;t it? O, <em>that Algebra!</em></p>
<h3>Example with <eqn><var>G</var> ={ i<sup><var>k</var></sup> | 0 &lt; <var>k</var> &le; 4 }</eqn></h3>
<p>Is that true, though? Let&#8217;s try it for the group <eqn><var>G</var> = { i, -1, -i, 1 }</eqn> (where i is the imaginary number defined by <eqn>i<sup>2</sup> = -1</eqn>. Pardon the typeface.)</p>
<p>Let <eqn><var>A</var> = { i, -1 }</eqn>, and let <eqn><var>B</var> = { -i, 1 }</eqn>.</p>
<p><eqn>(-1)i = -i &isin; <var>B</var></eqn>, so <var>A</var> is not closed.</p>
<p><eqn>(-i)(1) = -i &isin; <var>B</var></eqn>, and<br />
<eqn>(-i)(-i) = 1 &isin; <var>B</var></eqn>, and yes, too,<br />
<eqn>(1)(1) &isin; <var>B</var></eqn>, so <var>B</var> <strong>is</strong> closed.</p>
<p>Seems to work out in this example, anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://nosemaj.org/putnam-exam-problem/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wireless Linux at Lehigh with Network Manager</title>
		<link>http://nosemaj.org/lehigh-wireless-network-manager?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=lehigh-wireless-network-manager</link>
		<comments>http://nosemaj.org/lehigh-wireless-network-manager#comments</comments>
		<pubDate>Sat, 17 Jan 2009 06:11:49 +0000</pubDate>
		<dc:creator>Jameson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[lehigh]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[network]]></category>

		<guid isPermaLink="false">http://www.jamesonwilliams.com/?p=1411</guid>
		<description><![CDATA[There are two ways to use Lehigh's wireless network <var>lu</var> on Linux. The first (and more complicated) method involves removing the NetworkManager applet, and editing some configuration files. <a href="http://coral.ie.lehigh.edu/~asm4/howtos/wireless.html">That method is covered in another place</a>. This page describes howto use Lehigh's wireless with the NetworkManager GUI.]]></description>
			<content:encoded><![CDATA[<p>There are two ways to use Lehigh&#8217;s wireless network <var>lu</var> on Linux. The first (and more complicated) method involves removing the NetworkManager applet, and editing some configuration files. <a href="http://coral.ie.lehigh.edu/~asm4/howtos/wireless.html">That method is covered here</a>.</p>
<p>Assuming that you have a fully functional wireless setup, and that you have NetworkManager 0.7+, you can also use the GUI interface to configure your wireless. This method has two benefits.</p>
<ol>
<li>You can maintain roaming capability to other networks.</li>
<li>It&#8217;s less complicated to setup</li>
</ol>
<h3>Lehigh Wireless with NetworkManager</h3>
<p>Click on the NetworkManager applet icon on your taskbar. Locate <var>lu</var>, and click it. For &#8220;Wireless Security,&#8221; choose <var>Dynamic WEP (802.1x)</var>. This will create several new fields in the dialog box. For Authentication, select <var>Protected EAP (PEAP)</var>. This, too, will add a few fields to the dialog box. Change PEAP Version to <var>Version 0</var>. Type in Lehigh user ID and login password in the fields labeled &#8220;User Name&#8221; and &#8220;Password.&#8221; At this point, the dialog box should be filled in like this:</p>
<p><img src="/img/lehigh-wireless-howto.png" alt="[Screenshot of settings as described above]" /></p>
<p>Click &#8220;Connect,&#8221; and then &#8220;Ignore&#8221; the Certificate Authority dialog, and you should be on your way.</p>
]]></content:encoded>
			<wfw:commentRss>http://nosemaj.org/lehigh-wireless-network-manager/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Colored Bash Prompt for Accessible GNU/Linux Networks</title>
		<link>http://nosemaj.org/colored-bash-prompt?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=colored-bash-prompt</link>
		<comments>http://nosemaj.org/colored-bash-prompt#comments</comments>
		<pubDate>Thu, 08 Jan 2009 04:07:46 +0000</pubDate>
		<dc:creator>Jameson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[laptop]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.jamesonwilliams.com/?p=1288</guid>
		<description><![CDATA[Adding color to your bash prompt can be a neat thing to do &#8212; if you&#8217;re into that sort thing, or you might find it tacky. Uncommenting the commented out color prompt line in .bashrc on Debian family systems leads to what, I think, is a tacky command prompt. However, say you have a few [...]]]></description>
			<content:encoded><![CDATA[<p>Adding color to your bash prompt can be a neat thing to do &#8212; if you&#8217;re into that sort thing, or you might find it tacky. Uncommenting the commented out color prompt line in <code>.bashrc</code> on Debian family systems leads to what, I think, is a tacky command prompt.</p>
<p>However, say you have a few different machines on a local network that you switch between freely, and have trouble remembering where you are. After accidentally installing a test-release version of Rhythmbox to my server and then spending about ten minutes back tracing, I decided it was time to do something. I could not easily tell which system I was on, and this would eventually lead to much more serious mistakes on my end. (I like to issue <code>rm -rf /*</code> on my laptop all the time, obviously.)</p>
<p>So, I set up color prompts on my server and laptop to help give me a visual cue as to where I am at a given time. The following line in <code>.bashrc</code> makes the host name appear teal, and keeps everything else without color:</p>
<pre class="brush: bash; title: ; notranslate">export PS1='\u@\[&#92;&#48;33[01;34m\]\h\[&#92;&#48;33[00m\]:\w\$ '</pre>
]]></content:encoded>
			<wfw:commentRss>http://nosemaj.org/colored-bash-prompt/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Printing from Linux at Lehigh University</title>
		<link>http://nosemaj.org/linux-lehigh-printers?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linux-lehigh-printers</link>
		<comments>http://nosemaj.org/linux-lehigh-printers#comments</comments>
		<pubDate>Mon, 01 Sep 2008 04:33:06 +0000</pubDate>
		<dc:creator>Jameson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[lehigh]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[university]]></category>

		<guid isPermaLink="false">http://www.jamesonwilliams.com/?p=359</guid>
		<description><![CDATA[If you need to set up a printer on Windows or Mac OS X, you can just go to lehigh.edu/printers and run one of the VisualBasic or applescript scripts, respectively. Here are instructions for Linux. And immediately below is a rant on why printers are lame. And you thought CD-ROMs and traditional disk drives were [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to set up a printer on Windows or Mac OS X, you can just go to <a href="http://www.lehigh.edu/printers">lehigh.edu/printers</a> and run one of the VisualBasic or applescript scripts, respectively. Here are instructions for Linux. And immediately below is a rant on why printers are lame.</p>
<p>And you thought CD-ROMs and traditional disk drives were bad enough! It gets worse. I usually never use a printer for economic, environmental, and philosophical reasons. Paper and ink cost money, and printers are big and ugly. On the environmental side, clearly burning through reams of paper is a bad call, as is the entire messy world of ink / toner. Why you wouldn&#8217;t just (with the least sophistication) send a PDF is nearly beyond me. Printers are at a level of technology <em>below</em> electromechanical computing, and are contrary to our primary endeavors to increase speed and minimize power (in all walks of life.)</p>
<p>Anyway, sometimes someone asks you for a hard copy of something. This happened to me, and so I had to setup a printer. Printing is free for students at Lehigh, and there is a printer in nearly every building, so at least my economic complaint gets pushed back a few levels to the Bursar, who gets lots of my money, albeit not sacred pocket money.</p>
<p>So, steps to setup a printer at Lehigh with Linux:</p>
<ol>
<li>Go to <a href="http://www.lehigh.edu/printers">lehigh.edu/printers</a> and proceed with the steps to &#8220;install&#8221; a printer like you would if you were running Mac OS X.</li>
<li>Save the <code>install.applescript</code>.</li>
<li>Make note of the hostname of the printer you&#8217;re trying to install. You can get this by running
<pre class="brush: bash; title: ; notranslate">cat install.applescript  | grep DNS= | sed 's/DNS=//'</pre>
</li>
<li>Once you have <code>cupsd</code> installed and running, go to <a href="http://localhost:631">localhost:631</a>, the CUPS configuration interface.</li>
<li>Go to Administration > Add Printer. Everything from here on is fairly intuitive. Just make sure you select &#8220;Internet Printing Protocol&#8221; from the drop down &#8220;Device&#8221; list, and when it asks you for the device URI, enter <var>http://the-hostname-you-got-from-above</var>.</li>
</ol>
<p>That&#8217;s about it. Happy printing.</p>
]]></content:encoded>
			<wfw:commentRss>http://nosemaj.org/linux-lehigh-printers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

