Fahhem's Blog - Uncategorizedhttps://blog.fahhem.com/2011-09-14T05:44:00-07:00An intermittent post of thoughtsAn intermittent post of thoughtsHidden Talents in Movies and TV2011-09-14T05:44:00-07:002011-09-14T05:44:00-07:00fahhemtag:blog.fahhem.com,2011-09-14:/2011/09/hidden-talents-in-movies-and-tv/<p>Whenever the camera enters a character's house, that character always
does something 'to relax' or just in their free time, but they've done
it for several years and they're really, really good at it.</p>
<p>You never see a character say "Yeah, I paint" and then see horrible,
ugly, two year-old …<a class="read-more" href="/2011/09/hidden-talents-in-movies-and-tv/"><span>continue</span></a></p><p>Whenever the camera enters a character's house, that character always
does something 'to relax' or just in their free time, but they've done
it for several years and they're really, really good at it.</p>
<p>You never see a character say "Yeah, I paint" and then see horrible,
ugly, two year-old style paintings strewn over the floor. There's never
a bunch of misshapen wooden dolls on their desk, or a dead bird stuck in
a birdhouse gone awry.</p>
<p>There's also never any residue; he or she's never missing a finger from
woodworking accidents, have paint on their hands, or a hurt knee from
tripping on everything strewn on their floor.</p>
<p>I'd like to see a movie where some girl's apartment has a bunch of ugly,
monotonous pictures of walls, and she's incredibly proud of her
'statement' but in reality they're just pictures of walls and the main
character has to break it to her. If the main character is a guy and
thinks he's in love with her before he seeing the product of her idle
hands, it would be even more realistic, but I'd settle for reuniting
with a close friend after several years and suddenly she's got these
pictures everywhere.</p>
<p>If instead the character with the horrible pastime is male, the hobby
has to be more attached to his ego; for example, a misshapen wood piece
sitting uneven on a severely dinged desk with blueprints to a majestic
birdhouse, but he's made so much progress he doesn't see how far away he
is and instead he's become very proud of his work and is showing it off
to a buddy or a would-be girlfriend. Instead, they're taken aback and
can't say anything but smile and nod and ask for the bathroom, where
they go stare at themselves in the mirror and thought-narrate their next
move. "If I tell him, he'll be really hurt/angry at me and won't talk to
me for at least 2 days and I have that thing tomorrow I need his help
for. But if I don't tell him, he'll keep showing it to people..."</p>
<p>These are more realistic than "Oh, you paint? These are really good!"
and "Oh wow, and it has hinges and everything! Where did you learn to do
that? You taught yourself?" As if everyone goes around teaching
themselves how to whittle.</p>Surlex is Awesome2010-09-23T16:27:00-07:002010-09-23T16:27:00-07:00fahhemtag:blog.fahhem.com,2010-09-23:/2010/09/surlex-is-awesome/<p>I'm not sure why I haven't seen anybody using this since Surlex <a href="http://codysoyland.com/2009/sep/6/introduction-surlex/">came
out in 2009</a>.
Surlex is especially powerful when using it to match Django URLs.</p>
<p>I've written several Django apps recently that had relatively complex
URLs and Surlex has really saved the day for me. There are two …<a class="read-more" href="/2010/09/surlex-is-awesome/"><span>continue</span></a></p><p>I'm not sure why I haven't seen anybody using this since Surlex <a href="http://codysoyland.com/2009/sep/6/introduction-surlex/">came
out in 2009</a>.
Surlex is especially powerful when using it to match Django URLs.</p>
<p>I've written several Django apps recently that had relatively complex
URLs and Surlex has really saved the day for me. There are two main
features that I'd like to point out:</p>
<ol>
<li>from surlex.dj import surl</li>
<li>register_macro('macro','regex')</li>
</ol>
<h3>from surlex.dj import surl</h3>
<p>This function allows one to use surlex syntax in the urlpatterns and
simply put surl() around it instead of url() like so:</p>
<blockquote>
<p>surl(r'\^\<project:s>/photos/\<photo:#>\$',
'show_photo',name='show_photo'),</p>
</blockquote>
<p>This is a real URL pattern that I've put here. The 'normal' way to do
this would have been:</p>
<blockquote>
<p>url(r'\^(?P\<project>[\w-]+)/photos/(?P\<photo>\d+)\$',
'show_photo',name='show_photo'),</p>
</blockquote>
<p>That may make perfect sense to anyone who understands named groups in
regex, but I would rather not have to type such a complicated syntax for
such a common task in Django.</p>
<h3>register_macro('macro','regex')</h3>
<p>This one is really useful for all sorts of macros. I recently wrote a
yardbird-based IRC bot for <a href="http://recreclabs.com/">work</a> and needed a
bunch of macros for the irc message resolving portion:</p>
<blockquote>
<p>name = settings.YARDBIRD_NAME<br>
register_macro('ch','#[\w-]+')<br>
register_macro('nm','[\w_-]+')<br>
register_macro('botmsg','(?:chanmsg/%s[:,. ] ?|privmsg/)' % name)<br>
register_macro('msg','(?:chanmsg|privmsg)')</p>
</blockquote>
<p>To be honest, I've severely modified Yardbird and will eventually send
the patches back, so this stuff doesn't make as much sense without my
patches that increase the flexibility of Yardbird.</p>
<p>The 'ch' macro is for matching IRC channels, 'nm' is for nicknames,
'botmsg' is for messages directed to the bot, and 'msg' is for messages
in the channel or to the bot versus other types of messages, e.g. nick
changes come in as 'nick/' so we don't want to act on those as possible
commands.</p>
<p>The patterns for these macros are really simply and much easier to read
as well:</p>
<blockquote>
<p>surl(r'\^\<:botmsg>tell \<nick:nm> \<message=.*>\$', 'tell'),</p>
</blockquote>
<p>That command is for telling the bot to later tell a user a message when
they log in again. It checks if the command was to the bot through
'botmsg', sees the command as 'tell' and the command has two parameters,
'user' and 'message' the latter of which matches the rest of the
statement. All of this is accessible from a very quick glance at the
pattern instead of attempting to read this:</p>
<blockquote>
<p>'\^(?:chanmsg/bot_name[:,. ] ?|privmsg/)tell (?P\<nick>[\\w_-]+)
(?P\<message>.*)\$'</p>
</blockquote>
<p>The length of that regex is 77 characters, more than twice the 38
characters of the surlex pattern.</p>
<p>As I said before, Surlex is Awesome.</p>Browser-Based Javascript Libraries2010-08-29T16:34:00-07:002010-08-29T16:34:00-07:00fahhemtag:blog.fahhem.com,2010-08-29:/2010/08/browser-based-javascript-libraries/<p>Today I want to talk about another idea I had regarding increasing both
browser and server efficiency regarding javascript libraries.</p>
<p>There are a few major players in this realm including jQuery, mootools,
prototype, and a few others. These libraries spend a considerable amount
of processing time just checking the browser …<a class="read-more" href="/2010/08/browser-based-javascript-libraries/"><span>continue</span></a></p><p>Today I want to talk about another idea I had regarding increasing both
browser and server efficiency regarding javascript libraries.</p>
<p>There are a few major players in this realm including jQuery, mootools,
prototype, and a few others. These libraries spend a considerable amount
of processing time just checking the browser type and a percentage of
their size is useless to each browser. Also, many web developers
consider their sheer size as a large minus when choosing libraries.</p>
<p>As a way to offset both the inefficiency of browser-based javascript as
well as decrease bandwidth wasted on downloading multiple copies of each
library, a browser extension can be created for all major browsers with
functionality to basically locally host the latest version(s) of the
major libraries. Then, upon a website's request for the browser to
download a library, it can figure out the version based on the filename
(jquery.1.2.6.js) and push the local version instead. The local version
would be pre-compiled and browser-specific to allow the greatest speed,
and by not downloading the version from the server the page would load
faster as well.</p>
<p>The necessary steps are detailed below:</p>
<ul>
<li>Web developers would need to use the version of the library in the
filename, such as jquery.1.4.4.js or prototype.1.6.js, in a very
parse-able way.</li>
<li>Javascript library developers would provide browser-specific
versions of their library, though this isn't necessary just yet</li>
<li>Browsers or extension developers would create a
plugin/extension/feature that implements the localized library
extension</li>
</ul>
<p>A possible way to go about #2 would be to use pynarcissus
(http://code.google.com/p/pynarcissus/) in some way to find anything
that may be a browser check and create browser-specific versions through
that. I would work on this, but I don't have time so it's just an idea
for now.</p>
<div id="_mcePaste"
style="position: absolute; left: -10000px; top: 430px; width: 1px; height: 1px; overflow: hidden;">
http://code.google.com/closure/compiler/Goo
</div>Random math observation2010-08-22T19:24:00-07:002010-08-22T19:24:00-07:00fahhemtag:blog.fahhem.com,2010-08-22:/2010/08/random-math-observation/<blockquote>
<p>(x*y)%10=x%10 if (x%10)%2=0 and (y%10)=6</p>
</blockquote>
<p>In words: numbers multiplied by other numbers starting with 6 have the
same least-significant digit as before they were multiplied, but only if
that digit is a multiple of 2. This is probably due to some …<a class="read-more" href="/2010/08/random-math-observation/"><span>continue</span></a></p><blockquote>
<p>(x*y)%10=x%10 if (x%10)%2=0 and (y%10)=6</p>
</blockquote>
<p>In words: numbers multiplied by other numbers starting with 6 have the
same least-significant digit as before they were multiplied, but only if
that digit is a multiple of 2. This is probably due to some rule, but I
thought it was interesting as I multiplied a short list by 16 to see I
only had to modify all but one of the digits.</p>Berkeley Restaurant Hours2009-12-14T20:13:00-08:002009-12-14T20:13:00-08:00fahhemtag:blog.fahhem.com,2009-12-14:/2009/12/berkeley-restaurant-hours/<p>As a college student who eats out frequently (my cooking skills aren't
good enough for crunch time eating) and who is always up late, I'm
always wondering what restaurants are still open in the area. In order
to reduce crime, the City of Berkeley decided to make business close for …<a class="read-more" href="/2009/12/berkeley-restaurant-hours/"><span>continue</span></a></p><p>As a college student who eats out frequently (my cooking skills aren't
good enough for crunch time eating) and who is always up late, I'm
always wondering what restaurants are still open in the area. In order
to reduce crime, the City of Berkeley decided to make business close for
most of the night. They were successful, but this means that few places
are still open when you're up late studying.</p>
<p>So I'm listing restaurants that are open at the listed time and earlier:</p>
<p>12am midnight:</p>
<p>Fred's Deli</p>
<p>Blondie's Pizza</p>
<p>11pm:</p>
<p>House of Curries</p>
<p>10pm:</p>
<p>Tandor Kitchen</p>
<p>Note: This post is currently limited to the restaurants/stores that I
frequent, but I'll gladly add more restaurants if you comment with their
names/hours. Also, if it closes before 10pm I'm not interested.</p>Flatten scanned PDF2009-12-14T00:08:00-08:002009-12-14T00:08:00-08:00fahhemtag:blog.fahhem.com,2009-12-14:/2009/12/flatten-scanned-pdf/<p>Recently I've been working for a website that has a lot of scanned PDFs.
They need to make sure that they don't have the same problem as the
redacted PDFs of the FBI/CIA. You know, where you could copy-paste the
words out from behind black boxes?</p>
<p>Yeah, we had …<a class="read-more" href="/2009/12/flatten-scanned-pdf/"><span>continue</span></a></p><p>Recently I've been working for a website that has a lot of scanned PDFs.
They need to make sure that they don't have the same problem as the
redacted PDFs of the FBI/CIA. You know, where you could copy-paste the
words out from behind black boxes?</p>
<p>Yeah, we had that exact same problem. Except I'm not working for the
FBI.</p>
<p>Google didn't help one bit, "flatten pdf" means something entirely
different to most people, so I couldn't find it. Anyway, I chose to use
the awesome tool ImageMagick.</p>
<p>I tried converting from PDF to PDF, but what happens is the filesize
blows up if I want any sort of quality. Instead, I convert to PNG and
then back to PDF.</p>
<p>So below is the shell script, with the only dependency being
ImageMagick:</p>
<p><code>LINES=$(cat files.txt) COUNT=0</code></p>
<p><code>for LINE in $LINES do</code></p>
<p><code>COUNT=$(echo "$COUNT + 1"|bc) echo -n "Working on $LINE.."</code></p>
<p><code>if [ -f fixed/$LINE ]; then echo ". already done" continue fi</code></p>
<p><code>mkdir fixed/imgs-$LINE convert -density 400 broken/$LINE fixed/imgs-$LINE/out.png echo -n ".." convert -density 400 fixed/imgs-$LINE/out*.png fixed/$LINE rm -r fixed/imgs-$LINE echo ". done"</code></p>
<p><code>done</code></p>
<p>It takes files in the file "files.txt" from the broken/ folder and
outputs fixed ones to fixed/.</p>
<p>I did this to make sure the files were good and then let me upload them
later. The broken/ folder is an sshfs mount to the original server
mounted read-only.</p>
<p>Once they're all fixed, I tested a bunch out and they were no longer
copy-paste vulnerable and the info was completely boxed out with a
similarly sized PDF</p>Wind, water and sun beat other energy alternatives, study finds2008-12-12T20:26:00-08:002008-12-12T20:26:00-08:00fahhemtag:blog.fahhem.com,2008-12-12:/2008/12/wind-water-and-sun-beat-other-energy-alternatives-study-finds/<p><a href="http://news-service.stanford.edu/news/2009/january7/power-010709.html">Wind, water and sun beat other energy alternatives, study
finds</a>.</p>
<p>Looks like something the world should listen to. Well, at least the most
polluting country in the world (the USA). If anyone knows the candidate
of hope's number, please let him know about wind energy's superiority
over everything he's proposing …<a class="read-more" href="/2008/12/wind-water-and-sun-beat-other-energy-alternatives-study-finds/"><span>continue</span></a></p><p><a href="http://news-service.stanford.edu/news/2009/january7/power-010709.html">Wind, water and sun beat other energy alternatives, study
finds</a>.</p>
<p>Looks like something the world should listen to. Well, at least the most
polluting country in the world (the USA). If anyone knows the candidate
of hope's number, please let him know about wind energy's superiority
over everything he's proposing.</p>
<p>If you don't know his number, I recommend commenting this link to him
here:</p>
<p>Link:
<a href="http://news-service.stanford.edu/news/2009/january7/power-010709.html">http://news-service.stanford.edu/news/2009/january7/power-010709.html</a><br>
Candidate of Hope: <a href="http://change.gov/page/content/discussservice">http://change.gov/page/content/discussservice</a></p>
<p>You can find a place to post the comment at the VERY bottom of the page.</p>