<?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>The world (and word) of jaymz &#187; jaymz</title>
	<atom:link href="http://jaymz.eu/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://jaymz.eu</link>
	<description></description>
	<lastBuildDate>Tue, 14 Feb 2012 11:52:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Slide on overlay demo</title>
		<link>http://jaymz.eu/2012/02/slide-on-overlay-demo/</link>
		<comments>http://jaymz.eu/2012/02/slide-on-overlay-demo/#comments</comments>
		<pubDate>Tue, 14 Feb 2012 11:43:56 +0000</pubDate>
		<dc:creator>jaymz</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://jaymz.eu/?p=611</guid>
		<description><![CDATA[This is a test embed of this simple swipe on hover: iframes needed Embed code: &#60;iframe src=&#34;http://jaymz.eu/demos/swipe/&#34; width=&#34;300&#34; height=&#34;330&#34; scrolling=&#34;no&#34; frameborder=&#34;0&#34;&#62;iframes needed&#60;/iframe&#62;]]></description>
			<content:encoded><![CDATA[<p>This is a test embed of this simple <a target="_blank" href="http://jaymz.eu/demos/swipe/">swipe on hover</a>:</p>
<p><iframe src="http://jaymz.eu/demos/swipe/" width="300" height="330" scrolling="no" frameborder="0">iframes needed</iframe></p>
<p>Embed code:</p>
<p><code><br />
&lt;iframe src=&quot;http://jaymz.eu/demos/swipe/&quot; width=&quot;300&quot; height=&quot;330&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot;&gt;iframes needed&lt;/iframe&gt;<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://jaymz.eu/2012/02/slide-on-overlay-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic superusers via Active Collab for django</title>
		<link>http://jaymz.eu/2011/02/automatic-superusers-via-active-collab-for-django/</link>
		<comments>http://jaymz.eu/2011/02/automatic-superusers-via-active-collab-for-django/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 21:20:42 +0000</pubDate>
		<dc:creator>jaymz</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[active-collab]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://jaymz.eu/?p=553</guid>
		<description><![CDATA[Two things I use a lot at work &#8211; Django and Active Collab. One is the python framework we build everything on and the other is a project management tool that we use &#8211; think a local install of Basecamp roughly. It can get annoying when we create development versions of things we&#8217;re working on [...]]]></description>
			<content:encoded><![CDATA[<p>Two things I use a lot at work &#8211; <a href="http://www.djangoproject.com/">Django</a> and <a href="http://www.activecollab.com">Active Collab</a>. One is the python framework we build everything on and the other is a project management tool that we use &#8211; think a local install of Basecamp roughly.</p>
<p>It can get annoying when we create development versions of things we&#8217;re working on and have to go and create test users for people; so I thought since writing an auth backend for django is so easy why not just use that to allow any user with a valid Active Collab account to login to the dev admin.</p>
<p><a href="http://jaymz.eu/wp-content/uploads/2011/02/ac-authbackend.jpg"><img class="aligncenter size-full wp-image-560" title="ac-authbackend" src="http://jaymz.eu/wp-content/uploads/2011/02/ac-authbackend.jpg" alt="" width="525" height="295" /></a></p>
<p>The <a href="https://github.com/jaymzcd/django-acollabauth">code is on github</a> and will automatically create a superuser in django&#8217;s auth table. Users can then login with their active collab emails &amp; passwords without having to pass around test accounts. It also means users wont suddenly lose access when you nuke the database for imports saving you some earache. Just add your base active collab url to the <em>AC_URL</em> variable in settings.py and add &#8216;<em>acollabauth.backends.ActiveCollabBackend</em>&#8216; to your AUTHENTICATION_BACKENDS tuple.</p>
<p>I have also blogged about this <a href="http://www.u-dox.com/blog/2011/02/22/using-active-collab-to-authenticate-django-sites/">over at udox</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jaymz.eu/2011/02/automatic-superusers-via-active-collab-for-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Active Collab library in Python</title>
		<link>http://jaymz.eu/2011/02/active-collab-library-in-python/</link>
		<comments>http://jaymz.eu/2011/02/active-collab-library-in-python/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 12:31:23 +0000</pubDate>
		<dc:creator>jaymz</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[active-collab]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://jaymz.eu/?p=537</guid>
		<description><![CDATA[We use active collab at work to manage our various projects and track issues on sites we&#8217;re building. It comes complete with a REST API which returns results in XML. So I&#8217;ve written some code that abstracts out the process of making a request and displaying the returned data. It&#8217;s, predictably, on github. Here&#8217;s an example [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jaymz.eu/wp-content/uploads/2011/02/ac-library.jpg"><img class="aligncenter size-full wp-image-538" title="ac-library" src="http://jaymz.eu/wp-content/uploads/2011/02/ac-library.jpg" alt="" width="525" height="295" /></a></p>
<p>We use active collab at work to manage our various projects and track issues on sites we&#8217;re building. It comes complete with a REST API which returns results in XML. So I&#8217;ve written some code that abstracts out the process of making a request and displaying the returned data. It&#8217;s, predictably, on <a href="https://github.com/jaymzcd/pyacollab">github</a>.</p>
<p>Here&#8217;s an example based on the 0.2.0 code which is simply outputting data for now allowing me to check on open tickets easily from code. Remember, to enable write methods to work (setting a ticket to complete for example) you need to have <em>Write Access</em> enabled <a href="http://www.activecollab.com/docs/manuals/developers/api/api-status">via the config.php</a> file.</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jaymz.eu/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="python">In <span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>: <span class="kw1">from</span> activecollab.<span class="me1">library</span> <span class="kw1">import</span> ACRequest
&nbsp;
In <span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span>: req = ACRequest<span class="br0">&#40;</span><span class="st0">'projects'</span><span class="br0">&#41;</span>
&nbsp;
In <span class="br0">&#91;</span><span class="nu0">3</span><span class="br0">&#93;</span>: req.<span class="me1">execute</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
<span class="nu0">34</span>: AC <span class="nu0">101</span>: http://my.<span class="me1">ac</span>-<span class="kw3">site</span>.<span class="me1">com</span>/projects/<span class="nu0">34</span>
<span class="co1"># More results trimmed</span>
&nbsp;
In <span class="br0">&#91;</span><span class="nu0">4</span><span class="br0">&#93;</span>: req = ACRequest<span class="br0">&#40;</span><span class="st0">'projects'</span>, item_id=<span class="nu0">34</span>, subcommand=<span class="st0">'tickets'</span><span class="br0">&#41;</span>
&nbsp;
In <span class="br0">&#91;</span><span class="nu0">5</span><span class="br0">&#93;</span>: req.<span class="me1">execute</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
<span class="nu0">2208</span>: ie6 error when zooming on <span class="kw2">map</span>: http://my.<span class="me1">ac</span>-<span class="kw3">site</span>.<span class="me1">com</span>/projects/<span class="nu0">34</span>/tickets/<span class="nu0">1</span>: <span class="nu0">1</span>
<span class="nu0">2216</span>: <span class="kw3">new</span> <span class="kw3">user</span> accounts <span class="kw1">for</span> testing: http://my.<span class="me1">ac</span>-<span class="kw3">site</span>.<span class="me1">com</span>/projects/<span class="nu0">34</span>/tickets/<span class="nu0">3</span>: <span class="nu0">3</span></pre></div></div>
<p>I&#8217;ve also blogged about this over at our udox <a href="http://www.u-dox.com/blog/2011/02/16/python-library-for-active-collab/">company site</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jaymz.eu/2011/02/active-collab-library-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redirecting users in django based on client IP</title>
		<link>http://jaymz.eu/2011/02/redirecting-users-in-django-based-on-client-ip/</link>
		<comments>http://jaymz.eu/2011/02/redirecting-users-in-django-based-on-client-ip/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 10:34:55 +0000</pubDate>
		<dc:creator>jaymz</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[geocoding]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://jaymz.eu/?p=541</guid>
		<description><![CDATA[geoip-redirect is available on my github page.]]></description>
			<content:encoded><![CDATA[<p><a href="http://jaymz.eu/wp-content/uploads/2011/02/redirect-vans.jpg"><img class="aligncenter size-full wp-image-542" title="redirect-vans" src="http://jaymz.eu/wp-content/uploads/2011/02/redirect-vans.jpg" alt="" width="525" height="295" /></a><a href="https://github.com/jaymzcd/geoip-redirect"></a></p>
<p><a href="https://github.com/jaymzcd/geoip-redirect">geoip-redirect</a> is available on my github page.</p>
]]></content:encoded>
			<wfw:commentRss>http://jaymz.eu/2011/02/redirecting-users-in-django-based-on-client-ip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Geocoding and radial search of data for django apps</title>
		<link>http://jaymz.eu/2010/12/geocoding-radial-search-django/</link>
		<comments>http://jaymz.eu/2010/12/geocoding-radial-search-django/#comments</comments>
		<pubDate>Sun, 05 Dec 2010 16:28:14 +0000</pubDate>
		<dc:creator>jaymz</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[geocoding]]></category>
		<category><![CDATA[google maps]]></category>

		<guid isPermaLink="false">http://jaymz.eu/?p=527</guid>
		<description><![CDATA[Something that I&#8217;ve had need of more than once the past while is placing lots of address data on google maps. For a few places it&#8217;s easy to manually handle that but I&#8217;ve been having to work with databases with thousands and thousands of samples &#8211; many in an unclean form with fields missing. I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>Something that I&#8217;ve had need of more than once the past while is placing lots of address data on google maps. For a few places it&#8217;s easy to manually handle that but I&#8217;ve been having to work with databases with thousands and thousands of samples &#8211; many in an unclean form with fields missing.</p>
<p>I&#8217;ve ended up with a small django based library over at <a href="https://github.com/jaymzcd/django-geosearch">github</a>. For the data I had to work with much of the complications where the mis-matching of city/town level names &#8211; for example as well as <em>London</em> many items had the actual area listed instead, e.g. <em>Camden</em> or <em>Westminster</em>. When doing queries we wanted to be able to return items within certain areas but without having to manually clean everything up, so the model code provides a <em>within_radius</em> method which will return matching enteries that fall within the radial bounds given.</p>
<p>Within the scripts folder there&#8217;s an example of how I decided to work with an existing django based site that I then installed the geosearch code to.</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jaymz.eu/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="python"><span class="co1">#!/usr/bin/python2.7</span>
<span class="co1"># -*- coding: utf-8 -*-</span>
&nbsp;
<span class="co1"># To run this you'll need to set two environment variables. Could probably do this</span>
<span class="co1"># as a management command but seems a bit messy since it's a very specific thing...</span>
<span class="co1">#</span>
<span class="co1"># export PYTHONPATH=/home/jaymz/development/www/vansemea</span>
<span class="co1"># export DJANGO_SETTINGS_MODULE=settings</span>
<span class="co1">#</span>
<span class="co1"># Obviously you'll need to change that path if you want to run it yourself</span>
&nbsp;
<span class="kw1">from</span> locator.<span class="me1">models</span> <span class="kw1">import</span> Dealer, City
<span class="kw1">from</span> geosearch.<span class="me1">models</span> <span class="kw1">import</span> GeoEntry
<span class="kw1">from</span> base.<span class="me1">models</span> <span class="kw1">import</span> Country
<span class="kw1">from</span> django.<span class="me1">db</span>.<span class="me1">models</span> <span class="kw1">import</span> Count
&nbsp;
MAX_TOP_CITIES = <span class="nu0">30</span> <span class="co1"># how many of our &quot;has the most dealers&quot; to bin the others into</span>
BOUNDRY_RADIUS = <span class="nu0">25</span> <span class="co1"># number of *miles* from our source point to include</span>
CTYPES = <span class="br0">&#123;</span>
    <span class="st0">'dealer'</span>: <span class="nu0">32</span>,
    <span class="st0">'city'</span>: <span class="nu0">29</span>,
<span class="br0">&#125;</span>
&nbsp;
<span class="kw1">for</span> country <span class="kw1">in</span> Country.<span class="me1">objects</span>.<span class="me1">all</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:
    <span class="kw1">try</span>:
        cities = Dealer.<span class="me1">objects</span>.<span class="me1">values</span><span class="br0">&#40;</span><span class="st0">'city__pk'</span>, <span class="st0">'city__name'</span><span class="br0">&#41;</span> \
            .<span class="kw2">filter</span><span class="br0">&#40;</span>country=country<span class="br0">&#41;</span>.<span class="me1">annotate</span><span class="br0">&#40;</span>Count<span class="br0">&#40;</span><span class="st0">'city'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> \
            .<span class="me1">order_by</span><span class="br0">&#40;</span><span class="st0">'-city__count'</span><span class="br0">&#41;</span><span class="br0">&#91;</span>:MAX_TOP_CITIES<span class="br0">&#93;</span>
    <span class="kw1">except</span> <span class="kw2">IndexError</span>:
        <span class="kw1">print</span> <span class="st0">&quot;No data for %s&quot;</span> % country.<span class="me1">name</span>
&nbsp;
    <span class="kw1">print</span> <span class="st0">&quot;Working out cities for %s<span class="es0">\n</span>&quot;</span> % country
&nbsp;
    <span class="kw1">for</span> city <span class="kw1">in</span> cities<span class="br0">&#91;</span>::<span class="nu0">-1</span><span class="br0">&#93;</span>:
        <span class="co1"># Look up the GeoEntry for this city. If we have one then we'll get</span>
        <span class="co1"># back a list of other enteries which are within BOUNDRY_RADIUS miles</span>
        <span class="kw1">print</span> <span class="st0">&quot;<span class="es0">\n</span>Getting db places within %dmiles of %s...<span class="es0">\n</span>&quot;</span> % <span class="br0">&#40;</span>BOUNDRY_RADIUS, city<span class="br0">&#91;</span><span class="st0">'city__name'</span><span class="br0">&#93;</span><span class="br0">&#41;</span>
&nbsp;
        <span class="kw1">try</span>:
            primary_city = City.<span class="me1">objects</span>.<span class="me1">get</span><span class="br0">&#40;</span>pk=city<span class="br0">&#91;</span><span class="st0">'city__pk'</span><span class="br0">&#93;</span>, country=country<span class="br0">&#41;</span>
            primary_city.<span class="me1">primary_city</span> = primary_city
            primary_city.<span class="me1">save</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
        <span class="kw1">except</span>:
            <span class="st0">&quot;Could not find city matching %d and country id %d&quot;</span> % <span class="br0">&#40;</span>city<span class="br0">&#91;</span><span class="st0">'city__pk'</span><span class="br0">&#93;</span>, country.<span class="me1">pk</span><span class="br0">&#41;</span>
            <span class="kw1">continue</span>
&nbsp;
        <span class="kw1">try</span>:
            city_geoentry = GeoEntry.<span class="me1">objects</span>.<span class="me1">get</span><span class="br0">&#40;</span>content_type__pk=CTYPES<span class="br0">&#91;</span><span class="st0">'city'</span><span class="br0">&#93;</span>,
                object_id= city<span class="br0">&#91;</span><span class="st0">'city__pk'</span><span class="br0">&#93;</span><span class="br0">&#41;</span>
        <span class="kw1">except</span> GeoEntry.<span class="me1">DoesNotExist</span>:
            <span class="kw1">print</span> <span class="st0">&quot;No geoentry for %s&quot;</span> % city<span class="br0">&#91;</span><span class="st0">'city__name'</span><span class="br0">&#93;</span>
            <span class="kw1">continue</span>
&nbsp;
        radial_results = GeoEntry.<span class="me1">within_radius</span><span class="br0">&#40;</span>
            <span class="br0">&#91;</span>city_geoentry.<span class="me1">latitude</span>, city_geoentry.<span class="me1">longitude</span><span class="br0">&#93;</span>,
            BOUNDRY_RADIUS
        <span class="br0">&#41;</span>
&nbsp;
        <span class="co1"># Trim off our source point, reverse and update our source cities</span>
        <span class="co1"># (we need to reverse it to have it assign by most populated last)</span>
        <span class="kw1">for</span> point <span class="kw1">in</span> radial_results<span class="br0">&#91;</span><span class="nu0">1</span>:<span class="br0">&#93;</span><span class="br0">&#91;</span>::<span class="nu0">-1</span><span class="br0">&#93;</span>:
            <span class="kw1">if</span> point<span class="br0">&#91;</span><span class="st0">'content_type'</span><span class="br0">&#93;</span> == CTYPES<span class="br0">&#91;</span><span class="st0">'city'</span><span class="br0">&#93;</span>:
                source_city = City.<span class="me1">objects</span>.<span class="me1">get</span><span class="br0">&#40;</span>pk=point<span class="br0">&#91;</span><span class="st0">'object_id'</span><span class="br0">&#93;</span><span class="br0">&#41;</span>
                source_city.<span class="me1">primary_city</span> = primary_city
                source_city.<span class="me1">save</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
                <span class="kw1">print</span> <span class="st0">&quot;Set %s as primary city for %s&quot;</span> % <span class="br0">&#40;</span>primary_city, source_city<span class="br0">&#41;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://jaymz.eu/2010/12/geocoding-radial-search-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress plugin to post to Facebook wall and Twitter feed</title>
		<link>http://jaymz.eu/2010/10/wordpress-to-facebook-and-twitter/</link>
		<comments>http://jaymz.eu/2010/10/wordpress-to-facebook-and-twitter/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 16:29:36 +0000</pubDate>
		<dc:creator>jaymz</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://jaymz.eu/?p=515</guid>
		<description><![CDATA[We&#8217;ve recently had to do some automatic posting of content to facebook from a wordpress blog. I did find this wordbook plugin but it apparently has broke recently and people have been complaining it no longer works (27 out of 27!). So I&#8217;ve rolled my own. It&#8217;s in a very early stage but the code [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve recently had to do some automatic posting of content to facebook from a wordpress blog. I did find this <em><a href="http://wordpress.org/extend/plugins/wordbook/">wordbook</a></em><em> </em>plugin but it apparently has broke recently and people have been complaining it no longer works (27 out of 27!). So I&#8217;ve rolled my own. It&#8217;s in a very early stage but the code seems to work ok.</p>
<p><a href="http://jaymz.eu/wp-content/uploads/2010/10/wordpress-fb-post.png"><img class="aligncenter size-full wp-image-516" title="wordpress-fb-post" src="http://jaymz.eu/wp-content/uploads/2010/10/wordpress-fb-post.png" alt="" width="561" height="198" /></a></p>
<p>Instructions (you&#8217;ll need to create a new application and then authorize that for your user) and code are all <a href="http://github.com/jaymzcd/wp-twacepost">over at github</a>. I can&#8217;t really tell if I&#8217;m &#8220;doing it right&#8221; but it&#8217;s working and is a start. Fork and be happy&#8230;</p>
<p><a href="http://jaymz.eu/wp-content/uploads/2010/10/twacepost-options.png"><img class="aligncenter size-full wp-image-525" title="twacepost-options" src="http://jaymz.eu/wp-content/uploads/2010/10/twacepost-options.png" alt="" width="480" height="414" /></a></p>
<p><em><strong>Updated </strong><span style="font-style: normal;">I&#8217;ve now added in support to push the title to twitter. I&#8217;m currently working on hooking in Bit.ly support to add the short URL to the tweet. Code is pushed to GH.</span></em></p>
<p><strong><em>More updates </em><span style="font-weight: normal;">The twitter posting now uses the post tile + a bit.ly link to your blog permalink. I&#8217;ve decided it&#8217;s now worthy of v0.2!</span></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://jaymz.eu/2010/10/wordpress-to-facebook-and-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating ooyala in django (or just python)</title>
		<link>http://jaymz.eu/2010/07/integrating-ooyala-in-django-or-just-python/</link>
		<comments>http://jaymz.eu/2010/07/integrating-ooyala-in-django-or-just-python/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 11:34:26 +0000</pubDate>
		<dc:creator>jaymz</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[ooyala]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://jaymz.eu/?p=495</guid>
		<description><![CDATA[Ooyala is a feature rich video hosting platform. Something I needed recently was some way to link the data over at ooyala into a django site I&#8217;m building. So I wrote myself a library. It&#8217;s available over at github and it&#8217;s called (predictably) django-ooyala. Currently there is a management command syncooyala to pull in all [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jaymz.eu/wp-content/uploads/2010/07/django-ooyala-logo.png"><img class="aligncenter size-full wp-image-497" title="django-ooyala-logo" src="http://jaymz.eu/wp-content/uploads/2010/07/django-ooyala-logo.png" alt="" width="350" height="133" /></a></p>
<p>Ooyala is a feature rich video hosting platform. Something I needed recently was some way to link the data over at ooyala into a django site I&#8217;m building. So I wrote myself a library. It&#8217;s available over at github and it&#8217;s called (predictably) <em><a href="http://github.com/jaymzcd/django-ooyala">django-ooyala</a>.</em> Currently there is a management command <strong>syncooyala</strong> to pull in all the data using the Backlot Query API. These imported items are then linked to a specific URL. Finally in your templates there is a <em>ooyala_video</em> tag which when given the current path (via request.path) returns the &lt;script&gt; tags needed for it to render.</p>
<p>Expect some updates as I flesh it out into the front end over the next few days.</p>
<p><strong><em>Updated (11th August): <span style="font-weight: normal;">I have added in analytics support. You can now make requests for video stat&#8217;s for a given account or video. The facebook SDK has also been added with a new template tag to output the headers in your template for a given video. Remember to request whitelisting from facebook for SWF embeds to work.</span></em></strong></p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jaymz.eu/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="python"><span class="kw1">from</span> django.<span class="me1">http</span> <span class="kw1">import</span> HttpResponse
<span class="kw1">from</span> ooyala.<span class="me1">library</span> <span class="kw1">import</span> OoyalaAnalytics
<span class="kw1">from</span> ooyala.<span class="me1">constants</span> <span class="kw1">import</span> OoyalaConstants as O
<span class="kw1">from</span> ooyala.<span class="me1">models</span> <span class="kw1">import</span> OoyalaItem
&nbsp;
<span class="kw1">def</span> backlot_query<span class="br0">&#40;</span>request<span class="br0">&#41;</span>:
    req = OoyalaAnalytics<span class="br0">&#40;</span>video=OoyalaItem.<span class="me1">objects</span>.<span class="me1">all</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>.<span class="me1">embed_code</span>, \
        method=O.<span class="me1">ANALYTIC_METHODS</span>.<span class="me1">VIDEO</span><span class="br0">&#41;</span>
    ooyala_response = req.<span class="me1">process</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
    <span class="kw1">return</span> HttpResponse<span class="br0">&#40;</span>ooyala_response.<span class="me1">toprettyxml</span><span class="br0">&#40;</span><span class="br0">&#41;</span>, mimetype=<span class="st0">&quot;text/xml&quot;</span><span class="br0">&#41;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://jaymz.eu/2010/07/integrating-ooyala-in-django-or-just-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tube Delay Refund for android released</title>
		<link>http://jaymz.eu/2010/07/tube-delay-refund-for-android-released/</link>
		<comments>http://jaymz.eu/2010/07/tube-delay-refund-for-android-released/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 02:21:46 +0000</pubDate>
		<dc:creator>jaymz</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://jaymz.eu/?p=489</guid>
		<description><![CDATA[Update (v1.4.0) National Rail &#38; TFL Travelcard support has been added. (August 2nd) Update (v1.3.2) Some layout rejigging has been done, defaults added and a few more menu options for resetting/prefilling. The preferences layout has also been tidied. (July 17) Updated (v1.2.0) I have updated this app to disable submission until all the station/date info [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update (v1.4.0) </strong><em>National Rail &amp; TFL Travelcard support has been added. (August 2nd)</em></p>
<p><strong>Update<em> </em>(v1.3.2) </strong><em>Some layout rejigging has been done, defaults added and a few more menu options for resetting/prefilling. The preferences layout has also been tidied. (July 17)</em></p>
<p><strong>Updated (v1.2.0) </strong><em>I have updated this app to disable submission until all the station/date info is added. I&#8217;ve also added some more labels to show what&#8217;s been entered so far. You <span style="text-decoration: underline;">must</span> make sure you&#8217;ve filled in all the preferences or else it&#8217;ll fail (Click menu&gt;preferences). (July 16)</em></p>
<p>A few days ago I was in bed trying to sleep and I suddenly thought it would be good if there was an app to submit refunds for the tube as you come out. I had in my head the idea of a timer that would count down from 15 minutes and then alert you that you were in valid refund territory.</p>
<p style="text-align: center;"><a href="http://jaymz.eu/wp-content/uploads/2010/07/131.png"><img class="aligncenter size-full wp-image-508" title="131" src="http://jaymz.eu/wp-content/uploads/2010/07/131.png" alt="" width="576" height="432" /></a></p>
<p>After I coded said timer, I pushed it live without refund submissions working. I also did a quick google to see what else there was only to discover that there was a company that released the exact same app on the iPhone about 3 months ago. Let this be a lesson that if you are about to code something as an exercise <em>don&#8217;t</em> go googling first or you&#8217;ll inevitably be put off because &#8220;whats the point&#8221;.</p>
<p style="text-align: center;">
<p>Several hours later today and it is now submitting refund applications to TFL and I get an email confirmation with the reference number. I&#8217;m very happy if incredibly tired. The app is free for now, all the others that do these on Blackberry/iOS are paid for. There doesn&#8217;t seem to be one for android yet, the guys that did the iPhone app said they where working on one way back in March or April, not quite sure what happened to it. They&#8217;re about to release the blackberry one so for now this is the <em>only</em> refund submission app on android <img src='http://jaymz.eu/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Took me basically 2 days part time.</p>
<p><a href="http://www.androidzoom.com/android_applications/travel/tube-refund_ipjg.html"><img class="aligncenter size-full wp-image-491" title="promo" src="http://jaymz.eu/wp-content/uploads/2010/07/promo.png" alt="" width="180" height="120" /></a></p>
<p>From a technical point of view this is making use of the apache http libraries to do a GET request for the TFL refund page. It parses that to grab the ASPX Viewstate variable and session cookies. Then it grabs the data from the main activity and combines that with the data stored in shared preferences for the form variables. The POST request is processed and the response parsed again to find the reference number. That&#8217;s then displayed via a Toast call. Fairly simple, having to deal with the viewstate crap was probably the most annoying part, that and debugging the actual POST.</p>
]]></content:encoded>
			<wfw:commentRss>http://jaymz.eu/2010/07/tube-delay-refund-for-android-released/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SpineMagazine.com radio player &amp; news reader for android</title>
		<link>http://jaymz.eu/2010/07/spinemagazine-com-radio-player-news-reader-for-android/</link>
		<comments>http://jaymz.eu/2010/07/spinemagazine-com-radio-player-news-reader-for-android/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 00:20:38 +0000</pubDate>
		<dc:creator>jaymz</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://jaymz.eu/?p=467</guid>
		<description><![CDATA[Quite a while back I was trying to get my head around the fairly complex ListView control for android and something I thought perfect for it was the set of radio shows over at spine magazine. I have had this code sitting around for a while and I thought why not knock out the news [...]]]></description>
			<content:encoded><![CDATA[<p>Quite a while back I was trying to get my head around the fairly complex <a href="http://developer.android.com/reference/android/widget/ListView.html">ListView</a> control for android and something I thought perfect for it was the set of radio shows over at <a href="http://www.spinemagazine.com">spine magazine</a>.</p>
<table width="100%">
<tbody>
<tr>
<td>
<p style="text-align: center;"><a href="http://jaymz.eu/wp-content/uploads/2010/07/screen-shows.png"><img class="aligncenter size-full wp-image-469" title="screen-shows" src="http://jaymz.eu/wp-content/uploads/2010/07/screen-shows.png" alt="" width="224" height="336" /></a></p>
</td>
<td>
<p style="text-align: center;"><a href="http://jaymz.eu/wp-content/uploads/2010/07/screen-news1.png"><img class="aligncenter size-full wp-image-476" title="screen-news" src="http://jaymz.eu/wp-content/uploads/2010/07/screen-news1.png" alt="" width="224" height="336" /></a></p>
</td>
</tr>
</tbody>
</table>
<p>I have had this code sitting around for a while and I thought why not knock out the news code and release it and then just continue to work on it and update it. As the saying goes, <em>release early, release often!</em> I think it&#8217;ll be easy enough to add in reviews using the same sort of code to get the data and just re-using the show layout. This particular app was a lot more complicated than the django-reference thing, so here is some of what I&#8217;ve learned&#8230; You can get this in the marketplace now. Bug reports are expected &amp; indeed welcome.</p>
<p><a href="http://jaymz.eu/wp-content/uploads/2010/07/logo.png"><img class="aligncenter size-full wp-image-484" title="logo" src="http://jaymz.eu/wp-content/uploads/2010/07/logo.png" alt="" width="100" height="100" /></a></p>
<p><span style="color: #ff0000;"><strong>Warning! Technical crap follows.</strong></span></p>
<p>It takes a bit of time to get your head around it, essentially you subclass the <a href="http://developer.android.com/reference/android/widget/ArrayAdapter.html">ArrayAdapter</a> class with a container class to hold your list view elements. The ArrayAdapter is a templated class so you first need another class that is actually going to hold your data. This is were you&#8217;ll need to create a class for your data and then instantiate the ArrayList with this type. The code to hold my news post data is very simple:</p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jaymz.eu/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="java"><span class="kw2">package</span> eu.<span class="me1">jaymz</span>.<span class="me1">spinemag</span>;
&nbsp;
<span class="co2">import android.util.Log;</span>
&nbsp;
<span class="kw2">public</span> <span class="kw2">class</span> NewsPost <span class="br0">&#123;</span>
    <span class="kw2">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> title;
    <span class="kw2">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> description;
    <span class="kw2">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> date;
    <span class="kw2">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> author;
&nbsp;
    <span class="kw2">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> getTitle<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw2">return</span> title;
    <span class="br0">&#125;</span>
    <span class="kw2">public</span> <span class="kw4">void</span> setTitle<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> title<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw2">this</span>.<span class="me1">title</span> = title;
    <span class="br0">&#125;</span>
    <span class="kw2">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> getDescription<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw2">return</span> description;
    <span class="br0">&#125;</span>
    <span class="kw2">public</span> <span class="kw4">void</span> setDescription<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> description<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw2">this</span>.<span class="me1">description</span> = description;
    <span class="br0">&#125;</span>
    <span class="kw2">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> getAuthor<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw2">return</span> author;
    <span class="br0">&#125;</span>
    <span class="kw2">public</span> <span class="kw4">void</span> setAuthor<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> author<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw2">this</span>.<span class="me1">author</span> = author;
    <span class="br0">&#125;</span>
    <span class="kw2">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> getDate<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw2">return</span> date;
    <span class="br0">&#125;</span>
    <span class="kw2">public</span> <span class="kw4">void</span> setDate<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> date<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw2">this</span>.<span class="me1">date</span> = date;
    <span class="br0">&#125;</span>
&nbsp;
<span class="br0">&#125;</span></pre></div></div>
<p>Then in my main activity class I cast the templated ArrayList to a NewsPost class:</p>
<p><strong><strong>ArrayList&lt;NewsPost&gt; spr_news = new ArrayList&lt;NewsPost&gt;();</strong></strong></p>
<p>With the data structure sorted I need a method in my ListView activity to actually fill in the ArrayList with data. This is very typically something along the lines of the following, here I read the JSON data from a URL, decode it and assign it to the class members, finally appending it to the ArrayList from earlier.</p>
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jaymz.eu/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="java"><span class="kw2">private</span> <span class="kw4">void</span> getPosts<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw2">try</span> <span class="br0">&#123;</span>
            <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AURL+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">URL</span></a> url = <span class="kw2">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AURL+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">URL</span></a><span class="br0">&#40;</span><span class="st0">&quot;url for data&quot;</span><span class="br0">&#41;</span>;
            <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ABufferedReader+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">BufferedReader</span></a> in = <span class="kw2">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ABufferedReader+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">BufferedReader</span></a><span class="br0">&#40;</span><span class="kw2">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AInputStreamReader+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">InputStreamReader</span></a><span class="br0">&#40;</span>url.<span class="me1">openStream</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
            <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> str = in.<span class="me1">readLine</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
            in.<span class="me1">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
            spr_news = <span class="kw2">new</span> ArrayList&lt;NewsPost&gt;<span class="br0">&#40;</span><span class="br0">&#41;</span>;
            JSONObject json = <span class="kw2">new</span> JSONObject<span class="br0">&#40;</span>str<span class="br0">&#41;</span>;
            JSONArray posts = json.<span class="me1">getJSONArray</span><span class="br0">&#40;</span><span class="st0">&quot;posts&quot;</span><span class="br0">&#41;</span>;
            <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw4">int</span> x=<span class="nu0">0</span>; x &lt; posts.<span class="me1">length</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; x++<span class="br0">&#41;</span> <span class="br0">&#123;</span>
                JSONObject post_data = <span class="kw2">new</span> JSONObject<span class="br0">&#40;</span>posts.<span class="me1">get</span><span class="br0">&#40;</span>x<span class="br0">&#41;</span>.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
                NewsPost post = <span class="kw2">new</span> NewsPost<span class="br0">&#40;</span><span class="br0">&#41;</span>;
                post.<span class="me1">setTitle</span><span class="br0">&#40;</span>post_data.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;title&quot;</span><span class="br0">&#41;</span>.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
                post.<span class="me1">setDescription</span><span class="br0">&#40;</span>post_data.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;description&quot;</span><span class="br0">&#41;</span>.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
                post.<span class="me1">setDate</span><span class="br0">&#40;</span>post_data.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;date&quot;</span><span class="br0">&#41;</span>.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
                post.<span class="me1">setAuthor</span><span class="br0">&#40;</span>post_data.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;author&quot;</span><span class="br0">&#41;</span>.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
                spr_news.<span class="me1">add</span><span class="br0">&#40;</span>post<span class="br0">&#41;</span>;
                <span class="co1">//Log.d(&quot;NEW&quot;, &quot;added a post - &quot;+post.getTitle());</span>
            <span class="br0">&#125;</span>
        <span class="br0">&#125;</span> <span class="kw2">catch</span> <span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AException+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Exception</span></a> e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
        <span class="br0">&#125;</span>
        runOnUiThread<span class="br0">&#40;</span>setPosts<span class="br0">&#41;</span>;
    <span class="br0">&#125;</span></pre></div></div><br />
</strong></strong></p>
<p>With all the above in place the code is at the point where there is now an array full of structured data for our ArrayAdapter to show. To do this the ArrayAdapter needs subclassed to work with our earlier NewsPost classes members:</p>
<p><div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jaymz.eu/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><pre class="java"><span class="kw2">private</span> <span class="kw2">class</span> NewsAdapter <span class="kw2">extends</span> ArrayAdapter&lt;NewsPost&gt; <span class="br0">&#123;</span>
&nbsp;
        <span class="kw2">private</span> ArrayList&lt;NewsPost&gt; items;
&nbsp;
        <span class="kw2">public</span> NewsAdapter<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AContext+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Context</span></a> context, <span class="kw4">int</span> textViewResourceId, ArrayList&lt;NewsPost&gt; items<span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <span class="kw2">super</span><span class="br0">&#40;</span>context, textViewResourceId, items<span class="br0">&#41;</span>;
                <span class="kw2">this</span>.<span class="me1">items</span> = items;
        <span class="br0">&#125;</span>
        @Override
        <span class="kw2">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AView+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">View</span></a> getView<span class="br0">&#40;</span><span class="kw4">int</span> position, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AView+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">View</span></a> convertView, ViewGroup parent<span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AView+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">View</span></a> v = convertView;
                <span class="kw1">if</span> <span class="br0">&#40;</span>v == <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
                    LayoutInflater vi = <span class="br0">&#40;</span>LayoutInflater<span class="br0">&#41;</span>getSystemService<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AContext+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Context</span></a>.<span class="me1">LAYOUT_INFLATER_SERVICE</span><span class="br0">&#41;</span>;
                    v = vi.<span class="me1">inflate</span><span class="br0">&#40;</span>R.<span class="me1">layout</span>.<span class="me1">post</span>, <span class="kw2">null</span><span class="br0">&#41;</span>;
                <span class="br0">&#125;</span>
                NewsPost o = items.<span class="me1">get</span><span class="br0">&#40;</span>position<span class="br0">&#41;</span>;
                <span class="kw1">if</span> <span class="br0">&#40;</span>o != <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
                    <span class="coMULTI">/* hmm, this looks proper ugly */</span>
                    TextView title = <span class="br0">&#40;</span>TextView<span class="br0">&#41;</span>v.<span class="me1">findViewById</span><span class="br0">&#40;</span>R.<span class="me1">id</span>.<span class="me1">post_title</span><span class="br0">&#41;</span>;
                    TextView description = <span class="br0">&#40;</span>TextView<span class="br0">&#41;</span>v.<span class="me1">findViewById</span><span class="br0">&#40;</span>R.<span class="me1">id</span>.<span class="me1">post_description</span><span class="br0">&#41;</span>;
                    TextView date = <span class="br0">&#40;</span>TextView<span class="br0">&#41;</span>v.<span class="me1">findViewById</span><span class="br0">&#40;</span>R.<span class="me1">id</span>.<span class="me1">post_date</span><span class="br0">&#41;</span>;
                    TextView author = <span class="br0">&#40;</span>TextView<span class="br0">&#41;</span>v.<span class="me1">findViewById</span><span class="br0">&#40;</span>R.<span class="me1">id</span>.<span class="me1">post_author</span><span class="br0">&#41;</span>;
&nbsp;
                    description.<span class="me1">setText</span><span class="br0">&#40;</span>o.<span class="me1">getDescription</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
                    title.<span class="me1">setText</span><span class="br0">&#40;</span>o.<span class="me1">getTitle</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
                    author.<span class="me1">setText</span><span class="br0">&#40;</span>o.<span class="me1">getAuthor</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
                    date.<span class="me1">setText</span><span class="br0">&#40;</span>o.<span class="me1">getDate</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
                <span class="br0">&#125;</span>
                <span class="kw2">return</span> v;
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span></pre></div></div>
<p>All this code is really doing is loading the layout resource XML for our row and binding the data from the array elements members to views within the XML. Finally we need to tell the list view to update. Typically the above code has all been kicked off and ran in a thread, populating the ListView when it&#8217;s actually finished without stalling the phone itself.</p>
<div id="wpshdo_7" class="wp-synhighlighter-outer"><div id="wpshdt_7" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_7"></a><a id="wpshat_7" class="wp-synhighlighter-title" href="#codesyntax_7"  onClick="javascript:wpsh_toggleBlock(7)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_7" onClick="javascript:wpsh_code(7)" title="Show code only"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_print(7)" title="Print code"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jaymz.eu/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jaymz.eu/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_7" class="wp-synhighlighter-inner" style="display: block;"><pre class="java"><span class="kw1">for</span><span class="br0">&#40;</span><span class="kw4">int</span> i=<span class="nu0">0</span>;i&lt;spr_news.<span class="me1">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;i++<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    n_adapter.<span class="me1">add</span><span class="br0">&#40;</span>spr_news.<span class="me1">get</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span><span class="br0">&#41;</span>;
<span class="br0">&#125;</span>
m_ProgressDialog.<span class="me1">dismiss</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
n_adapter.<span class="me1">notifyDataSetChanged</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</pre></div></div>
<p>All the above is doing is updating the ArrayAdapter and adding our ArrayList elements to display. We then signal that the data has changed which will cause the ListView itself to update. Simple! <img src='http://jaymz.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Again, I must make the point of how verbose this all feels when I&#8217;m coding in python all day. I&#8217;m sure it needs a good refactor to now but I&#8217;m a lot more familiar with the way android works with layouts and indeed <strong>strong</strong> typing <img src='http://jaymz.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://jaymz.eu/2010/07/spinemagazine-com-radio-player-news-reader-for-android/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Google Blogger to Django integration</title>
		<link>http://jaymz.eu/2010/06/google-blogger-to-django-integration/</link>
		<comments>http://jaymz.eu/2010/06/google-blogger-to-django-integration/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 21:45:57 +0000</pubDate>
		<dc:creator>jaymz</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[blogger]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://jaymz.eu/?p=447</guid>
		<description><![CDATA[I&#8217;ve been working a lot on Vans recently and they have a large number of blogs that are currently hosted on the blogger platform. This works really well for them, they have a straightforward &#38; easy to use blog platform that does what they need it to do.  The sites themselves work great as they [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working a lot on <a href="http://www.vans.com">Vans</a> recently and they have a large number of blogs that are currently hosted on the blogger platform. This works really well for them, they have a straightforward &amp; easy to use blog platform that does what they need it to do.  The sites themselves work great as they are but the integration into the main site isn&#8217;t quite as nice.</p>
<p>If you go to the <a href="http://www.vans.com/vans/teamblog.asp">blogs section</a> on vans as it stands it will pull in an XML feed of all the current blogs and display them on one giagantic page. It can take a fair bit of time to load and its hard to see how each different blog gets displayed as its really one big list. For now it&#8217;s not so easy to pull in bits of content from the various blogs without someone having to mess with files or copy &amp; paste, with the build in django I wanted to create a much cleaner &amp; easier way to work with this content.</p>
<p><a href="http://github.com/jaymzcd/django-blogger"><img class="aligncenter size-full wp-image-460" title="blogger-django-logo" src="http://jaymz.eu/wp-content/uploads/2010/06/blogger-django-logo.png" alt="" width="100" height="99" /></a></p>
<p>For this I introduce <a href="http://github.com/jaymzcd/django-blogger">django-blogger</a>, a django application which will integrate Google Blogger blogs via their RSS feeds. As it is it will import the blogs for a given profile id and then sync up with the latest data via their RSS feeds. These can be <a href="http://www.google.com/support/blogger/bin/answer.py?hl=en&amp;answer=97933">enabled easily</a> for your given blogs. When you first install it comes with some admin actions which will all ow you to sync up the blogs manually all at once. There is also a management command, <em>syncblogs,</em> which is more suited to scheduling an update via cron (if you&#8217;re going to use cron you might be interested in <a href="http://code.google.com/p/django-crontab/">django-crontab</a>).</p>
<p><a href="http://jaymz.eu/wp-content/uploads/2010/06/djangoblogs-syncing-command.png"><img class="aligncenter size-full wp-image-451" title="djangoblogs-syncing-command" src="http://jaymz.eu/wp-content/uploads/2010/06/djangoblogs-syncing-command.png" alt="" width="514" height="252" /></a></p>
<p>This works on the feeds and not an archive, so it doesn&#8217;t require authentication, just access to the feed URL. A basic template is included to show how to render out the blog posts &amp; blogs as a menu, I override these myself for the format I need. The app itself now lets me pull content from any of the blogs and use it within the rest of the django based site cleanly &amp; easily. Rather than directly reading and displaying via the feed URL I&#8217;m creating actual objects for each post and blog so it&#8217;s easily extendible also, say to return posts in various formats or pulling images from each blog post to create blog galleries automatically.</p>
<p><img src="http://jaymz.eu/wp-content/uploads/2010/06/blogs-4.png" alt="" /></p>
<p>The code is available from <a href="http://github.com/jaymzcd/django-blogger">GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jaymz.eu/2010/06/google-blogger-to-django-integration/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

