<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>defectivejunk (Entries tagged as programming)</title>
    <link>http://www.defectivejunk.com/</link>
    <description>iono</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.3 - http://www.s9y.org/</generator>
    <pubDate>Tue, 31 Mar 2009 01:29:12 GMT</pubDate>

    <image>
        <url>http://www.defectivejunk.com/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: defectivejunk - iono</title>
        <link>http://www.defectivejunk.com/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Checking python images to see if they're grayscale</title>
    <link>http://www.defectivejunk.com/archives/164-Checking-python-images-to-see-if-theyre-grayscale.html</link>
            <category>blog</category>
    
    <comments>http://www.defectivejunk.com/archives/164-Checking-python-images-to-see-if-theyre-grayscale.html#comments</comments>
    <wfw:comment>http://www.defectivejunk.com/wfwcomment.php?cid=164</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.defectivejunk.com/rss.php?version=2.0&amp;type=comments&amp;cid=164</wfw:commentRss>
    

    <author>nospam@example.com (NN)</author>
    <content:encoded>
    Long story short, I need to check an entire folder of images to see if they&#039;re grayscale. Here&#039;s a python script I just wrote that will do that, and output the results to a timestamped log file. I added some comments to explain how it works.&lt;br /&gt;
&lt;br /&gt;
graycheck.py&lt;br /&gt;
&lt;blockquote&gt;&lt;pre&gt;from PIL import Image&lt;br /&gt;
import ImageChops&lt;br /&gt;
import os&lt;br /&gt;
import string&lt;br /&gt;
from time import strftime&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    subdir = &#039;C:\\pathtoimages\\&#039;&lt;br /&gt;
    diffdir = subdir + &#039;diff&#039; # output directory if you want to save the results&lt;br /&gt;
    badFiles = []&lt;br /&gt;
    &lt;br /&gt;
    for subdir, dirs, files in os.walk(subdir):&lt;br /&gt;
        if subdir != diffdir: #only check the main dir&lt;br /&gt;
            for file in files:&lt;br /&gt;
                if string.upper(file[-3:])==&quot;JPG&quot;: # jpegs only&lt;br /&gt;
                        im = Image.open(file)&lt;br /&gt;
                        imGray = im.convert(&quot;L&quot;) # convert the original jpeg to grayscale and keep a copy&lt;br /&gt;
&lt;br /&gt;
                        # need to convert back to RGB, but only if the original file wasn&#039;t already in mode L&lt;br /&gt;
                        if im.mode == &quot;RGB&quot;: &lt;br /&gt;
                            imGray = imGray.convert(&quot;RGB&quot;)&lt;br /&gt;
&lt;br /&gt;
                        # get the difference of the original image and the converted grayscale&lt;br /&gt;
                        # if the original was grayscale, there&#039;s no difference, so output will be entirely black&lt;br /&gt;
                        output = ImageChops.difference(imGray, im)&lt;br /&gt;
&lt;br /&gt;
                        i = 0&lt;br /&gt;
                        &lt;br /&gt;
                        for color in list(output.getdata()):&lt;br /&gt;
                            if color != (0,0,0): # check RGB black and single black value&lt;br /&gt;
                                if color != 0:&lt;br /&gt;
                                    # Image is not grayscale, for we found a difference&lt;br /&gt;
                                    i=i+1&lt;br /&gt;
                                    print i, color&lt;br /&gt;
                                    break                &lt;br /&gt;
   &lt;br /&gt;
                        outputFile = diffdir + &quot;\\&quot; + file[:-4] + &quot;_Diff.jpg&quot; # output dir plus filename only plus an extension&lt;br /&gt;
&lt;br /&gt;
                        if i==0: # image is all black, could not be blacker&lt;br /&gt;
                            badFiles.append(file)&lt;br /&gt;
                            # output.save(outputFile) # uncomment to save the results as an image - though it should be a solid black file&lt;br /&gt;
&lt;br /&gt;
    # print badFiles # uncomment to see the results&lt;br /&gt;
