<?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>corprewland &#187; programming</title>
	<atom:link href="http://www.corprew.org/blog/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.corprew.org</link>
	<description>(dis)information organization</description>
	<lastBuildDate>Thu, 04 Feb 2010 20:48:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>ruby/rails and the invited beta</title>
		<link>http://www.corprew.org/blog/2008/04/16/rubyrails-and-the-invited-beta/</link>
		<comments>http://www.corprew.org/blog/2008/04/16/rubyrails-and-the-invited-beta/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 06:31:59 +0000</pubDate>
		<dc:creator>corprew</dc:creator>
				<category><![CDATA[computer programming]]></category>
		<category><![CDATA[account]]></category>
		<category><![CDATA[acts_as_authenticated]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[guid]]></category>
		<category><![CDATA[invite]]></category>
		<category><![CDATA[invite functionality]]></category>
		<category><![CDATA[private beta]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[slicehost]]></category>
		<category><![CDATA[tristero]]></category>
		<category><![CDATA[welcome screen]]></category>

		<guid isPermaLink="false">http://www.corprew.org/blog/2008/04/16/rubyrails-and-the-invited-beta/</guid>
		<description><![CDATA[I&#8217;ve been working on a website in RoR for the last while, and it&#8217;s about to go live in the private beta sort of way that seems to be so popular these days. It&#8217;s handy that way, because that way I can set up the site at slicehost or similar and not have to worry [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a website in RoR for the last while, and it&#8217;s about to go live in the private beta sort of way that seems to be so popular these days.  It&#8217;s handy that way, because that way I can set up the site at slicehost or similar and not have to worry (too much) about my server slowing from getting overloaded.  This same site&#8217;s next incarnation is going to be facebook related, so that should overwhelm any sense of moderation (if I&#8217;m lucky.)</p>
<p>So, the key method of invitation to a private beta is that you mail someone a code allowing them access to the system, for these purposes, let&#8217;s just assume that the code is some reasonably long unique string (in my code, it&#8217;s actually a <code>uuid</code>.)  So, set up a migration something like this to manage them:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
    create_table <span style="color:#ff3333; font-weight:bold;">:invites</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
<span style="color:#008000; font-style:italic;"># deleted stuff</span>
      t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:guid</span>
      t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#ff3333; font-weight:bold;">:used_yet</span>
<span style="color:#008000; font-style:italic;"># deleted stuff</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><code>used_yet</code> isn&#8217;t a boolean for reasons that are too laborious to go into here, but reflect some functionality in the code that I&#8217;m not going to display.  Assuming that you&#8217;re using acts_as_authentication and are redirecting anyone who tries to access your app to the default welcome page according to the usual methods, set up something like this in your routes.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  map.<span style="color:#9900CC;">root</span> <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;welcome&quot;</span></pre></div></div>

<p>This is probably the case in like half the rails apps out there.  Have the <code>index</code> method of the welcome controller put up a form with a field like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#let's see if the formatter can handle rails erb without exploding.</span>
<span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span> form_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'welcome/checkinvite'</span>, <span style="color:#ff3333; font-weight:bold;">:method</span><span style="color:#006600; font-weight:bold;">=&gt;</span>:get<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span>= text_field_tag <span style="color:#996600;">'invite'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span>= submit_tag <span style="color:#996600;">'begin'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span></pre></div></div>

<p>This lets the user enter their invite in more or less the normal method.  Now in your &#8216;welcome&#8217; controller, you&#8217;ll need a &#8216;checkinvite&#8217; method that looks something like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"> <span style="color:#9966CC; font-weight:bold;">def</span> checkinvite
    <span style="color:#0066ff; font-weight:bold;">@inviteguid</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:invite</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#0066ff; font-weight:bold;">@invite</span> = Invite.<span style="color:#9900CC;">find_by_guid</span><span style="color:#006600; font-weight:bold;">&#40;</span>@inviteguid<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>@invite == <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Your invite was invalid&quot;</span>
      redirect_to root_url
      <span style="color:#0000FF; font-weight:bold;">return</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>@invite.<span style="color:#9900CC;">used_yet</span> == <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Your invite had already been used&quot;</span>
      redirect_to root_url
      <span style="color:#0000FF; font-weight:bold;">return</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>After this, you&#8217;ll need to have some code in your HTML page that links you to the account/signup functionality of acts_as_authenticated.  I&#8217;m not going to include that because I&#8217;m too lazy to fish it out of my app functionality, but you can do that pretty much with a link_to using <code>:invite=%gt;@invite_guid</code> as an extra parameter.</p>
<p>You need to put the same invite detection code in account/signup, and then when you&#8217;ve created the account, set <code>invite.used_yet = 1</code>.  This is about as simple as a method that I can think of for doing the private beta functionality that seems to be so much in vogue these days.  Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.corprew.org/blog/2008/04/16/rubyrails-and-the-invited-beta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>writing code on the macintosh and its derivatives</title>
		<link>http://www.corprew.org/blog/2008/03/12/writing-code-on-the-macintosh-and-its-derivatives/</link>
		<comments>http://www.corprew.org/blog/2008/03/12/writing-code-on-the-macintosh-and-its-derivatives/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 02:10:20 +0000</pubDate>
		<dc:creator>corprew</dc:creator>
				<category><![CDATA[computer programming]]></category>
		<category><![CDATA[CoreData]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[iphone process model]]></category>
		<category><![CDATA[macosx]]></category>
		<category><![CDATA[ManagedObjectContext]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[ogm]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.corprew.org/blog/2008/03/12/writing-code-on-the-macintosh-and-its-derivatives/</guid>
		<description><![CDATA[note that the latest revision of this blog&#8217;s theme seems to have introduced a weird bug with the code layout plugin (wp-syntax) on some browsers. i&#8217;m looking into it. I think the single most useful thing I&#8217;ve figured out recently in programming for MacOSX and the iPhone is this little snippet right here. - &#40;void&#41; [...]]]></description>
			<content:encoded><![CDATA[<p><b>note that the latest revision of this blog&#8217;s theme seems to have introduced a weird bug with the code layout plugin (wp-syntax) on some browsers.  i&#8217;m looking into it.</b></p>
<p>I think the single most useful thing I&#8217;ve figured out recently in programming for MacOSX and the iPhone is this little snippet right here.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> updateListForEntityNamed<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> entityName andSearchString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> queryString
<span style="color: #002200;">&#123;</span>
<span style="color: #002200;">&#91;</span>...<span style="color: #002200;">&#93;</span>
&nbsp;
	MyDocument<span style="color: #002200;">*</span> current <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDocumentController</span> sharedDocumentController<span style="color: #002200;">&#93;</span> currentDocument<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>current <span style="color: #002200;">&amp;&amp;</span> current <span style="color: #002200;">!=</span> self<span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;CurrentDocument:%@ != self:%@&quot;</span>, current, self<span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#91;</span>current updateListForEntityNamed<span style="color: #002200;">:</span> entityName andSearchString<span style="color: #002200;">:</span> queryString<span style="color: #002200;">&#93;</span>;
		<span style="color: #a61390;">return</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#91;</span>...<span style="color: #002200;">&#93;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>What this does is intercept incoming messages that are supposed to go to the current window, and redirect them to that instance.  I&#8217;ve run into issues in Leopard (MacOSX 10.5) where this is an issue.  To some extent, this is probably a misconfiguration in interface builder somewhere, but it also an issue when using CoreData, because the <code>ManagedObjectContext</code>s are particular to instances of <code>NSManagedDocument</code>, and there are issues that arise if you end up using the wrong context.</p>
<p>I am slowly becoming a great fan of CoreData, it&#8217;s a great <a href="http://developer.apple.com/macosx/coredata.html">persistence/object-graph-management layer</a>.  More on this later.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.corprew.org/blog/2008/03/12/writing-code-on-the-macintosh-and-its-derivatives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
