<?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>Code+Definition</title>
	<atom:link href="http://codedefinition.com/feed" rel="self" type="application/rss+xml" />
	<link>http://codedefinition.com</link>
	<description>Web Developer, Web Designer, a web guy</description>
	<lastBuildDate>Sat, 04 Feb 2012 20:10:41 +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>Scala Type covariance and contravariance</title>
		<link>http://codedefinition.com/scala-type-covariance-and-contravariance.html</link>
		<comments>http://codedefinition.com/scala-type-covariance-and-contravariance.html#comments</comments>
		<pubDate>Sat, 17 Sep 2011 13:58:44 +0000</pubDate>
		<dc:creator>Joao Silva</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://codedefinition.sonuz.com/?p=15</guid>
		<description><![CDATA[Type Covariance and Contravariance Quoting from wikipedia Within the type system of a programming language, covariance and contravariance refers to the ordering of types from narrower to wider and their interchangeability or equivalence in certain situations (such as parameters, generics, and return types). covariant: converting from wider (double) to narrower (float). contravariant: converting from narrower [...]]]></description>
			<content:encoded><![CDATA[<h3 id="type-covariance-and-contravariance">Type Covariance and Contravariance</h3>
<p>Quoting from <a href="http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)">wikipedia</a></p>
<blockquote><p>Within the type system of a programming language, covariance and contravariance refers to the ordering of types from narrower to wider and their interchangeability or equivalence in certain situations (such as parameters, generics, and return types).</p></blockquote>
<ul>
<li>covariant: converting from wider (double) to narrower (float).</li>
<li>contravariant: converting from narrower (float) to wider (double).</li>
<li>invariant: Not able to convert.</li>
</ul>
<p>The ability to send a collection of subclass instances to a collection of base class is called covariance</p>
<p>The ability to send a collection of superclass instances to a collection of subclass is called contravariance</p>
<p>By default scala does not allow covariance and contravariance, but there are some good use cases where you might want to use a derived type as a super type.</p>
<p>Lets prepare some base code:</p>
<pre>
class Person(val name: String) {
 override def toString = name
}

class Employee(override val name: String) extends Person(name)

val empList = List(new Employee("Joao"), new Employee("Andre"))
val peopleList = List(new Person("Martin"), new Person("Jonas"))

def sayHi(people:List[Employee]) = people.map { println _ }

sayHi(empList)
sayHi(peopleList) // compilation ERROR
</pre>
<p>The error is pretty obvious we can’t send a <code>List[Person]</code> as the <code>sayHi</code> function expects a <code>List[Employee]</code> as it’s formal parameter, and here is where <strong>covariance</strong>comes into place.</p>
<h3 id="covariance">Covariance</h3>
<p>To solve the above compilation error we have to let scala compiler know that it’s ok to treat a Person as an Employee, we do that as follows:</p>
<pre>
def sayHi[T &lt;: Person](people: List[T]) = people.map { println _ }
</pre>
<p><code>sayHi</code> has now a special syntax <strong>[T &lt;: Person]</strong>. This syntax indicates that <code>T</code> sould be of Type <code>Person</code> or any class that derives from <code>Person</code>, which means that know we can have something like:</p>
<pre>sayHi(empList) sayHi(peopleList)</pre>
<p>You can also indicate covariance at the <code>class</code> level by making the parameterized type<code>+T</code> instead off <code>T</code>.</p>
<pre>
class SomeCollection[+T]

var lst1 = new SomeCollection[Employee]
var lst2: SomeCollection[Person] = lst1</pre>
</pre>
<p>The above snippet is possible since <code>Employee</code> is a subclass of <code>Person</code></p>
<h3 id="contravariance">Contravariance</h3>
<p><strong>Contravariance</strong> is the literally the opposite of <strong>Covariance</strong>, Lets imagine we want to add <code>Employee</code> to <code>Person</code>, as you can see the relationship is from <strong>subclass to superclass</strong>.</p>
<pre>
def appendToPerson[T, D &lt;: T](employees: List[T], people: List[D]) = people ++ employees
</pre>
<p>With the syntax <code>[T, D &lt;: T]</code>, we have constrained the parameterized type D to be of the type T or a super type of T, so basically T sets the lower level in the Type hierarchy for type D. In our example the type <code>D</code> (Person) can be of type <code>T</code> (Employee) or its superclass.</p>
<p>Scala also has class level support for setting contravariance and as you might guess the parameterized type is -T</p>
<h3 id="summary">Summary</h3>
<ul>
<li>A class <code>C[T]</code>, when a method accepts only <code>C[T]</code> is invariant</li>
<li>A class <code>C[+T]</code>, when a method accepts <code>C[T]</code> i can also get any of it’s dervatives</li>
<li>A class <code>C[+-T]</code>, when a method accepts <code>C[T]</code> i can also get any of it’s super classes</li>
</ul>
<p><strong>Function Type bounds:</strong></p>
<pre>
def fun[T &lt;: A](arg:T) // covariant, arg must be of type T or any of it's subclasses
def fun[T &gt;: A](arg:T) // Contravariant, arg must be of type T or any of it's super class
</pre>
]]></content:encoded>
			<wfw:commentRss>http://codedefinition.com/scala-type-covariance-and-contravariance.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Install node.js and version management with N.</title>
		<link>http://codedefinition.com/install-node-js-and-version-management-with-n.html</link>
		<comments>http://codedefinition.com/install-node-js-and-version-management-with-n.html#comments</comments>
		<pubDate>Mon, 12 Sep 2011 14:01:38 +0000</pubDate>
		<dc:creator>Joao Silva</dc:creator>
				<category><![CDATA[node.js]]></category>

		<guid isPermaLink="false">http://codedefinition.sonuz.com/?p=17</guid>
		<description><![CDATA[node.js is just awesome as i can write scalable server side javascript with it and in this blog post will be used as a reference for the installation process on mac OSX so that in future i can refer to it. Install Node.js via mac ports sudo port selfupdate sudo port install nodejs Install Node.js [...]]]></description>
			<content:encoded><![CDATA[<p>node.js is just awesome as i can write scalable server side javascript with it and in this blog post will be used as a reference for the installation process on mac OSX so that in future i can refer to it.</p>
<h3 id="install-node.js-via-mac-ports">Install Node.js via mac ports</h3>
<pre>
sudo port selfupdate
sudo port install nodejs
</pre>
<h3 id="install-node.js-via-homebrew">Install Node.js via Homebrew</h3>
<pre>brew install node</pre>
<h3 id="build-in-30-seconds-by-isaac-z.-schlueterizs">Build in 30 seconds by Isaac Z. Schlueter(@izs)</h3>
<pre>echo 'export PATH=$HOME/local/bin:$PATH' &gt;&gt; ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install
# ok, fine, this step probably takes more than 30 seconds...
</pre>
<h3 id="install-npm-with">Install npm with</h3>
<pre>
curl http://npmjs.org/install.sh | sh

or

git clone http://github.com/isaacs/npm.git
cd npm
sudo make install
</pre>
<h3 id="node-version-management-with-n">Node version management with N</h3>
<p>Node version management is important so that you can switch node versions on the fly giving you a very flexible development environment, i like to use <a href="https://github.com/visionmedia/n">N</a> as is a great tool to manage any version of Node.</p>
<pre>nmp nstall n</pre>
<p>Grab the latest node version(stable or unstable) but sometimes the build does not complete if it downloads the unstable branch and this in terms has some glitches :</p>
<pre>n latest</pre>
<p>Install and activate a specified node version</p>
<pre>n 0.5.5</pre>
<p>Remove a specified node version</p>
<pre>n - 0.5.5</pre>
<p>Activated nodes are then installed to the prefix /usr/local, which may be altered via the PREFIX environment variable.</p>
<p>To alter where n operates simply export N_PREFIX to whatever you prefer.</p>
]]></content:encoded>
			<wfw:commentRss>http://codedefinition.com/install-node-js-and-version-management-with-n.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install Scala on Mac</title>
		<link>http://codedefinition.com/install-scala-on-mac.html</link>
		<comments>http://codedefinition.com/install-scala-on-mac.html#comments</comments>
		<pubDate>Sat, 06 Aug 2011 19:04:17 +0000</pubDate>
		<dc:creator>Joao Silva</dc:creator>
				<category><![CDATA[Scala]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://codedefinition.sonuz.com/?p=20</guid>
		<description><![CDATA[The Way i have installed scala on mac was simple due to the MacPorts project. Scala MacPorts If and once you have installed macports there is only one step: sudo port install scala29 I you ever need to work with different versions you can find more scala macports. To Manage Scala versions you should also install scala_select [...]]]></description>
			<content:encoded><![CDATA[<p>The Way i have installed scala on mac was simple due to the <a title="MacPorts project" href="http://www.macports.org/">MacPorts project</a>.</p>
<h3>Scala MacPorts</h3>
<p>If and once you have installed macports there is only one step:<code></code></p>
<pre>sudo port install scala29</pre>
<p>I you ever need to work with different versions you can find more <a href="http://www.macports.org/ports.php?by=name&amp;substr=scala">scala macports</a>.</p>
<p>To Manage Scala versions you should also install scala_select which lets you switch the default compiler by symlinking the standard compiler executables in the MacPorts prefix to the selected version.</p>
<pre>$ sudo port install scala_select 

# List available scala versions
$ scala_select -l 

# Select one of the available versions.
$ scala_select scala29</pre>
<p>That&#8217;s it.</p>
<p>You may also would like to have look into <a title="" href="http://mxcl.github.com/homebrew/">Homebrew</a> an alternative package manager for OS X.</p>
]]></content:encoded>
			<wfw:commentRss>http://codedefinition.com/install-scala-on-mac.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Play Framework tutorial with Scala</title>
		<link>http://codedefinition.com/play-framework-tutorial-with-scala.html</link>
		<comments>http://codedefinition.com/play-framework-tutorial-with-scala.html#comments</comments>
		<pubDate>Sat, 06 Aug 2011 14:06:11 +0000</pubDate>
		<dc:creator>Joao Silva</dc:creator>
				<category><![CDATA[Play Framework]]></category>

		<guid isPermaLink="false">http://codedefinition.sonuz.com/?p=22</guid>
		<description><![CDATA[I have been working with Play! Java web framework for a Google App Engine project. Play! is a very good java web framework making it comfortable and effective to create web applications in java, this framework was created with the web developer in mind not the Java programming language. I also have been reading and [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working with <a title="Play java web framework" href="http://www.playframework.org/">Play! Java web framework</a> for a <a title="Google App Engine" href="http://code.google.com/appengine/docs/">Google App Engine</a> project. Play! is a very good java web framework making it comfortable and effective to create web applications in java, this framework was created with the web developer in mind not the Java programming language. I also have been reading and learning about<a title="Scala programming language" href="http://www.scala-lang.org/node/25">Scala programming language</a> which is a very powerful and interesting programming language and platform more on that coming soon.</p>
<p>As i wanted to try <strong>Play Scala</strong> i created a simple URL shortener application which was useful to learn some Scala, Play! Scala concepts and paradigms.</p>
<p>On this example we will be using <em>java.security</em> for generation of the md5 of the full url this way we can detect if the url is already present in the database and if it is we just use that url, otherwise we save it and return the new shortUrl We will also use<em>scala.Random</em> and <em>Integer.to_s(36)</em> to generate a <a href="http://en.wikipedia.org/wiki/Base_36">Base 36</a> short url.</p>
<p>The last lib worth mention is the <a title="Anorm, SQL data access" href="http://scala.playframework.org/documentation/scala-0.9.1/anorm">Anorm, SQL data access</a>. Anorm is a data access layer that let us &#8220;talk&#8221; with databases and as far as i understood, the philosophy of it is that the developer should &#8220;Take Control of SQL code&#8221;.</p>
<p>Nowadays developers work at very high levels of abstractions and this is good for an accelerated development process but it can come at a cost of efficiency. Therefor i quite sympathize with the way Anorm works. At it will make me remember some SQL practices which have been abstracted from me for a while.</p>
<p>I will walk you through what i did and if you have any remarks or tips to the code please let me know as i am open minded and willing to improve.</p>
<p>The code is available at <a title="Tuturial available at github" href="https://github.com/JSilva/play-scala-url-shortener">github</a></p>
<h3>Prerequisites</h3>
<p>To get this going you should have <strong>scala</strong> and the <strong>Play! framework</strong> installed</p>
<p>You can <a title="Download Scala" href="http://www.scala-lang.org/downloads">download Scala</a> on the Scala Language website and if you are on a Mac you can read my how to <a href="http://codedefinition.com/backdoor/blog/blog/add/">Install Scala on Mac</a>.</p>
<p>For Play! you can head over to the official <a title="Play Framework installation guide" href="http://www.playframework.org/documentation/1.2.2/install">Play Framework installation guide</a> as is as complete as it gets.</p>
<h3>Generate the application with:</h3>
<pre>cd {your working directory}

play install scala

play new scalaPlayShortener --with scala

cd scalaPlayShortener &#038;&#038; play dependencies</pre>
<h3>Database Migrations</h3>
<p>Play has database migrations support know as (evolutions -&gt; http://www.playframework.org/documentation/1.2.2/evolutions), so lets create our evolution.</p>
<pre>cd {your working directory}/scalaPlayShorner &amp;&amp; mkdir -p db/evolutions</pre>
<p>Create a file called 1.sql and add the following SQL:</p>
<pre># Shortener schema
# --- !Ups

CREATE TABLE Shortener (
 id bigint(20) NOT NULL AUTO_INCREMENT,
 shortUrl varchar(12) NOT NULL,
 fullUrl varchar(4096) NOT NULL,
 fullUrlHash varchar(32) NOT NULL,
 PRIMARY KEY (id)
);

# --- !Downs

DROP TABLE Shortener;</pre>
<p>The SQL after <strong># &#8212; !Ups </strong>runs when you are applying the evolution and consequent SQL, on the other site <strong># &#8212; !Downs </strong>is run when the migration is being reverted.</p>
<h3>Routes</h3>
<p>We will use 3 routes, first for the landing page with the form, second for the POST request when user submits the long URL and third the route that dispatches/redirect from the short to the long URL</p>
<p>Open the file in conf/routes and add this routes at the top, the <a title="Play framework routes file syntax" href="http://www.playframework.org/documentation/1.2.2/routes#syntax">file syntax</a> is the same as in the Java version of the framework.</p>
<pre>
GET  / Application.index
POST / Application.shorten
GET  /{dispatchUrl} Application.dispatch
</pre>
<h3>Scala Tests</h3>
<p>Play Scala comes with <a href="http://www.scalatest.org/">scala test</a> which is a great tool/DSL. Those who have used RSpec from Ruby land will see that they are very similar.</p>
<p>The scalatest syntax is very clear and does not let any doubt on what the code is doing, for example:</p>
<pre>val url = "http://google.com"

Shortener.create(Shortener(url))

// Fetch Some DB Record
val shortenURL = Shortener.find( "fullUrl={fullUrl}")
 .on("fullUrl" -&gt; url )
 .first()

// The DB Record should not be of type None
shortenURL should not be (None)

shortenURL.get.fullUrl should be (url)

Shortener.count().single() should be (1)
</pre>
<p>The Above code sample contains a <strong>should</strong> verb which is made available through<a title="ScalaTest ShouldMatchers" href="http://www.scalatest.org/scaladoc-1.0/org/scalatest/matchers/ShouldMatchers.html">ShouldMatchers</a> trait. A <strong>must</strong> verb is also available through the <a title="ScalaTest MustMatchers" href="http://www.scalatest.org/scaladoc-1.0/org/scalatest/matchers/MustMatchers.html">MustMatchers</a></p>
<p>The full test case for this example application located at test ShortenerTests.scala:</p>
<pre>import play._
import play.test._

import org.scalatest._
import org.scalatest.junit._
import org.scalatest.matchers._

import models._
import play.db.anorm._

class ShortenerTests extends UnitFlatSpec with ShouldMatchers with BeforeAndAfterEach {

 override def beforeEach() {
 Fixtures.deleteDatabase()
 } 

 it should "create and retrieve a Shorten Url" in {
 val url = "http://google.com"
 val url2 = "http://playgramework.org"
 Shortener.create(Shortener(url))

 val shortenURL = Shortener.find( "fullUrl={fullUrl}")
 .on("fullUrl" -&gt; url )
 .first()

 shortenURL should not be (None)
 shortenURL.get.fullUrl should be (url)
 shortenURL.get.fullUrlHash should be ("c7b920f57e553df2bb68272f61570210")
 shortenURL.get.shortUrl should fullyMatch regex ("""[a-zA-z0-9]+""")
 Shortener.count().single() should be (1)

 // add url and increase count
 Shortener.create(Shortener(url2))
 Shortener.count().single() should be (2)

 // try to create an already existent url
 Shortener.create(Shortener(url2))

 //the count should be 2 since we are not saving the url just returning the existent one
 Shortener.count().single() should be (2)

 val shortUrl2 = Shortener.find( "fullUrl={fullUrl}")
 .on("fullUrl" -&gt; url2 )
 .first()

 // the url2 properties
 shortUrl2 should not be (None)
 shortUrl2.get.fullUrl should be (url2)
 shortUrl2.get.fullUrlHash should be ("7faf91bbbde823d7c27ad7aaa17e196e")
 shortUrl2.get.shortUrl should fullyMatch regex ("""[a-zA-z0-9]+""")
 }
}</pre>
<h3>Model iteration</h3>
<p>As mentioned above i access the database width Anorm. Anorm offers a Magic helper which allow us to match a case class to the database schema, however we are not required to match every table field if we don&#8217;t need to.</p>
<pre>case class Shortener(
 id: Pk[Long],
 fullUrl: String,
 fullUrlHash:String,
 shortUrl:String = { Shortener.convertToBase36 }
)</pre>
<p>The main Model interaction is done through an Object which extends the Magic helper. The magic helper provides some convenience methods about which you <a title="Adding some Magic[T]" href="http://scala.playframework.org/documentation/scala-0.9.1/anorm#AddingsomeMagicT">learn more here</a>. As an example the <em>find</em> helper used on the <em>findFirstByFullUrl</em> method:</p>
<pre>def findFirstByFullUrl(url:String) = {
 Shortener.find("fullUrl={fullUrl}")
 .on("fullUrl" -&gt; url)
 .first()
}</pre>
<p>Below you will find all of the shortener Model used in modes/shortener.scala .</p>
<pre>package models

import java.security._
import java.lang.Integer
import scala.util.Random

import play.db.anorm._
import play.db.anorm.defaults._

case class Shortener(
 id: Pk[Long],
 fullUrl: String,
 fullUrlHash:String,
 shortUrl:String = { Shortener.convertToBase36 }
)

object Shortener extends Magic[Shortener] {

 def apply(fullUrl:String) = {
 val urlHash = Shortener.urlHash(fullUrl);
 Shortener.find("fullUrlHash = {urlHash}")
          .on("urlHash" -&gt; urlHash)
          .first()
          .getOrElse {
            new Shortener(NotAssigned, fullUrl, Shortener.urlHash(fullUrl))
          }
 }

 def convertToBase36():String = {
   Integer.toString(new Random().nextInt(100000),36)
 }

 def findFirstByFullUrl(url:String) = {
   Shortener.find( "fullUrl={fullUrl}")
            .on("fullUrl" -&gt; url )
            .first()
 }

 def findFirstByShortlUrl(url:String) = {
   Shortener.find( "shortUrl={shortUrl}")
            .on("shortUrl" -&gt; url )
            .first()
 }

 def urlHash(url:String) = {
   val md = MessageDigest.getInstance("MD5");
   md.update( url.getBytes() );
   md.digest.map(0xFF &amp;amp; _).map { "%02x".format(_) }.foldLeft(""){_ + _}
 }
}</pre>
<h3>Controllers</h3>
<p>In Play Scala the controllers are singletons <em>object</em> which extend <strong>play.mvc.Controller</strong>. In our case is the Application controller which has 3 methods in which 2 of them take arguments sent to them via the Routes configuration and via a form.</p>
<pre>package controllers

import play._
import play.mvc._

import models.Shortener
import views.Application._

object Application extends Controller {

 def index = {
 // Call the views/Application/index.scala.html
 html.index()
 }

 // Get the POST.ed longUrl field from the submited form
 def shorten(longUrl:String) = {
 Shortener.create(Shortener(longUrl))
 val shortenURL = Shortener.findFirstByFullUrl(longUrl)

 // Call the view
 html.index(shortenURL)
 }

 // Get the dispatchUrl from the Routes Configuration
 def dispatch(dispatchUrl:String) = {
 val shortenURL = Shortener.findFirstByShortlUrl(dispatchUrl)
 shortenURL match {
 case None =&gt; NotFound
 case shortenURL:Option[Shortener] =&gt; Redirect(shortenURL.get.fullUrl)
 }
 }
}</pre>
<p>In the controller above we retrieve the data form our Shortener Model and deal with that data, either by executing a <em>Redirect</em>, calling the <em>NotFound</em> and by display the template view.</p>
<p>For displaying the views we call <em>html.index()</em> and <em>html.index(shortenURL)</em>, this call will retrieve the template in <em>views/Applicaion/index.scala.html</em>, so if we split the structure it will be <em>views/{ControllerName}/{ActionCalled}.scala.html</em>. Being ActionCalled <em>.index()</em>and <em>.index(shortenURL)</em>. The reason for this is that the templates/views files are special Scala source files.</p>
<p>Now how does the template get the data we have passed as the<em>shortenURL</em>parameter? that bring us to the views.</p>
<h3>Views</h3>
<p>On the file located in views/Applicaion/index.scala.html i have created very basic template, but important thing is how we declare the values which will be made available for the rest of the template, so on the top of the file you can find:</p>
<pre>@(
 short:Option[models.Shortener] = None,
 title:String = "Scala Url Shortener"
)</pre>
<p>If look at it closer you will find a nameless function <em>@(etc&#8230;)</em> with default parameters. The <em>short</em> parameter will be bound to the formal parameter <em>shortenURL</em>. The <em>@</em> is used to call Scala code. I am still getting to know the way of doing this style of templates.</p>
<p>There are a few more concepts to grasp with regards to the templating system as how to use @action to invoke controller methods and generate URLs.</p>
<h3>Conclusion</h3>
<p>I am still getting into Scala and the Play! Framework but for me this is obviously good stuff. I know that the above code can be improved and i will do so upon suggestions and future learnings.</p>
<p>There is one thing that kind bugged me which is the templates as they are different and maybe not so web designer friendly, but i will digg more into them and i know that scalate can be used as an alternative.</p>
<p>Overall this is nice stuff and i would like to know your feedback and tips.</p>
]]></content:encoded>
			<wfw:commentRss>http://codedefinition.com/play-framework-tutorial-with-scala.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Batch resize image with ruby</title>
		<link>http://codedefinition.com/batch-resize-image-with-ruby.html</link>
		<comments>http://codedefinition.com/batch-resize-image-with-ruby.html#comments</comments>
		<pubDate>Fri, 05 Aug 2011 14:11:46 +0000</pubDate>
		<dc:creator>Joao Silva</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://codedefinition.sonuz.com/?p=26</guid>
		<description><![CDATA[I was asked to scale and reduce the size of few gigabytes of images, so i picked up my swiss army knife, Ruby. This will be a quick post and Ruby code snippet i have used to automatically scale and resize those images. The process is simple just get the images in the folder containing [...]]]></description>
			<content:encoded><![CDATA[<p>I was asked to scale and reduce the size of few gigabytes of images, so i picked up my swiss army knife, Ruby.</p>
<p>This will be a quick post and Ruby code snippet i have used to automatically scale and resize those images.</p>
<p>The process is simple just get the images in the folder containing the original images, read in each image, call the &#8220;scale&#8221; method on the images and save the resized images into a new location.</p>
<p>You can also use the Kernel#sleep method to avoid your CPU to get overloaded.</p>
<pre>$ gem install RMagick</pre>
<pre>require 'rubygems'
require 'RMagick'

# get the folder containing the original images
folder = ARGV[0]

# reduce by 35% = 35/100
scale_by = 0.35

# Get the images in the folder
# (you may replace JPG for whatever extension you will be processing )

files = Dir.glob("#{folder}/*.JPG") do |f|
 # read the image
 image = Magick::Image.read(f).first

 # scale the images
 puts "resizing #{image.filename}"
 new_image = image.scale(scale_by)
 new_image.write("resized/#{image.filename}")

 # sleep(5)
end</pre>
<p>If anyone has a diferent solution please let me know i would love to know about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://codedefinition.com/batch-resize-image-with-ruby.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Website content management systems made simple</title>
		<link>http://codedefinition.com/website-content-management-systems-made-simple.html</link>
		<comments>http://codedefinition.com/website-content-management-systems-made-simple.html#comments</comments>
		<pubDate>Fri, 11 Feb 2011 13:57:46 +0000</pubDate>
		<dc:creator>Joao Silva</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://codedefinition.sonuz.com/?p=13</guid>
		<description><![CDATA[A web site can be developed in two diferent ways, either static or dynamic. Static Websites On static websites you will have to update, create, delete pages individually and manually. For instance if you have a web site with 10 pages and you want to change the footer information this had to be done ten [...]]]></description>
			<content:encoded><![CDATA[<p>A web site can be developed in two diferent ways, either static or dynamic.</p>
<h3>Static Websites</h3>
<p>On static websites you will have to update, create, delete pages individually and manually. For instance if you have a web site with 10 pages and you want to change the footer information this had to be done ten times in every page which is not very effective, creating extra work and this costs money.</p>
<p>So the solution is to go dynamic.</p>
<h3>Dynamic Websites</h3>
<p>Dynamic websites are powered by Content Management Systems(CMS for friends), this CMS’s provide a powerful way to manage not only content but the web site itself.</p>
<p>If we take the footer example from above if you have a content management system in place you would only need to change the footer information in one place and this change would apply to every page on your site, the advantages are very obvious.</p>
<p>With a good Content management system you will be in control of your web site from one central control panel and will save you to keep paying to web designers or other companies to to make superficial changes or add pages, etc..</p>
<p>Content management systems will cost you more when first developed or incorporated into your current static web site, but if you are serious about your online side of business in my opinion and Content management system is a must, not to mention the future economical savings.</p>
<p>Currently i work with three different Content Managements Systems and each of them are suitable for all tasks and i will help you choose the correct one depending on your needs.</p>
<h3>Conclusion</h3>
<p>If you wish to have an online presence you really should have a content management system to support you online web site, this will save money and in a long run you will be very happy with the fact that you manage your website by adding, changing content or new features.</p>
<p>Feel free to <a title="Codedefinition.com contact form" href="http://codedefinition.com/contacts">contact me</a> if you require support in selecting and implementing a Content Management System on your newly created or current website.</p>
]]></content:encoded>
			<wfw:commentRss>http://codedefinition.com/website-content-management-systems-made-simple.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>João Silva VCard Design</title>
		<link>http://codedefinition.com/joao-silva-vcard-design.html</link>
		<comments>http://codedefinition.com/joao-silva-vcard-design.html#comments</comments>
		<pubDate>Fri, 04 Feb 2011 13:18:22 +0000</pubDate>
		<dc:creator>Joao Silva</dc:creator>
				<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://codedefinition.com/?p=94</guid>
		<description><![CDATA[Photoshop Design • Web Design]]></description>
			<content:encoded><![CDATA[<p><strong>Joaosilva.co.uk</strong> is my individual <a title="VCard Design" href="http://en.wikipedia.org/wiki/VCard" target="_blank">VCard</a> or should I say <a title="Internet Business Cards Design" href="http://en.wikipedia.org/wiki/Internet_Business_Cards">Internet Business Card</a>.</p>
<p>The goal of the VCard Website is to direct visitors to any of my projects, portfolio and to prove an easy way for people to contact me on the social networks to which i am linked too.</p>
<p>The original idea for this style of web site was made popular by within the webdesign community by the designer  <a title="VCard Design" href="http://www.timvandamme.com/">Tim Van Damme</a> .</p>
<p>This website has quite some time and has been featured in a few popular webdesign blogs side by side with some of the most popular web designers out here.</p>
<p>Below you will a few of the websites that fearured this design.</p>
<ul>
<li><a title="Joao Silva VCard design featured at the sixrevisions blog" href="http://sixrevisions.com/design-showcase-inspiration/30-impressive-vcard-web-designs/">Six Revisions Web Design Blog</a></li>
<li><a title="VCard Design" href="http://timvandamme.com/wall-of-fame">Tim Van Damme</a></li>
<li><a title="Joao Silva VCard design featured at the inspiration feed blog" href="http://inspirationfeed.com/2010/06/45-great-examples-of-v-card-designs/">Inspiration Feed</a></li>
</ul>
<p><a title="Joaosilva.co.uk  VCard" href="http://joaosilva.co.uk/">visit <strong>joaosilva.co.uk</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://codedefinition.com/joao-silva-vcard-design.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FASHIONBLOGR.COM</title>
		<link>http://codedefinition.com/fashionblogr.html</link>
		<comments>http://codedefinition.com/fashionblogr.html#comments</comments>
		<pubDate>Fri, 04 Feb 2011 12:50:49 +0000</pubDate>
		<dc:creator>Joao Silva</dc:creator>
				<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://codedefinition.com/?p=84</guid>
		<description><![CDATA[Wordpress MU • Buddypress Development]]></description>
			<content:encoded><![CDATA[<p><strong><a title="FashionBlogr.com a fashion community" href="http://fashionblogr.com/">Fashionblogr.com</a> </strong>is a blogging platform and a fashion community.</p>
<p>This project was developed using WordPress Multisite and Buddypress, this two opensource projects combined can provide a very robust solution.</p>
<p>Firstly the initial goal was to provide the fashion community with an easy way to publish content and have their own website. Well the most appealing a solution was to use WordPress 3.0 which was freshly backed and released.</p>
<p>Secondly having a fashion community on board where bloggers could easily share their stories and news made sense, here is where <a title="budypress.org" href="http://buddypress.org/">Buddypress</a> came into play.</p>
<p><strong>Fashionblogr.com</strong> the site it self was designed by <a title="Sofiane Delloue" href="http://fr.linkedin.com/in/delloue">Sofiane Delloue</a> from <a title="digitalpublishing.cz" href="http://www.digitalpublishing.cz/">digitalpublishing.cz</a> which is also the owner and project manager.</p>
<p>On this project my responsibilities were to build and deploy using <strong>HTML</strong>, <strong>CSS</strong>, <strong>Javascript</strong>, <strong>WordPress,</strong> <strong>Buddypress</strong> as well as server administration.</p>
<p><a title="FashionBlogr.com a fashion community" href="http://fashionblogr.com/">visit <strong>fashionblogr.com</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://codedefinition.com/fashionblogr.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FASHION-THEMES.COM</title>
		<link>http://codedefinition.com/fashion-themes.html</link>
		<comments>http://codedefinition.com/fashion-themes.html#comments</comments>
		<pubDate>Fri, 04 Feb 2011 11:19:39 +0000</pubDate>
		<dc:creator>Joao Silva</dc:creator>
				<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://codedefinition.com/?p=70</guid>
		<description><![CDATA[Wordpress Design • Wordpress Development]]></description>
			<content:encoded><![CDATA[<p><strong>Fashion</strong>-<strong>themes</strong>.com is a gallery of freely available WordPress <strong>themes</strong>.</p>
<p><strong>Fashion</strong>-<strong>themes</strong>.com the site it self was designed by <a title="Sofiane Delloue" href="http://fr.linkedin.com/in/delloue">Sofiane Delloue</a> from<a title="digitalpublishing.cz" href="http://www.digitalpublishing.cz/">digitalpublishing.cz</a>. I have built the HTML, CSS and Javascript.</p>
<p>As part of this project i have designed and built WordPress <strong>themes</strong>, the brief for this <strong>themes</strong> was to have a clean and minimal design which would appeal to the target audience.</p>
<p>These <strong>themes</strong> were created with the propose of being used on <a title="fashionblogr.com" href="http://webcache.googleusercontent.com/portfolio/fashionblogr/">fashionblogr.com</a> a design community.</p>
<p>If you are looking for minimal and full featured wordpress <strong>themes</strong> you can try out the wordpress <strong>themes</strong>available at <a title="Top WordPress fashion themes for wordpress" href="http://fashion-themes.com/"><strong>fashion</strong>-<strong>themes</strong>.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codedefinition.com/fashion-themes.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web Design Prespective on Search Engine Optimization</title>
		<link>http://codedefinition.com/web-design-prespective-on-search-engine-optimization.html</link>
		<comments>http://codedefinition.com/web-design-prespective-on-search-engine-optimization.html#comments</comments>
		<pubDate>Sun, 31 Jan 2010 13:52:30 +0000</pubDate>
		<dc:creator>Joao Silva</dc:creator>
				<category><![CDATA[Search Engine Optimization]]></category>

		<guid isPermaLink="false">http://codedefinition.sonuz.com/?p=10</guid>
		<description><![CDATA[I am a web designer and not an Search Engine Optimization expert but i know what i do when i do it. My job is to design and develop websites which are SEO friendly and i mean this because without a well developed website you Search Engine Optimization efforts will be much harder to accomplish. [...]]]></description>
			<content:encoded><![CDATA[<p>I am a web designer and not an Search Engine Optimization expert but i know what i do when i do it. My job is to design and develop websites which are SEO friendly and i mean this because without a well developed website you Search Engine Optimization efforts will be much harder to accomplish.</p>
<p>To get started and prepared for a search engine optimized website there are three main foundations:</p>
<ul>
<li>Good Content Management System</li>
<li>Standard Compliant and Valid Code</li>
<li>Readable Content</li>
</ul>
<h3>Good Content Management System</h3>
<p>When setting up a website you should have a clear path on how you want your content to be delivered and how will you publish that content, this involves to choose the correct platform or Content Management System(CMS) for your needs.</p>
<p>Currently there are many options available in the market from open source(free) to expensive enterprises solutions.</p>
<p>For 90% of the case an open source solution is more then adequate and in my opinion will be an asset for your business due to its monetary and scalable vantages.</p>
<p>Just keep in mind that it is very important for your website success to define how will you publish and in what platform will you publish your content.</p>
<h3>Standard Compliant and Valid Code</h3>
<p>If you bout who is checking your web site besides the users one that comes into play is search engine robots, these are complex algorithms that navigate the collecting information about all websites.</p>
<p>These robots will collect data from your website and serve them to peoples search query thought their websites, being the most popular player Google.</p>
<p>Now your code its an important factor on this robots searches, because they crawl your website and if the code does not present errors they will crawl the website at a faster speed and will index the relevant content that you have to offer. In the other hand if all they find is errors these robots will have problems to do a good job and you will be losing upfront to other competitors with valid web sites.</p>
<p>The other aspect of good code is semantic code, this means that your content should be displayed in order of relevance(pretty obvious), but you will be surprised on how many web sites out there do not adware to this good practice.</p>
<p>The last aspect i would like to mention is speed, with good and valid code your website load times will increase and your visitors plus these robots will be very happy for that.</p>
<h3>Readable content</h3>
<p>Readable content plays a major part on your web site success and with this words i mean that some websites have a very small font, or the colors and tone are not correct, so even if you have fantastic content but people can’t read it obviously they will go somewhere else.</p>
<p>Adding to the above i believe that you should write content for users and not for robots, this is very important because people sometimes focus to much on the search engine results and forget their audience, and this is a terrible mistake to make online.</p>
<p>One last detail i would like to mention is be careful where you display advertisements in your site, if this advertisements create an obstacle to users to reach their goal which is your content, they will give up and all the effort put in place will be useless.</p>
<h3>Conclusion</h3>
<p>With good content management system, valid code and readable content you will have a very strong advantage over your competitors and you Search Engine campaigns will most likely be a success.</p>
<p>One last word is please be aware of those who guarantee top rankings in no time, those people will rip you off and destroy your online reputation.</p>
]]></content:encoded>
			<wfw:commentRss>http://codedefinition.com/web-design-prespective-on-search-engine-optimization.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