&lt;br /&gt;
    logfilename = strftime(&quot;%Y-%m-%d_%H-%M-%S&quot;) + &quot;.txt&quot;&lt;br /&gt;
    logfile = open(logfilename, &quot;w&quot;)&lt;br /&gt;
    &lt;br /&gt;
    for badFile in badFiles:&lt;br /&gt;
        logfile.write(badFile + &#039;\n&#039;)&lt;br /&gt;
&lt;br /&gt;
    logfile.close()&lt;br /&gt;
                        &lt;br /&gt;
if &lt;u&gt;_name_&lt;/u&gt; == &#039;&lt;u&gt;_main_&lt;/u&gt;&#039;: &lt;br /&gt;
     main() &lt;br /&gt;
&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;br /&gt;
If you desire me to release this under a license, consider it released under the &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/www.opensource.org/licenses/ms-pl.html&#039;);&quot; href=&quot;http://www.opensource.org/licenses/ms-pl.html&quot;&gt;MS Public License&lt;/a&gt;.  
    </content:encoded>

    <pubDate>Mon, 30 Mar 2009 21:29:12 -0400</pubDate>
    <guid isPermaLink="false">http://www.defectivejunk.com/archives/164-guid.html</guid>
    <category>programming</category>
<category>python</category>

</item>
<item>
    <title>Python 1</title>
    <link>http://www.defectivejunk.com/archives/111-Python-1.html</link>
            <category>blog</category>
    
    <comments>http://www.defectivejunk.com/archives/111-Python-1.html#comments</comments>
    <wfw:comment>http://www.defectivejunk.com/wfwcomment.php?cid=111</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.defectivejunk.com/rss.php?version=2.0&amp;type=comments&amp;cid=111</wfw:commentRss>
    

    <author>nospam@example.com (NN)</author>
    <content:encoded>
    Despite my misgivings, I&#039;m going to attempt to learn Python. I bought &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/www.amazon.com/gp/product/0596513984&#039;);&quot; href=&quot;http://www.amazon.com/gp/product/0596513984&quot;&gt;Learning Python&lt;/a&gt;. I&#039;m already tired of the pointless Monty Python refs.  
    </content:encoded>

    <pubDate>Sun, 20 Jul 2008 21:34:30 -0400</pubDate>
    <guid isPermaLink="false">http://www.defectivejunk.com/archives/111-guid.html</guid>
    <category>programming</category>

</item>
<item>
    <title>i kill you scum</title>
    <link>http://www.defectivejunk.com/archives/108-i-kill-you-scum.html</link>
            <category>blog</category>
    
    <comments>http://www.defectivejunk.com/archives/108-i-kill-you-scum.html#comments</comments>
    <wfw:comment>http://www.defectivejunk.com/wfwcomment.php?cid=108</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.defectivejunk.com/rss.php?version=2.0&amp;type=comments&amp;cid=108</wfw:commentRss>
    

    <author>nospam@example.com (NN)</author>
    <content:encoded>
    It&#039;s going to be a great day when it&#039;s 8:05 and I already want to kill someone.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;The following query will emulate a&lt;br /&gt;
&lt;br /&gt;
SELECT emp_id,lname,fname FROM employee LIMIT 20,10&lt;br /&gt;
&lt;br /&gt;
That says, give me 10 records starting at record 21. So what will be returned are rows 21-30. This is used heavily in web-based apps so you can do recordset paging. &lt;/blockquote&gt;&lt;br /&gt;
&lt;br /&gt;
No no no no no no no NO NO NO NO &lt;big&gt;&lt;big&gt;&lt;b&gt;NO NO NO NO NO NO!!!&lt;/b&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;
&lt;br /&gt;
This is NOT HOW RELATIONAL DATABASES WORK. There is NO guarantee AT ALL that you will get the rows back that you&#039;re expecting. Unless stupid ass MySQL actually does this, in which case it&#039;s even a worse, shittier database system than I realized. (and honestly, any db that doesn&#039;t support stored procs is already pretty low in my book.)  
    </content:encoded>

    <pubDate>Wed, 09 Jul 2008 08:07:10 -0400</pubDate>
    <guid isPermaLink="false">http://www.defectivejunk.com/archives/108-guid.html</guid>
    <category>programming</category>

</item>
<item>
    <title>noooo</title>
    <link>http://www.defectivejunk.com/archives/92-noooo.html</link>
            <category>blog</category>
    
    <comments>http://www.defectivejunk.com/archives/92-noooo.html#comments</comments>
    <wfw:comment>http://www.defectivejunk.com/wfwcomment.php?cid=92</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.defectivejunk.com/rss.php?version=2.0&amp;type=comments&amp;cid=92</wfw:commentRss>
    

    <author>nospam@example.com (NN)</author>
    <content:encoded>
    OK, I just came up with something evil. But, I like it because it saves doing that extra assignment every time &lt;img src=&quot;http://www.defectivejunk.com/templates/default/img/emoticons/laugh.png&quot; alt=&quot;:-D&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;br /&gt;
&lt;tt&gt;&lt;br /&gt;
StringBuilder qs = new StringBuilder();&lt;br /&gt;
bool firstKey = true;&lt;br /&gt;
foreach (KeyValuePair&lt;string, string&gt; kvp in param)&lt;br /&gt;
{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;qs.AppendFormat(&quot;{0}{1}={2}&quot;, (firstKey &amp;amp; !(firstKey = false) ) ? String.Empty : &quot;&amp;&quot;, kvp.Key, kvp.Value);&lt;br /&gt;
}&lt;br /&gt;
&lt;/tt&gt;&lt;br /&gt;
&lt;/blockquote&gt;  
    </content:encoded>

    <pubDate>Tue, 29 Apr 2008 16:40:45 -0400</pubDate>
    <guid isPermaLink="false">http://www.defectivejunk.com/archives/92-guid.html</guid>
    <category>coding horrors</category>
<category>programming</category>

</item>
<item>
    <title>nullable</title>
    <link>http://www.defectivejunk.com/archives/81-nullable.html</link>
            <category>fleeting thoughts</category>
    
    <comments>http://www.defectivejunk.com/archives/81-nullable.html#comments</comments>
    <wfw:comment>http://www.defectivejunk.com/wfwcomment.php?cid=81</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.defectivejunk.com/rss.php?version=2.0&amp;type=comments&amp;cid=81</wfw:commentRss>
    

    <author>nospam@example.com (NN)</author>
    <content:encoded>
    Why no &quot;??=&quot; operator in C#? Anyway, it&#039;s not like I can Google it. Maybe there is one, or some reason there isn&#039;t.  
    </content:encoded>

    <pubDate>Fri, 11 Apr 2008 13:47:42 -0400</pubDate>
    <guid isPermaLink="false">http://www.defectivejunk.com/archives/81-guid.html</guid>
    <category>fleeting thoughts</category>
<category>programming</category>

</item>
<item>
    <title>More insane code</title>
    <link>http://www.defectivejunk.com/archives/76-More-insane-code.html</link>
            <category>blog</category>
    
    <comments>http://www.defectivejunk.com/archives/76-More-insane-code.html#comments</comments>
    <wfw:comment>http://www.defectivejunk.com/wfwcomment.php?cid=76</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.defectivejunk.com/rss.php?version=2.0&amp;type=comments&amp;cid=76</wfw:commentRss>
    

    <author>nospam@example.com (NN)</author>
    <content:encoded>
    {&lt;br /&gt;
     if (Checked)&lt;br /&gt;
          Checked = false;&lt;br /&gt;
}  
    </content:encoded>

    <pubDate>Thu, 03 Apr 2008 09:42:56 -0400</pubDate>
    <guid isPermaLink="false">http://www.defectivejunk.com/archives/76-guid.html</guid>
    <category>coding horrors</category>
<category>programming</category>

</item>
<item>
    <title>C#</title>
    <link>http://www.defectivejunk.com/archives/74-C.html</link>
            <category>blog</category>
    
    <comments>http://www.defectivejunk.com/archives/74-C.html#comments</comments>
    <wfw:comment>http://www.defectivejunk.com/wfwcomment.php?cid=74</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.defectivejunk.com/rss.php?version=2.0&amp;type=comments&amp;cid=74</wfw:commentRss>
    

    <author>nospam@example.com (NN)</author>
    <content:encoded>
    One thing I just absolutely do not understand is using properties vs public members. If all you&#039;re doing is { get; set; }, then how is that different from just using a public variable? Because it makes you feel better, like you&#039;re not exposing a public variable? Maybe there&#039;s some difference I just don&#039;t recognize or know about. But, whatever.  
    </content:encoded>

    <pubDate>Tue, 01 Apr 2008 08:56:23 -0400</pubDate>
    <guid isPermaLink="false">http://www.defectivejunk.com/archives/74-guid.html</guid>
    <category>programming</category>

</item>
<item>
    <title>hourly wtf</title>
    <link>http://www.defectivejunk.com/archives/71-hourly-wtf.html</link>
            <category>blog</category>
    
    <comments>http://www.defectivejunk.com/archives/71-hourly-wtf.html#comments</comments>
    <wfw:comment>http://www.defectivejunk.com/wfwcomment.php?cid=71</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.defectivejunk.com/rss.php?version=2.0&amp;type=comments&amp;cid=71</wfw:commentRss>
    

    <author>nospam@example.com (NN)</author>
    <content:encoded>
    Drives me crazy when people create objects just to use them once, and don&#039;t even change the value of it that time. Especially when the thing goes out of scope immediately afterwards.&lt;br /&gt;
&lt;br /&gt;
For example.&lt;br /&gt;
&lt;br /&gt;
&lt;tt&gt;&lt;br /&gt;
{&lt;br /&gt;
     string message = &quot;Error: user is dumb&quot;;&lt;br /&gt;
     Textbox1.Text = message;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
return;&lt;br /&gt;
&lt;/tt&gt;&lt;br /&gt;
&lt;br /&gt;
WHY DO THIS. WHY. IS IT TO HASTEN MY INEVITABLE ANEURYSM. IS IT. BECAUSE THAT&#039;S WHAT IT SEEMS LIKE. JUST SHOOT ME IN THE FACE INSTEAD. PLEASE. AT LEAST THAT&#039;S MORE HONEST.  
    </content:encoded>

    <pubDate>Mon, 24 Mar 2008 13:44:12 -0400</pubDate>
    <guid isPermaLink="false">http://www.defectivejunk.com/archives/71-guid.html</guid>
    <category>coding horrors</category>
<category>programming</category>

</item>

</channel>
</rss>