<?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>My Initials Are TK &#187; code</title>
	<atom:link href="http://myinitialsare.tk/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://myinitialsare.tk</link>
	<description>jew, web, comedy</description>
	<lastBuildDate>Thu, 22 Dec 2011 16:17:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Yahoo Pipes Awesomeness</title>
		<link>http://myinitialsare.tk/2010/10/yahoo-pipes-awesomeness/</link>
		<comments>http://myinitialsare.tk/2010/10/yahoo-pipes-awesomeness/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 21:50:48 +0000</pubDate>
		<dc:creator>kremdela</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[delicious]]></category>
		<category><![CDATA[googlereader]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[yahoopipes]]></category>
		<category><![CDATA[Yelp]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://myinitialsare.tk/?p=2562</guid>
		<description><![CDATA[I totally forgot about building this until it came up in conversation today. At one time I was obsessed with filtering everything I did on the internet down into one mega rss feed. And Yahoo Pipes was the coolest new thing on the internet. So, the idea was to bring together: Videos I favorited on [...]]]></description>
			<content:encoded><![CDATA[<p>I totally forgot about building this until it came up in conversation today.<br />
At one time I was obsessed with filtering everything I did on the internet down into one mega rss feed.<br />
And <a href="http://pipes.yahoo.com">Yahoo Pipes</a> was the coolest new thing on the internet.</p>
<p>So, the idea was to bring together:</p>
<ul>
<li><a href="http://www.youtube.com/my_favorites">Videos I favorited on Youtube</a>.
</li>
<li>Entries from a <a href="http://tadalist.com/">tadalist</a> I kept.
</li>
<li>My Flickr Feed.
</li>
<li>Articles I wrote on Yelp
</li>
<li>My Blog RSS Feed.
</li>
<li>Shared Google Reader Items
</li>
<li>Sites I Bookmarked on Delicious</li>
</ul>
<p>You can check out the <a href="http://pipes.yahoo.com/kremdela/allthings">All Things Tyler Kremberg Yahoo Pipe here</a>. (Warning, you may need a Yahoo login to view)</p>
]]></content:encoded>
			<wfw:commentRss>http://myinitialsare.tk/2010/10/yahoo-pipes-awesomeness/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Who’s On First on Twitter</title>
		<link>http://myinitialsare.tk/2008/12/whos-on-first-on-twitter/</link>
		<comments>http://myinitialsare.tk/2008/12/whos-on-first-on-twitter/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 18:53:22 +0000</pubDate>
		<dc:creator>kremdela</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[comedystuff]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[silly]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.myinitialsare.tk/?p=595</guid>
		<description><![CDATA[I&#8217;ll start this by saying I know this is a dumb idea. I was looking up fictitious characters on Twitter and found Mia from Californication.  That and the Sterling Cooper [Mad Men] Crew. Anyway, I suggested to my buddy Ari that we should create fake twitters for West Wing Characters (LemonLyman!)  But alas, too much [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll start this by saying<strong> I know this is a dumb idea</strong>.</p>
<p>I was looking up fictitious characters on Twitter and found <a href="https://twitter.com/miacross">Mia from Californication</a>.  That and the <a href="http://wearesterlingcooper.com/">Sterling Cooper</a> [Mad Men] Crew. Anyway, I suggested to my buddy <a href="http://www.arijoseph.com">Ari</a> that we should create fake twitters for West Wing Characters (LemonLyman!)  But alas, too much conversation and too little <a href="http://www.andresdubouchet.com/blog/conan_packet_2007.html">movement through hallways</a>.  I also toyed with idea of re-creating I Have a Pony in realtime.</p>
<p>But twitter rate limiting (100 per hour) is a bitch.  Then it came to me. <strong>Who&#8217;s On First</strong>. </p>
<p><img class="alignnone size-medium wp-image-596" title="whosonfirstbudandlou" src="http://www.myinitialsare.tk/wp-content/uploads/2008/12/whosonfirstbudandlou-242x300.jpg" alt="" width="242" height="300" /></p>
<p>Feel free to follow <a href="http://www.twitter.com/bud_abbott">@bud_abbott</a> and <a href="http://www.twitter.com/lou_costello">@lou_costello</a> on Twitter.  I didn&#8217;t do too much error checking, so if the Twitter API wigs out, the conversation will stop.  If I get enough (read: any) followers I&#8217;ll start a nightly performance.</p>
<p>Here&#8217;s the source text: <a href="http://www.myinitialsare.tk/wp-content/uploads/2008/12/back_and_forth.txt">back_and_forth.txt</a></p>
<p>And the code:</p>
<pre lang="ruby">
require('rubygems')
gem('twitter4r', '0.3.0')
require 'twitter'
require 'time'

client_abbott = Twitter::Client.new(:login => 'bud_abbott', :password => 'XXXXXXXX')
client_costello = Twitter::Client.new(:login => 'lou_costello', :password => 'XXXXXXXX')

puts "Logged In, Now Lets Go Through The Script"

File.new('back_and_forth.txt').readlines.each { | response |
  who_said_it, line = response.split(": ")
  if who_said_it.to_s == "Abbott"
    puts "Abbott: #{line}"
    begin
      status = client_abbott.status(:post, line)
      rescue RESTError => re
        puts re.code, re.message, re.uri
    end
  elsif who_said_it.to_s == "Costello"
    puts "Costello: #{line}"
    begin
      status = client_costello.status(:post, line)
      rescue RESTError => re
        puts re.code, re.message, re.uri
    end
  end
}

puts "Finished!"
</pre>
]]></content:encoded>
			<wfw:commentRss>http://myinitialsare.tk/2008/12/whos-on-first-on-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stupid old PHP Database Normalization Script</title>
		<link>http://myinitialsare.tk/2008/03/stupid-old-php-database-normalization-script/</link>
		<comments>http://myinitialsare.tk/2008/03/stupid-old-php-database-normalization-script/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 17:39:16 +0000</pubDate>
		<dc:creator>kremdela</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[oldjunk]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.myinitialsare.tk/2008/03/13/stupid-old-php-database-normalization-script/</guid>
		<description><![CDATA[I found this in my collection of old random files. Fortunately this one was called normalize.php, rather than the numerous asdf7.php or so files I have. Anyway, at the time I had a huge database that was one big table and every field needed to be normalized into its own table. This was for a [...]]]></description>
			<content:encoded><![CDATA[<p>I found this in my collection of old random files.  Fortunately this one was called normalize.php, rather than the numerous asdf7.php or so files I have.  Anyway, at the time I had a huge database that was one big table and every field needed to be normalized into its own table.  This was for a belongs_to/ has_many.  (Although I guess since its in php, you&#8217;d refer to them as belongsTo/ hasMany. <img src='http://myinitialsare.tk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Anyway, I&#8217;m sure there are hundreds of better ways to do this, but this one is mine, written long ago and resurrected because I needed it.</p>
<pre lang="php">
$DATABASE = "db_name";
$TABLE = "big_table_name";

function exec_query($sql) {
	//echo $sql . "\n\n";
	$result = mysql_query($sql);
	if (!$result) { echo "Could not successfully run query ($sql) from DB: "
							. mysql_error(); exit; }
	return $result;
}

/* connect to database */
$link = mysql_connect('localhost', 'root', '');
if (!$link) { die('Could not connect: ' . mysql_error()); }

/* connect to db */
$db_selected = mysql_select_db($DATABASE, $link);
if (!$db_selected) { die ('Can\'t use db : ' . mysql_error()); }

/* Get fields and create table for each field name */
$result = exec_query("show fields from $TABLE");

while ($row = mysql_fetch_assoc($result)) {
	$drop_result = exec_query("DROP TABLE if exists $row[Field]");

	$create_table_query = "CREATE TABLE $row[Field]
				(id int(11) not null auto_increment
				, title varchar(256) not null
				, PRIMARY KEY(id))";
	$create_result = exec_query($create_table_query);

	// add foreign keys to main table
	$alter_result = exec_query("ALTER TABLE $TABLE
				ADD COLUMN $row[Field]_id INT(11)");

	// get all distinct values
	$distinct_values_result = exec_query("SELECT DISTINCT $row[Field]
					FROM $TABLE ORDER BY $row[Field]");

	while ($distinct_values_row = mysql_fetch_row($distinct_values_result)) {
		// add all data to newly created tables
		$insert_data_result = exec_query("INSERT INTO $row[Field]
						SET title = '$distinct_values_row[0]'");
 		$inserted_id = mysql_insert_id();

		// now update main table to reference newly created indices
		$update_big_table = "UPDATE $TABLE SET $row[Field]_id = '$inserted_id'
					WHERE $row[Field] = '$distinct_values_row[0]'";
		$update_big_table_result = exec_query($update_big_table);

		// then we can delete manually the old columns.
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://myinitialsare.tk/2008/03/stupid-old-php-database-normalization-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Last Facebook Ruby Code – Grids</title>
		<link>http://myinitialsare.tk/2007/07/last-facebook-ruby-code-grids/</link>
		<comments>http://myinitialsare.tk/2007/07/last-facebook-ruby-code-grids/#comments</comments>
		<pubDate>Thu, 05 Jul 2007 02:41:03 +0000</pubDate>
		<dc:creator>kremdela</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Jobs]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.myinitialsare.tk/?p=90</guid>
		<description><![CDATA[I promise, in remembering how much I don&#8217;t like optimization problems, I was playing around with the Facebook Grid Puzzle. Now I&#8217;m done looking at the Facebook problems, but in case anybody else is interested in playing around, here is some Ruby code I wrote that models the problem exactly: Also, as an aside, I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>I promise, in remembering how much I don&#8217;t like optimization problems, I was playing around with the <a href="http://www.facebook.com/jobs_puzzles/?puzzle_id=9">Facebook Grid Puzzle</a>.   Now I&#8217;m done looking at the Facebook problems, but in case anybody else is interested in playing around, here is some Ruby code I wrote that models the problem exactly:</p>
<p>Also, as an aside, I&#8217;ve noticed <a href="http://snippets.dzone.com/">http://snippets.dzone.com/</a> showing up in search results lately and it has lots of interesting examples, without all of the ugliness of devshed or any of that garbage.  Although its all tagging and not searchable &#8211; dumb.</p>
<pre lang="ruby">
class Grid
   attr_reader :two_d_array, :col_sum_array, :row_sum_array, :big_S

   def initialize(two_d_array)
      @two_d_array = two_d_array
      @col_sum_array = []
      @row_sum_array = []
      @big_S = 0
   end

   def calculations
      @col_sum_array = []
      @row_sum_array = []
      @big_S = 0
      col_krem = Array.new
      row_krem = Array.new
      two_d_array.each_with_index do |row, index|
         col_sub = 0
         row_sub = 0
         two_d_array[index].each_with_index do |col,i|
            col_sub += two_d_array[i][index]
            row_sub += two_d_array[index][i]
         end
         @col_sum_array &lt; &lt; col_sub
         @row_sum_array &lt;&lt; row_sub
         @big_S = @big_S + col_sub + row_sub
         p two_d_array[index]
      end
   end

   def flip_row(row_num)
     @two_d_array[row_num].each_with_index  do |v, index|
        @two_d_array[row_num][index] = v * -1
     end
     self.calculations
   end

   def flip_col(col_num)
     for i in (0...@two_d_array.length)
         @two_d_array[i][col_num] = @two_d_array[i][col_num] * -1
     end
     self.calculations
   end

end

two_d_array = Grid.new([ [3,1,-5,-3,4],[4,-5,-2,-3,-3],[6,-8,-2,-6,1],[3,4,1,-4,-8],[1,4,-2,7,-1] ])

puts "Initial Array"
puts "-------------"
two_d_array.calculations
puts "-------------"
puts "Initial Big S: #{two_d_array.big_S}"

puts "------------"
puts "------------"
puts "Flipping Row Zero"
puts "------------"
two_d_array.flip_row(0)

puts "------------"
puts "------------"
puts "Flipping Column One"
puts "------------"
two_d_array.flip_col(1)

puts "------------"
puts "------------"
puts "Column Sum Array"
p two_d_array.col_sum_array
puts "------------"
puts "Row Sum Array"
p two_d_array.row_sum_array
puts "------------"
puts "Big S: #{two_d_array.big_S}"</pre>
]]></content:encoded>
			<wfw:commentRss>http://myinitialsare.tk/2007/07/last-facebook-ruby-code-grids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

