<?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>blacknode &#187; Programming</title>
	<atom:link href="http://blog.blacknode.net/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.blacknode.net</link>
	<description>NO CARRIER</description>
	<lastBuildDate>Mon, 13 Jun 2011 07:12:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>6d6 Roll, roll, roll, roll&#8230;&#8230;</title>
		<link>http://blog.blacknode.net/2011/05/d20/</link>
		<comments>http://blog.blacknode.net/2011/05/d20/#comments</comments>
		<pubDate>Tue, 17 May 2011 22:45:03 +0000</pubDate>
		<dc:creator>jrod</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.blacknode.net/?p=799</guid>
		<description><![CDATA[I found this program while looking through some old backups labeled red_floppy. I thought it was pretty funny how shitty of a coder I was at 13. I am also kind of amazed at how much of a dork I was for writing a program to help AD&#38;D Character Generation. #define D 6 int roll(); ]]></description>
			<content:encoded><![CDATA[<p>I found this program while looking through some old backups labeled red_floppy. I thought it was pretty funny how shitty of a coder I was at 13. I am also kind of amazed at how much of a dork I was for writing a program to help AD&amp;D Character Generation.</p>
<pre><code>
#define D 6

int roll();
int * sort_roll(int u[]);
int score(int s[]);
void seed();

int roll()
{
    int z, x, rs[4], *rr, r;
    int j = 6;
    while(--j){
    for(x = 0; x &lt; 4; x++)
    {
          rs[x] = ((int) D * rand() / (RAND_MAX + 1.0)) + 1;
          for (z = 0; z &lt; 100; z++) rand();
    }
    rr = sort_roll(rs);
    r = score(rr);
    }
    return r;
}

int * sort_roll(int u[])
{
    int x,y,temp;

    for(x = 0;x &lt; 4; x++)
    {
      for(y = 0;y &lt; 4; y++)
      {
       if(u[x] &lt; u[y])
       {
         temp = u[x];
         u[x] = u[y];
         u[y] = temp;
       }
      }
    }
    return u;
} 

int score(int s[])
{
    return s[1] + s[2] + s[3];
}

void seed()
{
     srand((unsigned int)time((time_t *)NULL));
}

int main()
{
  int x, j;
  seed();
  do{
  for(x = 0; x &lt; 6; x++) printf("%d\n", roll());
  printf("\n\n");
  } while((j = toupper(getch()) == 'X'));
  system("pause");
  return 0;
}

</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.blacknode.net/2011/05/d20/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I don&#8217;t always test my code.</title>
		<link>http://blog.blacknode.net/2011/04/i-dont-always-test-my-code/</link>
		<comments>http://blog.blacknode.net/2011/04/i-dont-always-test-my-code/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 18:17:34 +0000</pubDate>
		<dc:creator>jrod</dc:creator>
				<category><![CDATA[LOL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[motherfucker.]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.blacknode.net/?p=795</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.blacknode.net/wp-content/uploads/2011/02/test_code.jpg"><img class="aligncenter size-full wp-image-796" title="test_code" src="http://blog.blacknode.net/wp-content/uploads/2011/02/test_code.jpg" alt="" width="287" height="360" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.blacknode.net/2011/04/i-dont-always-test-my-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>1337</title>
		<link>http://blog.blacknode.net/2010/11/1337/</link>
		<comments>http://blog.blacknode.net/2010/11/1337/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 07:31:53 +0000</pubDate>
		<dc:creator>jrod</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Turbogears]]></category>

		<guid isPermaLink="false">http://blog.blacknode.net/?p=751</guid>
		<description><![CDATA[﻿﻿﻿Calculating how many lines my project is at currently (not including tester code or templates): (kserve)@haven:~/kserve/fresh/kserver$ find lib/ controllers/ model/ -type f -name &#8220;*.py&#8221;  &#124; grep -v template.py &#124; grep -v auth.py &#124; grep -v error.py &#124; grep -v __init__ &#124;grep -v app_globals.py&#124; grep -v base.py &#124;xargs cat  &#124; wc -l 1337 l33t.. no bs. ]]></description>
			<content:encoded><![CDATA[<p>﻿﻿﻿Calculating how many lines my project is at currently (not including  tester code or templates):</p>
<p>(kserve)@haven:~<em>/kserve/fresh/kserver$ find lib/</em> controllers/ model/ -type f -name &#8220;*.py&#8221;  | grep -v template.py | grep  -v auth.py | grep -v error.py | grep -v __init__ |grep -v  app_globals.py| grep -v base.py |xargs cat  | wc -l<br />
1337</p>
<p>l33t.. no bs.</p>
<p>Unfortunately, it is not done. I am going to to have to code 30,000 more  lines now.. damnit!</p>
<p>Jrod.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.blacknode.net/2010/11/1337/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Woe to the client&#8230;</title>
		<link>http://blog.blacknode.net/2010/11/woe-to-the-client/</link>
		<comments>http://blog.blacknode.net/2010/11/woe-to-the-client/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 23:02:57 +0000</pubDate>
		<dc:creator>jrod</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.blacknode.net/?p=735</guid>
		<description><![CDATA[that triggers this exception! Woe to them indeed!]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.blacknode.net/wp-content/uploads/2010/11/Consequences.png"><img class="alignleft size-full wp-image-739" title="Consequences" src="http://blog.blacknode.net/wp-content/uploads/2010/11/Consequences.png" alt="" width="562" height="148" /></a></p>
<p>that triggers this exception! Woe to them indeed!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.blacknode.net/2010/11/woe-to-the-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQLAlchemy declarative_base: setting the storage engine and other table options</title>
		<link>http://blog.blacknode.net/2010/11/sqlalchemy-declarative_base-setting-the-storage-engine-and-other-table-options/</link>
		<comments>http://blog.blacknode.net/2010/11/sqlalchemy-declarative_base-setting-the-storage-engine-and-other-table-options/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 23:25:05 +0000</pubDate>
		<dc:creator>jrod</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQLAlchemy]]></category>
		<category><![CDATA[Turbogears]]></category>

		<guid isPermaLink="false">http://blog.blacknode.net/?p=728</guid>
		<description><![CDATA[Using mysql for your Engine. DeclarativeBase = declarative_base() class TableClass(DeclarativeBase): __tablename__ = 'table_name' __table_args__ = {'mysql_engine':'InnoDB', 'mysql_charset':'utf8'} col_id = Column(Integer, primary_key=True) ]]></description>
			<content:encoded><![CDATA[<p>Using mysql for your Engine.</p>
<pre>DeclarativeBase = declarative_base()
class TableClass(DeclarativeBase):
    __tablename__ = 'table_name'
    __table_args__ =  {'mysql_engine':'InnoDB', 'mysql_charset':'utf8'}
    col_id = Column(Integer, primary_key=True)
    ...</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.blacknode.net/2010/11/sqlalchemy-declarative_base-setting-the-storage-engine-and-other-table-options/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exposing sqlalchemy engine in turbogears 2.1</title>
		<link>http://blog.blacknode.net/2010/11/exposing-sqlalchemy-engine-in-turbogears-2-1/</link>
		<comments>http://blog.blacknode.net/2010/11/exposing-sqlalchemy-engine-in-turbogears-2-1/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 20:25:20 +0000</pubDate>
		<dc:creator>jrod</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQLAlchemy]]></category>
		<category><![CDATA[Turbogears]]></category>

		<guid isPermaLink="false">http://blog.blacknode.net/?p=694</guid>
		<description><![CDATA[Getting access to the internals of the sqlalchemy stack in turbogears can be difficult if you do not know where to look. The use of declarative_base() to create model classes further obfuscates the location of the table and metadata objects. In order to create/drop a table using an SQLAlchemy object, you need access to the table ]]></description>
			<content:encoded><![CDATA[<p>Getting access to the internals of the sqlalchemy stack in turbogears can be difficult if you do not know where to look. The use of declarative_base() to create model classes further obfuscates the location of the table and metadata objects.</p>
<p>In order to create/drop a table using an SQLAlchemy object, you need access to the table object, the table metadata, and a database engine object. When extending DeclarativeBase, the table object is exposed by the __table__ attribute of every model class. For instance:</p>
<blockquote><p>class Distro(DeclarativeBase):<br />
__tablename__ = &#8216;distro&#8217;<br />
id = Column(Integer, primary_key=True, unique=True)<br />
label = Column(Unicode(35), nullable=False)</p>
<p>In [1]: from yourapp.model import *</p>
<p>In [2]: import transaction</p>
<p>In [3]: distro_obj = Distro()</p>
<p>In [4]: print distro_obj.__table__.__doc__<br />
&#8212;&#8212;&gt; print(distro_obj.__table__.__doc__)<br />
Represent a table in a database.</p>
<p>e.g.::</p>
<p>mytable = Table(&#8220;mytable&#8221;, metadata,<br />
Column(&#8216;mytable_id&#8217;, Integer, primary_key=True),<br />
Column(&#8216;value&#8217;, String(50))<br />
)</p></blockquote>
<p>As you can see, you may access the methods of Table() from the DeclarativeBase __table__ attribute. In order to use the model to create/drop the table it describes, you need to bind the table metadata to an instantiated SQLAlchemy engine object. Pylons, the framework which Turbogears 2+ is based, stores the engine (defined in the paster .ini configuration) in the config global configuration dictionary, specifically:</p>
<pre>config['pylons.app_globals'].sa_engine</pre>
<p>Going back to the model we created, we can create the table using the Table() method create.</p>
<pre>distro_obj.__table__.create(config['pylons.app_globals'].sa_engine)</pre>
<p>Now that the table is created you may use the session object to interact with the table.</p>
<pre>In [5]: distro_obj.label = 'rhel5_minimal'
In [6]: DBSession.add(distro_obj)
In [7]: transaction.commit()
In [8]: distro_label = DBSession.query(Distro.label).filter(Distro.label=='rhel5_minimal').one()[0]
In [9]: print distro_label
-------&gt; print(distro_label)
rhel5_minimal</pre>
<p>For more information, take a look at the documentation for <a href="http://www.turbogears.org/2.1/docs/">TG2.1</a> and <a href="http://www.sqlalchemy.org/docs/orm/extensions/declarative.html">SQLAlchemy declarative syntax</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.blacknode.net/2010/11/exposing-sqlalchemy-engine-in-turbogears-2-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A good day</title>
		<link>http://blog.blacknode.net/2010/11/a-good-day/</link>
		<comments>http://blog.blacknode.net/2010/11/a-good-day/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 18:30:51 +0000</pubDate>
		<dc:creator>jrod</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://blog.blacknode.net/2010/11/a-good-day/</guid>
		<description><![CDATA[@ the office]]></description>
			<content:encoded><![CDATA[<p><img style="display:block;margin-right:auto;margin-left:auto;" alt="image" src="http://blog.blacknode.net/wp-content/uploads/2010/11/wpid-IMG_20101101_133028.jpg" /></p>
<p>@ the office</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.blacknode.net/2010/11/a-good-day/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>sqlalchemy, MySQLdb, debian</title>
		<link>http://blog.blacknode.net/2010/10/sqlalchemy-mysqldb-debian/</link>
		<comments>http://blog.blacknode.net/2010/10/sqlalchemy-mysqldb-debian/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 23:09:18 +0000</pubDate>
		<dc:creator>jrod</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sqlalchemy]]></category>

		<guid isPermaLink="false">http://blog.blacknode.net/?p=553</guid>
		<description><![CDATA[(in virtualevn) $ sudo apt-get install libmysqlclient-dev python-dev $ easy_install SQLAlchemy mysql-python Not sure why the package is labeled mysql-python. Also, you need the development headers because the MySQLdb module is written in c]]></description>
			<content:encoded><![CDATA[<p>(in virtualevn)</p>
<blockquote><p>$ sudo apt-get install libmysqlclient-dev python-dev<br />
$ easy_install SQLAlchemy mysql-python</p></blockquote>
<p>Not sure why the package is labeled mysql-python. Also, you need the development headers because the MySQLdb module is written in c.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.blacknode.net/2010/10/sqlalchemy-mysqldb-debian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rackspace Cloud API</title>
		<link>http://blog.blacknode.net/2009/07/rackspace-cloud-api/</link>
		<comments>http://blog.blacknode.net/2009/07/rackspace-cloud-api/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 17:01:28 +0000</pubDate>
		<dc:creator>jrod</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[System Administration]]></category>

		<guid isPermaLink="false">http://blog.blacknode.net/?p=209</guid>
		<description><![CDATA[In an article here, Rackspace is announcing the availability of their beta web services api that can be used to jack into their cloud. Much like EC2, this should lead the way for projects like scaler, that dynamically grow a configuration as thresholds are reached. Check out http://www.rackspacecloud.com/ for more info. I am going to ]]></description>
			<content:encoded><![CDATA[<p>In an article <a href=http://www.rackspace.com/information/mediacenter/release.php?id=8417>here,</a> Rackspace is announcing the availability of their beta web services api that can be used to jack into their cloud.  Much like EC2, this should lead the way for projects like scaler, that dynamically grow a configuration as thresholds are reached. </p>
<p>Check out <a href="http://www.rackspacecloud.com/">http://www.rackspacecloud.com/</a> for more info. I am going to sign up, I will let you know how it goes. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.blacknode.net/2009/07/rackspace-cloud-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stop the plesk adminstrator from recieving dr.web license failures</title>
		<link>http://blog.blacknode.net/2009/03/stop-the-plesk-adminstrator-from-recieving-drweb-license-failures/</link>
		<comments>http://blog.blacknode.net/2009/03/stop-the-plesk-adminstrator-from-recieving-drweb-license-failures/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 02:33:31 +0000</pubDate>
		<dc:creator>jrod</dc:creator>
				<category><![CDATA[pets]]></category>
		<category><![CDATA[Plesk]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[System Administration]]></category>

		<guid isPermaLink="false">http://blog.blacknode.net/?p=148</guid>
		<description><![CDATA[&#8230; And other things that might annoy him/her There was a request that went around for months from a plesk administrator griping about the various messages that appear in his mailbox, such as the dr.web license notification. By default, messages to the root and postmaster accounts are sent to the plesk administrator. This is accomplished ]]></description>
			<content:encoded><![CDATA[<p>&#8230; And other things that might annoy him/her</p>
<p>There was a request that went around for months from a plesk administrator griping about the various messages that appear in his mailbox, such as the dr.web license notification.  By default, messages to the root and postmaster accounts are sent to the plesk administrator. This is accomplished via qmail aliases.</p>
<p># cd /var/qmail/alias/<br />
# ls -al<br />
total 28<br />
drwxr-sr-x   2 alias qmail 4096 Mar  9 01:59 .<br />
drwxr-xr-x  11 root  qmail 4096 Sep 29 21:14 ..<br />
-rw-r&#8211;r&#8211;   1 root  qmail   26 Dec 10  2007 .qmail-mailer-daemon<br />
-rw-r&#8211;r&#8211;   1 root  qmail   16 Mar  9 01:57 .qmail-postmaster<br />
-rw-r&#8211;r&#8211;   1 root  qmail   16 Mar  9 01:57 .qmail-root</p>
<p>Typically these look something link this:<br />
# cat .qmail-postmaster<br />
&#038;plesk_admin_address@foo.bar.com</p>
<p>To keep the customer happy, I made a slight amendment to the alias:</p>
<p># cat .qmail-postmaster<br />
|cat >/dev/null<br />
# cat .qmail-root<br />
|cat >/dev/null</p>
<p>Removing the aliases will cause all kinds of noise in the logs and actually break the server&#8217;s already fragile rfc compliance (rfc2821:4.5.1) . This allows the messages to be &#8216;handled&#8217; silently. Since most plesk &#8216;administrators&#8217; don&#8217;t  care to know how many failed ssh attempts there were in a month, or how much disk space they are using, it is usually a working solution when you can&#8217;t get dr.web to stfu.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.blacknode.net/2009/03/stop-the-plesk-adminstrator-from-recieving-drweb-license-failures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

