<?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>blogg nr. 176 671 167 &#187; development</title>
	<atom:link href="http://3djegrad.net/blog/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://3djegrad.net/blog</link>
	<description>verden sett fra mine snarveier</description>
	<lastBuildDate>Tue, 09 Nov 2010 13:58:24 +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>My files are number one. Mostly.</title>
		<link>http://3djegrad.net/blog/2010/09/benford-files/</link>
		<comments>http://3djegrad.net/blog/2010/09/benford-files/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 19:25:35 +0000</pubDate>
		<dc:creator>chrleon</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://3djegrad.net/blog/?p=413</guid>
		<description><![CDATA[I&#8217;m neither a mathematician, or statistician, but these things fascinate me. For the remaining people still awake after that statement, I want to share the (insanely great) RadioLab podcast titled &#8216;Numbers&#8217;, where I first heard of a phenomenon called Benford&#8217;s Law ..and maybe a wallpaper, too. Benford&#8217;s Law says: in lists of numbers from many [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m neither a mathematician, or statistician, but these things fascinate me. For the remaining people still awake after that statement, I want to share the (insanely great) <a href="http://www.radiolab.org">RadioLab podcast</a> titled &#8216;Numbers&#8217;, where I first heard of a phenomenon called Benford&#8217;s Law ..and maybe a wallpaper, too.</p>

<p><a href="http://en.wikipedia.org/wiki/Benford%27s_law">Benford&#8217;s Law</a> says:</p>

<blockquote>
  <p>in lists of numbers from many (but not all) real-life sources of data, the leading digit is distributed in a specific, non-uniform way. According to this law, the first digit is 1 almost one third of the time, and larger digits occur as the leading digit with lower and lower frequency, to the point where 9 as a first digit occurs less than one time in twenty.</p>
</blockquote>

<p>What this means is numbers starting with 1 are more likely to crop up in large datasets, than numbers starting with the other eight digits.</p>

<p>As I am a sceptical geek I had to test this out for myself.</p>

<h2>Large sets of numbers, eh?</h2>

<p>I could go out and find data from data.gov, or statistics from web-servers, but why leave the comfort of my own chair, when a simple bash-command would gather large numbers for me?</p>

<p><code>sudo ls -A -o -R / &gt; benford.txt</code></p>

<p>That command runs through my entire harddrive, searching through each and every folder it finds and spitting out lines and lines of filenames and sizes into the aptly named file &#8216;benford.txt&#8217;. Actually it generated one million, thirty one thousand, three hundred and twenty two lines, equal to a whopping 68.2 MB of text and almost as large as an empty canvas in Illustrator :p</p>

<p>What now? The lines look like this:
<code>-rw-r--r--   1 root    150 Jul  3  2009 InfoPlist.strings</code></p>

<p>I&#8217;m guessing, not being a unix professional, that there are ways to make the ls command only print the filesize and the name, and saving me the time of editing one million, thirty one thousand, three hundred and twenty two lines to only have lines like these
<code>150    InfoPlist.strings</code></p>

<p>Here&#8217;s where <a href="http://regular-expressions.info/">regular expressions</a> make their appearance. And the excellent <a href="http://gskinner.com/RegExr/desktop/">RegExr Desktop</a> is a great tool for it! Seeing as I&#8217;m no RegEx pro, either, I want to test my expressions before they run amok on my dataset :)</p>

<p><img src="/blog/wp-content/uploads/regexr-test.png" alt="RegExr Desktop App" /></p>

<p>After testing my regular expressions in RegExr, I went into the great <a href="http://barebones.com/products/textwrangler/">TextWrangler</a> and started to find and replace. It went very well, as you can see :)</p>

<p><img src="/blog/wp-content/uploads/twregex.png" alt="Find and replace FTW!" /></p>

<p><img src="/blog/wp-content/uploads/twregex2.png" alt="find and replace ftw!" /></p>

<p>My filelist is now complete, and it&#8217;s also a tab-delimited textfile, which is great for filling into a [MySQL database][]. The great thing with having this data inside a database, is the ease of which you can pull data out, and I&#8217;m looking for the amount of lines starting with 1,2,3 etc. So I made a database-table with three columns: Id, filesize, name, and started to import my filelist into it. After all the find/replace in TextWrangler, the filesize had shrunk to 25.1 MB.</p>

<p><img src="/blog/wp-content/uploads/import-csv.png" alt="mysql database is populated" /></p>

<p>Now I can start datamining, to see if this all was for nothing, or if my computers files also adhered to Benford&#8217;s Law.</p>

<h2>Squeal or Sequel?</h2>

<p>I like to use <a href="http://www.sequelpro.com/">Sequel Pro</a> for all MySQL needs, and it&#8217;s open-source and free. It lets you manage the database easily in a GUI, and also makes it easy to type your own SQL-statements and run them against the server. Sequel Pro is a fork of the discontinued CocoaMySQL.</p>

<p>Running <code>select filesize from benford where filesize rlike '^[1-9]'</code> on the database yields ninehundred sixty thousand twohunded seventy three rows. This shows all lines and is equal to 100%. Now the calulations begin.</p>

<p><img src="/blog/wp-content/uploads/alldatabase.png" alt="It's all in my database" /></p>

<p>So what does the number s look like? It was fun to see that the numbers were distributed mostly like Benford&#8217;s Law dictated. Check it out. Benford percentage on the left, my numbers in the middle, and the total amount to the right :)</p>

<ol>
<li>30,10 / 35,14 / 337 445</li>
<li>17,60 / 17,04 / 163 654</li>
<li>12,50 / 12,03 / 115 551</li>
<li>9,70 / 10,47 / 100 493</li>
<li>7,90 / 7,29 / 70 044</li>
<li>6,70 / 5,92 / 56 815</li>
<li>5.80 / 4,70 / 45 114</li>
<li>5,10 / 4,10 / 39 363</li>
<li>4,60 / 3,31 / 31 795</li>
</ol>

<p>Mathematics and statistics can be fun, especially when they are this close to /home :p</p>
]]></content:encoded>
			<wfw:commentRss>http://3djegrad.net/blog/2010/09/benford-files/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>webdev on network without NAT-loopback</title>
		<link>http://3djegrad.net/blog/2010/05/webdev-on-network-without-nat-loopback/</link>
		<comments>http://3djegrad.net/blog/2010/05/webdev-on-network-without-nat-loopback/#comments</comments>
		<pubDate>Wed, 19 May 2010 21:07:31 +0000</pubDate>
		<dc:creator>chrleon</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://3djegrad.net/blog/?p=368</guid>
		<description><![CDATA[I&#8217;ve been using WordPress for a while now, and I&#8217;m doing development on a local apacheserver. Since I&#8217;m used to not having NAT loopback on my network, I usually setup wordpress on the local dev-server and pass the blog URL as localhost:portnumber. When clients want to see progress, I upload to the www, and give [...]]]></description>
			<content:encoded><![CDATA[<h3>I&#8217;ve been using WordPress for a while now, and I&#8217;m doing development on a local apacheserver. Since I&#8217;m used to not having NAT loopback on my network, I usually setup wordpress on the local dev-server and pass the blog URL as localhost:portnumber. When clients want to see progress, I upload to the www, and give them the link.</h3>

<p>But I wanted the clients to be able to check out what I&#8217;m doing without uploading, so I had to find a way to enter the blog URL so it would work from outside too. If I put in localhost:portnumber, WordPress reroutes the visitor to that internal address which is not available from outside the LAN.</p>

<h3>Enter DynDNS!</h3>

<p><a href="http://www.dyndns.org">Dynamic DNS</a> was the solution: So I entered myurl.dyndns.org:portnumber. It works like a charm, but since I&#8217;m inside a network without NAT-loopback, when I try to go to myurl.dyndns.org:portnumber, it won&#8217;t resolve for me. Another thing to solve.</p>

<h3>Enter /etc/hosts!</h3>

<p>If I modify my hosts file on my developer-machine, I can reroute all traffic to the dynamic dns URL, to the internal one, which is localhost:portnumber. So I added this to my /etc/hosts file:</p>

<p><code>
//webdev locally on network without NAT-loopback<br />
//10.0.0.2 is my dev-server<br />
10.0.0.2    myurl.dyndns.org
</code></p>

<h3>Enter Terminal</h3>

<p><img src="http://3djegrad.net/blog/wp-content/uploads/terminal-img.png" alt="terminal-img" title="terminal-img" width="96" height="96" class="alignleft size-full wp-image-391" />
To use these hosts-settings without a reboot, enter terminal on macosx and type
<code>
sudo dscacheutil -flushcache
</code></p>

<p>So this is how I&#8217;ll do it going forward. Any tips and ideas can be put in the comments below.</p>
]]></content:encoded>
			<wfw:commentRss>http://3djegrad.net/blog/2010/05/webdev-on-network-without-nat-loopback/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quicksilver: Klar.. Ferdig&#8230; Programmér!</title>
		<link>http://3djegrad.net/blog/2010/02/quicksilver/</link>
		<comments>http://3djegrad.net/blog/2010/02/quicksilver/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 19:13:36 +0000</pubDate>
		<dc:creator>chrleon</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[quicksilver]]></category>

		<guid isPermaLink="false">http://3djegrad.net/blog/?p=117</guid>
		<description><![CDATA[Denne står også på mac1.no, skrevet av meg. Jeg legger den her også for flere. Mange filer, liten tid Når jeg holder på med et prosjekt er det endel mapper og filer som går igjen på nesten alle sites. Dette er en struktur på filene som jeg trives med. Eksempler på dette kan være: .htaccess [...]]]></description>
			<content:encoded><![CDATA[<p>Denne står også på <a href="http://mac1.no/artikkel/5868/quicksilver-klar-ferdig-programm%C3%A9r">mac1.no</a>, skrevet av meg.
Jeg legger den her også for flere.</p>

<p><strong>Mange filer, liten tid</strong>
Når jeg holder på med et prosjekt er det endel mapper og filer som går igjen på nesten alle sites. 
Dette er en struktur på filene som jeg trives med.</p>

<p>Eksempler på dette kan være: 
<strong>.htaccess</strong> &#8211; for å kontrollere apache-serveren</p>

<p><strong>&#8216;ilegg/&#8217;</strong> &#8211; mappe for php-includes</p>

<p><strong>&#8216;ilegg/start.php&#8217;</strong> &#8211; som er en php-fil med diverse variabler som skal inn i alle dokumenter på siten</p>

<p><strong>&#8216;grafikk/bilder&#8217;</strong> &#8211; mappe for bilder til siten</p>

<p><strong>&#8216;grafikk/logo&#8217;</strong> &#8211; mappe for logoer til siten (forskjellige størrelser til ulike formål)</p>

<p><strong>&#8216;grafikk/css&#8217;</strong> &#8211; mappe for bilder som blir brukt som bakgrunner ol. i css-filen</p>

<p><strong>&#8216;stilsett/&#8217;</strong> &#8211; mappe for css</p>

<p><strong>&#8216;stilsett/skjerm.css&#8217;</strong> &#8211; stilsett for skjermvisning</p>

<p><strong>&#8216;stilsett/print.css&#8217;</strong> &#8211; stilsett for utskrift</p>

<p><strong>&#8216;js/&#8217;</strong> &#8211; mappe for javascript</p>

<p><strong>&#8216;js/start.js&#8217;</strong> &#8211; kildefil for eksterne javascript</p>

<p><strong>&#8216;_arbeidsfiler/&#8217;</strong> &#8211; for arbeidsfiler (.psd, .ai og denslags).</p>

<p><strong>&#8216;index.php&#8217;</strong> &#8211; indexfilen som også er en malfil for resten av siten. Denne filen inneholder også include-kommando og javascript-kommandoer som henter inn de to startfilene ovenfor, samt style-tagg med attributt som henviser til de ulike css filene</p>

<p>Dette er jo en hel haug med filer som skal opprettes og kan fort gå litt tid dersom du skal opprette alt dette og skrive all koden for å hente inn de ulike stilsett, php-filer og javascript-kodefiler som skal henge med. Heldigvis kan QS gjøre dette nesten automatisk for meg.</p>

<p><strong>QuickSilver fikser.</strong>
Opprett alle disse filene i en mappe du kaller f.eks. <strong>&#8216;ny web&#8217;</strong>. I denne mappen setter du opp alle filene slik du ønsker å ha de, dvs. at index-filen kan ha doctype som validerer den mot xhtml-strict og inkludere start.php/start.js og begge stilsettene.</p>

<p>Stilsettene kan du sette opp slik at alle marger og luft rundt alle objekter er fjernet 
* { margin:0;padding:0; } og denslags. Du skjønner tegningen..?</p>

<p>Deretter kopierer du hele denne mappen inn i <strong>~/Library/Application Support/Quicksilver/Templates. </strong>Om ikke templates mappen er der, kan du opprette den.</p>

<p><img src='http://bildr.no/image/95975.jpeg' alt='' /></p>

<p><strong>Do or Do Not. There is no Try</strong>
Deretter er det enkelt i Quicksilver å opprette et nytt webprosjekt i mappen Kunder/Kundenavn ved å gjøre følgende:</p>

<p>Åpne Quicksilver (ctrl-space som standard), skriv <strong>&#8216;Kunder</strong>.
- QS gir deg da mappen kunder og du kan bla deg nedover til den kunden du skal opprette web for.
- Deretter tab&#8217;er du til neste og skriver <strong>&#8216;Make New&#8217;</strong> (eller bare <strong>&#8216;mn&#8217;</strong>).
- QS vil da gi deg en liste over alle filer som ligger i mappen Templates vi lagde tidligere. 
  Om du har flere maler i denne mappen, blar du deg nedover til du finner &#8216;Ny web&#8217;, og trykker &#8216;enter&#8217;.</p>

<p><img src='http://bildr.no/image/95977.jpeg' alt='' /></p>

<p>Nå har QS opprettet mappen <strong>&#8216;untitled.&#8217;</strong> i den mappen du valgte, og <strong>&#8216;untitled.&#8217;</strong> inneholder alle filene som er i <strong>&#8216;ny web&#8217;</strong>.
<strong>Merk: .htaccess er en skjult fil, ettersom den starter med &#8216;.&#8217;, men Quicksilver kopierer den likevel. I bildet over heter filen kun &#8216;htaccess&#8217; uten &#8216;.&#8217; fordi den skal vises på bildet.</strong></p>

<p><strong>Hva heter barnet..?</strong>
Det som er flott nå er at QS åpner seg selv igjen, med <strong>&#8216;untitled.&#8217;</strong> valgt som ikon og du kan enkelt tab&#8217;e bort til neste vindu i QS og skrive <strong>&#8216;rename&#8217;</strong> og døpe om &#8216;untitled.&#8217; til navnet på domenet du jobber med f.eks. <strong>3djegrad.net</strong>.</p>

<p><img src='http://bildr.no/image/95979.jpeg' alt='' /></p>

<p><strong>Programmér</strong>
Mappen 3djegrad.net er opprettet med alle filene du ønsket i mappen Kunder. Ferdig!</p>

<p><img src='http://bildr.no/image/95980.jpeg' /></p>

<p><strong>&#8211;Noen siste tanker&#8211;</strong>
Utvidelser av denne funksjonen kan være: 
<strong>&#8216;ny web mysql&#8217;</strong> &#8211; mappesett som inneholder php-filer med informasjon du trenger for å koble til databaser, 
og for innloggingssystem.
<strong>&#8216;ny web html&#8217;</strong> &#8211; mappesett som kun er et standard statisk nettsted med kun rene html filer
<strong>&#8216;ny web xhtml strict&#8217;</strong> &#8211; mappesett som kan være et utgangspunktet for et nettsted som validerer med korrekt Doctype mot XHTML 1.0 Strict
<strong>&#8216;ny web xhtml trans&#8217;</strong> &#8211; mappesett som kan være et utgangspunktet for et nettsted som validerer med korrekt Doctype mot XHTML 1.0 Transitional</p>

<p>Om filen du renamer til allerede finnes vil QuickSilver ikke gjøre noe, bortsett fra å gi deg en feilmelding neste gang du åpner QuickSilver. Men du skal jo ha såpass oversikt over hvilke sider du har laget tidligere, at du kaller evt nye versjoner av nettsder for v2 på slutten? :)</p>

<p>Jeg har også en egen QS Template som heter <strong>&#8216;ny kunde&#8217;</strong>, og den fungerer på akkurat samme måten som ovenfor, men lager en mappe i <strong>&#8216;Kunder&#8217;</strong>, som inneholder bl.a. mappene &#8216;<strong>_logoprofil/&#8217;</strong> og <strong>&#8216;prosjekter/&#8217;</strong>, som brukes til å lagre logomateriell for ny kunde og en egen undermappe for prosjekter. Da kan jeg, om det kommer en ny kunde som skal ha nettside, vha. QS lage en mappe for denne nye kunden med egen mappe for logoer og prosjekter. Ettersom QS viser det siste elementet du brukte, om du ikke venter for lenge, kan jeg dermed åpe QS engang til øyeblikkelig og navigere til <strong>&#8216;prosjekter/&#8217;</strong> og lage en <strong>&#8216;ny web&#8217;</strong> mappe.</p>

<p>Kjapt og gale. Dette tar ikke engang et minutt, og du er sikret lik struktur på alle jobber, og ikke minst. det er superlett å arkivere slike strukturer når du skal ta backup.</p>

<p><strong>Merk: .htaccess er en skjult fil, ettersom den starter med &#8216;.&#8217;, men Quicksilver kopierer den likevel.</strong></p>

<p><strong>Håper dette var til hjelp for noen. Det hjelper ihvertfall meg.</strong></p>

<p>Lykke til!</p>

<ul>
<li>christian</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://3djegrad.net/blog/2010/02/quicksilver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Submit and forget</title>
		<link>http://3djegrad.net/blog/2009/06/submit-and-forget/</link>
		<comments>http://3djegrad.net/blog/2009/06/submit-and-forget/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 12:08:01 +0000</pubDate>
		<dc:creator>chrleon</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://3djegrad.net/blog/?p=261</guid>
		<description><![CDATA[How to make password reminders remember the password even though you use the Cleartext option on passwords. Jakob Nielsen made an alertbox entry about password fields, recently. The gist of what he said, is that it&#8217;s user-unfriendly to obscure the passwords, on websites, which presents a password field to their users. He proposes to just [...]]]></description>
			<content:encoded><![CDATA[<p>How to make password reminders remember the password even though you use the Cleartext option on passwords.</p>

<p>Jakob Nielsen made an alertbox entry <a href="useit.com/alertbox">about password fields</a>, recently.</p>

<p>The gist of what he said, is that it&#8217;s user-unfriendly to obscure the passwords, on websites, which presents a password field to their users. He proposes to just use cleartext and not bullets, in these fields, and also suggests a solution to the secrecy problem on public computers: Have an option to show and hide the password field, in case someone looks over your shoulder.</p>

<p>Jakob Nielsen propose that the password is cleartexted as default, but I, and <a href="http://www.wait-till-i.com/2009/06/26/on-password-fields-masking-and-jakob-nielsen/">others</a> disagree. Chris Heilmann shows a way to make a show / hide link on all password fields, on a page.</p>

<p>It looks like an elegant script. Kudos to him, for sharing it.</p>

<p>What about password reminders? They only trigger on password-fields.<br />
Password reminders, I believe, will remember passwords if input type=&#8217;password&#8217;, when you hit submit.<br />
There should be a script that checks to see if the field is text or password, and turns it into password on submit, so that password reminders can remember the passwords even though you use the cleartext method.</p>

<p>Thanks to <a href="http://www.wait-till-i.com/2009/06/26/on-password-fields-masking-and-jakob-nielsen/">Chris Heilmann</a> for making the script in the first place.
<br />
<br />
<br />
UPDATE:
And btw: I tried my hand at an icon for show/hide password link.
It&#8217;s of-course under Creative Commons.<br />
<div id="attachment_276" class="wp-caption alignleft" style="width: 710px"><a href="http://3djegrad.net/blog/wp-content/uploads/hidepassword.gif"><img src="http://3djegrad.net/blog/wp-content/uploads/hidepassword1.gif" alt="Hide/show password icon. With a Creative Commons license." title="hidepassword.gif" width="95" height="24" class="size-full wp-image-276" /></a><p class="wp-caption-text">Hide/show password icon. With a Creative Commons license.</p></div></p>

<p><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0 Unported License</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://3djegrad.net/blog/2009/06/submit-and-forget/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A moat against spammers</title>
		<link>http://3djegrad.net/blog/2009/05/a-moat-against-spammers/</link>
		<comments>http://3djegrad.net/blog/2009/05/a-moat-against-spammers/#comments</comments>
		<pubDate>Fri, 01 May 2009 11:10:04 +0000</pubDate>
		<dc:creator>chrleon</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://3djegrad.net/blog/?p=218</guid>
		<description><![CDATA[If you&#8217;re like me, you probably have eliminated almost all of your daily spam email, by being very diligent. You, and I, read every privacy section on every beta we apply for, to feel secure that our email address won&#8217;t get in the Infernal Spam Database(TM). It pays to be diligent, and safeguarding your email [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re like me, you probably have eliminated almost all of your daily spam email, by being very diligent.</p>

<p>You, and I, read every privacy section on every beta we apply for, to feel secure that our email address won&#8217;t get in the Infernal Spam Database(TM). It pays to be diligent, and safeguarding your email address is a smart thing to do, and you should, but you can&#8217;t do it forever, you know.
<span id="more-218"></span></p>

<p>Some day, on some website, you need to use that precious email address, so People actually can contact you, and People generally like to do so, since that is what the internet is all about. These same People also don&#8217;t like to fill out forms, they like to click links, especially <a href="mailto:iluvspam@3djegrad.net">mailto: links</a> . This gives them a warm and fuzzy feeling, and also let&#8217;s them keep a copy in their Sent folder.</p>

<p>You and I have a strained relationship with mailto:links. So we have devised schemes (like mail-obfuscation) and voodoo-trickery to let People use mailto:links so long as they themselves use voodoo, in the form of JavaScript-enabled browsers. This leaves The Spammers in the dark. At least for now.</p>

<h3>The Spammer Never Sleeps</h3>

<p>Spammers don&#8217;t like to be in the dark, and so They strive for perfection in their spam-robots. Using all Their knowledge about searching text, and using a heap of <abbr title="Regular Expressions">regex</abbr> The Spammers usually manage to suck out all the email addresses They want. According to the report from <a href="http://www.cdt.org/speech/spam/030319spamreport.shtml">Centre for Democracy &amp; Technology</a>, published in 2003, e-mail obfuscation seems to work, but for how long? Probably only so long as it takes Them to make a regex converting obfuscated email addresses into correct email addresses. Considering 2009 &#8211; 2003 = 6 years They are probably on to Us.</p>

<p>The goal must be to hide that mailto-link and the email address with it, but still make it possible for the People to click links.</p>

<h3>For those about to be spammed, we salute you</h3>

<p>We have two requirements for our email-address:<br />
1. It has to be easy to type for an author / contributor. No large codes!<br />
2. We have to be able to use any email on whatever domain.</p>

<p>Seeing as every email-address under a domain is unique, we can simplify emails that belongs to the current domain to only the username.</p>

<p>I&#8217;ll be using the address &#8216;iluvspam@3djegrad.net&#8217; for this article. On the <a href="3djegrad.net/articles/moat/demo-site/" rel="nofollow" target="_blank">demo-site</a>, the link for this email-address will let People click it, open Their favourite email-app, send the email and continue on their Quest to find the End of the Internet.</p>

<p>To do this we&#8217;ll use Apache&#8217;s mod_rewrite capabilities, to rewrite URLs on the fly, and we will be able to write the email above as:</p>

<pre><code>&lt;a href="contact/iluvspam" rel="no-follow"&gt;iluvspam&lt;/a&gt;
</code></pre>

<p>Open up your favourite text-editor (notepad, or textedit will do fine though I prefer the excellent and gratis <a href="http://www.barebones.com">TextWrangler</a> from BareBones Software), and start a new file called &#8216;.htaccess&#8217;. Save this file in your root directory on the webserver.</p>

<p>If you have used mod_rewrite before, the already existing .htaccess will probably look something like this.</p>

<pre><code>&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
&lt;/IfModule&gt;
</code></pre>

<p>This enables the RewriteEngine in Apache and sets the RewriteBase to /, sort of like BASEHREF in HTML, but not exactly the same.</p>

<p>What we need to add is a RewriteRule which fires every time someone clicks the <a href="contact/iluvspam" rel="nofollow">iluvspam</a> link.</p>

<pre><code>&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /

#Email-harvest prevention for any domain
RewriteRule contact/([a-zA-Z0-9-_\.]+)/([a-zA-Z0-9-_\.]+) email.php?email=$1&amp;domain=$2  

# Email-harvest for this domain
RewriteRule contact/([a-zA-Z0-9-_\.]+) email.php?email=$1

&lt;/IfModule&gt;
</code></pre>

<p><a name="regex-start"></a></p>

<h3>Rewrite-email-to-the-what-now?</h3>

<p>Before we start, grab a box of concentration and open your head.</p>

<p>All those characters jumbled together like an imploded anthill, are regex. As I said earlier, regex are regular expressions which lets Spammers work with text. We can also use them for Good.</p>

<ul>
<li>^ (the caret sign) means &#8216;the start of the text&#8217;  </li>
<li>() parenthesis groups text together in a variable which can be used again.  </li>
<li>$ means the end of the string.  </li>
<li>[] groups together a string of letters to be handled later by another parameter, like &#8216;+&#8217; or &#8216;*&#8217;.  </li>
</ul>

<p>As an example:
- ^abc matches abcdef but not aabcdef, since the match doesn&#8217;t start with abc
- abc$ matches aabc, but not abcd, since the string &#8216;abcd&#8217; doesn&#8217;t end in abc
- ^abc$ only matches abc, seeing as we tell the regex-engine to look for a string that starts with abc and ends with abc.</p>

<p>Back to our .htaccess-file:</p>

<pre><code># Email-harvest for this domain
RewriteRule contact/([a-zA-Z0-9-_\.]+) email.php?email=$1
</code></pre>

<p>The RewriteRule above tells Apache to forward all links which refer to &#8216;contact/(something)&#8217; to the email.php script which parses the URL and returns the correct email to the (hopefully shiny and happy) People.</p>

<p>Phew! Take a deep breath before we dive back in &#8230; Ready? Let&#8217;s go!</p>

<p>The RewriteRule utilize <abbr title="Regular Expressions">regex</abbr> for pattern recognition. The pattern it looks for is &#8216;contact/&#8217; followed by  any letter between a-z in either lower- or UPPERCASE and/or any digits from 0-9 and/or the characters &#8216;-&#8217;, &#8216;_&#8217; and &#8216;.&#8217;.</p>

<p>This should cover all email-adresses. The plus sign at the end tells the Apache-server that we are looking for multiple characters. If you&#8217;re observant you might have noticed that the period-sign (.) has a backslash infront of it (&#46;), and a bracket encloses the text inside the parentheses. The backslash is an escape-character in regex, and tells the regex-engine that it should allow the literal character &#8216;.&#8217; (period), and not treat it like a wildcard, which is the default behavior for &#8216;.&#8217; in Regular Expressions. The bracket groups text together to be worked on by parameters later, like the &#8216;+&#8217;</p>

<pre><code># Email-harvest for this domain
RewriteRule contact/([a-zA-Z0-9-_\.]+) email.php?email=$1
</code></pre>

<p>The $1 in /email.php?email=$1 tells the regex-engine to use the found-text variable we grouped with parenthesis ([a-zA-Z0-9-_&#46;]+) and set the variable email to the found text, which in our case is iluvspam. The rewritten URL will then be: /email.php?email=iluvspam</p>

<p>So when People click &#8216;iluvspam&#8217; they send the variable &#8216;iluvspam&#8217; into email.php. email.php in turn is configured to append 3djegrad.net after all email variables, unless something else is defined.</p>

<p>As you&#8217;ve seen, we have two RewriteRules in our .htaccess-file and the other one let&#8217;s us type and send email to addresses on other domains, besides our own. That line looks like this.</p>

<pre><code>#Email-harvest prevention for any domain
RewriteRule contact/([a-zA-Z0-9-_\.]+)/([a-zA-Z0-9-_\.]+) email.php?epost=$1&amp;domene=$2
</code></pre>

<p>Using the knowledge you&#8217;ve gained above, you should be able to recognize that we now have two variables in the RewriteRule. The first variable is the email and the second is the domain. This RewriteRule let&#8217;s us write email-adresses to other domains like so:</p>

<pre><code>Contact him via&lt;a href="contact/chrleon/gmail.com" rel="no-follow"&gt;his email-adress&lt;/a&gt;
</code></pre>

<p>Just one thing. The more advanced RewriteRule has to be defined before the simpler ones, or the regex-engine will recognize the simpler form before the more advanced one and fire, never activating the more advanced one. So in this case the .htaccess looks like this:</p>

<pre><code>&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /

#Email-harvest prevention for any domain
RewriteRule contact/([a-zA-Z0-9-_\.]+)/([a-zA-Z0-9-_\.]+) email.php?epost=$1&amp;domene=$2 

# Email-harvest for this domain
RewriteRule contact/([a-zA-Z0-9-_\.]+) email.php?epost=$1
&lt;/IfModule&gt;
</code></pre>

<p><a name="regex-links"></a>
You can learn more about Regular Expressions at <a href="http://www.reguar-expressions.info">regular-expressions.info</a> and at <a href="http://weblogtoolscollection.com/regex/regex.php?page=3"> weblogtoolscollection</a>. Or do you need to <a href="#regex-start">read it again?</a></p>

<p>.htaccess files are extra configuration-files for the Apache web-server. To learn more about them, got to the Apache documentation <a href="http://www.apache.org/docs/2.0/">website</a>.</p>

<h3>So, what does email.php look like?</h3>

<p>The file is relatively simple. All it conceptually does is to get the user-name from the email/iluvspam and append the domain address. Try to also check the email-variable for non-allowed characters, or better yet do a white-list check where you only allow the characters a-zA-Z0-9.-_. That way you guard against injection-attacks. Any comments on the security issues are most welcome.</p>

<p>Here is the code for email.php, with comments.</p>

<pre><code>//  set two variables to hold the generated email-adress
//  the $domain variable is used for email-addresses on THIS domain
//  if no domain is entered in the link like contact/abc123
//  then the email will be sent to 'abc123@3djegrad.net'
$recipient = " ";
$domain = "3djegrad.net";


//  The email-address is gathered from the GET-request
//  This GET-request is from the link you clicked
//  An if-statement checks to see that the email is set
if ($_GET['email']) {
$recipient = $_GET['email'];
}

//  The domain is gathered from the GET-request.
//  if it is set, we replace the $domain variable with the correct domain
if($_GET['domain']) {
$domain = $_GET['domain'];
}
</code></pre>

<p>This is the gist of it, but we still haven&#8217;t made any headway on opening uur Readers&#8217; email-application. That&#8217;s the next step.</p>

<p>We open the Readers&#8217; email.application with a header-change in php, like so:</p>

<pre><code>header("Location: mailto:$recipient@$domain");
</code></pre>

<p>This will open the mail-app with the correct email-address, already filled in. But there&#8217;s just a blank page in the browser.</p>

<p>All the People who want to contact you, don&#8217;t like to see blank pages. They&#8217;re a tough crowd.</p>

<p>For this to work we must rely on <abbr title="JavaScript"> voodoo-trickery</abbr>, since PHP won&#8217;t let us send two header(location)-commands to the browser. If we try to send two header(location), only the last one fires. Even with the PHP function <a href="http://no.php.net/ob_start">ob_start()</a>. This is for security-reasons.</p>

<pre><code>echo '&lt;script type="text/javascript"&gt;history.back()&lt;/script&gt;';

$explanation = file_get_contents("spamexplain.html");
echo '&lt;noscript&gt;';
echo $explanation;
echo '&lt;/noscript&gt;';
</code></pre>

<p>The code above does just that. The first line tells the browser to go back one page. The following lines prepare a page for those Readers who for some reason have Javascript turned off or there is no Javascript available to them. This is our graceful fail.</p>

<p>But we&#8217;re not in Kansas yet, Dorothy.</p>

<p><img src="http://3djegrad.net/blog/wp-content/uploads/pie-chart-cc.jpg" alt="pie-chart-cc" title="pie-chart-cc" width="600" height="183" class="alignnone size-full wp-image-221" /></p>

<h3>Oi! What about my statistics!?</h3>

<p>It seems that Firefox and Opera generates a hit when you use the back-button, and so does using the history.back() function. Safari is the only browser not doing this, as I can tell from my tests.</p>

<p>The solution for this is to set a $_SESSION-variable in the email.script and test for that variable on the article page. If the variable is set, then don&#8217;t load the counters. After that test is run, destroy the session-variable. Now the count won&#8217;t register.</p>

<p>For this example I just use a date and time-stamp in a textfile</p>

<pre><code>if (!isset($_SESSION['url'])) { 
$filename = fopen("counter.txt", a);
//  This could be Google Analytics or others
//  like so: include('google-analytics-script.php');

//  write the date and time in the logfile, followed by a newline 
$dateandtime = date("d-m-Y - H:i:s",time());

fwrite($filename, $dateandtime . "\n");

fclose($filename); // close the file

unset($_SESSION['url']); 
//  unset the session-variable so that the counting still works on 
//  the rest of the page. Remember, we only want to drop the count
//  on this one page, after People have clicked their happy 
//  mailto:links.

    } 
</code></pre>

<h3>Try it out</h3>

<p>Demo-site: <a href="http://www.3djegrad.net/moat">3djegrad.net/moat</a></p>

<p>So there you have it. Hopefully spamfree, and humanreadable email-addresses on the internet.<br />
The People will be glad they can click on mailto-links again. Wayhey!</p>

<p>Thanks for reading. Any comments? Submit them below.</p>

<p>Creative Commons photos by: 

http://www.flickr.com/photos/wheatfields/</p>
]]></content:encoded>
			<wfw:commentRss>http://3djegrad.net/blog/2009/05/a-moat-against-spammers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Subversion &#8211; del 1</title>
		<link>http://3djegrad.net/blog/2009/03/subversion-1/</link>
		<comments>http://3djegrad.net/blog/2009/03/subversion-1/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 21:02:20 +0000</pubDate>
		<dc:creator>chrleon</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://3djegrad.net/blog/?p=169</guid>
		<description><![CDATA[Se i prosjektmappene dine. Har du mange filer som heter index.php, index2.php, index3.php, index4.php, index5.php? Da er nok Subversion for deg og meg. Jeg har bestemt meg for å installere Subversion for å drive versjonskontroll på kode jeg skriver. Subversion er OpenSource Version Control System, som lar deg ta vare på alle versjoner av kode, [...]]]></description>
			<content:encoded><![CDATA[<p>Se i prosjektmappene dine. Har du mange filer som heter index.php, index2.php, index3.php, index4.php, index5.php? Da er nok Subversion for deg og meg.</p>

<p>Jeg har bestemt meg for å installere Subversion for å drive versjonskontroll på kode jeg skriver. Subversion er OpenSource Version Control System, som lar deg ta vare på alle versjoner av kode, og gjør at du kan dele prosjektet som et team og alle kan sjekke inn og ut kode. For min del er versjons-styringen det viktigste, ettersom jeg jobber alene på programmeringsprosjekter, og har foreløpig ikke så mye bruk for team-delen.
Les mer på <a href="http://subversion.tigris.org">subversion.tigris.org</a>.</p>

<p><img src="http://3djegrad.net/blog/wp-content/uploads/2009/03/instaaling-svn-macports.jpg" alt="instaaling-svn-macports" title="instaaling-svn-macports" width="600" height="347" class="alignnone size-full wp-image-174" /></p>

<p>Installasjonen av <a href="http://subversion.tigris.org/">Subversion</a> skjer gjennom <a href="http://macports.org">MacPorts</a>, et prosjekt som er laget for å installere og administrere fri kildekode under OS X.</p>

<p>Følg med fremover for mer informasjon om hvordan jeg opplever Subversion.</p>

<h4>Installasjon av Subversion</h4>

<p><a href="http://subversion.tigris.org/">subversion.tigris.org</a> &#8211; her finner du Subversion<br />
<a href="http://macports.org">MacPorts</a> &#8211; er programvare for å installere FLOSS (free software / opensource) under OS X</p>

<h4>GUI for Subversion i OS X &#8211; Både fri og lukket</h4>

<p><a href="http://www.lachoseinteractive.net/en/community/subversion/svnx/features/">svnX</a> &#8211; open source<br />
<a href="http://versionsapp.com/">Versions</a> &#8211; ser unektelig sexy ut. €39 &#8211; demoversjon<br />
<a href="http://www.syncrosvnclient.com/">Syncro SVN Client</a> &#8211; $59 &#8211; årlig avgift</p>

<p>Hva er dine erfaringer med Subversion? Noen gode tips eller fallgruver jeg bør være obs på?</p>
]]></content:encoded>
			<wfw:commentRss>http://3djegrad.net/blog/2009/03/subversion-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache og VirtualHosts</title>
		<link>http://3djegrad.net/blog/2009/02/apache-virtualhosts/</link>
		<comments>http://3djegrad.net/blog/2009/02/apache-virtualhosts/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 15:40:10 +0000</pubDate>
		<dc:creator>chrleon</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[tipstriks]]></category>

		<guid isPermaLink="false">http://3djegrad.net/blog/?p=102</guid>
		<description><![CDATA[Portbasert virtual hosts ved utvikling av nettsider har en fordel. Du kan da sette opp f.eks localhost:3000 for et nettsted og localhost:3002 for et helt annet. Problemer du kan støte på underveis: ./apachectl -S gir en bus error Kan ikke koble til localhost Error i syntax 1. Bus error Dette kan være mye. Det jeg [...]]]></description>
			<content:encoded><![CDATA[<p>Portbasert virtual hosts ved utvikling av nettsider har en fordel.
Du kan da sette opp f.eks localhost:3000 for et nettsted og localhost:3002 for et helt annet.</p>

<p>Problemer du kan støte på underveis:</p>

<ol>
    <li>./apachectl -S gir en bus error</li>
    <li>Kan ikke koble til localhost</li>
    <li>Error i syntax</li>
</ol>

<h3>1. Bus error</h3>

<p>Dette kan være mye. Det jeg har erfart er at det noen ganger mangler en innstilling i httpd.conf filen som sier hvilken fil serveren skal lete etter som startfil (index.htm/index.php/index.html)</p>

<h3>2. kan ikke koble til localhost:</h3>

<p>Dette betyr at serveren ikke klarer å koble seg til den adressen du har oppgitt.
Bruk porter over 1024 i OS X. Jeg bruker fra 3000 og oppover.
Du kan også på Mac gå til Verktøy &gt; Nettverksverktøy og klikke på Port Scan for å se om noen programmer på maskinen bruker portene du velger. Da velger su 127.0.0.1 i feltet &#8216;Oppgi en Internett- eller IP-adresse for å søke etter åpne utganger&#8217; og haker av &#8216;Test kun utganger mellom&#8217; og skriver inn 3000, 3100 i de to feltene. Du vil da få opp alle programmer som bruker port 3000 &#8211; 3100. Mest sannsynlig ingen.
<img src="http://3djegrad.net/blog/wp-content/uploads/2009/02/portscan-384x231.png" alt="Portscanning" title="Portscanning" width="384" height="231" class="size-medium wp-image-103" /></p>

<h3>3. Error i syntax</h3>

<p>Her er det viktig at filer faktisk finnes
At du fører DocumentRoot-banen inn i anførselstegn.
DocumentRoot &#8220;/Bane/til/fil&#8221;
Du trenger ikke / etter siste mappenavn.</p>

<p>Husk at httpd.conf filen er case-sensitiv, dvs at den skiller mellom små og store bokstaver.</p>

<h3>4. Siste tips</h3>

<p>Legg alle Virtual Hosts i egen fil, eksempelvis conf/vhosts.conf,
og legg inn en ekstra linje i httpd.conf som henter inn denne filen
Include conf/vhosts.conf</p>
]]></content:encoded>
			<wfw:commentRss>http://3djegrad.net/blog/2009/02/apache-virtualhosts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tekstkoding i Leopard / TextWrangler</title>
		<link>http://3djegrad.net/blog/2009/02/tekstkoding-i-leopard-textwrangler/</link>
		<comments>http://3djegrad.net/blog/2009/02/tekstkoding-i-leopard-textwrangler/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 15:02:46 +0000</pubDate>
		<dc:creator>chrleon</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[tipstriks]]></category>
		<category><![CDATA[txt]]></category>

		<guid isPermaLink="false">http://3djegrad.net/blog/?p=68</guid>
		<description><![CDATA[For å få korrekt visning av æøå med QuickLook i Leopard (Mac OS X 10.5.x) bør filkoding være satt til Unicode UTF-8. Ikke bruk Unicode UTF-8 NO-BOM, då blir det noen feil med æøå. Bildet viser innstillingene i TextWrangler fra BareBones Software.]]></description>
			<content:encoded><![CDATA[<p>For å få korrekt visning av æøå med QuickLook i Leopard (Mac OS X 10.5.x) bør filkoding være satt til Unicode UTF-8.</p>

<p>Ikke bruk Unicode UTF-8 NO-BOM, då blir det noen feil med æøå. Bildet viser innstillingene i <a title="Gratis teksteditor fra BBSoft" href="http://www.barebones.com/products/textwrangler/" target="_blank">TextWrangler</a> fra BareBones Software.</p>

<div id="attachment_71" class="wp-caption alignnone" style="width: 274px"><a rel="attachment wp-att-71" href="http://3djegrad.net/blog/2009/02/tekstkoding-i-leopard-textwrangler/utf8-tw/"><img class="size-medium wp-image-71" title="utf8-tw" src="http://3djegrad.net/blog/wp-content/uploads/2009/02/utf8-tw.png" alt="Her er det satt i TextWrangler" width="264" height="320" /></a><p class="wp-caption-text">Her er det satt i TextWrangler</p></div>
]]></content:encoded>
			<wfw:commentRss>http://3djegrad.net/blog/2009/02/tekstkoding-i-leopard-textwrangler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

