<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:atom="https://www.w3.org/2005/Atom"><channel><title>Gaya Kessler's Blog</title><atom:link href="https://gaya.pizza/feed.xml" rel="self" type="application/rss+xml"></atom:link><link>https://gaya.pizza</link><description>Web development articles written for web developers</description><pubDate>Tue, 30 Jun 2020 00:00:00 +0000</pubDate><generator>Wintersmith - https://github.com/jnordberg/wintersmith</generator><language>en</language><item><title>Cleaner Code</title><link>https://gaya.pizza/articles/cleaner-code/</link><pubDate>Tue, 30 Jun 2020 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/cleaner-code/</guid><author></author><description>&lt;p&gt;One of the things I take pride in is writing &lt;em&gt;simple, easy to follow, and clean code&lt;/em&gt;. My peers and clients appreciate the fact that I can write code in a way that the next person is able to understand what I am trying to convey.&lt;/p&gt;
&lt;p&gt;This makes my work a lot more usable and makes it easier for future programmers to be onboarded into the product I worked on.&lt;/p&gt;
&lt;p&gt;I want to share with you some principles I keep in the back of my mind when writing code.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/cleaner-code&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/cleaner-code/cleaner-code.jpg&quot; alt=&quot;Cleaner Code&quot; title=&quot;Cleaner Code&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Following are the key concepts that make my work better to understand and follow. This greatly improves the way I can teach people how to code or how they could think about writing code.&lt;/p&gt;
&lt;h2 id=&quot;write-as-if-the-next-person-reading-has-zero-context-of-the-problem-you-re-solving&quot;&gt;Write as if The Next Person Reading Has Zero Context of The Problem You’re Solving&lt;/h2&gt;
&lt;p&gt;Have you ever been asked to review a pull request and immediately saw a &lt;em&gt;large portion of code&lt;/em&gt; that made your head hurt? This is an &lt;strong&gt;early warning&lt;/strong&gt; the code is going to be hard to understand.&lt;/p&gt;
&lt;p&gt;The author might understand it perfectly, and you yourself might have written code like this before too: a large complex block of code that is using all kinds of cool tricks to create a desired outcome. While this can be smart, it &lt;em&gt;might be very hard to understand&lt;/em&gt; for the next person.&lt;/p&gt;
&lt;p&gt;A simple trick I like to use is to &lt;strong&gt;write code so that the next person reading it will be able to follow it without context&lt;/strong&gt;. This means I stay away from code that has the reader jump up and down in the code to be able to follow what’s going on.&lt;/p&gt;
&lt;p&gt;Write in short blocks of code, use clear naming, break it in smaller digestible bits, and give all your functions names. Good names.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Code has to read like a story&lt;/strong&gt;. When it reads like a story, when it has simple instructions, it is easier for the next person to go through.&lt;/p&gt;
&lt;p&gt;So the next time you finish a piece of code, go back and think: &lt;em&gt;“Would someone without any context understand this?”&lt;/em&gt; &lt;/p&gt;
&lt;h2 id=&quot;naming-of-things&quot;&gt;Naming of Things&lt;/h2&gt;
&lt;p&gt;One of the hardest things in software engineering is &lt;em&gt;naming things&lt;/em&gt;. Naming variables, functions, files, classes, folders, and the project itself.&lt;/p&gt;
&lt;p&gt;It’s really important to pick correct naming. Especially for the next person who’s going to read your code. It helps to take the time to &lt;strong&gt;think about a good name&lt;/strong&gt;, but do not overthink it. A function name or variable name taking up half the screen does not help either.&lt;/p&gt;
&lt;p&gt;For variables, give it a name that reflects something in the real world, or simply put: &lt;strong&gt;tell what it is&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Instead of &lt;code&gt;items.forEach((item) =&amp;gt; item.drive())&lt;/code&gt; try to use naming like &lt;code&gt;cars.forEach((car) =&amp;gt; car.drive())&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In that same regard, always try to &lt;em&gt;avoid abbreviations and shortened names&lt;/em&gt;. Name things by their name, instead of using a single letter or a few letters.&lt;/p&gt;
&lt;p&gt;Consider the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; list = getPersons();

list.forEach(&lt;span class=&quot;function&quot;&gt;(&lt;span class=&quot;params&quot;&gt;i&lt;/span&gt;) =&amp;gt;&lt;/span&gt; {
    doStuff(i.name);

    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (someCondition) {
        i.hire();
    }
})&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is hard to follow because you’d need to know what is in &lt;code&gt;list&lt;/code&gt; to understand what &lt;code&gt;i&lt;/code&gt; is. Only after you’ve seen &lt;code&gt;getPersons()&lt;/code&gt; does the reader know there are persons in &lt;code&gt;list&lt;/code&gt;. &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The reader might not start reading code from the top!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;You can make this easier to read when you formulate it like so:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; persons = getPersons();

persons.forEach(&lt;span class=&quot;function&quot;&gt;(&lt;span class=&quot;params&quot;&gt;person&lt;/span&gt;) =&amp;gt;&lt;/span&gt; {
    doStuff(person.name);

    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (someCondition) {
        person.hire();
    }
})&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;From looking at the variable name &lt;code&gt;person&lt;/code&gt;  I know I am looking at a list of persons. This creates a much &lt;em&gt;smaller mental model&lt;/em&gt; to work with.&lt;/p&gt;
&lt;p&gt;As for classes and functions. &lt;strong&gt;Try to keep the naming short and to the point&lt;/strong&gt;. If the function is doing too many things to give it a short name, &lt;em&gt;break the function up in smaller, easier to follow, parts&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id=&quot;return-values-early&quot;&gt;Return Values Early&lt;/h2&gt;
&lt;p&gt;One simple trick to make your code much easier to follow is to return early. You can write every bit of code you want without using &lt;code&gt;else&lt;/code&gt; by returning early.&lt;/p&gt;
&lt;p&gt;When sorting objects in a list by age, you can use a compare function which can return 3 different outcomes: 1, -1, or 0.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;sortByAge&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;firstPerson, secondPerson&lt;/span&gt;) &lt;/span&gt;{
  &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (firstPerson.age &amp;gt; secondPerson.age) {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;;
  } &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (secondPerson.age &amp;gt; firstPerson.age) {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;-1&lt;/span&gt;;
  } &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;;
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can also read this code if you read &lt;strong&gt;all the if statements&lt;/strong&gt; to understand the code fully. In order to make this code more readable you can return early. Make the function stop without having to create if else statements.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;sortByAge&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;firstPerson, secondPerson&lt;/span&gt;) &lt;/span&gt;{
  &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (firstPerson.age &amp;gt; secondPerson.age) {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;;
  }

  &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (secondPerson.age &amp;gt; firstPerson.age) {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;-1&lt;/span&gt;;
  }

  &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is but a simple example, but as your code and functions get more complex, this will &lt;em&gt;greatly improve the readability&lt;/em&gt; of your code. It takes a while to get used to writing like so, but it will pay off.&lt;/p&gt;
&lt;p&gt;Another thing you can avoid is creating temporary variables which get assigned and changed later on in your code. The reader has to track all the possible changes which can be made throughout the code.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;let&lt;/span&gt; name;

&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (user.loggedIn) {
  name = user.name;
} &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; {
  name = &lt;span class=&quot;string&quot;&gt;'No name'&lt;/span&gt;;
}

&lt;span class=&quot;comment&quot;&gt;// VS&lt;/span&gt;

&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;getName&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;person&lt;/span&gt;) &lt;/span&gt;{ 
  &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (person.loggedIn) {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; person.name;
  }

  &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;'No name'&lt;/span&gt;;
}

&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; name = getName(user);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It’s not the greatest example, but avoiding using mutable variables will make following your narrative a lot easier, &lt;em&gt;especially in larger function bodies&lt;/em&gt;. If you have to keep track of changes to variables in conditions, loops, and loops within loops, it will become &lt;strong&gt;hard to follow&lt;/strong&gt; fast.&lt;/p&gt;
&lt;p&gt;On that note… let’s move on to working with pure functions.&lt;/p&gt;
&lt;h2 id=&quot;pure-and-simplicity&quot;&gt;Pure and Simplicity&lt;/h2&gt;
&lt;p&gt;When creating functions, have it do one thing, and one thing good. Using pure functions will help you in making your code much easier to understand and reuse.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;It’s easier to reason about a function that does one thing&lt;/strong&gt; instead of a function that manipulates data, does some calculations, and return something completely different.&lt;/p&gt;
&lt;p&gt;A pure function &lt;em&gt;always returns the same result&lt;/em&gt; based on what is given to it, and has &lt;em&gt;no side effects&lt;/em&gt;. A side effect is when a function touches another part of your application and causes a mutation outside of the function.&lt;/p&gt;
&lt;p&gt;Pure functions are fundamentally mathematical. You provide them with input, and they’ll return a result, &lt;strong&gt;without touching the input&lt;/strong&gt; itself. That’s very important.&lt;/p&gt;
&lt;p&gt;For instance, rather than looping over a list to fill a new one, you can use &lt;code&gt;Array.map&lt;/code&gt; to create a new one. Rather than changing a property inside of an object, let a function take the original as input and return a copy with the property changed.&lt;/p&gt;
&lt;p&gt;Immutability has a lot of advantages, and one of them is &lt;em&gt;making the code easier to understand and follow&lt;/em&gt;. You’ll know for a fact that the input to functions will not be touched or changed in a way that’s not expected.&lt;/p&gt;
&lt;p&gt;Writing in pure functions need some getting used to, but once you start using them you’ll never want to go back.&lt;/p&gt;
&lt;p&gt;I know it’s a bit ironic I didn’t use 100% pure examples in this article, but I was trying to illustrate situations.&lt;/p&gt;
&lt;h2 id=&quot;keep-it-short-and-simple&quot;&gt;Keep it Short and Simple&lt;/h2&gt;
&lt;p&gt;I’ll close this article with one of the hardest things in programming. &lt;strong&gt;Keep your code short and simple&lt;/strong&gt;. More often than not are we prone to write complex and large chunks of code.&lt;/p&gt;
&lt;p&gt;By keeping your code in &lt;em&gt;short and concise chunks&lt;/em&gt; you can digest it a lot easier. Even when going back to your own code later you’ll thank yourself for writing it in such a way.&lt;/p&gt;
&lt;p&gt;So what if you can’t make your code readable? Write the code that will reach the goal you want to reach the way you would, be it not so readable. It is time to rethink what you just wrote. What is really happening in the code? Can I simplify?&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Write once, then write the code again.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;You’ll see that this time what you wrote it a lot easier to understand and follow. This &lt;em&gt;trains your brain&lt;/em&gt; to think about future problems the same way and avoids making the same mistakes later. Making your code cleaner.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The best way to solve a complex problem is more often than not a clean and simple solution.&lt;/strong&gt;&lt;/p&gt;
</description></item><item><title>Better Understanding of JavaScript Through Debugging</title><link>https://gaya.pizza/articles/better-understanding-javascript-through-debugging/</link><pubDate>Mon, 25 May 2020 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/better-understanding-javascript-through-debugging/</guid><author></author><description>&lt;p&gt;The moment when I increased my understanding of JavaScript the most was when I started to use the
debugging tools in my browser more efficiently.&lt;/p&gt;
&lt;p&gt;When teaching JavaScript, I am surprised at how little developers seem to know about debugging or
how to debug their code in a way that makes sense.&lt;/p&gt;
&lt;p&gt;This guide will provide some of the tricks I use to quickly find out what is wrong with my code, or
how to find out what is actually happening in your code.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/better-understanding-javascript-through-debugging&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/better-understanding-javascript-through-debugging/better-understanding-javascript-through-debugging-poster.jpg&quot; alt=&quot;Better Understanding of JavaScript Through Debugging&quot; title=&quot;Better Understanding of JavaScript Through Debugging&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;benefits-of-debugging&quot;&gt;Benefits of Debugging&lt;/h2&gt;
&lt;p&gt;When I started to write code, I’d check out what I could see in the browser, spot an error, change
the code, hope for a better outcome, reload the page, check the browser again. Rinse and repeat.&lt;/p&gt;
&lt;p&gt;While this strategy might work, I quickly found out that there are situations which are a bit harder
to solve just using this method.&lt;/p&gt;
&lt;p&gt;I wanted to know what value is stored in variables at a certain point in my code. Application code
took a while to transpile, making the refresh of the page a long wait. Getting to some points in
your application might also take a few actions, which can take up quite some of your development and
debugging time.&lt;/p&gt;
&lt;p&gt;If you get to know the debugging tools available in your browser, you can make your workflow a lot
more efficient.&lt;/p&gt;
&lt;h2 id=&quot;getting-to-know-the-debugger&quot;&gt;Getting to Know the Debugger&lt;/h2&gt;
&lt;p&gt;Most browsers ship with developer tools. In Firefox you can open the debugger by going to &lt;strong&gt;Tools &amp;gt; Web Developer &amp;gt; Debugger&lt;/strong&gt;
or by pressing &lt;code&gt;⌥⌘Z&lt;/code&gt; on MacOS.&lt;/p&gt;
&lt;p&gt;What will show up in the debugger, the tool we can use to inspect parts of our code. By pressing &lt;code&gt;esc&lt;/code&gt;
you can show or hide the console input at the bottom.&lt;/p&gt;
&lt;p&gt;Here we can enter JavaScript expressions directly (see below image) which are executed in the context
of where you currently “are” in the code. So if you just have your web page opened and are not 
stopped at a breakpoint (&lt;em&gt;I’ll get back to that later&lt;/em&gt;), it will just be another line of JavaScript 
executing.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/better-understanding-javascript-through-debugging/the-debugger.png&quot; alt=&quot;Developer Tools&quot; title=&quot;Developer Tools&quot;&gt;&lt;/p&gt;
&lt;p&gt;Now that you have your developer tools open, we can use all kinds of tricks to dive into our code
some more.&lt;/p&gt;
&lt;h2 id=&quot;the-humble-console-log&quot;&gt;The Humble console.log&lt;/h2&gt;
&lt;p&gt;Putting &lt;code&gt;console.log()&lt;/code&gt; in your code allows you to output values at any time in your developer tool’s
console.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;let&lt;/span&gt; i = &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;; i &amp;lt;= &lt;span class=&quot;number&quot;&gt;10&lt;/span&gt;; i += &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;) {
  &lt;span class=&quot;built_in&quot;&gt;console&lt;/span&gt;.log(i);
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You’ll see the following in your developer tool’s console.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/better-understanding-javascript-through-debugging/logs-debugger.png&quot; alt=&quot;Developer Tools console.log&quot; title=&quot;Developer Tools console.log&quot;&gt;&lt;/p&gt;
&lt;p&gt;This most likely is the most wide-used tool to debug code, but a rather overused one if you ask me. 
You’ll have to change the code and refresh the page when you want to log something else or want to 
inspect a different value.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;console.log&lt;/code&gt; and it’s neighbour methods are great when you have a lot to output, and you can’t 
pause the execution of the code. It’s great for logging values that are based on events.&lt;/p&gt;
&lt;p&gt;The console has a &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Console&quot;&gt;bunch of methods&lt;/a&gt; you can make use of. I’ll highlight &lt;code&gt;time&lt;/code&gt; and &lt;code&gt;timeEnd&lt;/code&gt; later on. Good ones to learn about are: &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Console/dir&quot;&gt;&lt;code&gt;console.dir&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Console/table&quot;&gt;&lt;code&gt;console.table&lt;/code&gt;&lt;/a&gt;,
they display the provided data in a certain way that it might match your content better.&lt;/p&gt;
&lt;h2 id=&quot;clean-up-after-yourself&quot;&gt;Clean up After Yourself&lt;/h2&gt;
&lt;p&gt;Avoid leaving in console methods in your code. They will be visible to everyone using the developer
tools (so including the end user).&lt;/p&gt;
&lt;p&gt;Browsers which don’t have console methods will also &lt;strong&gt;crash your code&lt;/strong&gt; when you try to use them 
because console does not exist there. This used to be quite a common error in Internet Explorer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A much better way&lt;/strong&gt; to figure out values of variables is to &lt;strong&gt;use breakpoints&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&quot;figuring-out-your-scope-using-the-debugger-statement&quot;&gt;Figuring out Your Scope Using the Debugger Statement&lt;/h2&gt;
&lt;p&gt;One of the things I teach the most to developers, also experienced ones, is the &lt;code&gt;debugger;&lt;/code&gt; statement.&lt;/p&gt;
&lt;p&gt;What it does is create a breakpoint in your code and makes the browser pause execution of the code
when it comes across this line. You can also put breakpoints directly on lines using the browser’s
debugger, but I find this method often to be quicker.&lt;/p&gt;
&lt;p&gt;Say we have the following piece of code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;callback&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;event&lt;/span&gt;) &lt;/span&gt;{
  &lt;span class=&quot;comment&quot;&gt;// I would like to inspect what is in `event` here&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;debugger&lt;/span&gt;;
}

&lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;.getElementById(&lt;span class=&quot;string&quot;&gt;'input'&lt;/span&gt;)
  .addEventListener(&lt;span class=&quot;string&quot;&gt;'change'&lt;/span&gt;, callback);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will make the debugger pause the code execution when the input with id “input” on the page will
fire a change event. Now we are able to safely inspect what contents of &lt;code&gt;event&lt;/code&gt; are.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/better-understanding-javascript-through-debugging/breakpoint-debugger.png&quot; alt=&quot;Breakpoint in Developer Tools&quot; title=&quot;Breakpoint in Developer Tools&quot;&gt;&lt;/p&gt;
&lt;p&gt;By hovering over the variable you want to know at this point in time of your code the developer tools
will show you the value in a nice little popup.&lt;/p&gt;
&lt;p&gt;You can also type the variable name in the console, and it will output it if you execute it. Just
putting the variable name will return the contents to the console which it will show.&lt;/p&gt;
&lt;p&gt;You can continue execution by pressing the “play” or “continue” button on the top right.&lt;/p&gt;
&lt;p&gt;Just like console methods, &lt;strong&gt;remove&lt;/strong&gt; debugger statements from your code to prevent the end user’s
browser from creating breakpoints.&lt;/p&gt;
&lt;h2 id=&quot;placing-breakpoints-directly-in-the-debugger&quot;&gt;Placing Breakpoints Directly in the Debugger&lt;/h2&gt;
&lt;p&gt;A safer way to create breakpoints, and not risk leaving &lt;code&gt;debugger&lt;/code&gt; statements inside of your code is
to put breakpoints directly in your code through the browser’s debugger.&lt;/p&gt;
&lt;p&gt;Open your browsers developer tools and go to the debugger.&lt;/p&gt;
&lt;p&gt;You might already have the JavaScript file you want to create a breakpoint in opened, if not: press
&lt;code&gt;⌘P&lt;/code&gt; to look for the file by name. Your browser will look through loaded JavaScript files on the
web page.&lt;/p&gt;
&lt;p&gt;This even works when you have transpiled modern JavaScript through a tool like Webpack. The only
thing you need to make sure is that you’re using sourcemaps.&lt;/p&gt;
&lt;p&gt;To create a breakpoint, &lt;strong&gt;click on the line number&lt;/strong&gt; next to the line you want your code to break.  &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/better-understanding-javascript-through-debugging/manual-breakpoint-debugger.png&quot; alt=&quot;Manual breakpoint in Developer Tools&quot; title=&quot;Manual breakpoint in Developer Tools&quot;&gt;&lt;/p&gt;
&lt;p&gt;Next time the browser comes across this line it will stop on this line of code and will pause
execution.&lt;/p&gt;
&lt;p&gt;If you open the secondary menu by right-clicking on the line number you’ll see that you can
also make the breakpoint conditional and that you can add log points. This makes &lt;code&gt;console.log&lt;/code&gt; even
unnecessary as you can do it right there!&lt;/p&gt;
&lt;h2 id=&quot;measuring-performance&quot;&gt;Measuring Performance&lt;/h2&gt;
&lt;p&gt;Most modern developer tools allow you to use &lt;code&gt;console.time&lt;/code&gt; and &lt;code&gt;console.timeEnd&lt;/code&gt;. This is a quick
and  easy way to measure the performance of pieces of code.&lt;/p&gt;
&lt;p&gt;Find a part of the code you want to measure. Add &lt;code&gt;console.time(&amp;#39;calculation&amp;#39;)&lt;/code&gt; the line above.
&lt;code&gt;&amp;#39;calculation&amp;#39;&lt;/code&gt; is the label of our measurement. After the piece of code you want to measure, place
&lt;code&gt;console.timeEnd(&amp;#39;calculation&amp;#39;)&lt;/code&gt; with the same label.&lt;/p&gt;
&lt;p&gt;In the console you’ll now see how long it took to go from &lt;code&gt;time&lt;/code&gt; to &lt;code&gt;timeEnd&lt;/code&gt;. Great for measuring
how long function calls take or renders of your components.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;built_in&quot;&gt;console&lt;/span&gt;.time(&lt;span class=&quot;string&quot;&gt;'calculation'&lt;/span&gt;);

&lt;span class=&quot;comment&quot;&gt;// some super complex code here&lt;/span&gt;

&lt;span class=&quot;built_in&quot;&gt;console&lt;/span&gt;.timeEnd(&lt;span class=&quot;string&quot;&gt;'calculation'&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;how-to-narrow-down-problems&quot;&gt;How to Narrow Down Problems&lt;/h2&gt;
&lt;p&gt;I want to end with a technique I use to narrow down problematic parts of an application or when I
want to figure out which part of the application is slowing everything down.&lt;/p&gt;
&lt;p&gt;First I like to start with commenting out stuff that might be breaking by reading the error messages
in the console or on the page. Especially in React it’s pretty clear which components make the
application throw errors.&lt;/p&gt;
&lt;p&gt;Piece by piece, enable lines of code again, and you’ll soon find that where the problem lies.&lt;/p&gt;
&lt;p&gt;I do the same for performance improvements. I start by measuring the speed of a large chunk and then
narrow it down to specific parts in the code. You’ll find that a lot of the times the slowness is in
one particular part of the application.&lt;/p&gt;
&lt;p&gt;Being able to pin point problematic areas like so makes it easier in the future to understand where
problems come from and by using the debugging techniques in this article makes you understand the
“why” more rather than the “how”.&lt;/p&gt;
&lt;h2 id=&quot;wrapping-up&quot;&gt;Wrapping Up&lt;/h2&gt;
&lt;p&gt;These few tips will help you debug your code more easily from now on. There is a lot more you can do
with your browser’s debugger, and it’s worth reading up about it more in-depth once you get used to
the basics.&lt;/p&gt;
&lt;p&gt;Feel free to reach out with questions or suggestions for techniques you think need to be included in
this article.&lt;/p&gt;
</description></item><item><title>Extending Create React App's ESLint config</title><link>https://gaya.pizza/articles/extending-cra-eslint-airbnb/</link><pubDate>Mon, 04 May 2020 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/extending-cra-eslint-airbnb/</guid><author></author><description>&lt;p&gt;Using &lt;a href=&quot;https://create-react-app.dev/&quot;&gt;Create React App&lt;/a&gt; you can easily start using React and develop
your own web applications. It also includes a linter which helps you write consistent and quality
code.&lt;/p&gt;
&lt;p&gt;However, I really like to use a different style guide a top of the default. Luckily for us, Create
React App enables us to extend ESLint to use other configuration presets.&lt;/p&gt;
&lt;p&gt;This article goes into how to set up the Airbnb style guide in Create React App. It also includes a
guide for when you’re using TypeScript.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/extending-cra-eslint-airbnb&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/extending-cra-eslint-airbnb/extending-cra-eslint-airbnb-poster.jpg&quot; alt=&quot;Extending Create React App&amp;#39;s ESLint config&quot; title=&quot;Extending Create React App&amp;#39;s ESLint config&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;version-disclaimer&quot;&gt;Version disclaimer&lt;/h2&gt;
&lt;p&gt;At the time of writing, Create React App (&lt;code&gt;react-scripts&lt;/code&gt;) is at 3.4.0, which is where this guide was
written for. In the mean time things can have changed, so take that in mind.&lt;/p&gt;
&lt;h2 id=&quot;no-config-no-problem-&quot;&gt;No Config, No Problem.&lt;/h2&gt;
&lt;p&gt;I love the idea and project that is &lt;a href=&quot;https://create-react-app.dev/&quot;&gt;Create React App&lt;/a&gt;. No hastle, no
config or setup, just start coding with the latest and greatest tools in React development.&lt;/p&gt;
&lt;p&gt;It takes care of all config, but that also means it takes a bit away from customising the workflow
to your liking. I do not mind this sacrifice since it takes a lot of trouble out of your hands.&lt;/p&gt;
&lt;p&gt;However, Create React App enables us to &lt;a href=&quot;https://create-react-app.dev/docs/setting-up-your-editor/#experimental-extending-the-eslint-config&quot;&gt;extend their ESLint configuration&lt;/a&gt;. Which is exactly what I want to add Airbnb’s
style guide rules to the project.&lt;/p&gt;
&lt;h2 id=&quot;adding-airbnb-style-guide-to-create-react-app&quot;&gt;Adding Airbnb style guide to Create React App&lt;/h2&gt;
&lt;p&gt;For these steps I assume you’ve already created a Create React App project. If you haven’t, please
read the &lt;a href=&quot;https://create-react-app.dev/docs/getting-started&quot;&gt;getting started guide&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;First thing we want to do is create an &lt;code&gt;.env&lt;/code&gt; file in your project (if haven’t already.)&lt;/p&gt;
&lt;h3 id=&quot;enable-extending-in-env&quot;&gt;Enable extending in &lt;code&gt;.env&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;In this &lt;code&gt;.env&lt;/code&gt; file you’ll need to put the following line:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;EXTEND_ESLINT=true&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This tells Create React App you’re extending the ESLint config it provides. Without this, the next
steps will have no effect.&lt;/p&gt;
&lt;p&gt;The official documentation has a great &lt;a href=&quot;https://create-react-app.dev/docs/adding-custom-environment-variables/&quot;&gt;article on how to and why you’d want to add environment variables&lt;/a&gt; to your project.&lt;/p&gt;
&lt;h3 id=&quot;install-airbnb-style-guide&quot;&gt;Install Airbnb style guide&lt;/h3&gt;
&lt;p&gt;Next we’re going to install the Airbnb style guide into our project. We can do this by running the
following command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install eslint-config-airbnb -D&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There is no need to install peer-dependencies because they are already included in Create React App.&lt;/p&gt;
&lt;h3 id=&quot;add-airbnb-to-the-eslint-config&quot;&gt;Add Airbnb to the ESLint config&lt;/h3&gt;
&lt;p&gt;In the root of your project open the &lt;code&gt;package.json&lt;/code&gt; file. In it you’ll find a property called &lt;code&gt;eslintConfig&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;All you need to do here is add &lt;code&gt;&amp;quot;airbnb&amp;quot;&lt;/code&gt; to the extends option.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &amp;quot;dependencies&amp;quot;: { ... },
  &amp;quot;scripts&amp;quot;: { ... },
  &amp;quot;eslintConfig&amp;quot;: {
      &amp;quot;extends&amp;quot;: [&amp;quot;react-app&amp;quot;, &amp;quot;airbnb&amp;quot;]
  },
  &amp;quot;browserslist&amp;quot;: { ... }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;And that’s it!&lt;/strong&gt; Your project is now checked against the Airbnb JavaScript style guide.&lt;/p&gt;
&lt;p&gt;First thing you might notice is that it will not want you to put JSX inside &lt;code&gt;.js&lt;/code&gt; files, but rather in &lt;code&gt;.jsx&lt;/code&gt; files.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;If you do not use TypeScript, you’re done now.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;adding-airbnb-style-guide-to-a-typescript-project&quot;&gt;Adding Airbnb style guide to a TypeScript project&lt;/h2&gt;
&lt;p&gt;If you’re using &lt;a href=&quot;https://create-react-app.dev/docs/adding-typescript&quot;&gt;TypeScript with Create React App&lt;/a&gt;
you’ll have to do a few extra steps.&lt;/p&gt;
&lt;p&gt;Do all of the steps as described above to install the Airbnb style guide into your project.&lt;/p&gt;
&lt;h3 id=&quot;install-typescript-import-resolver&quot;&gt;Install TypeScript import resolver&lt;/h3&gt;
&lt;p&gt;The airbnb style guide will enforce that your imports resolve, and ESLint can’t automatically figure
imports of TypeScript source.&lt;/p&gt;
&lt;p&gt;Run the following command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install eslint-import-resolver-typescript -D&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;setting-up-the-eslint-config&quot;&gt;Setting up the ESLint config&lt;/h3&gt;
&lt;p&gt;Open up your &lt;code&gt;package.json&lt;/code&gt; and navigate to the &lt;code&gt;eslintConfig&lt;/code&gt; property again. The following is a
base config to make Airbnb work for TypeScript files:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
 &lt;span class=&quot;attr&quot;&gt;&quot;eslintConfig&quot;&lt;/span&gt;: {
    &lt;span class=&quot;attr&quot;&gt;&quot;extends&quot;&lt;/span&gt;: [
      &lt;span class=&quot;string&quot;&gt;&quot;react-app&quot;&lt;/span&gt;,
      &lt;span class=&quot;string&quot;&gt;&quot;airbnb&quot;&lt;/span&gt;,
      &lt;span class=&quot;string&quot;&gt;&quot;plugin:@typescript-eslint/eslint-recommended&quot;&lt;/span&gt;,
      &lt;span class=&quot;string&quot;&gt;&quot;plugin:@typescript-eslint/recommended&quot;&lt;/span&gt;
    ],
    &lt;span class=&quot;attr&quot;&gt;&quot;overrides&quot;&lt;/span&gt;: [
      {
        &lt;span class=&quot;attr&quot;&gt;&quot;files&quot;&lt;/span&gt;: [&lt;span class=&quot;string&quot;&gt;&quot;**/*.ts?(x)&quot;&lt;/span&gt;],
        &lt;span class=&quot;attr&quot;&gt;&quot;rules&quot;&lt;/span&gt;: {
          &lt;span class=&quot;attr&quot;&gt;&quot;react/jsx-filename-extension&quot;&lt;/span&gt;: [
            &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;,
            { &lt;span class=&quot;attr&quot;&gt;&quot;extensions&quot;&lt;/span&gt;: [&lt;span class=&quot;string&quot;&gt;&quot;.tsx&quot;&lt;/span&gt;] }
          ],
          &lt;span class=&quot;attr&quot;&gt;&quot;import/extensions&quot;&lt;/span&gt;: [
            &lt;span class=&quot;string&quot;&gt;&quot;error&quot;&lt;/span&gt;,
            &lt;span class=&quot;string&quot;&gt;&quot;ignorePackages&quot;&lt;/span&gt;,
            {
              &lt;span class=&quot;attr&quot;&gt;&quot;ts&quot;&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;never&quot;&lt;/span&gt;,
              &lt;span class=&quot;attr&quot;&gt;&quot;tsx&quot;&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;never&quot;&lt;/span&gt;
            }
          ]
        }
      }
    ],
    &lt;span class=&quot;attr&quot;&gt;&quot;settings&quot;&lt;/span&gt;: {
      &lt;span class=&quot;attr&quot;&gt;&quot;import/parsers&quot;&lt;/span&gt;: {
        &lt;span class=&quot;attr&quot;&gt;&quot;@typescript-eslint/parser&quot;&lt;/span&gt;: [&lt;span class=&quot;string&quot;&gt;&quot;.ts&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;.tsx&quot;&lt;/span&gt;]
      },
      &lt;span class=&quot;attr&quot;&gt;&quot;import/resolver&quot;&lt;/span&gt;: {
        &lt;span class=&quot;attr&quot;&gt;&quot;typescript&quot;&lt;/span&gt;: {
          &lt;span class=&quot;attr&quot;&gt;&quot;alwaysTryTypes&quot;&lt;/span&gt;: &lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;
        }
      }
    }
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It’s a bit more scary for TypeScript, but this enables everything for the Airbnb style guide to
work properly with TypeScript.&lt;/p&gt;
&lt;h3 id=&quot;bonus-lint-from-command-line&quot;&gt;Bonus: lint from command line&lt;/h3&gt;
&lt;p&gt;If you’re using TypeScript it is now possible to lint your code from the command line too! Execute
the following command and it will lint all your TypeScript files:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;./node_modules/.bin/eslint . --ext .ts,.tsx&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;em&gt;Tip&lt;/em&gt;: add this as a script in your &lt;code&gt;package.json&lt;/code&gt; so your can run it more easily next time.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &lt;span class=&quot;attr&quot;&gt;&quot;scripts&quot;&lt;/span&gt;: {
    &lt;span class=&quot;attr&quot;&gt;&quot;lint&quot;&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;eslint . --ext .ts,.tsx&quot;&lt;/span&gt;  
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;wrapping-up&quot;&gt;Wrapping up&lt;/h2&gt;
&lt;p&gt;I hope this guide helped you in adding your favourite style guide to your Create React App project.&lt;/p&gt;
&lt;p&gt;It’s really cool to see that the project enables you to extend the ESLint config without having to
eject the project, which you should avoid doing at all times.&lt;/p&gt;
</description></item><item><title>Cleaning and Recycling Old Projects (or How I Simplified my Build)</title><link>https://gaya.pizza/articles/cleaning-recycling-old-projects/</link><pubDate>Tue, 18 Feb 2020 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/cleaning-recycling-old-projects/</guid><author></author><description>&lt;p&gt;Sometimes projects run for so long they get dusty. Not maintaining them will leave them to wither and slowly fade away. Even worse is when parts of your projects are too outdated to work and too scary to touch.&lt;/p&gt;
&lt;p&gt;I was writing for my blog occasionally, but the system it was built on was terribly outdated and didn’t work properly anymore. I haven’t had the courage or time to actually fix the underlying system. It was time to change this.&lt;/p&gt;
&lt;p&gt;In this article I want to take you through my process of dusting off and cleaning up an old project to breathe new life into it all without starting over completely from scratch.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/cleaning-recycling-old-projects&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/cleaning-recycling-old-projects/cleaning-recycling-old-projects-poster.jpg&quot; alt=&quot;Cleaning and Recycling Old Projects (or How I Simplified my Build)&quot; title=&quot;Cleaning and Recycling Old Projects (or How I Simplified my Build)&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-reason-for-cleaning-up&quot;&gt;The Reason for Cleaning up&lt;/h2&gt;
&lt;p&gt;Every time I wanted to write something on this blog, I had to make sure the conditions were perfect. The project ran on node.js version &lt;code&gt;0.10.35&lt;/code&gt; and didn’t install locally a lot of the times because of old packages which were out of date too.&lt;/p&gt;
&lt;p&gt;I was still able to deploy new content, but getting it all to work was a drag and made me dread writing new stuff. Such a shame, since I really like sharing knowledge.&lt;/p&gt;
&lt;p&gt;A solution was to write something new or learn from my previous mistakes and clean up. I choose the latter as creating something completely new from scratch could potentially introduce the same problems I have right now.&lt;/p&gt;
&lt;h2 id=&quot;the-goal&quot;&gt;The Goal&lt;/h2&gt;
&lt;p&gt;What I wanted to achieve is a much &lt;strong&gt;simpler build pipeline&lt;/strong&gt; whilst &lt;strong&gt;not changing too much&lt;/strong&gt; about the source material I had to work with.&lt;/p&gt;
&lt;p&gt;I also wanted to clean the project of old and out-of-date dependencies and upgrade the required node.js version to a recent one.&lt;/p&gt;
&lt;p&gt;The static site generator I am using, &lt;code&gt;wintersmith&lt;/code&gt;, still serves its purpose perfectly, and I am not looking to replace it. This part will stay as is.&lt;/p&gt;
&lt;h2 id=&quot;too-complicated-to-replace&quot;&gt;Too Complicated to Replace&lt;/h2&gt;
&lt;p&gt;Have you ever had that feeling in a project where you looked at a piece of code or pipeline and thought: &lt;em&gt;“Well… I am not touching that.”&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This is even more painful when that part of a project was introduced by yourself. But now imagine how complicated and confusing this must be for &lt;strong&gt;another person&lt;/strong&gt; looking at it.&lt;/p&gt;
&lt;p&gt;My blog had a pretty intricate way of building all its assets. All HTML content was statically generated, and that was perfectly fine to be honest. However, a large portion of the other assets were generated using various &lt;code&gt;gulp&lt;/code&gt; tasks. Remember that? These were all painfully outdated and were not working anymore.&lt;/p&gt;
&lt;p&gt;I needed to change this, because &lt;strong&gt;it’s better to write code that is easy to delete, rather than easy to extend&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&quot;moving-to-npm-scripts-instead-on-gulp-or-grunt-&quot;&gt;Moving to NPM scripts instead on Gulp (or Grunt)&lt;/h2&gt;
&lt;p&gt;These days we have great web app bundlers like &lt;code&gt;webpack&lt;/code&gt; which take a lot of manual pipeline building we used to do out of our hands. Every dependency is managed in our JavaScript bundles through importing. But that wasn’t the case before.&lt;/p&gt;
&lt;p&gt;There used to be a great interest in task running tools like &lt;code&gt;grunt&lt;/code&gt; and &lt;code&gt;gulp&lt;/code&gt;. These tools were not a bad idea, and allowed us to streamline our development processes.&lt;/p&gt;
&lt;p&gt;What happened is that we lost sight of what we were really doing. Most of the stuff we were writing for these task runners could easily be &lt;strong&gt;just a short CLI command&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;And this is exactly how I plan to solve the generating of my assets. Your old projects could possibly benefit from this too. Simplifying these step and moving them to a more streamlined bundling strategy will prevent over complicating your build pipeline.&lt;/p&gt;
&lt;h2 id=&quot;but-what-about-watchers-&quot;&gt;But what about watchers?&lt;/h2&gt;
&lt;p&gt;Yes, sure. Watchers are a nice to have, and &lt;code&gt;grunt&lt;/code&gt; and &lt;code&gt;gulp&lt;/code&gt; were mostly used for that, but can be replaced if you want.&lt;/p&gt;
&lt;p&gt;Tools like &lt;code&gt;webpack&lt;/code&gt; can be integrated with &lt;code&gt;webpack-dev-server&lt;/code&gt; which allow to generate assets on change. You can also use file watchers in IDEs or in CLI to allow for a more streamlined development process.&lt;/p&gt;
&lt;p&gt;For my blog this was not needed as the HTML, CSS, and the JS part of the project had already been written.&lt;/p&gt;
&lt;p&gt;The static generator I use already has a watcher functionality build into their cli tool, so I can use that for writing.  &lt;/p&gt;
&lt;h2 id=&quot;simplify-javascript-bundles&quot;&gt;Simplify JavaScript Bundles&lt;/h2&gt;
&lt;p&gt;First thing to fix was my JavaScript. I was inspecting what I was using and came to the conclusion that &lt;strong&gt;I could throw away&lt;/strong&gt; everything except one small part which is handling how my header menu is rendered.&lt;/p&gt;
&lt;p&gt;Previously it was bundling a couple of files using &lt;code&gt;browserify&lt;/code&gt; and &lt;code&gt;gulp&lt;/code&gt;. Then on release it was also minified using &lt;code&gt;Uglify&lt;/code&gt;. This resulted in a bundle at a whooping &lt;code&gt;46kb&lt;/code&gt;. Just for some minor tweaks and polyfills which were not even that necessary.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The web is becoming more and more bloated&lt;/strong&gt;, and I want to reduce the impact the best I can. So adding all this fluff didn’t make any sense. Especially since I was already putting a lot of effort in delivering content statically. &lt;/p&gt;
&lt;p&gt;If you run a website, blog, or something alike. Have a good look at what you’re serving your visitors. Do you really need all these scripts you include on every page? I bet you there is a lot you can save by not adding useless stuff.&lt;/p&gt;
&lt;p&gt;In the end I figured I could add a CLI command to &lt;code&gt;Uglify&lt;/code&gt; the source file and place it in an output folder. The bundle is now &lt;code&gt;680bytes&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;oh-my-sass&quot;&gt;Oh my Sass&lt;/h2&gt;
&lt;p&gt;The Sass part of the project was something I dreaded doing, but in the end it was one of the easiest parts to do. I copied the settings and options I used in &lt;code&gt;gulp&lt;/code&gt; and reused most of it.&lt;/p&gt;
&lt;p&gt;To my surprise, even after updating all the &lt;code&gt;sass&lt;/code&gt; dependencies, it worked just as expected.&lt;/p&gt;
&lt;h2 id=&quot;handling-image-assets&quot;&gt;Handling image assets&lt;/h2&gt;
&lt;p&gt;There were two parts to handling images. Copy static assets from the source folder to my &lt;code&gt;/public&lt;/code&gt; folder and afterwards optimise all the images in the &lt;code&gt;/public&lt;/code&gt; folder. &lt;/p&gt;
&lt;p&gt;Because &lt;code&gt;wintersmith&lt;/code&gt; automatically copies over post assets, these were all already in the correct folders. I added a simple &lt;code&gt;cp -r ./src/images ./public&lt;/code&gt; to my NPM scripts to copy my other images to &lt;code&gt;/public/images&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The most complicated part of this redo is how I optimise images. I am using &lt;code&gt;imagemin&lt;/code&gt; and sadly it doesn’t allow to scan for files and replace those with the optimised version in the same folder structures.&lt;/p&gt;
&lt;p&gt;So I wrote a script in node.js which looks for all images in &lt;code&gt;/public&lt;/code&gt;, optimises them one by one and saves them in the same place.&lt;/p&gt;
&lt;h2 id=&quot;the-result&quot;&gt;The Result&lt;/h2&gt;
&lt;p&gt;In just a few hours &lt;strong&gt;I removed a lot of unneeded dependencies&lt;/strong&gt; and am able to run my blog locally again. I didn’t replace every part, and I &lt;strong&gt;didn’t opt-in to use the latest shiny technology stacks&lt;/strong&gt;. What I did do was &lt;strong&gt;get rid of a lot of complicated steps&lt;/strong&gt; in building my blog.&lt;/p&gt;
&lt;p&gt;I have a project right now that I know is easier to maintain since I chopped up the build pipeline is smaller easy to replace steps.&lt;/p&gt;
&lt;p&gt;You can see all the steps needed in the &lt;a href=&quot;https://github.com/Gaya/gaya.pizza/blob/main/package.json&quot;&gt;package.json file&lt;/a&gt; of my blog’s repository. All the step required can be executed by running &lt;code&gt;npm run build&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now The project feels a lot cleaner and nicer to work with. You do not have to throw away all previous effort to refresh and clean up your projects.&lt;/p&gt;
</description></item><item><title>Leveraging Hooks to Fetch Data Async in React</title><link>https://gaya.pizza/articles/leveraging-hooks-fetch-data-async-react/</link><pubDate>Tue, 25 Jun 2019 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/leveraging-hooks-fetch-data-async-react/</guid><author></author><description>&lt;p&gt;Most of the React mindset is thinking synchronous and has a lot of similarities with functional programming. Output is generated based on input and is calculated at each render. This means that handling information which is not available at the moment of rendering a bit harder.&lt;/p&gt;
&lt;p&gt;This article aims to give a solution to this problem using React Hooks.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/leveraging-hooks-fetch-data-async-react&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/leveraging-hooks-fetch-data-async-react/async_fetch_hooks_poster_1.jpg&quot; alt=&quot;Leveraging Hooks to Fetch Data Async in React&quot; title=&quot;Leveraging Hooks to Fetch Data Async in React&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;We’re used to using lifecycle methods to fetch data on component mount or when props change, and it’s always something you have to implement outside of your render function. We don’t want render functions causing side-effects.&lt;/p&gt;
&lt;p&gt;Luckily for us, &lt;a href=&quot;https://reactjs.org/docs/hooks-intro.html&quot;&gt;React Hooks&lt;/a&gt; came out not too long ago which allows us to have side-effects and local state for functional (pure) components.&lt;/p&gt;
&lt;h2 id=&quot;managing-data&quot;&gt;Managing Data&lt;/h2&gt;
&lt;p&gt;In an ideal situation, we’d request data at render of a component, and re-render the component when the data has resolved. Without state, we could only rely on the parent components to pass the correct data to functional components.&lt;/p&gt;
&lt;p&gt;The container / presentation component principle works for this situation, but made for kind of complex container components in the end. Data is fetched on mount, a loading state is managed, and when the data is received it had to be updated. It even gets more complex when working with a state management solution like Redux.&lt;/p&gt;
&lt;p&gt;Wouldn’t it be cool if we could request the data in the render function itself?&lt;/p&gt;
&lt;h2 id=&quot;async-data-fetching-is-a-side-effect&quot;&gt;Async Data Fetching is a Side-effect&lt;/h2&gt;
&lt;p&gt;A possible solution to handling async data is to threat resolving data as a side-effect. In the render function, we request the data using a hook. This hook will return the found data, if the data is still loading, and if there was an error fetching.&lt;/p&gt;
&lt;p&gt;It’s a lot easier to reason about this information then having a lot of state triggering all over your app. The hook itself will handle the fetching, data resolving and error catching.&lt;/p&gt;
&lt;p&gt;I tried to make the idea more clean using a flow diagram of how everything would play out using hooks:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/leveraging-hooks-fetch-data-async-react/hooks-flow.png&quot; alt=&quot;React Hooks Data Fetch Flow&quot;&gt;&lt;/p&gt;
&lt;p&gt;First the component will request the data from the hook. It will return nothing, as it has nothing, but also tells the component it is loading.&lt;/p&gt;
&lt;p&gt;The hook will fire a side-effect and remembers it is busy. When the data is resolved it will update its state internally with the data it resolved. It will also update itself to a non-loading state. Updating the local state of the hook will tell React to re-render the component using the hook.&lt;/p&gt;
&lt;p&gt;The component renders and requests the data again, but this time the data will resolve immediately, resulting in rendering of the data.&lt;/p&gt;
&lt;h2 id=&quot;advantages-of-lifecycle-hooks&quot;&gt;Advantages of Lifecycle Hooks&lt;/h2&gt;
&lt;p&gt;You might ask yourself what the point is if we can do the same with state in the component and lifecycle hooks. The big difference here is that we can treat data fetching as a side-effect to data changing in the component.&lt;/p&gt;
&lt;p&gt;If you want to fetch a profile based on the props, the profile data will be re-fetched once that information changes, automatically, without using lifecycle hooks. This is because &lt;code&gt;useEffect&lt;/code&gt; is intelligent enough to trigger only when its dependency array changes.&lt;/p&gt;
&lt;p&gt;Another great feature of hooks is that you can use it in any functional component without duplicating functionality across different component classes.&lt;/p&gt;
&lt;p&gt;Hiding the handling of async data fetching in a hook makes the app a lot easier to reason about and prevents a lot of boilerplate code. A lot of Redux based applications suffer from this, which is not a problem of Redux, but the approach we take fetching data there.&lt;/p&gt;
&lt;h2 id=&quot;a-simple-example&quot;&gt;A Simple Example&lt;/h2&gt;
&lt;p&gt;For the purpose of illustration I made a simple example app of how this hook can be implemented in your own applications.&lt;/p&gt;
&lt;p&gt;Full code to this example can be found at &lt;a href=&quot;https://github.com/Gaya/fetch-with-react-hooks/tree/master/src&quot;&gt;https://github.com/Gaya/fetch-with-react-hooks/tree/master/src&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The app has a component which displays profile information. It will request the data using a &lt;code&gt;Promise&lt;/code&gt;. The profile will be loaded each time the requested profile id changes.&lt;/p&gt;
&lt;h3 id=&quot;writing-the-data-fetching-mechanism&quot;&gt;Writing the Data Fetching Mechanism&lt;/h3&gt;
&lt;p&gt;First, let’s write the profile fetching mechanism inside our functional component:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; id = &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;;
&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; resolver = React.useCallback(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;params&quot;&gt;()&lt;/span&gt; =&amp;gt;&lt;/span&gt; fetchProfile(id), [id]);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We use &lt;code&gt;useCallback&lt;/code&gt; to prevent React from creating a new function each time the component renders.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;fetchProfile&lt;/code&gt; is a function which returns a &lt;code&gt;Promise&lt;/code&gt; and resolves the requested profile information. &lt;a href=&quot;https://github.com/Gaya/fetch-with-react-hooks/blob/master/src/fetch.js&quot;&gt;Read the implementation on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;preparing-the-hook&quot;&gt;Preparing the Hook&lt;/h3&gt;
&lt;p&gt;We want to create a hook which will except the resolver from before and use it to return the data to use when it’s ready. It’s also good to have a loading state and error state would anything go wrong. The basis of the hook could look like the following.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; { useState } &lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;'react'&lt;/span&gt;;

&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;usePromise&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;resolver&lt;/span&gt;) &lt;/span&gt;{
  &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; [isPending, setPending] = useState(&lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt;);
  &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; [error, setError] = useState(&lt;span class=&quot;literal&quot;&gt;undefined&lt;/span&gt;);
  &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; [resolvedValue, setValue] = useState(&lt;span class=&quot;literal&quot;&gt;undefined&lt;/span&gt;);

  &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; [resolvedValue, isPending, error];
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I am not using &lt;code&gt;useReducer&lt;/code&gt; to keep the example as simple as possible. In this case it might be better to use &lt;code&gt;useReducer&lt;/code&gt;, but for now let’s stick with &lt;code&gt;useState&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This hook will be called in our logic component after the resolver we created earlier:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; [profile, isPending, error] = usePromise(resolver);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If there is an error, we can render an error component. If the &lt;code&gt;Promise&lt;/code&gt; is still pending, we can render a loader. If all is good, we can render the profile data. It’s as simple as that!&lt;/p&gt;
&lt;h3 id=&quot;writing-the-resolve-mechanism&quot;&gt;Writing the Resolve Mechanism&lt;/h3&gt;
&lt;p&gt;Now we want to resolve the &lt;code&gt;Promise&lt;/code&gt; provided to the hook as a side-effect of the hook being called.&lt;/p&gt;
&lt;p&gt;We’re going to introduce &lt;code&gt;useEffect&lt;/code&gt; for this to actually resolve and handle the &lt;code&gt;Promise&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Here you’ll see why the &lt;code&gt;useCallback&lt;/code&gt; from earlier is important. We’re going to use the callback function to trigger the side-effect.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; { useState, useEffect } &lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;'react'&lt;/span&gt;;

&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;usePromise&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;resolver&lt;/span&gt;) &lt;/span&gt;{
  &lt;span class=&quot;comment&quot;&gt;// ... code from previous snippet&lt;/span&gt;

  useEffect(
    &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;params&quot;&gt;()&lt;/span&gt; =&amp;gt;&lt;/span&gt; {
      &lt;span class=&quot;comment&quot;&gt;// reset hook state values&lt;/span&gt;
      setPending(&lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;);
      setError(&lt;span class=&quot;literal&quot;&gt;undefined&lt;/span&gt;);

      &lt;span class=&quot;comment&quot;&gt;// resolve the Promise&lt;/span&gt;
      resolver()
        .then(&lt;span class=&quot;function&quot;&gt;(&lt;span class=&quot;params&quot;&gt;value&lt;/span&gt;) =&amp;gt;&lt;/span&gt; {
          setValue(value);
        })
        .catch(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;params&quot;&gt;e&lt;/span&gt; =&amp;gt;&lt;/span&gt; {
          setError(e);
        })
        .then(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;params&quot;&gt;()&lt;/span&gt; =&amp;gt;&lt;/span&gt; {
          setPending(&lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt;);
        });
    },
    &lt;span class=&quot;comment&quot;&gt;// if resolver changes, resolve again&lt;/span&gt;
    [resolver],
  );

  &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; [resolvedValue, isPending, error];
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each time the resolver changes, the side-effect will be triggered. If you didn’t use &lt;code&gt;useCallback&lt;/code&gt; to wrap the resolver, it would trigger each render.&lt;/p&gt;
&lt;p&gt;On each trigger of the side-effect we’ll reset the state values of the hook and set the pending state to &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Next we try to resolve the &lt;code&gt;Promise&lt;/code&gt;. If it succeeds it will update the value stored in the hook state. If it fails, it will set the error returned to the hook state. In the end, whether it failed or succeeded, we’ll tell the hook it’s no longer pending.&lt;/p&gt;
&lt;p&gt;This will instruct React to re-render the component using the hook because the state inside the hook changed.&lt;/p&gt;
&lt;p&gt;When the component calls the hook this next time, it will get the resolved data back.&lt;/p&gt;
&lt;h2 id=&quot;further-thoughts&quot;&gt;Further Thoughts&lt;/h2&gt;
&lt;p&gt;The reason I came up with this strategy for fetching and handling async data was because I was finding different ways to handle Redux fetching and side effects.&lt;/p&gt;
&lt;p&gt;I bet this way of fetching data async has been described before in a similar form, but I wanted to get it out here to share my thoughts on it.&lt;/p&gt;
&lt;p&gt;The way I use it with Redux, or any context based approach is that the data to be fetched can also be cached. I wanted to have a selector which would result in: the data I selected, a loading state, or an error.&lt;/p&gt;
&lt;p&gt;Redux in turn would fire the fetching of data as a side-effect when the data resulted from the selector proved non-existent. The resulting request would then fail or succeed.&lt;/p&gt;
&lt;p&gt;Dispatching data received / fetch failed would happen as a side-effect just like my example before.&lt;/p&gt;
&lt;p&gt;We can prevent the making complex constructions like this and make our apps easier to read and understand.&lt;/p&gt;
&lt;h2 id=&quot;in-closing&quot;&gt;In Closing&lt;/h2&gt;
&lt;p&gt;I keep falling in love with React Hooks more and more. The way we can approach problems is so much more clear and easy to follow right now. It’s almost a crime how complicated we were making things before. Luckily we can reason about what we make a lot easier using hooks.&lt;/p&gt;
&lt;p&gt;I hope you liked reading about this and started thinking about other great stuff you could solve using hooks and side-effects. Feel free to reach out if you have any questions regarding my solution.&lt;/p&gt;
</description></item><item><title>The Value of Not Working</title><link>https://gaya.pizza/articles/the-value-of-not-working/</link><pubDate>Wed, 06 Mar 2019 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/the-value-of-not-working/</guid><author></author><description>&lt;p&gt;Since going freelance I learned about the value of not working at all, and how it affects me and my
work when I actually do work for clients.&lt;/p&gt;
&lt;p&gt;These are my insights in how I feel like I struck a good balance between working for clients and
working on my own projects (or not working at all).&lt;/p&gt;
&lt;p&gt;This article is not strictly meant for freelancers, but also people working on a payroll.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/the-value-of-not-working/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/the-value-of-not-working/not-working-poster.jpg&quot; alt=&quot;The Value of Not Working&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;short-attention-span&quot;&gt;Short Attention Span&lt;/h2&gt;
&lt;p&gt;I’ve worked at quite a few companies, some better than others, but never have I worked at a
single company for too long. I have never hit the five year mark anywhere I have worked.&lt;/p&gt;
&lt;p&gt;A lot of times I felt stuck in the work I was doing, and could not get out of it. Of course there
were times I could have talked about it more, but at the time I did not really know why I felt like
I did.&lt;/p&gt;
&lt;p&gt;I get bored way too easily when I solve the same problem repeatedly. Even if this problem is 
something other people were not so good at solving. I could not find joy in doing these tasks at a
certain point.&lt;/p&gt;
&lt;p&gt;This resulted in me searching for new challenges outside of what I was doing at the time. Meaning I
switched jobs quite a few times. &lt;/p&gt;
&lt;h2 id=&quot;how-i-tried-to-keep-myself-motivated&quot;&gt;How I Tried to Keep Myself Motivated&lt;/h2&gt;
&lt;p&gt;A possible solution to my problem was to work a lot more on my side-projects in my free time, which
I started doing a lot more over the years. This rekindled the excitement for the work I was doing
for a while.&lt;/p&gt;
&lt;p&gt;This also made it quite clear that I love working on my own projects more than working on actual
work I did at the office day in day out.&lt;/p&gt;
&lt;p&gt;I asked to work a day less, and my employer at the time thought it was a great idea. The money which
I earned was still enough to support my lifestyle, so I could afford to do this. Yes, I earned less
money than I did before, but all that did not matter to me, because I valued my free time over time
I spent at the office.&lt;/p&gt;
&lt;h2 id=&quot;picking-myself-over-job-security&quot;&gt;Picking Myself Over Job Security&lt;/h2&gt;
&lt;p&gt;After about two years of working less and working more on my own projects I felt like I still wanted
to spend more time working on my own side-projects.&lt;/p&gt;
&lt;p&gt;That’s when I decided it was time for me to get a more risky about my approach to work. Take on jobs
as a freelancer and allow my side-projects to fill in the rest of the time I have left during the
week.&lt;/p&gt;
&lt;p&gt;Essentially giving up on the security a job at a company gave me, and making sure I could manage to
get clients to hire me to support my life.&lt;/p&gt;
&lt;h2 id=&quot;say-no-more-often&quot;&gt;Say “No” More Often&lt;/h2&gt;
&lt;p&gt;I cannot stress this enough. Part of knowing what is good for you, is knowing when to say “no”.&lt;/p&gt;
&lt;p&gt;When working at companies I’ve always felt like “no” was not an option most of the time. Saying
“no” means refusing to work, and thus going against the contract you signed when you started working
for them.&lt;/p&gt;
&lt;p&gt;I know this is not entirely true as you can most likely talk about certain situations, but a lot of
times saying “no” is actually not an option. A lot of decisions about where the company is heading
are out of your hands.&lt;/p&gt;
&lt;p&gt;It is important to share what you think with the company you’re working for. Being able to discuss
the work you’re doing and steering it in an enjoyable direction is really important. Being able to
say “no” to questions makes your wishes more clear, and people know what to expect from you.&lt;/p&gt;
&lt;p&gt;The same goes for when you are a freelancer. For me right now, I could say “yes” to every job offer
and can take on as much work as I possibly can, but I choose not to. Saying “no” has given me the 
room to know what is good for me, and what is not.&lt;/p&gt;
&lt;p&gt;I’d rather be honest about not wanting to do something and telling them someone else can probably do
it better and cheaper, than to take on a job I did not want to do in the first place.&lt;/p&gt;
&lt;h2 id=&quot;do-work-which-works-in-your-favour&quot;&gt;Do Work Which Works in Your Favour&lt;/h2&gt;
&lt;p&gt;Saying “no” more often also leads to being able to pick work which you feel more comfortable with. I
have found that I’d rather not take on any new clients for months than to take on work which I know
will not improve me in some way.&lt;/p&gt;
&lt;p&gt;If the job allows me to explore some new territories and if I can learn something on the job I am
always more likely to find enjoyment in it. An ideal job at a company would look like this for me,
but that is really hard to come by.&lt;/p&gt;
&lt;p&gt;However, going freelance has allowed me to do this. I know I am in a lucky position as the things I
do are quite niche and there is a lot of market for it, but to not take advantage of this situation 
would be foolish.&lt;/p&gt;
&lt;h2 id=&quot;side-projects-are-an-investment&quot;&gt;Side Projects Are an Investment&lt;/h2&gt;
&lt;p&gt;I grade the work I do on side-projects just as important as the work I do for clients. Sure, the
work I do for clients brings in money on the short term, the time invested in side-projects will
pay off in the long run.&lt;/p&gt;
&lt;p&gt;Every minute I spend working on side-projects is a learning experience for me. I get to test out
new unexplored technologies, I get to try some solutions to problems, I will take the time to
actually learn something new.&lt;/p&gt;
&lt;p&gt;What I learn from the failures and successes of these projects I will bring into the work I do for
clients. This results in better work for my clients, which in turn will lead to better job offers.&lt;/p&gt;
&lt;p&gt;I view working on side-projects as work too. Some might say you’re “not working”, but it is just as
important as regular work to me, maybe even more important.&lt;/p&gt;
&lt;h2 id=&quot;strike-a-good-work-life-balance&quot;&gt;Strike a Good Work / Life Balance&lt;/h2&gt;
&lt;p&gt;It’s hard to invest a lot of time in side-projects when you have a full-time job. That’s the reason
why I quit my job before. It’s possible to do both, sure, but in my case I had too little time to
do all which I wanted to do.&lt;/p&gt;
&lt;p&gt;Some people value free time away from the desk more than others, but it’s important to make sure you
do not overwork yourself. Too much work leads to bad performance.&lt;/p&gt;
&lt;p&gt;I can determine my own pace when I am working on side-projects which gives me a lot of room to not
work at all. Taking time off from the desk job and doing something different. Something which can be
hard when working with strict times.&lt;/p&gt;
&lt;p&gt;Determining my own pace resulted in much better concentration and shorter bursts of inspiration for
me. These little bursts of output and inspiration are super valuable to me now. Something which
would previously cost me a day to do can sometimes be done in an hour, but at the same time the next
day I might not be feeling it at all and get nowhere.&lt;/p&gt;
&lt;p&gt;Being able to be more flexible about my schedule was allowed me to work more efficiently, but that
might not be the case for others. I’ve seen it backfire for some. &lt;/p&gt;
&lt;p&gt;That’s why I try to stop thinking in time and rather think in the value of the work that needs to be
done. No matter how you get there and how long it takes, the value of the outcome is always the
same to the client.&lt;/p&gt;
&lt;p&gt;Value does not equal the time you put into it. Just make sure you provide the value you promise. If 
that means you need to take more time off, do it, live a little.&lt;/p&gt;
&lt;h2 id=&quot;the-value-of-not-working&quot;&gt;The Value of Not Working&lt;/h2&gt;
&lt;p&gt;Side-projects have helped me see what’s important in my work life. It’s not about working all the
time, but finding the right things to do.&lt;/p&gt;
&lt;p&gt;Short term money does not the weigh up to the long term benefits of working on myself. In a way you
could say that not working is also working.&lt;/p&gt;
&lt;p&gt;Not working helps me reflect and improve. Helps me do the things I love in my field of work. It
shows me not to worry as much.&lt;/p&gt;
&lt;p&gt;I am sure my opinion and approach will change over time, and that is what makes life and work
exciting. There is always room for improvement and self-reflection.&lt;/p&gt;
&lt;p&gt;What I hope is that we can all find a great balance in the work we do. Everyone works in a different
way.&lt;/p&gt;
</description></item><item><title>Presenting Thyme Premium</title><link>https://gaya.pizza/articles/presenting-thyme-premium/</link><pubDate>Tue, 18 Dec 2018 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/presenting-thyme-premium/</guid><author></author><description>&lt;p&gt;At the start of this year I started working on &lt;a href=&quot;https://usethyme.com&quot;&gt;a little project called Thyme&lt;/a&gt;
to make tracking my time easier. &lt;/p&gt;
&lt;p&gt;Like a lot of services and apps, the idea came from having to manage data through Excel sheets, 
which did not really hold up in the long run.&lt;/p&gt;
&lt;p&gt;Almost a year of improving the platform here and there in my spare time &lt;strong&gt;I am launching my fun 
project&lt;/strong&gt; as a paid service!&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/presenting-thyme-premium/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/presenting-thyme-premium/thyme-poster.jpg&quot; alt=&quot;Presenting Thyme Premium&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 style=&quot;display: flex;&quot;&gt;
    &lt;a class=&quot;big-button&quot; href=&quot;https://usethyme.com/premium/&quot;&gt;Check out Thyme Premium&lt;/a&gt;
&lt;/h2&gt;

&lt;h2 id=&quot;why-thyme-&quot;&gt;Why Thyme?&lt;/h2&gt;
&lt;p&gt;Thyme is a privacy centric time tracker which is 100% private from the start. You don’t share your
data with 3th parties (and even Thyme itself!) by default, which in these days is a great thing to
have.&lt;/p&gt;
&lt;p&gt;Data is stored in the browser’s local storage, and can be exported at any time.&lt;/p&gt;
&lt;p&gt;Thyme is focused on being as simple as possible without too many bells and whistles which distract
you from what you want to do with a time tracker: just keep track of the time I spent doing stuff!&lt;/p&gt;
&lt;h2 id=&quot;why-not-a-different-service-&quot;&gt;Why not a different service?&lt;/h2&gt;
&lt;p&gt;Back when I first started to take on freelance jobs, I started writing down the start and end time
and the stuff I worked on for a client on paper.&lt;/p&gt;
&lt;p&gt;A while later I started writing it down in Excel sheets, which made calculation a bit easier, but
managing and entering the data didn’t feel right.&lt;/p&gt;
&lt;p&gt;What I really wanted was a simple web based app where I could fill in the same information and
create reports for clients for them to see how much time I spent on their projects.&lt;/p&gt;
&lt;p&gt;While searching for the perfect time tracker, I didn’t really find one which suited me, so I
thought it would be a fun challenge to build my own based on the techniques of local storage and
progressive web apps.&lt;/p&gt;
&lt;h2 id=&quot;what-is-thyme-premium-&quot;&gt;What is Thyme Premium?&lt;/h2&gt;
&lt;p&gt;Apart from all the regular free features Thyme offers, Thyme Premium allows you to have &lt;strong&gt;unlimited
syncing of timesheet data between devices&lt;/strong&gt;. Data you enter is safely stored in an encrypted format
only for you to read.&lt;/p&gt;
&lt;p&gt;All &lt;strong&gt;data you enter is safely backed up&lt;/strong&gt; every time you make a change.&lt;/p&gt;
&lt;p&gt;Premium also offers a way to add &lt;strong&gt;hourly rates&lt;/strong&gt; to projects you’re working on and have &lt;strong&gt;daily 
insights&lt;/strong&gt; in the time you spent on projects.&lt;/p&gt;
&lt;p&gt;I have many more features planned out which I want to share in a road map soon.&lt;/p&gt;
&lt;h2 id=&quot;completely-open-source&quot;&gt;Completely open source&lt;/h2&gt;
&lt;p&gt;Why trust me on my word if I can also show you how Thyme works internally? I have &lt;a href=&quot;https://github.com/ThymeApp&quot;&gt;open sourced all
of Thyme on Github&lt;/a&gt;. Allowing me to be as transparent about what
happens behind the scenes.&lt;/p&gt;
&lt;p&gt;Here you can check out how the app works, how the backend works, and you can even see my planned
work to start making plugins in Thyme possible.&lt;/p&gt;
&lt;h2 id=&quot;more-to-come&quot;&gt;More to come&lt;/h2&gt;
&lt;p&gt;I have a lot of nice things planned out for Thyme. If you have any suggestions or questions: feel
free to reach out!&lt;/p&gt;
</description></item><item><title>Two Sites on One Domain, with Netlify.</title><link>https://gaya.pizza/articles/two-sites-one-domain-netlify/</link><pubDate>Fri, 03  Aug 2018 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/two-sites-one-domain-netlify/</guid><author></author><description>&lt;p&gt;Recently I started hosting my open source projects on Netlify because of how easy (and free) it is.&lt;/p&gt;
&lt;p&gt;One of the web app projects I made was in need of a website, but I didn’t want to pollute the app’s
repository with the website’s source.&lt;/p&gt;
&lt;p&gt;I found out that it’s possible to have Netlify show multiple sites on the same domain name. I’ll try
to explain what the problem is I was trying to solve and how I solved it.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/two-sites-one-domain-netlify/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/two-sites-one-domain-netlify/netlify-poster.jpg&quot; alt=&quot;Two Sites on One Domain, with Netlify&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;A note before I begin. &lt;a href=&quot;https://netlify.com&quot;&gt;Netlify&lt;/a&gt; is &lt;strong&gt;not sponsoring&lt;/strong&gt; this article, nor
did I ever have contact with them about it. All views and opinions in this article are my own.&lt;/p&gt;
&lt;h2 id=&quot;the-situation&quot;&gt;The situation&lt;/h2&gt;
&lt;p&gt;At the beginning of this year I launched a &lt;a href=&quot;https://usethyme.com&quot;&gt;time tracking web application called Thyme&lt;/a&gt;. This little
web app was hosted on Netlify from the domain name &lt;a href=&quot;https://usethyme.com&quot;&gt;usethyme.com&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Netlify allows you to create a “site” which is based off a git repository. The Thyme application is
based on the &lt;a href=&quot;https://github.com/Gaya/thyme&quot;&gt;public repository on Github&lt;/a&gt;. Because the application
was bootstrapped using &lt;a href=&quot;https://github.com/facebook/create-react-app&quot;&gt;create-react-app&lt;/a&gt; it was
fairly easy for Netlify to recognize how it should build and host the app.&lt;/p&gt;
&lt;p&gt;Every time I update the &lt;em&gt;master&lt;/em&gt; branch on the Github repository, Netlify will automatically release
a new version of the app on &lt;a href=&quot;https://usethyme.com&quot;&gt;usethyme.com&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/two-sites-one-domain-netlify/netlify-diagram-1.png&quot; alt=&quot;Simple app deployment to Netlify&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;/h2&gt;
&lt;p&gt;After a while I decided that it would be good if the domain name &lt;a href=&quot;https://usethyme.com&quot;&gt;usethyme.com&lt;/a&gt;
was used as a front-face of the app. A website that details the functionality and has a bit of
documentation on the project. The app had to make room for this to happen.&lt;/p&gt;
&lt;p&gt;This meant I had to create a website that Netlify can update and publish to &lt;a href=&quot;https://usethyme.com&quot;&gt;usethyme.com&lt;/a&gt;.
I could add the website’s source to the application repository, but felt like it was best if I keep
both projects in a separate repository since I didn’t want people working on the application to get
the whole site too.&lt;/p&gt;
&lt;p&gt;It also worked the other way around. I didn’t want the website to be in control of the application’s
published version or have to update the website with an updated app each time.&lt;/p&gt;
&lt;p&gt;Netlify can assign a custom domain name to a site so the built version of the repository is hosted
on said domain. A solution to having two sites on a single domain name is using subdomains. Sadly
this was not a possibility for Thyme.&lt;/p&gt;
&lt;h2 id=&quot;why-not-just-a-subdomain-for-the-app-&quot;&gt;Why not just a subdomain for the app?&lt;/h2&gt;
&lt;p&gt;Since Thyme heavily relies on the usage of localStorage, moving to a different subdomain would mean
all the current users would loose their access to data already stored in the &lt;strong&gt;usethyme.com&lt;/strong&gt; storage.
If I were to put the application on &lt;strong&gt;app.usethyme.com&lt;/strong&gt; the localStorage data from &lt;strong&gt;usethyme.com&lt;/strong&gt;
wouldn’t be accessible for good security reasons.&lt;/p&gt;
&lt;p&gt;So what I had to figure out was if it was possible to have two separate Netlify sites, but have the
application running in a sub path of the website.&lt;/p&gt;
&lt;h2 id=&quot;the-solution&quot;&gt;The solution&lt;/h2&gt;
&lt;p&gt;When digging through the documentation of Netlify I found out you can &lt;a href=&quot;https://www.netlify.com/docs/redirects/#proxying&quot;&gt;proxy content through redirects&lt;/a&gt;.
That’s exactly what I needed! I can have &lt;strong&gt;usethyme.com/thyme&lt;/strong&gt; on my website act as if it is my app.&lt;/p&gt;
&lt;p&gt;All I had to change to the app was that it was being served from &lt;strong&gt;/thyme/&lt;/strong&gt; instead of &lt;strong&gt;/&lt;/strong&gt;. All the
routing done in the app and the assets would have to be accessible through &lt;strong&gt;usethyme.com/thyme&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/two-sites-one-domain-netlify/netlify-diagram-2.png&quot; alt=&quot;Combined site proxy in Netlify&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;the-application-part&quot;&gt;The application part&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;create-react-app&lt;/strong&gt; and &lt;strong&gt;react-router&lt;/strong&gt; allow you to do this quite easily, but you have to know where
to change the source.&lt;/p&gt;
&lt;p&gt;In order for &lt;strong&gt;react-router&lt;/strong&gt; to work in a sub path of a domain, you have to pass it a “basename”. In
my case, the following change was enough while setting up the “BrowserRouter”:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;BrowserRouter basename={process.env.PUBLIC_URL}&amp;gt;
  ...
&amp;lt;/BrowserRouter&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;WebPack and WebPack’s dev server provide &lt;code&gt;process.env.PUBLIC_URL&lt;/code&gt; while building and serving your
project. This will tell &lt;strong&gt;react-router&lt;/strong&gt; what to root of your application is and will act accordingly.&lt;/p&gt;
&lt;p&gt;For &lt;strong&gt;create-react-app&lt;/strong&gt; you have to tell the application what its public path is, which they call a
“homepage”. In your &lt;code&gt;package.json&lt;/code&gt; of the app add a property called “homepage” and add the path where
the app will be located.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{
  &amp;quot;homepage&amp;quot;: &amp;quot;/thyme/&amp;quot;
}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you’re not using &lt;code&gt;create-react-app&lt;/code&gt;, you can provide the &lt;code&gt;PUBLIC_URL&lt;/code&gt; to webpack through its
config to have the same outcome.&lt;/p&gt;
&lt;h3 id=&quot;the-netlify-part&quot;&gt;The Netlify part&lt;/h3&gt;
&lt;p&gt;For Netlify I had to make sure my website was being built and hosted correctly. I removed my custom
domain from my app’s site and added it to my website’s site in Netlify.&lt;/p&gt;
&lt;p&gt;Right now my app was not available on &lt;code&gt;usethyme.com&lt;/code&gt; anymore, but it would show my website. My app
was now living at &lt;code&gt;https://thyme.netlify.com&lt;/code&gt;. Using proxying I had to proxy all traffic to
&lt;code&gt;usethyme.com/thyme&lt;/code&gt; to &lt;code&gt;https://thyme.netlify.com/&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Using the example I came up with the following content for &lt;code&gt;_redirects&lt;/code&gt; (to be placed inside the
website’s root folder):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/thyme/*  https://thyme.netlify.com/:splat  200&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And it works perfectly! All my localStorage is still available to the application and my
application’s assets are proxied through to &lt;code&gt;usethyme.com/thyme&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A little side note though. Since &lt;code&gt;create-react-app&lt;/code&gt; uses service workers I had to put in a little
extra proxy line because the browser was not able to find the service worker in the website’s root.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/service-worker.js  https://thyme.netlify.com/service-worker.js  200&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;In theory, you can create as many sites as you’d like and make them available on a single domain name
using this method.&lt;/p&gt;
&lt;p&gt;If you like to keep your repositories clean, this is a great way to do it.&lt;/p&gt;
</description></item><item><title>React vs Vue pt. 1: JSX and Vue Template Syntax</title><link>https://gaya.pizza/articles/react-vs-vue-1-jsx-vue-template-syntax/</link><pubDate>Thu, 26 Apr 2018 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/react-vs-vue-1-jsx-vue-template-syntax/</guid><author></author><description>&lt;p&gt;For the last couple of years I’ve been working with React, and as of late I’ve been getting into Vue as well. A question lots of people ask me is:&lt;/p&gt;
&lt;p&gt;“So tell me, which one is better?”&lt;/p&gt;
&lt;p&gt;There is simply no short or correct answer to this question. There are a lot of factors which come into play. That’s why I wanted to start writing a mini-series on some topics which demonstrate differences between Vue and React and the pros and cons using either one of the frameworks.&lt;/p&gt;
&lt;p&gt;In this first instalment of this “React vs Vue“ series, I want to get into how both frameworks allow you to render content.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/react-vs-vue-1-jsx-vue-template-syntax/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/react-vs-vue-1-jsx-vue-template-syntax/react_vs_vue_1_og_image.jpg&quot; alt=&quot;React vs Vue pt. 1: JSX and Vue Template Syntax&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;how-to-render-&quot;&gt;How To Render?&lt;/h2&gt;
&lt;p&gt;Rendering content on the page is one of the most important things React and Vue do for us. Given some data and definitions of how to render will give the desired output. That is the promise they give us.&lt;/p&gt;
&lt;p&gt;First I want to take a look at how React does things. Which is mainly two different approaches. You can either go 100% plain old JavaScript or use JSX to simplify the process.&lt;/p&gt;
&lt;h2 id=&quot;jsx-createelement-and-render-in-react&quot;&gt;JSX, createElement, and render() in React&lt;/h2&gt;
&lt;p&gt;React uses a &lt;code&gt;render&lt;/code&gt; method in its components to create elements in the environment you’re running it in. I’ll take the browser and the DOM as the environment throughout this article.&lt;/p&gt;
&lt;p&gt;Every time React thinks it should update a component (and its children) it will run the &lt;code&gt;render()&lt;/code&gt; method of that component.
In this method, you’ll return a &lt;a href=&quot;https://reactjs.org/docs/rendering-elements.html&quot;&gt;React element&lt;/a&gt; which can, in turn, have nested children in it. Just like an HTML document is able to have.&lt;/p&gt;
&lt;p&gt;You can do this by using the &lt;a href=&quot;https://reactjs.org/docs/react-api.html#createelement&quot;&gt;&lt;code&gt;createElement&lt;/code&gt;&lt;/a&gt; function React provides. It creates the React element you need to return from the &lt;code&gt;render&lt;/code&gt; method.&lt;/p&gt;
&lt;p&gt;First it accepts what you want to create as its argument. Second is an object of props to pass to the element. And third is an array of children, all of which are React elements too.&lt;/p&gt;
&lt;p&gt;A simple example of this would be:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;class&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;Hello&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;React&lt;/span&gt;.&lt;span class=&quot;title&quot;&gt;Component&lt;/span&gt; &lt;/span&gt;{
  render() {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; React.createElement(
      &lt;span class=&quot;string&quot;&gt;'p'&lt;/span&gt;,
      &lt;span class=&quot;literal&quot;&gt;null&lt;/span&gt;,
      &lt;span class=&quot;string&quot;&gt;`Hello &lt;span class=&quot;subst&quot;&gt;${&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.props.what}&lt;/span&gt;!`&lt;/span&gt;,
    );
  }
}

&lt;span class=&quot;class&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;React&lt;/span&gt;.&lt;span class=&quot;title&quot;&gt;Component&lt;/span&gt; &lt;/span&gt;{
  render() {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; React.createElement(&lt;span class=&quot;string&quot;&gt;'div'&lt;/span&gt;, &lt;span class=&quot;literal&quot;&gt;null&lt;/span&gt;, [
      React.createElement(
        Hello,
        { &lt;span class=&quot;attr&quot;&gt;what&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;'world'&lt;/span&gt; },
        &lt;span class=&quot;literal&quot;&gt;null&lt;/span&gt;,
      ),
    ]);
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The HTML for this would look like:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;p&lt;/span&gt;&amp;gt;&lt;/span&gt;Hello world!&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;p&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;While this code looks very redundant, it’s the 100% JavaScript way of creating elements in React. Whenever &lt;code&gt;render()&lt;/code&gt; is triggered, it will execute this method once again to create all the elements to show on the page. You can put JavaScript expressions anywhere you’d like in this code, just like any other part of your JavaScript code.&lt;/p&gt;
&lt;p&gt;JSX is basically syntactical sugar around the &lt;code&gt;React.createElement&lt;/code&gt; function. It’s a custom syntax which is not part of JavaScript, but &lt;a href=&quot;https://babeljs.io/docs/plugins/transform-react-jsx/&quot;&gt;can be transpiled by a tool like Babel&lt;/a&gt;. If you choose to use JSX, you need to have a build system in place to handle this.&lt;/p&gt;
&lt;p&gt;The example above would look a bit different, but not that different if written in JSX.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;class&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;Hello&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;React&lt;/span&gt;.&lt;span class=&quot;title&quot;&gt;Component&lt;/span&gt; &lt;/span&gt;{
  render() {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;xml&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;p&lt;/span&gt;&amp;gt;&lt;/span&gt;Hello { this.props.what }!&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;p&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;;
  }
}

&lt;span class=&quot;class&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;React&lt;/span&gt;.&lt;span class=&quot;title&quot;&gt;Component&lt;/span&gt; &lt;/span&gt;{
  render() {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; (
      &lt;span class=&quot;xml&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;Hello&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;what&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;world&quot;&lt;/span&gt; /&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    );
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All JSX enables us to do is write shorter, easier to read and understand code to structure our React components. Your transpiler will eventually translate this code into something the browser can read, which is just using plain &lt;code&gt;React.createElement&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can use JavaScript expressions by using &lt;code&gt;{}&lt;/code&gt; anywhere in your JSX. Want to pass a JavaScript variable as a prop? No problem. Want to do some &lt;code&gt;map&lt;/code&gt; or &lt;code&gt;reduce&lt;/code&gt; on an array? You can do that.&lt;/p&gt;
&lt;p&gt;You only have to learn how JSX is transformed into plain JavaScript and that’s all there is to it.&lt;/p&gt;
&lt;h2 id=&quot;pros-and-cons-to-the-react-way&quot;&gt;Pros and cons to the React way&lt;/h2&gt;
&lt;p&gt;One &lt;strong&gt;con&lt;/strong&gt; I have experienced when getting into React was the mental change I had to go through not to think in templates. I came from a Model-View-Controller approach using templates for my views. One of the things that got me the most, in the beginning, was creating lists. You can return an array of children just like you would in a &lt;code&gt;for&lt;/code&gt; loop of a template language, but it just looked weird typing it like this.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;class&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;Example&lt;/span&gt; &lt;/span&gt;{
  render() {
    &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; names = [&lt;span class=&quot;string&quot;&gt;'John'&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;'Harry'&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;'Tom'&lt;/span&gt;];

    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; (
      &lt;span class=&quot;xml&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;ul&lt;/span&gt;&amp;gt;&lt;/span&gt;
        { names.map(name =&amp;gt; &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt;&amp;gt;&lt;/span&gt;{ name }&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt;&amp;gt;&lt;/span&gt;) }
      &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;ul&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    );
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;map&lt;/code&gt; method of the &lt;code&gt;names&lt;/code&gt; array will return a new array with React elements returned by the arrow function. It’s essentially the same &lt;code&gt;for&lt;/code&gt; loop, but you have to get used to it.&lt;/p&gt;
&lt;p&gt;Since data binding in React is just one way, you can not directly change values of a component, you have to explicitly tell React to update values of the state using &lt;code&gt;setState&lt;/code&gt;. This makes React prefer immutability, which is kind of hard to get into if you’re not used to it.&lt;/p&gt;
&lt;p&gt;A &lt;strong&gt;huge pro&lt;/strong&gt; which evolved out of this con is that you’ll become a lot better at making your components clean and lean. Everything has to work in a pure functional way and should always return the same result given the same input. Given any state or props, the component will always turn out the same, at least that’s the philosophy behind React.&lt;/p&gt;
&lt;p&gt;Another &lt;strong&gt;pro&lt;/strong&gt; is that everything you write is JavaScript in the end. You don’t need to learn a new templating language, you’re only learning how to use the React API to your advantage. The fact that everything is &lt;em&gt;just JavaScript&lt;/em&gt; makes this method very predictable.&lt;/p&gt;
&lt;p&gt;A &lt;strong&gt;con&lt;/strong&gt;, in turn, is that everything &lt;em&gt;is&lt;/em&gt; JavaScript, so there is not much to help you out of the box. For instance, the way I am rendering the list of names, I pass an arrow function inside of the &lt;code&gt;map&lt;/code&gt; method. This arrow function is created each time the &lt;code&gt;render&lt;/code&gt; method gets called, which could lead to performance issues. You see this a lot too when people want to bind &lt;code&gt;this&lt;/code&gt; on an event listener.&lt;br /&gt;
A solution to this is to bind or define all function before &lt;code&gt;render&lt;/code&gt; is called. In the &lt;code&gt;constructor&lt;/code&gt; of a component class for instance.&lt;/p&gt;
&lt;p&gt;This is also a &lt;strong&gt;pro&lt;/strong&gt; because it will teach you a lot about how JavaScript works. Maybe this a lot to take in when you first start out, but in the end, this will make you better understand how the language works and what its pitfalls are.&lt;/p&gt;
&lt;h2 id=&quot;vue-templates-and-render&quot;&gt;Vue templates and render&lt;/h2&gt;
&lt;p&gt;You can use &lt;a href=&quot;https://vuejs.org/v2/guide/syntax.html&quot;&gt;Vue templates&lt;/a&gt; right in your HTML document. Which makes it super easy to get started with. When a Vue component thinks it should render it will read the template written on the page and render all the elements and binds all events it needs to.&lt;/p&gt;
&lt;p&gt;A very basic example would look like:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;app&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
  Hello {{ what }}!
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;actionscript&quot;&gt;
&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; app = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; Vue({
  el: &lt;span class=&quot;string&quot;&gt;'#app'&lt;/span&gt;,
  data: {
    what: &lt;span class=&quot;string&quot;&gt;'world'&lt;/span&gt;,
  },
});
&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Vue allows you to do all kinds of great stuff in their templates. You can interpolate JavaScript values, you can set attributes with plain values or bind attributes to JavaScript values which live inside of the Vue component. You can do expressions too, to do some JavaScript calculation along the way.&lt;/p&gt;
&lt;p&gt;It has its own way of rendering conditionally, rendering lists, binding events, and binding form inputs. Binding events and form inputs can come in quite handy as things like these are not build-in into React. It does introduce a little bit of magic, but since it’s a templating language, that’s fine a lot of the time.&lt;/p&gt;
&lt;p&gt;However, if you feel like the template language is not suited for a case, or if you simply cannot achieve what you’d like using the template language, you can &lt;a href=&quot;https://vuejs.org/v2/guide/render-function.html&quot;&gt;use the &lt;code&gt;render&lt;/code&gt; method of a Vue component&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Yes. Vue too has a &lt;code&gt;render&lt;/code&gt; method and it also uses the same concept as React by providing a &lt;code&gt;createElement&lt;/code&gt; function.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;Vue.component(&lt;span class=&quot;string&quot;&gt;'hello'&lt;/span&gt;, {
  render(createElement) {
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; createElement(&lt;span class=&quot;string&quot;&gt;'h1'&lt;/span&gt;, {}, &lt;span class=&quot;string&quot;&gt;'Hello!'&lt;/span&gt;);
  }
})&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Instead of importing a function from Vue itself, Vue provides the &lt;code&gt;createElement&lt;/code&gt; function to use as the first argument of the &lt;code&gt;render&lt;/code&gt; method.&lt;/p&gt;
&lt;p&gt;Providing props and other data to &lt;code&gt;createElement&lt;/code&gt; works a bit different from React, as Vue is more of a complete framework which provides you with a lot of functionality out of the box.&lt;br /&gt;
You can read up on &lt;a href=&quot;https://vuejs.org/v2/guide/render-function.html#The-Data-Object-In-Depth&quot;&gt;the Vue data object&lt;/a&gt; in details in their docs.&lt;/p&gt;
&lt;h2 id=&quot;two-way-binding-and-event-binding&quot;&gt;Two-way binding and Event binding&lt;/h2&gt;
&lt;p&gt;A concept which is used in Vue is two-way binding. People coming from Angular will definitely recognise this concept. Let’s say we have an input in our Vue component we keep track of the value. We want the input to be able to adjust the value in the Vue component’s data, but when the Vue’s data changes: the input value should change too. Vue does this through the &lt;code&gt;v-model&lt;/code&gt; on inputs. Vue also allows components to use two-way binding using &lt;code&gt;v-model&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Events on elements can be directed to a method inside of your Vue component or can execute a JavaScript expression. The thing that comes in handy here is that &lt;code&gt;this&lt;/code&gt; is automatically bound to the current Vue component you’re in. So you do not need to go and bind &lt;code&gt;this&lt;/code&gt; to the functions passed into event handlers.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;app&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
  Count: {{ count }}
  &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;button&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;v-on:click&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;increment&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;value&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;Increment&quot;&lt;/span&gt; /&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;button&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;v-on:click&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;count = count - 1&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;value&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;Decrement&quot;&lt;/span&gt; /&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;actionscript&quot;&gt;
&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; app = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; Vue({
  el: &lt;span class=&quot;string&quot;&gt;'#app'&lt;/span&gt;,
  data: {
    count: &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;,
  },
  methods: {
    increment() {
      &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.count = &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.count + &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;;
    },
  },
});
&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The benefit here is you have to write less code and know all is handled well under the hood.&lt;/p&gt;
&lt;p&gt;Another great thing about event binding in Vue is that they allow you to use &lt;a href=&quot;https://vuejs.org/v2/guide/events.html#Event-Modifiers&quot;&gt;event modifiers&lt;/a&gt;. They give you a simple way to bind modified event handlers on components. For instance, automatically do &lt;code&gt;event.preventDefault&lt;/code&gt; before executing the function you bound to an element.&lt;/p&gt;
&lt;h2 id=&quot;pros-and-cons-of-vue-template-language&quot;&gt;Pros and cons of Vue template language&lt;/h2&gt;
&lt;p&gt;I want to start of with a &lt;strong&gt;pro&lt;/strong&gt; off using Vue templates. It’s quite easy to get going pretty quick. Most developers are familiar with using template languages and it does kind of resemble the outcome you’re expecting in HTML.&lt;/p&gt;
&lt;p&gt;The downside, however, is that you have to learn a new templating language. And that, in my opinion, is quite a &lt;strong&gt;big con&lt;/strong&gt;. A lot of the times I am found reading the template language documentation pages over and over, to see what I am missing or just simply how to do something like a conditional rendering again. I know it’s part of learning a framework like Vue, but outside of Vue, this skill is kind of useless.&lt;/p&gt;
&lt;p&gt;A &lt;strong&gt;pro&lt;/strong&gt; I cannot ignore is the event binding on elements. It’s just so convenient. You have to accept the magic happening under the hood though. Everything inside Vue templates gets an automatic &lt;code&gt;this&lt;/code&gt; reference. So instead of writing &lt;code&gt;{{ this.name }}&lt;/code&gt; inside of the templates you just write &lt;code&gt;{{ name }}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;What I also found is that using JavaScript expressions and references to data inside of my components always feel like a guessing game. I often times think to myself: “Will this work?”. Sometimes it does. sometimes it doesn’t. That’s because of all the magic happening out of sight and that can become a little dangerous. I consider this a &lt;strong&gt;con&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Small pro&lt;/strong&gt;, some people like to keep their templates out of their JavaScript (and think JSX is also a template). Vue templates do that, so it gives the illusion of separation of concerns. I don’t see JSX as being the template, it’s just a way to structure &lt;code&gt;createElement&lt;/code&gt; code.&lt;/p&gt;
&lt;p&gt;I found myself reaching for the &lt;code&gt;render&lt;/code&gt; method at some points. There where situations where the templating language didn’t have enough power to provide me with the functionality I needed, which is fine, but most of the times when I was using the templating language I just wanted to turn to the &lt;code&gt;render&lt;/code&gt; function again. I know you can use JSX in Vue if you want, but I don’t really see it used a lot in examples or in the community’s code. I’d stay away from it and use templates as much as possible.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;With this article, I hope to have giving you a clear look at how React and Vue handle the creation of documents.&lt;/p&gt;
&lt;p&gt;To me there is no clear winner here, it all depends on what you like more. If you’re not afraid of learning a template language and don’t have too complex components, Vue is pretty sweet.&lt;/p&gt;
&lt;p&gt;Vue helps the developer solve a lot of “hard” stuff which is not baked into React. React on the other hand allows the developer more control over how the code works.&lt;/p&gt;
&lt;p&gt;My personal preference goes to React + JSX, not just because I don’t like templating languages in general, but because it’s just JavaScript, and it made me a way better developer than I used to be, being way more conscious about what I was doing.&lt;/p&gt;
</description></item><item><title>Going Freelance Changed Me</title><link>https://gaya.pizza/articles/going-freelance-changed-me/</link><pubDate>Thu, 15 Feb 2018 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/going-freelance-changed-me/</guid><author></author><description>&lt;p&gt;As some of you might know, I quit my day job last September to focus on my own projects and go
freelance at the same time.&lt;/p&gt;
&lt;p&gt;A lot has happened in the meantime, so I thought it would be nice to share my experiences so far.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;before-going-freelance&quot;&gt;Before going freelance&lt;/h2&gt;
&lt;p&gt;Quitting my day job was a very hard decision. There were a lot of possible problems and challenges I
had to take into account. I had just a little bit of extra funds to last me a few months, but I knew
that when those funds were going to run out, I would have to have some sort of income to support my
life.&lt;/p&gt;
&lt;p&gt;I also had a job to leave which I also liked. The team I worked in was nice, the work I did was
good. Leaving something like that behind is always a big risk, it’s possible you’ll never find
anything like that again. And who is to say I’ll like freelancing better?&lt;/p&gt;
&lt;p&gt;When I talked about the idea of quitting my job and going freelance on the side, people were saying:
“Oh, you’ll do just fine! Do not worry.”. Which at the time made me even more nervous, what if it
all doesn’t work out? What if I am going to be a complete failure at this?&lt;/p&gt;
&lt;p&gt;The thing that got me to take the leap of faith was when I was talking with someone about a personal
project I was working on. He ended up asking me how much I would need to start doing it full time,
he was willing to invest that.&lt;/p&gt;
&lt;p&gt;It really got me thinking: if people are willing to invest in an idea, why should I not believe in
taking this opportunity to go totally freelance? And if all else fails… I could probably try and
find myself a new job.&lt;/p&gt;
&lt;h2 id=&quot;the-period-after-quitting&quot;&gt;The period after quitting&lt;/h2&gt;
&lt;p&gt;The first few weeks after quitting I spent letting people around me and my professional network
(whatever that is) know that I went freelance. The number of responses I got was overwhelming,
which I never expected when I first made the decision to quit.&lt;/p&gt;
&lt;p&gt;In the beginning, I wanted to focus working on my own projects, so I politely declined work. I was
also feeling a bit insecure about accepting work from people I’ve never met and do not know
personally.&lt;/p&gt;
&lt;p&gt;In these two months of not accepting any jobs I discovered the amount of work which is out there for
me to do, which made me worry less about my financial future, and in turn allowed me to focus on the
work I was doing.&lt;/p&gt;
&lt;h2 id=&quot;accepting-my-first-contract-job&quot;&gt;Accepting my first contract job&lt;/h2&gt;
&lt;p&gt;After a while, I got an email from one of my first employers to have a talk about possibly doing
some work for them. They needed my expertise for an in-house project.&lt;/p&gt;
&lt;p&gt;This was a perfectly scoped and low risk assignment, perfect to start out with. Familiar faces and
people I already knew how to work with.&lt;/p&gt;
&lt;p&gt;It felt really good to accept my first official job as a freelance web developer. It was all
beginning to look like I made the right choice.&lt;/p&gt;
&lt;h2 id=&quot;responsibilities-and-being-more-responsible&quot;&gt;Responsibilities and being more responsible&lt;/h2&gt;
&lt;p&gt;Because I only worked a couple of days a week, it felt like I had to take a lot of responsibility
moving the project forward. A feeling which has never been as strong before.&lt;/p&gt;
&lt;p&gt;In my day jobs, I usually found myself struggling to find motivation and inspiration to give my
absolute best for the tasks and features at hand. I had to take my own responsibility to make it the
best I could, but the motivation just wasn’t quite there.&lt;/p&gt;
&lt;p&gt;I always wished I could have given these jobs my best, but always found that my personal projects
were the ones that got me at my best.&lt;/p&gt;
&lt;p&gt;The intrinsic motivation to give it my best was lacking for projects I got from employers. A lot of
times I got the feeling that whatever I wanted to change would have to pass a lot of layers of
management and reviews before I was able move on.&lt;/p&gt;
&lt;p&gt;At a point, it got tiring to work like this. Especially if you’re not really invested in the project
and don’t truly stand behind what you’re doing. I could change the situation myself, but I just
wasn’t putting in the effort anymore, which not helped anyone.&lt;/p&gt;
&lt;h2 id=&quot;excited-about-doing-work&quot;&gt;Excited about doing work&lt;/h2&gt;
&lt;p&gt;The added responsibility of making sure projects are a success and delivering the best I can for my
clients has given me back the excitement I lost doing day jobs.&lt;/p&gt;
&lt;p&gt;Work doesn’t feel like work I don’t really like doing anymore, it helps a lot. At the moment I am
able to accept the projects and jobs that I find interesting and help me forward as a person.&lt;/p&gt;
&lt;p&gt;Now I can focus on myself, my clients, and becoming better while also delivering much better work at
the same time.&lt;/p&gt;
&lt;p&gt;It feels great to feel like this again.&lt;/p&gt;
&lt;h2 id=&quot;remote-work-and-travelling&quot;&gt;Remote work and travelling&lt;/h2&gt;
&lt;p&gt;One of the things which helped me find my motivation back is to work from home. I am able to fill in
my work days as I see fit.&lt;/p&gt;
&lt;p&gt;Sometimes I feel like working for just a few hours a day, while the next day I can be on a spree and
go on for more than nine hours. My previous jobs were also pretty flexible, but it was always in the
time I spent at the office.&lt;/p&gt;
&lt;p&gt;Come in at eight in the morning, leave whenever. Right now I can have a lengthy lunch break and
continue work later and not feel sorry about it. It really helps that I do not travel to work
anymore.&lt;/p&gt;
&lt;p&gt;Some clients prefer it if I am at the office, which I can understand, and I’ll visit them. I do feel
that eliminating the travel time I used to have has helped me a lot in feeling free. It allows me to
work at the times I feel comfortable.&lt;/p&gt;
&lt;h2 id=&quot;looking-forward-to-the-future-&quot;&gt;Looking forward to the future!&lt;/h2&gt;
&lt;p&gt;As I write this post I am looking back on the last couple of months and am amazed by the progress I
made in such a small period of time. Loving every second of it right now, and hope it will stay like
this for long.&lt;/p&gt;
&lt;p&gt;The most important thing for me is to keep validating the projects I am working on and if they work
for me as a person. I’d rather spend my client’s money on things I get excited about than things I’d
rather not be doing, losing motivation in the process.&lt;/p&gt;
&lt;p&gt;Going freelance has been the best move I made in recent years, professionally and personally. I can
truly say I live a better life.&lt;/p&gt;
</description></item><item><title>Orchestrate Actions with Redux Listeners</title><link>https://gaya.pizza/articles/orchestrate-actions-redux-listeners/</link><pubDate>Tue, 05 Dec 2017 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/orchestrate-actions-redux-listeners/</guid><author></author><description>&lt;p&gt;There are multiple ways and libraries to handle asynchronous data flows in Redux. Some do a lot,
some do just a little.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/Gaya/redux-listeners&quot;&gt;redux-listeners&lt;/a&gt; is a small middleware for Redux which
makes handling async are orchestrating action in Redux a breeze.&lt;/p&gt;
&lt;p&gt;It’s the sweet spot in-between &lt;code&gt;redux-thunk&lt;/code&gt; and &lt;code&gt;redux-saga&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;what-is-redux-listeners-&quot;&gt;What is redux-listeners?&lt;/h2&gt;
&lt;p&gt;With &lt;a href=&quot;https://github.com/Gaya/redux-listeners&quot;&gt;redux-listeners&lt;/a&gt; I aim to make it easy to respond to
actions being dispatched to the store without adjusting the action itself.&lt;/p&gt;
&lt;p&gt;It allows you to listen in on action types being dispatched to the store and dispatching new actions
afterwards. This way you can separate your action creators from the logic which follows the action.&lt;/p&gt;
&lt;p&gt;The data flow can be described as such:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Action is dispatched to the store&lt;/li&gt;
&lt;li&gt;&lt;code&gt;redux-listener&lt;/code&gt; middleware sees type of action matches a registered listener&lt;/li&gt;
&lt;li&gt;Listener is executed, which chooses to dispatch a new action to the store&lt;/li&gt;
&lt;li&gt;Reducers of the original action are handled&lt;/li&gt;
&lt;li&gt;New action will be dispatched to the store&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;example-usage&quot;&gt;Example usage&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; { createStore, applyMiddleware } &lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;'redux'&lt;/span&gt;;
&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; { createMiddleware } &lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;'redux-listeners'&lt;/span&gt;;

&lt;span class=&quot;comment&quot;&gt;// import your reducers&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; rootReducer &lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;'./reducers'&lt;/span&gt;;

&lt;span class=&quot;comment&quot;&gt;// create action middleware&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; listenMiddleware = createMiddleware();

&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; store = createStore(
  rootReducer,
  applyMiddleware(listenMiddleware),
);

&lt;span class=&quot;comment&quot;&gt;// registering the listeners&lt;/span&gt;
listenMiddleware.addListener(&lt;span class=&quot;string&quot;&gt;'FETCH_DATA'&lt;/span&gt;, &lt;span class=&quot;keyword&quot;&gt;async&lt;/span&gt; (dispatch) =&amp;gt; {
  &lt;span class=&quot;keyword&quot;&gt;try&lt;/span&gt; {
    &lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; response = &lt;span class=&quot;keyword&quot;&gt;await&lt;/span&gt; fetch(&lt;span class=&quot;string&quot;&gt;'/some-data'&lt;/span&gt;);
    dispatch({
      &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;'FETCH_DATA_SUCCESS'&lt;/span&gt;,
      &lt;span class=&quot;attr&quot;&gt;payload&lt;/span&gt;: &lt;span class=&quot;keyword&quot;&gt;await&lt;/span&gt; response.text(),
    });
  } &lt;span class=&quot;keyword&quot;&gt;catch&lt;/span&gt; (err) {
    dispatch({
      &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;'FETCH_DATA_FAILED'&lt;/span&gt;,
      &lt;span class=&quot;attr&quot;&gt;payload&lt;/span&gt;: err,
    })
  }
});

listenMiddleware.addListener(&lt;span class=&quot;string&quot;&gt;'FETCH_DATA_FAILED'&lt;/span&gt;, (dispatch, action) =&amp;gt; {
  &lt;span class=&quot;comment&quot;&gt;// display the error in console by reading the action&lt;/span&gt;
  &lt;span class=&quot;built_in&quot;&gt;console&lt;/span&gt;.error(action.payload.message);
});

&lt;span class=&quot;comment&quot;&gt;// Make the listeners start fetching data&lt;/span&gt;
store.dispatch({ &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;'FETCH_DATA'&lt;/span&gt; });&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;documentation&quot;&gt;Documentation&lt;/h2&gt;
&lt;p&gt;Visit &lt;a href=&quot;https://github.com/Gaya/redux-listeners&quot;&gt;&lt;code&gt;redux-listeners&lt;/code&gt; on Github&lt;/a&gt; for a full explanation,
how to install, and documentation.&lt;/p&gt;
&lt;h2 id=&quot;separating-actions-from-logic&quot;&gt;Separating actions from logic&lt;/h2&gt;
&lt;p&gt;In my opinion, actions creators should only contain create action objects to be dispatched on the
store. All side effects (like fetching data) should be handled elsewhere.&lt;/p&gt;
&lt;p&gt;Most of the times you also want to keep logic like this out of your application to keep it as simple
as possible and make the logic behind actions flexible and easy to replace without touching the
application itself.&lt;/p&gt;
&lt;h2 id=&quot;possible-use-cases&quot;&gt;Possible use cases&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Fetching data async&lt;/em&gt; is just one of the examples of how to use redux-listeners, but there are way
more ways you can use and combine redux-listeners with other principles.&lt;/p&gt;
&lt;p&gt;redux-listeners is great for handling parts of the program which live &lt;em&gt;outside of the Redux cycle&lt;/em&gt;.
You can orchestrate mutations on localStorage or other parts of the browser’s API.&lt;/p&gt;
&lt;p&gt;Redirecting to other pages after an action is dispatched is also a use case I use myself.&lt;/p&gt;
&lt;h2 id=&quot;wrapping-up&quot;&gt;Wrapping up&lt;/h2&gt;
&lt;p&gt;Use redux-listeners if you’re looking for something other then &lt;code&gt;redux-thunk&lt;/code&gt;, but not as complex and
big as &lt;code&gt;redux-saga&lt;/code&gt;.&lt;/p&gt;
</description></item><item><title>Introducing Formable - Beautiful forms for your websites</title><link>https://gaya.pizza/articles/introducing-formable/</link><pubDate>Tue, 24 Oct 2017 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/introducing-formable/</guid><author></author><description>&lt;p&gt;Today I am very pleased to reveal to you what I’ve been working on for the last couple of months.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.getformable.com&quot;&gt;Formable&lt;/a&gt; is a service I developed which will help you create forms and embed them on your websites. Without the hassle of coding the whole form yourself or installing another unnecessary plugin.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/introducing-formable/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/introducing-formable/formable_og_image.png&quot; alt=&quot;Formable - Beautiful forms for your websites&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;why-formable-&quot;&gt;Why Formable?&lt;/h2&gt;
&lt;p&gt;When I create a website of any kind, I find that coding forms is always a tedious and boring task. Especially if you need to create a way to handle messages and their input.&lt;/p&gt;
&lt;p&gt;It’s time-consuming, and overall a task I wouldn’t mind skipping.&lt;/p&gt;
&lt;p&gt;Imagine assembling a form and then adding a snippet of embed code to your site is all you have to do: this is Formable.&lt;/p&gt;
&lt;h2 id=&quot;perfect-for-all-types-of-websites&quot;&gt;Perfect for all types of websites&lt;/h2&gt;
&lt;p&gt;It doesn’t matter if you run a WordPress site, created your website with a service like Wix, or if you just have a static website. &lt;em&gt;Formable will fit perfectly on all these platforms&lt;/em&gt; and will work the same everywhere.&lt;/p&gt;
&lt;p&gt;Because Formable is embedded with a simple external script, you won’t need to add your own backend code or install a plugin. It will work out of the box!&lt;/p&gt;
&lt;h2 id=&quot;evolving-possibilities&quot;&gt;Evolving possibilities&lt;/h2&gt;
&lt;p&gt;You can create contact forms, subscription forms, surveys, and more. With the online form builder, you can create forms to your liking.&lt;/p&gt;
&lt;p&gt;Fields can be validated before they are sent to you. Make them required fields, have an email address check. _Remember, you don’t have to code anything for this_!&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/introducing-formable/form-examples.png&quot; alt=&quot;Form Builder&quot;&gt;&lt;/p&gt;
&lt;p&gt;Formable is also easily adjusted with some plain CSS. You can even choose to exclude CSS from the embedded forms altogether.&lt;/p&gt;
&lt;p&gt;I am working on improving the possibilities of Formable. If you have any suggestions: please reach out!&lt;/p&gt;
&lt;h2 id=&quot;try-it-now-&quot;&gt;Try it now!&lt;/h2&gt;
&lt;p&gt;You can try Formable for yourself. &lt;a href=&quot;https://getformable.com/pricing&quot;&gt;Pick a plan&lt;/a&gt; and start working or &lt;a href=&quot;https://app.getformable.com/sign-up&quot;&gt;start for free&lt;/a&gt; and try Formable.&lt;/p&gt;
&lt;p&gt;In the meantime, &lt;a href=&quot;https://twitter.com/getformable&quot;&gt;follow Formable on Twitter&lt;/a&gt; and &lt;a href=&quot;https://www.facebook.com/getformable&quot;&gt;like Formable on Facebook&lt;/a&gt; to get updates and see where Formable is heading.&lt;/p&gt;
</description></item><item><title>Replacing React with Preact in Your Projects</title><link>https://gaya.pizza/articles/replacing-react-with-preact/</link><pubDate>Fri, 01 Sep 2017 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/replacing-react-with-preact/</guid><author></author><description>&lt;p&gt;While React is becoming more popular by the day, so are alternatives to the JavaScript framework.&lt;/p&gt;
&lt;p&gt;One of these frameworks is &lt;a href=&quot;https://preactjs.com/&quot;&gt;Preact&lt;/a&gt;, which does not aim to do things that
much different per sé, but focuses on performance and bundle size.&lt;/p&gt;
&lt;p&gt;This article will take you through the why and how of replacing React with Preact in your existing
project.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;a-bit-more-about-preact&quot;&gt;A bit more about Preact&lt;/h2&gt;
&lt;p&gt;Preact is the 3kB alternative to React. They strive to provide the same ES6 as React and even
provide an extra layer of compatibility with React, which will make most of the React project work
as intended out of the box!&lt;/p&gt;
&lt;p&gt;This compatibility layer is totally optional for using Preact, but is needed for the purposes of
this article.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/replacing-react-with-preact/preact.png&quot; alt=&quot;Preact&quot; title=&quot;Preact logo&quot;&gt;&lt;/p&gt;
&lt;p&gt;Even in already existing projects, it’s possible to start using Preact instead of React. For me,
this brought instant performance improvements and my bundle size went down significantly.&lt;/p&gt;
&lt;h2 id=&quot;show-me-the-code-&quot;&gt;Show me the code!&lt;/h2&gt;
&lt;p&gt;To switch to using Preact instead of React you only need to install Preact’s dependencies and adjust
your WebPack configuration accordingly.&lt;/p&gt;
&lt;p&gt;First, add Preact to your project:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install --save preact preact-compat&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now adjust your WebPack config to alias &lt;code&gt;react&lt;/code&gt; to &lt;code&gt;preact-compat&lt;/code&gt;. In &lt;code&gt;webpack.config.js&lt;/code&gt; add:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;{
  &lt;span class=&quot;attr&quot;&gt;resolve&lt;/span&gt;: {
    &lt;span class=&quot;attr&quot;&gt;alias&lt;/span&gt;: {
      &lt;span class=&quot;attr&quot;&gt;react&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;'preact-compat'&lt;/span&gt;,
      &lt;span class=&quot;string&quot;&gt;'react-dom'&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;'preact-compat'&lt;/span&gt;,
    },
  },
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There is a more &lt;a href=&quot;https://preactjs.com/guide/switching-to-preact&quot;&gt;in-depth explanation of switching to Preact&lt;/a&gt;
over at Preact’s docs. Give it a read if you don’t use WebPack for instance.&lt;/p&gt;
&lt;p&gt;In order to get &lt;em&gt;React Dev-Tools&lt;/em&gt; working nicely with Preact, I suggest you include the following
snippet in your app’s entry point. At least as it’s before calling &lt;code&gt;ReactDOM.render&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;built_in&quot;&gt;module&lt;/span&gt;.hot) {
  &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'preact/devtools'&lt;/span&gt;);
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will add &lt;code&gt;devtools&lt;/code&gt; compatibility when you’re running your app in WebPack’s &lt;code&gt;dev-server&lt;/code&gt; mode.
If you &lt;code&gt;require&lt;/code&gt; the &lt;code&gt;devtools&lt;/code&gt; outside of the if-statement it will be included in the production
bundle of your app, best avoid that!&lt;/p&gt;
&lt;p&gt;And that’s all there is to it!&lt;/p&gt;
&lt;h2 id=&quot;but-why-switch-&quot;&gt;But, why switch?&lt;/h2&gt;
&lt;p&gt;There are many possible reasons one would choose to switch from using React, but the one I’ve been
hearing a lot as of late is people having concerns around &lt;a href=&quot;https://code.facebook.com/posts/112130496157735/explaining-react-s-license/&quot;&gt;React’s license&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I can imagine people don’t want to be dependent on big software companies like Facebook or Google
for their projects. Luckily, &lt;a href=&quot;https://github.com/developit/preact/blob/master/LICENSE&quot;&gt;Preact has the MIT license&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;performance-and-size&quot;&gt;Performance and size&lt;/h2&gt;
&lt;p&gt;While React is super fast on its own, Preact delivers an even faster experience. In my case, I
couldn’t really tell much of a difference in the beginning, but I noticed Preact executed some
bindings a bit differently. This made my components mount earlier than in React. Nice.&lt;/p&gt;
&lt;p&gt;The biggest difference was in the size of the bundle. Using &lt;a href=&quot;https://github.com/th0r/webpack-bundle-analyzer&quot;&gt;&lt;code&gt;webpack-bundle-analyzer&lt;/code&gt;&lt;/a&gt;
I compared the two bundles which were built with WebPack. Both cases used the &lt;code&gt;--optimize-minimize&lt;/code&gt;
flag to ensure they both got minified in the process.&lt;/p&gt;
&lt;h3 id=&quot;bundle-with-react&quot;&gt;Bundle with React&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/replacing-react-with-preact/react-package.png&quot; alt=&quot;React bundle&quot; title=&quot;React bundle size&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;bundle-with-preact&quot;&gt;Bundle with Preact&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/replacing-react-with-preact/preact-package.png&quot; alt=&quot;Preact bundle&quot; title=&quot;Preact bundle size&quot;&gt;&lt;/p&gt;
&lt;p&gt;Look at the difference compared to the other libraries living in the bundle! I was amazed by the
decrease in size I was able to get.&lt;/p&gt;
&lt;p&gt;The bundle went from 111.97KB gzipped to 57.47KB gzipped. That’s a whooping 54.5KB less.&lt;/p&gt;
&lt;h2 id=&quot;compatibility-with-other-libraries-and-ides&quot;&gt;Compatibility with other libraries and IDEs&lt;/h2&gt;
&lt;p&gt;The great thing about &lt;code&gt;preact-compat&lt;/code&gt; is, is that it also provides compatibility with popular
libraries you might already use in your project. For me, &lt;code&gt;react-redux&lt;/code&gt; and &lt;code&gt;react-router&lt;/code&gt; just worked
after I applied the alias technique described earlier. You should test your app thoroughly though.&lt;/p&gt;
&lt;p&gt;You could go without this compatibility layer and go plain Preact, but it might require some extra
working making your components and 3th party libraries work.&lt;/p&gt;
&lt;p&gt;Another thing I really like is how well &lt;code&gt;eslint&lt;/code&gt; and &lt;code&gt;flow&lt;/code&gt; work with this approach. They’ll still
think you’re using React, which certain rules in &lt;code&gt;eslint&lt;/code&gt; can check for.&lt;/p&gt;
&lt;p&gt;When I added Preact as a standalone earlier in the project I couldn’t get &lt;code&gt;eslint&lt;/code&gt; to stop telling
me to include React in &lt;code&gt;JSX&lt;/code&gt; files, but I was using Preact for that. Aliasing solves this.&lt;/p&gt;
&lt;p&gt;Another really great win is &lt;strong&gt;compatibility with the IDE&lt;/strong&gt; I use most: WebStorm. Same as for &lt;code&gt;eslint&lt;/code&gt; it
will still consider &lt;code&gt;import React from &amp;#39;react&amp;#39;;&lt;/code&gt; to be just React, while in truth it’s Preact which
get included in your bundle in the end.&lt;/p&gt;
&lt;p&gt;Jason Miller, the author of the library, reached out to me to tell that if you’re running a plain
Preact without &lt;code&gt;preact-compat&lt;/code&gt; setup you can also get these benefits by aliasing &lt;code&gt;react&lt;/code&gt; to &lt;code&gt;preact&lt;/code&gt;
in your WebPack config. So that’s a &lt;em&gt;pro-tip&lt;/em&gt; there!&lt;/p&gt;
&lt;h2 id=&quot;wrapping-up&quot;&gt;Wrapping up&lt;/h2&gt;
&lt;p&gt;Hopefully, I got you excited to try and apply Preact to your current projects. It’s not too much
work and you don’t actually need to adjust your code base, so that’s awesome.&lt;/p&gt;
&lt;p&gt;Feel free to reach out if you have any questions!&lt;/p&gt;
</description></item><item><title>I Quit!</title><link>https://gaya.pizza/articles/i-quit/</link><pubDate>Tue, 08  Aug 2017 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/i-quit/</guid><author></author><description>&lt;p&gt;More specifically: I quit my job, to start my own business.&lt;/p&gt;
&lt;p&gt;For the last couple of years, I spent a lot of time working on personal projects next to my day time job. I even decided to work four days instead of five to spend an extra day doing what I love: getting my hands dirty on stuff I came up with myself.&lt;/p&gt;
&lt;p&gt;Because it still feels like I still have too little time and I want to focus on building my own products, I decided to quit my job. Which is a really big step for me.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;what-will-i-be-doing-&quot;&gt;What will I be doing?&lt;/h2&gt;
&lt;p&gt;The last couple of months I have been working on a project which I will soon post more information about. Most of my time in the near future will be spent on this product’s launch and I hope to do so soon. I am really excited about this and is the main reason I decided to take the plunge and quit my job.&lt;/p&gt;
&lt;p&gt;In the meantime, I want to focus some more on pet projects like &lt;strong&gt;&lt;a href=&quot;https://www.dramm.it&quot;&gt;Drammit&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;Open Source Software&lt;/strong&gt; I have on &lt;a href=&quot;https://github.com/Gaya&quot;&gt;my GitHub account&lt;/a&gt;. It’s been quite a while since I made the time to improve on them. I always loved to put effort in projects like these.&lt;/p&gt;
&lt;p&gt;Also, &lt;strong&gt;blogging&lt;/strong&gt;. I used to love writing about stuff I learned on my blog, but I quickly lost interest when development became a day to day thing. It felt like everything I could write about was already on the Internet, explained by much smarter people than I. Now that I can plan my own time, I will try to include blogging in my day to day tasks.&lt;/p&gt;
&lt;p&gt;Expect articles about _React_, _Redux_, and how to tackle certain problems while making (web) apps.&lt;/p&gt;
&lt;h2 id=&quot;available-for-hire&quot;&gt;Available for hire&lt;/h2&gt;
&lt;p&gt;Aside from all of the above, I will be &lt;strong&gt;available for hire&lt;/strong&gt;. I plan on taking on some jobs to pay the bills and expenses made working on my projects.&lt;/p&gt;
&lt;p&gt;Feel free to &lt;a href=&quot;https://www.theclevernode.com/#contact&quot;&gt;contact me&lt;/a&gt; if you’re looking for an &lt;em&gt;expert in JavaScript, React, and web applications&lt;/em&gt;. I am available for freelance jobs.&lt;/p&gt;
&lt;p&gt;For more information, please check out my company’s website at: &lt;a href=&quot;https://theclevernode.com&quot;&gt;https://theclevernode.com&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;onwards-to-a-bright-future&quot;&gt;Onwards to a bright future&lt;/h2&gt;
&lt;p&gt;I am very excited to start working on all the ideas I have and figure out what my future is going to look like.&lt;/p&gt;
&lt;p&gt;For now I am curious, excited, and calm at the same time. Only time can tell how well all will work out.&lt;/p&gt;
</description></item><item><title>Using Flow instead of prop-types in React</title><link>https://gaya.pizza/articles/using-flow-instead-of-prop-types/</link><pubDate>Mon, 19 Jun 2017 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/using-flow-instead-of-prop-types/</guid><author></author><description>&lt;p&gt;One of the most used ways to check the “type” of a property which is passed to a React component is
through &lt;a href=&quot;https://github.com/facebook/prop-types&quot;&gt;&lt;code&gt;prop-types&lt;/code&gt;&lt;/a&gt;. The main problem is that all the
type checking is done on run-time, and not statically.&lt;/p&gt;
&lt;p&gt;This article will explain how to go from type checking with &lt;code&gt;prop-types&lt;/code&gt; to static type checking
with &lt;a href=&quot;https://flow.org&quot;&gt;Flow&lt;/a&gt; in React.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;why-flow-&quot;&gt;Why Flow?&lt;/h2&gt;
&lt;p&gt;The first and foremost reason for choosing Flow is that is opt-in. You can choose to type check a
file or not.&lt;/p&gt;
&lt;p&gt;When a project is already alive and well &lt;strong&gt;the last thing we want to do is rewrite everything&lt;/strong&gt;. Flow
enables you to add type checking step by step into your application.&lt;br /&gt;
This is also true for &lt;a href=&quot;http://www.typescriptlang.org/&quot;&gt;Typescript&lt;/a&gt;, but I choose Flow because it’s
not a compiler, simply a checker. Babel can take care of the extra annotations.&lt;/p&gt;
&lt;p&gt;Type checking is for some a missing part in JavaScript, which some developers might question. Is it
really necessary? Does it make my code any better? &lt;strong&gt;Isn’t type checking just a tool for the
developer?&lt;/strong&gt; (Yes it is)&lt;/p&gt;
&lt;p&gt;The main reason I choose to add a tool like Flow to my projects is to ensure I think about what goes
in and goes out throughout my application. &lt;strong&gt;Type strictness helps my IDE understand&lt;/strong&gt; what I type
and what I should pass in function and props of React Components.&lt;br /&gt;
In a way I am already documenting my code, which makes my developer self quite happy if I look back
at components I made a month ago.&lt;/p&gt;
&lt;p&gt;Because Flow checks types statically it can be run outside of the run-time environment. This makes
type checking errors in the browser a thing of the past and can be detected before building the
application.&lt;/p&gt;
&lt;h2 id=&quot;type-checking-with-prop-types&quot;&gt;Type checking with prop-types&lt;/h2&gt;
&lt;p&gt;Consider the following setup, done with plain old &lt;code&gt;prop-types&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; React &lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;'react'&lt;/span&gt;;
&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; { bool, node } &lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;'prop-types'&lt;/span&gt;;

&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; propTypes = {
    &lt;span class=&quot;attr&quot;&gt;visible&lt;/span&gt;: bool,
    &lt;span class=&quot;attr&quot;&gt;children&lt;/span&gt;: node.isRequired,
};

&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; Toggle = &lt;span class=&quot;function&quot;&gt;(&lt;span class=&quot;params&quot;&gt;{ visible, children }&lt;/span&gt;) =&amp;gt;&lt;/span&gt; (
    &lt;span class=&quot;xml&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;style&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;{{&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;display:&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;visible&lt;/span&gt; ? '&lt;span class=&quot;attr&quot;&gt;block&lt;/span&gt;' &lt;span class=&quot;attr&quot;&gt;:&lt;/span&gt; '&lt;span class=&quot;attr&quot;&gt;none&lt;/span&gt;' }}&amp;gt;&lt;/span&gt;
        { children }
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
);

Toggle.propTypes = propTypes;

&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; otherComponent = &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;params&quot;&gt;()&lt;/span&gt; =&amp;gt;&lt;/span&gt; (
    &lt;span class=&quot;xml&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;section&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;Toggle&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;visible&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;true&lt;/span&gt; /&amp;gt;&lt;/span&gt; {/* Error at run-time! Missing children */}
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;Toggle&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;visible&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;true&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt; {/* Error at run-time! Not boolean */}
            ...
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;Toggle&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;Toggle&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;visible&lt;/span&gt;&amp;gt;&lt;/span&gt; {/* Passes */}
            ...
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;Toggle&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;section&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In my opinion, throwing this error at run-time, most of the time in the browser, is kind of too
late.&lt;/p&gt;
&lt;p&gt;Reporting the mistake a developer has made in the IDE or different tool he’s using is a lot more
convenient. This also helps with components other developers made and how to use them.&lt;/p&gt;
&lt;p&gt;Type strictness here would also be documenting the use of the component.&lt;/p&gt;
&lt;h2 id=&quot;type-checking-with-flow&quot;&gt;Type checking with Flow&lt;/h2&gt;
&lt;p&gt;Let’s rewrite the previous example using Flow.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// @flow&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; React &lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;'react'&lt;/span&gt;;
&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; type { Element, Children } &lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;'react'&lt;/span&gt;;

&lt;span class=&quot;comment&quot;&gt;// define the type of the props object which gets passed to the PureComponent&lt;/span&gt;
type toggleType = {
    visible?: boolean,     &lt;span class=&quot;comment&quot;&gt;// visible is optional&lt;/span&gt;
    &lt;span class=&quot;attr&quot;&gt;children&lt;/span&gt;: Children,    &lt;span class=&quot;comment&quot;&gt;// children is mandatory&lt;/span&gt;
};

&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; Toggle = ({ visible, children }: toggleType): Element&amp;lt;any&amp;gt; =&amp;gt; (
    &lt;span class=&quot;xml&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;style&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;{{&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;display:&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;visible&lt;/span&gt; ? '&lt;span class=&quot;attr&quot;&gt;block&lt;/span&gt;' &lt;span class=&quot;attr&quot;&gt;:&lt;/span&gt; '&lt;span class=&quot;attr&quot;&gt;none&lt;/span&gt;' }}&amp;gt;&lt;/span&gt;
        { children }
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
);

&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; otherComponent = (): Element&amp;lt;any&amp;gt; =&amp;gt; (
    &lt;span class=&quot;xml&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;section&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;Toggle&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;visible&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;true&lt;/span&gt; /&amp;gt;&lt;/span&gt; {/* Error! Missing children */}
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;Toggle&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;visible&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;true&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt; {/* Error! Not boolean */}
            ...
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;Toggle&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;Toggle&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;visible&lt;/span&gt;&amp;gt;&lt;/span&gt; {/* Passes */}
            ...
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;Toggle&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;section&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All the errors in the last example would have been reported in the IDE or when you run Flow. And
yes: Flow supports JSX, so that’s pretty awesome!&lt;/p&gt;
&lt;h2 id=&quot;in-closing&quot;&gt;In closing&lt;/h2&gt;
&lt;p&gt;Flow makes it easier for me to enforce the correct use of my components in my applications. Adding
type checking on other parts of your application is also a great idea, as you might grow more aware
of the code you’re writing.&lt;/p&gt;
&lt;p&gt;There is a great &lt;a href=&quot;https://flow.org/en/docs/getting-started/&quot;&gt;getting started guide&lt;/a&gt; on Flow’s website.
Also a page on how to &lt;a href=&quot;https://flow.org/en/docs/editors/&quot;&gt;get Flow up and running in your favourite editor&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Happy checking!&lt;/p&gt;
</description></item><item><title>Uploading files with superagent in the browser</title><link>https://gaya.pizza/articles/uploading-files-superagent-in-browser/</link><pubDate>Sun, 16  Aug 2015 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/uploading-files-superagent-in-browser/</guid><author></author><description>&lt;p&gt;Sending files in the browser using XHR can give the user a great experience. I like to use &lt;a href=&quot;https://visionmedia.github.io/superagent/&quot;&gt;superagent&lt;/a&gt;
for sending requests, it’s a great light-weight API which doesn’t require other third party libraries and works great
when bundling with CommonJS.&lt;/p&gt;
&lt;p&gt;Uploading files using a multipart requests in the browser is sadly not supported through their API at the moment, but
it’s possible following a few short steps. I’ll explain how I got multipart uploading to work using superagent in the
browser in this article.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-way-we-are-used-to&quot;&gt;The way we are used to&lt;/h2&gt;
&lt;p&gt;Uploading files using a &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; in HTML takes a simple &lt;code&gt;&amp;lt;input type=&amp;#39;file&amp;#39; /&amp;gt;&lt;/code&gt; and an attribute on your form set to
&lt;code&gt;enctype=&amp;#39;multipart/form-data&amp;#39;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This will submit the file using multipart and you’re be able to receive the file on your server.&lt;/p&gt;
&lt;p&gt;Luckily we can send a similar request using JavaScript.&lt;/p&gt;
&lt;h2 id=&quot;multipart-and-superagent&quot;&gt;Multipart and superagent&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://visionmedia.github.io/superagent/#multipart-requests&quot;&gt;superagent enables multipart building&lt;/a&gt; on the server-side,
but the browser implementation is sadly missing.&lt;/p&gt;
&lt;p&gt;Because you can use superagent on both server-side and client-side it uses different implementations in both cases. The
&lt;code&gt;.attach()&lt;/code&gt; method is aimed to only work in the server at the moment.&lt;/p&gt;
&lt;h2 id=&quot;welcome-formdata&quot;&gt;Welcome, FormData&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://developer.mozilla.org/en/docs/Web/API/FormData&quot;&gt;FormData&lt;/a&gt; is a simple way to construct a key value paired data
object which can be send to the server. superagent accepts &lt;code&gt;FormData&lt;/code&gt;, so we can send data using this method, and also
files.&lt;/p&gt;
&lt;p&gt;Constructing &lt;code&gt;FormData&lt;/code&gt; is done like so:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; formData = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; FormData();

formData.append(&lt;span class=&quot;string&quot;&gt;'key'&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;'value'&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Pretty straight forward.&lt;/p&gt;
&lt;h2 id=&quot;reading-files-from-an-input&quot;&gt;Reading files from an input&lt;/h2&gt;
&lt;p&gt;Let’s say we have an element which looks like this: &lt;code&gt;&amp;lt;input type=&amp;#39;file&amp;#39; id=&amp;#39;file_to_upload&amp;#39; /&amp;gt;&lt;/code&gt;. We can read the files
it contains using this &lt;code&gt;.files&lt;/code&gt; property the element has.&lt;/p&gt;
&lt;p&gt;For each file which is present in the &lt;code&gt;FileList&lt;/code&gt;, we can append that data to &lt;code&gt;FormData&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; files = &lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;.getElementById(&lt;span class=&quot;string&quot;&gt;'file_to_upload'&lt;/span&gt;).files;
&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; formData = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; FormData();

&lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; key &lt;span class=&quot;keyword&quot;&gt;in&lt;/span&gt; files) {
    &lt;span class=&quot;comment&quot;&gt;// is the item a File?&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (files.hasOwnProperty(key) &amp;amp;&amp;amp; files[key] &lt;span class=&quot;keyword&quot;&gt;instanceof&lt;/span&gt; File) {
        formData.append(key, files[key]);
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;sending-it-with-superagent&quot;&gt;Sending it with superagent&lt;/h2&gt;
&lt;p&gt;To wrap things up, we can now send this data with superagent using &lt;code&gt;.send()&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;superagent.post(&lt;span class=&quot;string&quot;&gt;'/some-url/'&lt;/span&gt;)
  .send(formData)
  .end(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;err, response&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;comment&quot;&gt;//upload done!&lt;/span&gt;
  });&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is how I send my files using superagent. You can include an upload indicator and send other data in the &lt;code&gt;FormData&lt;/code&gt;
too.&lt;/p&gt;
&lt;p&gt;Hope this article helped for those pulling out their hair.&lt;/p&gt;
</description></item><item><title>Explore and improve your development skills</title><link>https://gaya.pizza/articles/explore-improve-development-skills/</link><pubDate>Sat, 18 Jul 2015 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/explore-improve-development-skills/</guid><author></author><description>&lt;p&gt;My jobs have always been focused on the technologies and stacks I was used to. This is a safe and efficient
way to get work done, but what I didn’t realise is that it only hold me back on learning different ways.&lt;/p&gt;
&lt;p&gt;In this post I am sharing my findings of joining a company which uses a different approach to development, stacks
and work flows than I was used to.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;be-not-afraid-of-change&quot;&gt;Be not afraid of change&lt;/h2&gt;
&lt;p&gt;Change is hard, especially for people who tend to follow a strict pattern of applied methods. I am one of those people
who likes to do the things I do following a strict way and thinks teams should all do that. It can improve team work and
the quality of the products delivered.&lt;/p&gt;
&lt;p&gt;The problem with this is that I forgot to take a look at other methods and thus not change my ways.&lt;/p&gt;
&lt;p&gt;I was used to the most common PHP, HTML, CSS, JS stack. Made a lot of websites using WordPress, which I was never really
fond of, but there were no better alternatives in my stack. I had grown to love and hate the stack at the same time.&lt;/p&gt;
&lt;p&gt;After a while I grew to like Node.js and started working in the backend again, which opened my eyes to all the great
things I was missing out on. This triggered my will or maybe even the need to change.&lt;/p&gt;
&lt;h2 id=&quot;learn-from-broken-systems&quot;&gt;Learn from broken systems&lt;/h2&gt;
&lt;p&gt;Even if you’re not willing to learn a certain method a team is using, just try it out. Especially in JavaScript development
there is an overload in different frameworks. Some you might not like, some you might want to use. Since I joined a team
which already used frameworks I was not familiar with, I had to in order to be part of the team.&lt;/p&gt;
&lt;p&gt;I started learning Angular because of a lot of projects were made using it. It opened my eyes to a lot of new
possibilities, but also made me see the pitfalls of the system. This is a good thing. Learn from mistakes, and also if
you made them yourself in the past.&lt;/p&gt;
&lt;p&gt;It might take some time to get into something new, but it’s really worth it in the end. You’ll help yourself to a lot
more knowledge and insights.&lt;/p&gt;
&lt;h2 id=&quot;the-problem-of-different-programming-languages&quot;&gt;The problem of different programming languages&lt;/h2&gt;
&lt;p&gt;In the past, I always had trouble switching programming languages. The syntax was hard for me to learn, nothing really
went right the first time and it frustrated me a lot. The problem was, which I recently realised, was that I was not an
experienced enough programmer.&lt;/p&gt;
&lt;p&gt;I was not used to solving complex problems and choosing the right architectures for my applications yet. No full
understanding of programming principles makes it hard to learn a new language. You’ll get a lot of new principles and
ways thrown at you before you can even make up your own mind about them.&lt;/p&gt;
&lt;p&gt;Recently I started learning Python. In the beginning I couldn’t really read the code which was in front of me and it kind
of gave me an headache. When I started learning the syntax I quickly learned how clean it is and not really that different
from the languages I am used to write. The only hurdles I had to overcome were how to do certain things in the language
which I already use in other languages.&lt;/p&gt;
&lt;h2 id=&quot;in-closing&quot;&gt;In closing&lt;/h2&gt;
&lt;p&gt;Try something different. Learn a new language. Create something totally different. Not all the methods and principles
have to be followed as strict as you’re used to, but try to apply what you’ve learned in the past on new information
you’ll learn.&lt;/p&gt;
</description></item><item><title>Testing JavaScript using BrowserSync, Mocha and PhantomJS</title><link>https://gaya.pizza/articles/testing-javascript-browsersync-mocha-phantomjs/</link><pubDate>Wed, 18 Mar 2015 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/testing-javascript-browsersync-mocha-phantomjs/</guid><author></author><description>&lt;p&gt;It’s a good idea to test your JavaScript applications using a testing framework. It improves the integrity of your
software and enables you to do Test Driven Development.&lt;/p&gt;
&lt;p&gt;You can do your testing in Mocha, but you can also expand it a bit further with browser specific behaviour testing. This
article is aimed to get you started with testing using &lt;a href=&quot;http://www.browsersync.io&quot;&gt;BrowserSync&lt;/a&gt;,
&lt;a href=&quot;http://mochajs.org&quot;&gt;Mocha&lt;/a&gt; and &lt;a href=&quot;http://phantomjs.org&quot;&gt;PhantomJs&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;what-we-re-going-to-make&quot;&gt;What we’re going to make&lt;/h2&gt;
&lt;p&gt;We are going to make a fairly straightforward test that can be tested in the browser and on command-line. This way we
can also integrate our tests with services like &lt;a href=&quot;https://travis-ci.org/&quot;&gt;Travis CI&lt;/a&gt; to automatically perform tests on
future releases.&lt;/p&gt;
&lt;p&gt;At the end of the article you’ll have a project where you can write your tests in. You’ll have JavaScript code that can
be tested on command-line and an HTML page where the script you want to test will live. It will allow us to actually
&lt;em&gt;see&lt;/em&gt; the tests.&lt;/p&gt;
&lt;p&gt;All changes will be watched and checked automatically. You can keep your focus on writing code while the test results
get updated elsewhere.&lt;/p&gt;
&lt;p&gt;We’re going to use &lt;a href=&quot;http://gulpjs.com&quot;&gt;Gulp&lt;/a&gt; for this workflow. You can also do without, but it comes in handy later
when we want to watch our files for changes and automatically reload the tests in BrowserSync.&lt;/p&gt;
&lt;p&gt;For bundling our code and not breaking the Mocha way of testing Node.js code we’re going to use
&lt;a href=&quot;http://browserify.org&quot;&gt;Browserify&lt;/a&gt;.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Getting started&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;First off, create a project folder which will hold the files and navigate to that folder in your terminal.&lt;/p&gt;
&lt;p&gt;Init an npm project:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm init&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Install Gulp globally if you haven’t already:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install -g gulp&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Install all the dependencies we’ll be using:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install --save browser-sync browserify gulp gulp-mocha-phantomjs mocha-phantomjs mocha vinyl-source-stream&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The reason I install &lt;code&gt;gulp-mocha-phantomjs&lt;/code&gt;, &lt;code&gt;mocha-phantomjs&lt;/code&gt; and &lt;code&gt;mocha&lt;/code&gt; is for easier access later on.&lt;/p&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;Creating something to test&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;Let’s say we want to create a JavaScript library that changes the text inside a given DOM element to something else.&lt;/p&gt;
&lt;p&gt;In order to know what to do next is to determine the way our module will be used and what the outcome should be.&lt;/p&gt;
&lt;p&gt;We’ll call the module &lt;code&gt;TextChanger&lt;/code&gt; which holds a method called &lt;code&gt;replaceText&lt;/code&gt;. The &lt;code&gt;replaceText&lt;/code&gt; method will accept two
parameters: a DOM element and a string with text which will be placed inside.&lt;/p&gt;
&lt;p&gt;If we’re going to follow a TDD approach we need to write tests for this method before even implementing the code of
&lt;code&gt;TextChanger&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Create a new folder called &lt;code&gt;test&lt;/code&gt; and place a file called &lt;code&gt;tests.js&lt;/code&gt; in it. Place the following inside the file:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; assert = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;assert&quot;&lt;/span&gt;);

describe(&lt;span class=&quot;string&quot;&gt;'TextChanger'&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/span&gt;{
    &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; element = &lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;.createElement(&lt;span class=&quot;string&quot;&gt;&quot;section&quot;&lt;/span&gt;);
    element.appendChild(
        &lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;.createElement(&lt;span class=&quot;string&quot;&gt;&quot;span&quot;&lt;/span&gt;)
            .appendChild(
                &lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;.createTextNode(&lt;span class=&quot;string&quot;&gt;&quot;Replace me&quot;&lt;/span&gt;)
            )
    );

    describe(&lt;span class=&quot;string&quot;&gt;'#changeText(element, text)'&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
        it(&lt;span class=&quot;string&quot;&gt;'should replace the content of the element with given text'&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
            assert.equal(&lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt;, &lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;);
        });

        it(&lt;span class=&quot;string&quot;&gt;'should throw and error if element is not a DOM element'&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
            assert.equal(&lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt;, &lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;);
        });
    });
});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These tests do not do anything yet. They fail because &lt;code&gt;false&lt;/code&gt; is not &lt;code&gt;true&lt;/code&gt;. I do this on purpose because we have to
write correct tests first.&lt;/p&gt;
&lt;p&gt;Would you run this test using just &lt;code&gt;mocha test/tests.js&lt;/code&gt;, Mocha would complain &lt;code&gt;ReferenceError: document is not defined&lt;/code&gt;.
Mocha is not run in a browser environment, just like Node.js. In order to enable testing in a browser environment we
need to use PhantomJS.&lt;/p&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;An HTML document to run the tests&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;In order to run the tests in a browser environment we’re going to need an HTML document which will load the necessary
scripts and styles. While Mocha can test &lt;code&gt;.js&lt;/code&gt; files, Mocha PhantomJS takes &lt;code&gt;.html&lt;/code&gt; files. In this document we’re going
to load Mocha and our tests.&lt;/p&gt;
&lt;p&gt;Create a new file in the &lt;code&gt;test&lt;/code&gt; folder called &lt;code&gt;tests.html&lt;/code&gt; and place the following content in it.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;meta&quot;&gt;&amp;lt;!DOCTYPE &lt;span class=&quot;meta-keyword&quot;&gt;html&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;html&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;head&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;lang&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;en&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;meta&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;charset&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;UTF-8&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;title&lt;/span&gt;&amp;gt;&lt;/span&gt;TextChanger tests&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;title&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;../node_modules/mocha/mocha.css&quot;&lt;/span&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;body&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;mocha&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;../node_modules/mocha/mocha.js&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;actionscript&quot;&gt;mocha.setup(&lt;span class=&quot;string&quot;&gt;'bdd'&lt;/span&gt;)&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;tests-browserify.js&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;javascript&quot;&gt;
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;built_in&quot;&gt;window&lt;/span&gt;.mochaPhantomJS) {
            mochaPhantomJS.run();
        } &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; {
            mocha.run();
        }
    &lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;body&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;html&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We are loading Mocha from the &lt;code&gt;node_modules&lt;/code&gt; folder, our tests (which do not exist yet) and running the tests in the end.&lt;/p&gt;
&lt;p&gt;The reason we need a different test file from the one we created earlier is because the browser doesn’t understand
&lt;code&gt;require()&lt;/code&gt;. We can solve this by using Browserify to bundle our script.&lt;/p&gt;
&lt;ol start=&quot;4&quot;&gt;
&lt;li&gt;Watching and serving the tests&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;In this step we’re going to create our workflow. We’ll use Gulp as our runner, use BrowserSync as our web server which
can automatically reload and Browserify to bundle our test script.&lt;/p&gt;
&lt;p&gt;Create a &lt;code&gt;gulpfile.js&lt;/code&gt; file in the root of your project. Add the following contents.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; gulp = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;gulp&quot;&lt;/span&gt;),
    browserSync = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;browser-sync&quot;&lt;/span&gt;),
    browserify = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;browserify&quot;&lt;/span&gt;),
    source = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;vinyl-source-stream&quot;&lt;/span&gt;),
    mochaPhantomJS = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;gulp-mocha-phantomjs&quot;&lt;/span&gt;);

gulp.task(&lt;span class=&quot;string&quot;&gt;&quot;browser-sync&quot;&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;string&quot;&gt;&quot;use strict&quot;&lt;/span&gt;;
    browserSync({
        &lt;span class=&quot;attr&quot;&gt;server&lt;/span&gt;: {
            &lt;span class=&quot;comment&quot;&gt;//serve tests and the root as base dirs&lt;/span&gt;
            &lt;span class=&quot;attr&quot;&gt;baseDir&lt;/span&gt;: [&lt;span class=&quot;string&quot;&gt;&quot;./test/&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;./&quot;&lt;/span&gt;],
            &lt;span class=&quot;comment&quot;&gt;//make tests.html the index file&lt;/span&gt;
            &lt;span class=&quot;attr&quot;&gt;index&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;tests.html&quot;&lt;/span&gt;
        }
    });
});

gulp.task(&lt;span class=&quot;string&quot;&gt;&quot;browserify&quot;&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;string&quot;&gt;&quot;use strict&quot;&lt;/span&gt;;
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; browserify(&lt;span class=&quot;string&quot;&gt;&quot;./test/tests.js&quot;&lt;/span&gt;)
        .bundle()
        .on(&lt;span class=&quot;string&quot;&gt;&quot;error&quot;&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;err&lt;/span&gt;) &lt;/span&gt;{
            &lt;span class=&quot;built_in&quot;&gt;console&lt;/span&gt;.log(err.toString());
            &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.emit(&lt;span class=&quot;string&quot;&gt;&quot;end&quot;&lt;/span&gt;);
        })
        .pipe(source(&lt;span class=&quot;string&quot;&gt;&quot;tests-browserify.js&quot;&lt;/span&gt;))
        .pipe(gulp.dest(&lt;span class=&quot;string&quot;&gt;&quot;test/&quot;&lt;/span&gt;))
        .pipe(browserSync.reload({&lt;span class=&quot;attr&quot;&gt;stream&lt;/span&gt;:&lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;}));
});

gulp.task(&lt;span class=&quot;string&quot;&gt;&quot;test&quot;&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;string&quot;&gt;&quot;use strict&quot;&lt;/span&gt;;
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; gulp.src(&lt;span class=&quot;string&quot;&gt;&quot;./test/tests.html&quot;&lt;/span&gt;)
        .pipe(mochaPhantomJS());
});

gulp.task(&lt;span class=&quot;string&quot;&gt;&quot;serve&quot;&lt;/span&gt;, [&lt;span class=&quot;string&quot;&gt;&quot;browserify&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;browser-sync&quot;&lt;/span&gt;], &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;string&quot;&gt;&quot;use strict&quot;&lt;/span&gt;;
    &lt;span class=&quot;comment&quot;&gt;//when tests.js changes, browserify code and execute tests&lt;/span&gt;
    gulp.watch([&lt;span class=&quot;string&quot;&gt;&quot;test/tests.js&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;src/text-changer.js&quot;&lt;/span&gt;], [&lt;span class=&quot;string&quot;&gt;&quot;browserify&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;test&quot;&lt;/span&gt;]);
});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;browser-sync&lt;/code&gt; task makes sure the &lt;code&gt;test&lt;/code&gt; folder and the root of the project get served as a web server. It will
also set &lt;code&gt;tests.html&lt;/code&gt; as the index so it will open said file when browsing to &lt;code&gt;http://localhost:3000&lt;/code&gt;. When this task
is run it automatically opens the link in your browser.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;browserify&lt;/code&gt; task bundles the &lt;code&gt;tests.js&lt;/code&gt; file and creates a browser runnable tests file.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;test&lt;/code&gt; tasks executes &lt;code&gt;mocha-phantomjs&lt;/code&gt; and outputs the outcome in the terminal. This is the same output you get in
your browser.&lt;/p&gt;
&lt;p&gt;To start serving the tests and rerun them every time you make a change in the tests file you need to run the following
command in your terminal.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;gulp serve&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&quot;5&quot;&gt;
&lt;li&gt;Finishing the tests&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;If you have your web server running using the &lt;code&gt;gulp serve&lt;/code&gt; command we just implemented you’ll see a web page with two
errors complaining that &lt;code&gt;true&lt;/code&gt; does not equal &lt;code&gt;false&lt;/code&gt;. Which is good. Now we can make write some useful tests.&lt;/p&gt;
&lt;p&gt;With the watcher in Gulp running it will run Browserify and reload the tests once you make a change. You don’t have to
run the test command yourself.&lt;/p&gt;
&lt;p&gt;Let’s create a file where the source of &lt;code&gt;TextChanger&lt;/code&gt; will be defined. Create a folder called &lt;code&gt;src&lt;/code&gt; and create a new file
called &lt;code&gt;text-changer.js&lt;/code&gt;. Leave it empty for now.&lt;/p&gt;
&lt;p&gt;Open up the &lt;code&gt;test/tests.js&lt;/code&gt; file, it’s time to fill in the tests.&lt;/p&gt;
&lt;p&gt;First we need to require the &lt;code&gt;TextChanger&lt;/code&gt; module. Do so after &lt;code&gt;var assert = require(&amp;quot;assert&amp;quot;);&lt;/code&gt; by adding:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; assert = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;assert&quot;&lt;/span&gt;),
    textChanger = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;../src/text-changer.js&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that we’ve included our empty module, we can use it in our tests. The first test will check if the given element
holds a &lt;code&gt;textNode&lt;/code&gt; with a string value. The &lt;code&gt;textChanger&lt;/code&gt; object will be a factory which returns an object which holds
the method &lt;code&gt;replaceText&lt;/code&gt;. Given this info the first test can be made.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;it(&lt;span class=&quot;string&quot;&gt;'should replace the content of the element with given text'&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    textChanger().replaceText(element, &lt;span class=&quot;string&quot;&gt;&quot;test&quot;&lt;/span&gt;);

    assert.equal(element.childNodes[&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;].nodeValue, &lt;span class=&quot;string&quot;&gt;&quot;test&quot;&lt;/span&gt;);
});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The second test checks if the method throws an error if no real DOM element is given. Which can be done by doing:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;it(&lt;span class=&quot;string&quot;&gt;'should throw and error if element is not a DOM element'&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    assert.throws(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
        textChanger().replaceText(&lt;span class=&quot;literal&quot;&gt;null&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;test&quot;&lt;/span&gt;);
    }, /DOM element/);
});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that the tests are ready to check our implementation we can continue to coding the module. The biggest advantage we
have now is that we know what the implementation should look like.&lt;/p&gt;
&lt;ol start=&quot;6&quot;&gt;
&lt;li&gt;Implementing your module&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;It is time to make our tests succeed. We know how the module has to work, now we have to make it work.&lt;/p&gt;
&lt;p&gt;Open up the empty &lt;code&gt;src/text-changer.js&lt;/code&gt; file.&lt;/p&gt;
&lt;p&gt;At first we need a little base to fill in our implementation. Place the following content inside.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; textChanger = {
    &lt;span class=&quot;attr&quot;&gt;replaceText&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;element, newText&lt;/span&gt;) &lt;/span&gt;{
        &lt;span class=&quot;comment&quot;&gt;//check if element is a DOM element&lt;/span&gt;

        &lt;span class=&quot;comment&quot;&gt;//remove all the children&lt;/span&gt;

        &lt;span class=&quot;comment&quot;&gt;//add textNode to element&lt;/span&gt;
    }
};

&lt;span class=&quot;built_in&quot;&gt;module&lt;/span&gt;.exports = &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;built_in&quot;&gt;Object&lt;/span&gt;.create(textChanger);
};&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that we have this basis, we see that we might need two extra methods. I’ll call them &lt;code&gt;isDomElement&lt;/code&gt; and
&lt;code&gt;removeChildren&lt;/code&gt;. You could (and should) go back to the tests file and write some tests for these methods too. To keep
this tutorial short, I’ll skip this part.&lt;/p&gt;
&lt;p&gt;Add two extra methods in the &lt;code&gt;textChanger&lt;/code&gt; object called &lt;code&gt;isDomElement&lt;/code&gt; and &lt;code&gt;removeChildren&lt;/code&gt;. Give them the following
implementation:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;isDomElement: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;element&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; (element &amp;amp;&amp;amp; element.nodeType &amp;amp;&amp;amp; element.nodeType === &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;);
},

&lt;span class=&quot;attr&quot;&gt;removeChildren&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;element&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;keyword&quot;&gt;while&lt;/span&gt; (element.firstChild) {
        element.removeChild(element.firstChild);
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So far we’re not doing anything in the &lt;code&gt;replaceText&lt;/code&gt; method which gets called yet. It’s time to implement the first rule
we defined in our tests: *”it should replace the content of the element with given text”*.&lt;/p&gt;
&lt;p&gt;Place the following in the &lt;code&gt;replaceText&lt;/code&gt; method and save the file:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.removeChildren(element);

element.appendChild(
    &lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;.createTextNode(newText)
);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Look at your browser and terminal. You’ll see that the first test is now succeeding. Great! Time to put a check for the
given &lt;code&gt;element&lt;/code&gt; in the method as well.&lt;/p&gt;
&lt;p&gt;Put the following code at the beginning of the &lt;code&gt;replaceText&lt;/code&gt; method:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (!&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.isDomElement(element)) {
    &lt;span class=&quot;keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;built_in&quot;&gt;Error&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;element is not a DOM element&quot;&lt;/span&gt;);
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Save the file and… success! Both tests succeed and should be green in the future of your application. It’s okay to
refactor your tests, as long the integrity stays the same.&lt;/p&gt;
&lt;p&gt;The finished implementation should look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; textChanger = {
    &lt;span class=&quot;attr&quot;&gt;replaceText&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;element, newText&lt;/span&gt;) &lt;/span&gt;{
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (!&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.isDomElement(element)) {
            &lt;span class=&quot;keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;built_in&quot;&gt;Error&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;element is not a DOM element&quot;&lt;/span&gt;);
        }

        &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.removeChildren(element);

        element.appendChild(
            &lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;.createTextNode(newText)
        );
    },

    &lt;span class=&quot;attr&quot;&gt;isDomElement&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;element&lt;/span&gt;) &lt;/span&gt;{
        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; (element &amp;amp;&amp;amp; element.nodeType &amp;amp;&amp;amp; element.nodeType === &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;);
    },

    &lt;span class=&quot;attr&quot;&gt;removeChildren&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;element&lt;/span&gt;) &lt;/span&gt;{
        &lt;span class=&quot;keyword&quot;&gt;while&lt;/span&gt; (element.firstChild) {
            element.removeChild(element.firstChild);
        }
    }
};

&lt;span class=&quot;built_in&quot;&gt;module&lt;/span&gt;.exports = &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;built_in&quot;&gt;Object&lt;/span&gt;.create(textChanger);
};&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;onwards&quot;&gt;Onwards&lt;/h2&gt;
&lt;p&gt;Now you can easily test your JavaScript modules and scripts in your terminal and browser at the same time. Without
having to reload your browser or running a test task all the time.&lt;/p&gt;
&lt;p&gt;Using the following command you can execute the test in your terminal:
&lt;code&gt;node ./node_modules/mocha-phantomjs/bin/mocha-phantomjs test/tests.html&lt;/code&gt;. Keep in mind that you still have to
Browserify your code after you make changes to your tests and implementations.&lt;/p&gt;
&lt;p&gt;I hope this gave you a quick intro into testing your JavaScript code. It takes some time to get used to write your tests
before your code, but it’s worth it in the end.&lt;/p&gt;
</description></item><item><title>Migrating from WordPress to Wintersmith</title><link>https://gaya.pizza/articles/migrating-wordpress-to-wintersmith/</link><pubDate>Thu, 26 Feb 2015 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/migrating-wordpress-to-wintersmith/</guid><author></author><description>&lt;p&gt;Static websites load blazing fast and are fun to make. Having your website calculated for each request is getting out
of style and is becoming less necessary.&lt;/p&gt;
&lt;p&gt;I went through the process of turning the WordPress version of this blog into a statically served website. This article
explains the process behind it and what I did to achieve the current static website.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;##Why static?&lt;/p&gt;
&lt;p&gt;WordPress was my platform of choice back in 2008 when I started writing and publishing articles. Back then I liked the
comfort of not having to write my own content management system for posting blog posts. The amount of plugins available
helped me implement stuff I didn’t really know how to make.&lt;/p&gt;
&lt;p&gt;Years and a lot of web development related experience later I learned that WordPress is not for me. I explained why in
a &lt;a href=&quot;https://gaya.pizza/articles/moving-gaya-design-to-gaya-ninja-blog/&quot;&gt;previous post about rebranding Gaya Design&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;With a static approach I could make my blog behave the way I think it should behave. Calculate the content before it
will is served, not at the time it is requested, like what happens on a typical blog system. You &lt;em&gt;can&lt;/em&gt; kind of prevent
calculations using caching tools, but &lt;em&gt;it still is no holy grail&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;It was a nice challenge for me, since I never really made a statically generated site before. My weblog was the perfect
case for me to go and try it out. I was going to change my blog’s name anyway, so I might as well go ahead and create a
new site along with it.&lt;/p&gt;
&lt;p&gt;##Planning it all out&lt;/p&gt;
&lt;p&gt;There were a few requirements my new weblog had to meet. Since I am quite picky on the quality of my own workflow I
decided I wouldn’t make it easy for myself.&lt;/p&gt;
&lt;p&gt;The things I really wanted were:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Generate everything from the source. Do &lt;strong&gt;not&lt;/strong&gt; have any compiled or generated content in my repository.&lt;/li&gt;
&lt;li&gt;Ability to write posts using MarkDown.&lt;/li&gt;
&lt;li&gt;Being able to test and write for my site locally and deploy it with the same content.&lt;/li&gt;
&lt;li&gt;Deployment from my weblog’s repository. No uploading through FTP.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This meant that I had to go and search for a static site generator that meets these needs. If it had blogging support it
would be even better.&lt;/p&gt;
&lt;p&gt;##Looking for a Static Site Generator&lt;/p&gt;
&lt;p&gt;To be more specific, I was really looking for a static blog generator. I played around with a few, one was &lt;a href=&quot;http://jekyllrb.com&quot;&gt;Jekyll&lt;/a&gt;.
Which is pretty nice, but I came to the conclusion that I wanted to make a Node.js powered blog. Ruby gems were also
driving me nuts, and I am no Ruby specialist, so I stopped there.&lt;/p&gt;
&lt;p&gt;I quickly came across &lt;a href=&quot;https://github.com/hexojs/hexo&quot;&gt;Hexo&lt;/a&gt;, &lt;a href=&quot;http://assemble.io&quot;&gt;Assemble&lt;/a&gt; and
&lt;a href=&quot;http://wintersmith.io&quot;&gt;Wintersmith&lt;/a&gt;, which are all fine frameworks in their own way.&lt;/p&gt;
&lt;p&gt;Before I used &lt;a href=&quot;http://gulpjs.com&quot;&gt;Gulp&lt;/a&gt; I was using &lt;a href=&quot;http://gruntjs.com&quot;&gt;Grunt&lt;/a&gt;, and in that time I’ve had some experience
using Assemble. Which also has a bit of Gulp support, but it only works half of the time and is not recommended for
production environments. This options went out of the window pretty quickly.&lt;/p&gt;
&lt;p&gt;When I started using Wintersmith I completely fell in love. It’s so quick and has a &lt;a href=&quot;https://github.com/jnordberg/wintersmith#using-wintersmith-programmatically&quot;&gt;great programmable interface&lt;/a&gt;
to work with. So that works perfectly if I want to integrate Wintersmith in my Gulp streamline.&lt;/p&gt;
&lt;p&gt;The templating looked easy enough, and there is a &lt;a href=&quot;https://github.com/jnordberg/wintersmith/wiki/Plugins#template-plugins&quot;&gt;large variety of Wintersmith template plugins&lt;/a&gt;
available. Along with the dynamically generated content I was going to need, Wintersmith looked like a solid choice.
Sorry Hexo! Looks like I didn’t even give you a chance.&lt;/p&gt;
&lt;p&gt;##Creating the templates&lt;/p&gt;
&lt;p&gt;In order to go about and create the looks of the website I picked my typical workflow. First I setup my Gulp tasks to
handle processing my Sass files, JavaScript and &lt;a href=&quot;http://www.browsersync.io&quot;&gt;have BrowserSync serve&lt;/a&gt; it with the HTML to
my browser.&lt;/p&gt;
&lt;p&gt;To process my Sass I used &lt;a href=&quot;https://github.com/dlmanning/gulp-sass&quot;&gt;gulp-sass&lt;/a&gt;. It runs on &lt;a href=&quot;https://github.com/sass/libsass&quot;&gt;libsass&lt;/a&gt;,
which makes it super fast too. That’s a great thing when you’re using BrowserSync because the newly generated assets
will be available in the browser really quickly. Especially when you have two monitors where one holds a browser window
and the other one your editor.&lt;/p&gt;
&lt;p&gt;Frameworks I used for styling worth mentioning are: &lt;a href=&quot;http://neat.bourbon.io&quot;&gt;Neat for responsive layout grids&lt;/a&gt;
and &lt;a href=&quot;http://bourbon.io&quot;&gt;Bourbon for standard mixins&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;##SVG&lt;/p&gt;
&lt;p&gt;For my SVG images on the site I used a SVG sprite generator. I choose not to include the SVGs as images in my DOM so I
could keep styling of icons out of my templates. This way I can keep my HTML clean. The only problem was that I needed
a way to calculate the SVG sprite width and height for each element to scale dynamically.&lt;/p&gt;
&lt;p&gt;To generate the SVG sprite from a source folder I used &lt;a href=&quot;https://github.com/jkphl/svg-sprite&quot;&gt;svg-sprite&lt;/a&gt;, a Node.js
module that gathers the SVGS and optimises the output. It also allows you to output a &lt;code&gt;.sass&lt;/code&gt; file to be used. So with
that I generated a Sass file that calculated all the necessary widths and heights.&lt;/p&gt;
&lt;p&gt;##Working with Wintersmith&lt;/p&gt;
&lt;p&gt;The first thing I noticed about Wintersmith is that it, like a lot of other great Node.js projects, uses Jade. I don’t
really like it that much, so I looked for an alternative. &lt;a href=&quot;http://mozilla.github.io/nunjucks/&quot;&gt;Nunjucks&lt;/a&gt; is a templating
language heavily inspired by jinja2, which I was already familiar with. It looked fairly straight-forward, so I went
with it. Looking at &lt;a href=&quot;https://github.com/jnordberg/wintersmith/tree/master/examples/blog/templates&quot;&gt;the examples of Wintersmith&lt;/a&gt;
it was relatively easy to convert my HTML files to Wintersmith templates.&lt;/p&gt;
&lt;p&gt;The only thing I had to do was to create a 404, about and contact page. That was it. Pretty harmless task since
it already took care of most of my requirements.&lt;/p&gt;
&lt;p&gt;As I said before, Wintersmith works really well as a Node.js module, so I created a watcher in Gulp that looks for
changes and regenerates the whole blog on change. The great thing is that it only takes about 1 second for Wintersmith
to do that.&lt;/p&gt;
&lt;p&gt;##Converting content from WordPress to Wintersmith&lt;/p&gt;
&lt;p&gt;Wintersmith is pretty clean in its article structure. It follows a convention that allow me to create a new article in a
folder which contains the MarkDown file with the post. All the images that are used in the MarkDown file can be put in
the same folder.&lt;/p&gt;
&lt;p&gt;The challenge here was to get all the posts from WordPress, add the correct meta data in YAML format and convert the
posts to MarkDown syntax while copying all the images. All the code snippets and internal URLs in the posts had to be
changed as well.&lt;/p&gt;
&lt;p&gt;I wrote a quick convert script for this and it saved me a lot of time. It was a dirty job, but I &lt;strong&gt;had&lt;/strong&gt; to do it.&lt;/p&gt;
&lt;p&gt;##Optimising all the assets&lt;/p&gt;
&lt;p&gt;From the source folder all the assets had to be optimised before serving them to the browser. This happens after all the
files are put in the folder that gets served. After which the server checks all the files and optimises them.&lt;/p&gt;
&lt;p&gt;For image optimisation I used &lt;a href=&quot;https://github.com/imagemin/imagemin&quot;&gt;imagemin&lt;/a&gt;, a pretty quick module that minifies the
images that get passed in. This way I don’t have to optimise the images myself before committing them.&lt;/p&gt;
&lt;p&gt;For my JavaScript I used &lt;a href=&quot;https://github.com/terinjokes/gulp-uglify&quot;&gt;uglify&lt;/a&gt; after it had been bundled using &lt;a href=&quot;http://browserify.org&quot;&gt;Browserify&lt;/a&gt;
and my CSS is shrunk with &lt;a href=&quot;https://github.com/torrottum/gulp-cssshrink&quot;&gt;cssshrink&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To optimise the loading speed of my pages I extracted and inlined the critical-path CSS from my generated pages. This
will allow the pages of my site to be loaded with visual content without blocking the loading with the external CSS file.
To do this I used &lt;a href=&quot;https://github.com/addyosmani/critical&quot;&gt;critical&lt;/a&gt; which scans my pages one by one and injects the
correct inline CSS.&lt;/p&gt;
&lt;p&gt;##Creating a server to serve my content&lt;/p&gt;
&lt;p&gt;What I needed was a simple web server that could serve static files (which were build by my tasks), compress those files
and create a fallback for pages that are not found. An easy way to get this done is to use &lt;a href=&quot;http://expressjs.com&quot;&gt;express&lt;/a&gt;
as the framework.&lt;/p&gt;
&lt;p&gt;For serving content the &lt;a href=&quot;https://github.com/expressjs/serve-static&quot;&gt;serve-static&lt;/a&gt; middleware is really easy to use. For
compression of the output I used &lt;a href=&quot;https://github.com/expressjs/compression&quot;&gt;compression&lt;/a&gt;. For the pages that are not
found I wrote my own middleware that serves my own &lt;code&gt;404.html&lt;/code&gt; file I created.&lt;/p&gt;
&lt;p&gt;All that was left was to build a middleware that handles my contact form submissions. I wrote up a little tool that
handles the given data, puts it in an email and sends it to me. It responds with a simple JSON object telling the sender
everything worked out.&lt;/p&gt;
&lt;p&gt;##Deploying it all&lt;/p&gt;
&lt;p&gt;I went a bit into deploying Node.js applications and came across &lt;a href=&quot;https://github.com/progrium/dokku&quot;&gt;dokku&lt;/a&gt;. It behaves
like Heroku in a way that I can deploy my code on a repository that is hosted on my server and let dokku do the rest.&lt;/p&gt;
&lt;p&gt;Once I push code to my dokku server through Git it will start to install all the dependencies defined in &lt;code&gt;package.json&lt;/code&gt;.
It will than execute the npm scripts I defined in my &lt;code&gt;package.json&lt;/code&gt; file. It will build the site, optimise everything and
test if it worked afterwards. Then it will switch my current running version with the new one. Perfect!&lt;/p&gt;
&lt;p&gt;Now I can finally keep all my source the same on every machine and deploy my article whenever I want them to.&lt;/p&gt;
&lt;p&gt;Have suggestions or found better ways to go static? Feel free to &lt;a href=&quot;https://twitter.com/GayaKessler&quot;&gt;reach out on Twitter&lt;/a&gt;.&lt;/p&gt;
</description></item><item><title>Hire Me</title><link>https://gaya.pizza/articles/hire-me/</link><pubDate>Mon, 23 Feb 2015 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/hire-me/</guid><author></author><description>&lt;p&gt;After a long time of hard consideration I decided to leave my current job. It’s an awesome place to work at and the
management couldn’t be better, but I feel like I am moving in a different direction.&lt;/p&gt;
&lt;p&gt;That said: &lt;del&gt;I am looking for a new job&lt;/del&gt;. I have found a fitting position. A big thank you to all who shared.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/stuck-at-your-web-development-job-break-your-routine/&quot;&gt;As I mentioned before&lt;/a&gt;, being stuck at my job is not
something I want. Being unhappy is something I want to avoid and looking for something else seems like the best solution.&lt;/p&gt;
&lt;p&gt;##What I &lt;del&gt;am&lt;/del&gt; was looking for
Currently I am largely interested in working on JavaScript applications, from in-browser web applications to server-side
Node.js applications. I also love automating all the things and streamlining the development process, the less coders
need to do, the better.&lt;/p&gt;
&lt;p&gt;As much as I love working in offices, I am also open to working remote.&lt;/p&gt;
&lt;p&gt;##Let me know if you know something
If you might know a company that is looking for a JavaScript developer and wants to talk to me, please let me know by
sending an &lt;a href=&quot;mailto:hi@gaya.pizza&quot;&gt;email to hi@gaya.pizza&lt;/a&gt;. You can also &lt;a href=&quot;https://gaya.pizza/contact&quot;&gt;reach me through my contact page&lt;/a&gt; or
&lt;a href=&quot;https://twitter.com/GayaKessler&quot;&gt;my Twitter profile&lt;/a&gt;.&lt;/p&gt;
</description></item><item><title>Moving Gaya Design to Gaya Ninja Blog</title><link>https://gaya.pizza/articles/moving-gaya-design-to-gaya-ninja-blog/</link><pubDate>Mon, 16 Feb 2015 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/moving-gaya-design-to-gaya-ninja-blog/</guid><author></author><description>&lt;p&gt;Since 2008 I’ve been blogging with the name “Gaya Design”. Which is pretty weird since I am not even blogging about
design and am not professionally a designer. It was time to make a move to a different domain and operate with a new name.&lt;/p&gt;
&lt;p&gt;I am very proud to introduce to you: Gaya Ninja Blog.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;##I am not a designer
Ever since my blog took off I felt like I was stuck with the name I once choose to host my blog on. Even before
gayadesign.com was a blog I kind of struggled with the name. It’s a name I made up a long time ago when I started getting
into web design.&lt;/p&gt;
&lt;p&gt;At that time I didn’t even know whether I’d go with a design or development career. I really liked both at the time, but
went with development pretty soon, and I am glad I made that choice.&lt;/p&gt;
&lt;p&gt;When I finally found the time to do something about this problem I began re-branding small parts of my online presence.
&lt;a href=&quot;https://twitter.com/GayaKessler&quot;&gt;My Twitter account&lt;/a&gt; has been renamed to @GayaNinja for a while now and I launched a
website for my personal / professional profile at &lt;a href=&quot;http://gaya.ninja&quot;&gt;http://gaya.ninja&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;##New looks
The looks of Gaya Ninja Blog are not that different from what Gaya Design looked like. The logo is the same, and I
basically use the same colours. I did change the layout and typography, making it more fluid using a grid system.&lt;/p&gt;
&lt;p&gt;I believe that the new looks convey my message in a better and more readable way.&lt;/p&gt;
&lt;p&gt;##Going static
WordPress has been my blog engine on Gaya Design, but it felt like I was using it for the wrong reasons. I don’t
like admin panels, configuring stuff in what seem to be endless forms and writing in a WYSIWYG editor.&lt;/p&gt;
&lt;p&gt;Static website generators have become more popular over time, and since they come so close to front-end development work
I took the plunge and dug into different generator.&lt;/p&gt;
&lt;p&gt;The cool thing now is that I can write my posts in the editor I work mostly in and it’s blazing fast. No need for
sluggish dynamic web pages to write my content in, but plain text in combination with
&lt;a href=&quot;http://daringfireball.net/projects/markdown/&quot;&gt;Markdown&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;##No traditional shared hosting
One of the reasons I wanted to make something new was to experience deployment of applications in a very different way.
Most shared hosting services just have simple FTP deployment and don’t support any custom packages you might want to use.&lt;/p&gt;
&lt;p&gt;I wanted an environment where I could deploy code to and it would build and run my application, in my case my blog.&lt;/p&gt;
&lt;p&gt;Writing my posts in static files also means I can add them to my git repository, making it an awesome way to see how a
post evolved and not having to sync a local and remote database for my data.&lt;/p&gt;
&lt;p&gt;##How I switched
You can read about how I switched from WordPress to a static website in another article called &lt;a href=&quot;https://gaya.pizza/articles/migrating-wordpress-to-wintersmith/&quot;&gt;Migrating from WordPress
to Wintersmith&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;##Let me know what you think
I’d love to hear what you think about the new blog. If you have any suggestions you can tell my on
&lt;a href=&quot;http://twitter.com/GayaKessler&quot;&gt;Twitter&lt;/a&gt; or &lt;a href=&quot;https://gaya.pizza/contact/&quot;&gt;use my contact form&lt;/a&gt;.&lt;/p&gt;
</description></item><item><title>Make Developing Front-end Projects in WordPress Work</title><link>https://gaya.pizza/articles/make-developing-front-end-projects-wordpress-work/</link><pubDate>Fri, 21 Nov 2014 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/make-developing-front-end-projects-wordpress-work/</guid><author></author><description>&lt;p&gt;Working as a front-end developer should be a job where you worry about the stuff you’re good at: creating HTML, CSS and JavaScript. In a perfect setting you don’t have to worry about the CMS or framework the website / app is going to use.&lt;br&gt; When the team chooses to use WordPress, you might be in for a struggle though. Separation between front and back-end development in WordPress is quite vague and is smeared all over the place.&lt;/p&gt;
&lt;p&gt;This article is aimed to convince you why WordPress is bad to front-end developers, what has to be done about it, and finally how a better way of developing can be achieved.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/make-developing-front-end-projects-wordpress-work&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/make-developing-front-end-projects-wordpress-work/make-developing-front-end-projects-wordpress-work1.jpg&quot; alt=&quot;Make Developing Front-end Projects in WordPress Work&quot;&gt;&lt;/a&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;tl-dr&quot;&gt;TL;DR&lt;/h2&gt;
&lt;p&gt;Because of the lengthy nature of this article I am going to put the main point of the article in the following paragraph.&lt;/p&gt;
&lt;p&gt;Front-end development for projects that will use WordPress is bad, but it can be fixed. You can do completely decoupled front-end development for WordPress &lt;strong&gt;without&lt;/strong&gt; using or touching WordPress itself.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;why-front-end-development-in-wordpress-is-bad&quot;&gt;Why front-end development in WordPress is bad&lt;/h2&gt;
&lt;p&gt;There are a few things that smell when you dig into WordPress’ way of handling templates. The first thing that comes to mind when I think about front-end development is creating templates, styling them accordingly and making them interactive using scripts.&lt;/p&gt;
&lt;p&gt;Idealy, the templates we create are generated after we’ve fed them with data and are compiled to some output. For browsers, this is HTML.&lt;/p&gt;
&lt;h3 id=&quot;wordpress-offers-no-real-separation-between-data-and-template&quot;&gt;WordPress offers no real separation between data and template&lt;/h3&gt;
&lt;p&gt;Proven design patterns like the Model View Controller pattern preach that we keep our views away from collecting any data. The views, HTML templates with just a small amount of logic, are only fed with data which they can utilize. If it doesn’t have the correct data, it’s not up to the views to figure that out, it’s what the controller should do.&lt;/p&gt;
&lt;p&gt;If you’d go about and request data from the system directly in your views you’re relying upon the system at hand. In WordPress we use PHP to get posts and loop through them, even requesting information about the posts as we go. This should have been done before the view was loaded.&lt;/p&gt;
&lt;p&gt;We can’t move our code and use the templates in another project that doesn’t use WordPress. We’re too heavily coupled to WordPress.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/make-developing-front-end-projects-wordpress-work/architecture-wordpress.jpg&quot; alt=&quot;Architecture in WordPress gets pretty awkward since we can&amp;#39;t really decouple front-end from server-side.&quot;&gt;&lt;/p&gt;
&lt;p&gt;Architecture in WordPress gets pretty awkward since we can’t really decouple front-end from server-side.&lt;/p&gt;
&lt;h3 id=&quot;we-re-front-end-developers-and-we-re-using-php&quot;&gt;We’re front-end developers, and we’re using PHP&lt;/h3&gt;
&lt;p&gt;It’s rather strange that we’re being forced to use PHP when coding a theme in WordPress. This makes our project dependent not only on WordPress, but also on PHP. There is no way we can move our code to a Ruby on Rails project or a Node.js project that uses something like Handlebars to generate HTML.&lt;/p&gt;
&lt;p&gt;We’re using a server-side only language, why keep stacking up different languages on top of our development work? Is keeping track of HTML, CSS, JavaScript, template languages and pre-processors not enough?&lt;/p&gt;
&lt;h3 id=&quot;where-do-you-stop-developing-the-front-end-&quot;&gt;Where do you stop developing the front-end?&lt;/h3&gt;
&lt;p&gt;There is no real reason for a front-end developer to even have to use WordPress to work on a project. When the source of your templates have to be adjusted to the actual system it will be run on it’s not perfect.&lt;/p&gt;
&lt;p&gt;Are you just going to deliver some HTML, CSS and JavaScript to a back-end developer and let them do the rest? That sounds a lot like the waterfall project method, just throwing stuff over the fence.&lt;/p&gt;
&lt;p&gt;There is no way for you to simultaneously work on the same project without one of the parties having to integrate each other’s code.&lt;/p&gt;
&lt;h3 id=&quot;wordpress-forces-us-to-follow-their-structure&quot;&gt;WordPress forces us to follow their structure&lt;/h3&gt;
&lt;p&gt;The root of a theme has to at least contain a &lt;code&gt;style.css&lt;/code&gt; file and an &lt;code&gt;index.php&lt;/code&gt; file. It’s pretty weird that the information of the theme is stored in a CSS file in the root, while we might not want our stylesheet to live in this location. Why is there no configuration file that allows me to set these kind of parameters?&lt;/p&gt;
&lt;p&gt;We can work around this problem, but still we’re forced to use this strange way of passing information. It’s cluttering our file structure.&lt;/p&gt;
&lt;h3 id=&quot;adjusting-your-work-along-the-way-is-a-pain&quot;&gt;Adjusting your work along the way is a pain&lt;/h3&gt;
&lt;p&gt;You’ll have to either work on the project that has been integrated in a WordPress theme directly, or deliver new lines of code and risk for the changes to be interpreted differently from what you meant them to be.&lt;/p&gt;
&lt;p&gt;If there is one thing that’s bad, it’s having to run a complete WordPress install, import a database dump and setup WordPress to ‘just’ adjust a small problem in HTML, CSS or JavaScript.&lt;/p&gt;
&lt;p&gt;Now imagine the project extending with new functionality. There we go again.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;what-we-need-for-it-to-work&quot;&gt;What we need for it to work&lt;/h2&gt;
&lt;p&gt;Ranting about a subject is rather easy if it’s in a really bad state, but saying what needs to be done is worth a lot more.&lt;/p&gt;
&lt;h3 id=&quot;we-need-a-way-to-template-without-using-wordpress&quot;&gt;We need a way to template without using WordPress&lt;/h3&gt;
&lt;p&gt;There is a simple need to be able to start up a project from scratch without thinking about which Content Management System or framework will be used later. As a front-end developer you can decide to use a templating language which your tools can generate HTML out of.&lt;/p&gt;
&lt;p&gt;This way we can prevent WordPress from even touching our work and still make our HTML powered templates and styling. You do have to keep in mind which templating languages can be used.&lt;/p&gt;
&lt;h3 id=&quot;have-a-way-to-create-dynamic-pages-generated-from-our-templates&quot;&gt;Have a way to create dynamic pages, generated from our templates&lt;/h3&gt;
&lt;p&gt;Without having WordPress to support generating our pages, we need a way to dynamically generate pages to be able to use a base template we can extend to generate different types of pages.&lt;/p&gt;
&lt;p&gt;We want to be able to loop through simple data structures and output them dynamically through our templates. This test data we will provide ourselves.&lt;/p&gt;
&lt;h3 id=&quot;defining-the-data&quot;&gt;Defining the data&lt;/h3&gt;
&lt;p&gt;Before we can start creating templates we have to define the data we want to use. This way we can create a layer between our views and the underlaying information. It helps the back-end developer too, since they will know what information you need on certain pages.&lt;/p&gt;
&lt;p&gt;It’s also a good way to hand over your project to the back-end developers since they’re already informed of the information the pages need in order to work correctly.&lt;/p&gt;
&lt;p&gt;This also be reversed if the back-end developer defined the available information beforehand.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/make-developing-front-end-projects-wordpress-work/no-cms1.png&quot; alt=&quot;No CMS allowed&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;all-previous-points-have-to-work-independent-of-any-cms-or-framework&quot;&gt;All previous points have to work independent of any CMS or framework&lt;/h3&gt;
&lt;p&gt;The views, templates, styles, and JavaScript you make should be able to work in different environments.&lt;/p&gt;
&lt;p&gt;When a change has to be made along the way, you only have to adjust your work and it has to be able to be applied in different environments without testing it there. In this case WordPress.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;how-to-improve-front-end-development-in-wordpress&quot;&gt;How to improve front-end development in WordPress&lt;/h2&gt;
&lt;p&gt;Luckily for us, more people struggle with seperation of data / logic and views in WordPress theming. &lt;a href=&quot;https://github.com/jarednova/timber&quot;&gt;Timber&lt;/a&gt; is a plugin that uses the &lt;a href=&quot;http://twig.sensiolabs.org&quot;&gt;Twig Template Engine&lt;/a&gt; to render HTML output.&lt;/p&gt;
&lt;p&gt;Twig is heavily inspired by &lt;a href=&quot;http://jinja.pocoo.org&quot;&gt;Jinja&lt;/a&gt;, which is also used by other templating languages used on different platforms. It makes for a good interchangeable way of templating.&lt;/p&gt;
&lt;h3 id=&quot;use-timber-for-view-and-logic-separation&quot;&gt;Use Timber for view and logic separation&lt;/h3&gt;
&lt;p&gt;Timber will serve as a simple layer between WordPress’ theme approach and your templates. It will query data using its own methods in the theme’s PHP files and pass it to your templates.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://upstatement.com/timber/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/make-developing-front-end-projects-wordpress-work/timber-logo.png&quot; alt=&quot;Timber&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The great thing about this is that we can forget about using WordPress altogether and let the back-end developer take it from here. We’ve finally created a separation between front-end and back-end.&lt;/p&gt;
&lt;h3 id=&quot;use-timber-s-starter-theme&quot;&gt;Use Timber’s starter theme&lt;/h3&gt;
&lt;p&gt;In the plugin source of Timber you can find &lt;a href=&quot;https://github.com/jarednova/timber/tree/master/timber-starter-theme&quot;&gt;the starter theme&lt;/a&gt;. This gives you and the back-end developer a great way to start using Timber in WordPress.&lt;/p&gt;
&lt;p&gt;I won’t go deep into the functionality of Timber. The documentation is very clear and the learning curve is quite low.&lt;/p&gt;
&lt;h3 id=&quot;twig-js-to-render-templates&quot;&gt;Twig.js to render templates&lt;/h3&gt;
&lt;p&gt;If we are going to stop using WordPress to render our templates, we have to start using another render engine. Since Timber uses Twig, we have to look for a front-end development stack friendly alternative.&lt;/p&gt;
&lt;p&gt;With the popularity of build tools like Grunt and Gulp being used in development flows, it’s great to know that there is a JavaScript implementation of Twig. It’s called &lt;a href=&quot;https://github.com/justjohn/twig.js&quot;&gt;Twig.js&lt;/a&gt; and can be found on GitHub.&lt;/p&gt;
&lt;p&gt;Use Twig.js to render your template files with mock-up data you provide.&lt;/p&gt;
&lt;h3 id=&quot;an-example-of-rendering-with-twig-js&quot;&gt;An example of rendering with Twig.js&lt;/h3&gt;
&lt;p&gt;Node.js can utilize Twig.js, feed it mock-up data and save the &lt;code&gt;*.twig&lt;/code&gt; files as &lt;code&gt;*.html&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Given the following Twig template file:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;html&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;title&lt;/span&gt;&amp;gt;&lt;/span&gt;{{ title }}&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;title&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;body&lt;/span&gt;&amp;gt;&lt;/span&gt;
        {% for item in arrayWithData %}
            {{ item }}
        {% endfor %}
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;body&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;html&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and the following script in Node.js:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; Twig = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'twig'&lt;/span&gt;),
    twig = Twig.twig;

&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; html = twig({
    &lt;span class=&quot;attr&quot;&gt;path&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;'path/to/template.twig'&lt;/span&gt;,
    &lt;span class=&quot;attr&quot;&gt;async&lt;/span&gt;: &lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt;
}).render({
    &lt;span class=&quot;attr&quot;&gt;arrayWithData&lt;/span&gt;: [&lt;span class=&quot;string&quot;&gt;&quot;Twig&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;is&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;fun!&quot;&lt;/span&gt;]
});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Running the code would result in the following HTML in the &lt;code&gt;var html&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;html&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;title&lt;/span&gt;&amp;gt;&lt;/span&gt;Title&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;title&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;body&lt;/span&gt;&amp;gt;&lt;/span&gt;
        Twig is fun!
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;body&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;html&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;use-it-in-your-workflow-&quot;&gt;Use it in your workflow!&lt;/h3&gt;
&lt;p&gt;There is a &lt;a href=&quot;https://www.npmjs.org/package/gulp-twig&quot;&gt;Gulp plugin for Twig.js&lt;/a&gt;, and a &lt;a href=&quot;https://github.com/adamdicarlo/grunt-twig&quot;&gt;Twig.js plugin for Grunt&lt;/a&gt;. You can use these to compile Twig files which can later be used in Timber.&lt;/p&gt;
&lt;p&gt;This way you don’t have to use WordPress to create dynamic webpages.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;my-approach-to-developing-front-end-for-wordpress-and-timber-using-gulp-and-twig-js&quot;&gt;My approach to developing front-end for WordPress and Timber using Gulp and Twig.js&lt;/h2&gt;
&lt;p&gt;In order to start working with Twig.js and Timber we need a way to convert our Twig templates to HTML and feed data to the templates while we do so. The next part shows an approach that can be used in combination with Gulp or just plain Node.js.&lt;/p&gt;
&lt;h3 id=&quot;what-the-gulp-task-will-do&quot;&gt;What the Gulp task will do&lt;/h3&gt;
&lt;p&gt;When creating templates for Timber I use the &lt;a href=&quot;http://codex.wordpress.org/Page_Templates&quot;&gt;page template approach WordPress uses&lt;/a&gt;. This also means I’ll be naming my templates this way: &lt;code&gt;template-*.twig&lt;/code&gt;. We only need to compile these files to see the pages we create.&lt;/p&gt;
&lt;p&gt;We need a way to get these files, feed them some information about the site and optionally information about the page Twig is rendering at that point.&lt;/p&gt;
&lt;p&gt;The task will do a few things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Look for &lt;code&gt;template-*.twig&lt;/code&gt; files.&lt;/li&gt;
&lt;li&gt;Get the basic information.&lt;/li&gt;
&lt;li&gt;Extend the basic information with template specific information if available.&lt;/li&gt;
&lt;li&gt;Render the template file with the information it gathered.&lt;/li&gt;
&lt;li&gt;Save the HTML version somewhere.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;installing-dependencies&quot;&gt;Installing dependencies&lt;/h3&gt;
&lt;p&gt;We need a few things in order for the script to work. Install them with &lt;code&gt;npm&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install --save-dev twig underscore gulp&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;the-gulp-task&quot;&gt;The gulp task&lt;/h3&gt;
&lt;p&gt;The following is the gulp task I came up with. Feel free to fiddle with it a bit and test is out by running &lt;code&gt;gulp timber&lt;/code&gt; in the terminal.&lt;/p&gt;
&lt;p&gt;I’ve placed &lt;a href=&quot;https://github.com/Gaya/gulp-timber-example&quot;&gt;an example of using only Gulp and Twig in a project on GitHub&lt;/a&gt;. It illustrates how to use the following task in Gulp.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; gulp = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'gulp'&lt;/span&gt;),
    Twig = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'twig'&lt;/span&gt;),
    fs = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'fs'&lt;/span&gt;),
    _ = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'underscore'&lt;/span&gt;);

&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; paths = {
    &lt;span class=&quot;attr&quot;&gt;views&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;./views&quot;&lt;/span&gt;, &lt;span class=&quot;comment&quot;&gt;//path where your .twig files are&lt;/span&gt;
    &lt;span class=&quot;attr&quot;&gt;data&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;./data&quot;&lt;/span&gt;, &lt;span class=&quot;comment&quot;&gt;//path to the data .json files&lt;/span&gt;
    &lt;span class=&quot;attr&quot;&gt;dest&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;./dist&quot;&lt;/span&gt; &lt;span class=&quot;comment&quot;&gt;//destination of the html files&lt;/span&gt;
};

gulp.task(&lt;span class=&quot;string&quot;&gt;'timber'&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;cb&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;string&quot;&gt;&quot;use strict&quot;&lt;/span&gt;;
    &lt;span class=&quot;comment&quot;&gt;//standard function called in Timber templates&lt;/span&gt;
    Twig.extendFunction(&lt;span class=&quot;string&quot;&gt;&quot;function&quot;&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;name&lt;/span&gt;) &lt;/span&gt;{
        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&quot;&amp;lt;!--- function called &quot;&lt;/span&gt; + name + &lt;span class=&quot;string&quot;&gt;&quot; --&amp;gt;&quot;&lt;/span&gt;;
    });
    Twig.cache(&lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt;); &lt;span class=&quot;comment&quot;&gt;//disable cache to prevent HTML not updating&lt;/span&gt;

    &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; files = fs.readdirSync(&lt;span class=&quot;string&quot;&gt;&quot;./&quot;&lt;/span&gt; + paths.views); &lt;span class=&quot;comment&quot;&gt;//read all the files in 'views'&lt;/span&gt;
    files.forEach(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;file&lt;/span&gt;) &lt;/span&gt;{
        &lt;span class=&quot;comment&quot;&gt;//if the file name doesn't match template-*.twig: skip this file&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (file.substr(&lt;span class=&quot;number&quot;&gt;-5&lt;/span&gt;) !== &lt;span class=&quot;string&quot;&gt;&quot;.twig&quot;&lt;/span&gt; || file.indexOf(&lt;span class=&quot;string&quot;&gt;&quot;template-&quot;&lt;/span&gt;) === &lt;span class=&quot;number&quot;&gt;-1&lt;/span&gt;) {
            &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt;; 
        }

        &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; template = Twig.twig({
            &lt;span class=&quot;attr&quot;&gt;path&lt;/span&gt;: paths.views + &lt;span class=&quot;string&quot;&gt;&quot;/&quot;&lt;/span&gt; + file,
            &lt;span class=&quot;attr&quot;&gt;async&lt;/span&gt;: &lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt;
        }); &lt;span class=&quot;comment&quot;&gt;//read the file with Twig&lt;/span&gt;

        &lt;span class=&quot;comment&quot;&gt;//read the base Timber .json file&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; data = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(paths.data + &lt;span class=&quot;string&quot;&gt;&quot;/timber.json&quot;&lt;/span&gt;);

        &lt;span class=&quot;comment&quot;&gt;//check it template-*.json exists&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; templateData = file.replace(&lt;span class=&quot;string&quot;&gt;&quot;.twig&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;.json&quot;&lt;/span&gt;);
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (fs.existsSync(paths.data + &lt;span class=&quot;string&quot;&gt;&quot;/&quot;&lt;/span&gt; + templateData)) {
            &lt;span class=&quot;comment&quot;&gt;//if so, join its data with the base information&lt;/span&gt;
            _.extend(data, &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(paths.data + &lt;span class=&quot;string&quot;&gt;&quot;/&quot;&lt;/span&gt; + templateData));
        }

        &lt;span class=&quot;comment&quot;&gt;//replace .twig with .html in the file name, render the file and save the outcome&lt;/span&gt;
        fs.writeFile(paths.dest + &lt;span class=&quot;string&quot;&gt;&quot;/&quot;&lt;/span&gt; + file.replace(&lt;span class=&quot;string&quot;&gt;&quot;.twig&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;.html&quot;&lt;/span&gt;), template.render(data));
    });
    cb();
});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;a href=&quot;https://github.com/Gaya/gulp-timber-example/blob/master/data/timber.json&quot;&gt;basic timber.json file&lt;/a&gt; which is being referred to in the code can be used as a data template for the Twig template you can find in the Timber Starter Theme. It has the structure to get you going.&lt;/p&gt;
&lt;h3 id=&quot;adding-your-own-data&quot;&gt;Adding your own data&lt;/h3&gt;
&lt;p&gt;You can add global data that has to be applied on all templates in the &lt;code&gt;timber.json&lt;/code&gt; file in &lt;code&gt;./data/&lt;/code&gt;. To add template specific data you have to create a file with the same name in the &lt;code&gt;./data/&lt;/code&gt; folder, but replace the extension with &lt;code&gt;.json&lt;/code&gt; instead of &lt;code&gt;.twig&lt;/code&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-bad-parts-about-the-solution&quot;&gt;The bad parts about the solution&lt;/h2&gt;
&lt;p&gt;The only bad things I can say so far is that we’re tied to Twig since Timber uses that. It also follows a pretty stict data structure as can be seen in the &lt;code&gt;timber.json&lt;/code&gt; file, but once you get to know the structure of the data Timber gives you, it’s not that hard to get used to it. Besides, Twig is almost 100% interchangeable with other template rendering solutions based on the same principles.&lt;/p&gt;
&lt;h2 id=&quot;conclusion-and-onwards&quot;&gt;Conclusion and onwards&lt;/h2&gt;
&lt;p&gt;Using the approach discussed earlier you can separate yourself completely from the server-side of web development in WordPress. You can focus on creating templates, while the back-end developer can focus on providing the correct data using your crafted template files.&lt;/p&gt;
&lt;p&gt;Now you can create a deployment flow with your back-end developer as to how he will receive your templates. The great thing is that is that you never have to fiddle with getting a WordPress setup running before you can test your own templates. Adjust, test and validate them so you can give them to your back-end developer to apply them on production.&lt;/p&gt;
&lt;p&gt;Developing in a team that uses WordPress has just become a bit less painful.&lt;/p&gt;
</description></item><item><title>Simple Node.js web server on DigitalOcean</title><link>https://gaya.pizza/articles/simple-node-js-web-server-digitalocean/</link><pubDate>Thu, 30 Oct 2014 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/simple-node-js-web-server-digitalocean/</guid><author></author><description>&lt;p&gt;With &lt;a href=&quot;https://www.digitalocean.com/?refcode=d5a2f709c373&quot;&gt;DigitalOcean&lt;/a&gt; you can deploy your very own cloud based server in a very short time. This makes is perfect for hosting web apps. You can use Node.js to run as a web server and serve files and responses to the client. Setting up a Node.js powered web server is relatively easy when using DigitalOcean.&lt;/p&gt;
&lt;p&gt;In this article I’ll guide you from setting up a DigitalOcean droplet to running a simple HTTP static file server in Node.js.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/simple-node-js-web-server-digitalocean/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/simple-node-js-web-server-digitalocean/simple-node-js-web-server-on-digitalocean.jpg&quot; alt=&quot;Simple Node.js web server on DigitalOcean&quot;&gt;&lt;/a&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;You can use Node.js to act as a static file server. It receives a request for a file, and Node.js returns the file contents. It’s very basic and standard functionality you see in most HTTP servers like Apache and nginx.&lt;/p&gt;
&lt;p&gt;In order to get the web server running we need to do four things:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;#1-sign-up-for-digitalocean&quot;&gt;Sign up for DigitalOcean&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#2-create-a-droplet-from-a-predefined-image&quot;&gt;Create a Droplet from a predefined image&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#3-install-a-node-js-web-server-on-your-droplet&quot;&gt;Install a Node.js web server on your droplet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#4-create-startup-script-to-run-your-application-as-a-service&quot;&gt;Create startup script to run your application as a service&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;##1. Sign up for DigitalOcean&lt;/p&gt;
&lt;p&gt;First things first, in order to follow this tutorial you’ll have to &lt;a href=&quot;https://www.digitalocean.com/?refcode=d5a2f709c373&quot;&gt;register for an account at DigitalOcean&lt;/a&gt;. With this referral link you’ll get $10 in credits for free!&lt;/p&gt;
&lt;p&gt;You can skip this step if you’re already signed up.&lt;/p&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;Create a Droplet from a predefined image&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;Once you’re signed up and logged in to your account, you’ll end up on the list of droplets you own. If you’re new it should be an empty list.&lt;/p&gt;
&lt;p&gt;Go ahead and press the big green ‘create’ or blue ‘create droplet’ button to &lt;a href=&quot;https://cloud.digitalocean.com/droplets/new&quot;&gt;create a new droplet&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/simple-node-js-web-server-digitalocean/create-new-droplet-digital-ocean.jpg&quot; alt=&quot;Create new droplet in Digital Ocean&quot;&gt;
&lt;em&gt;Create new droplet in Digital Ocean&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Enter a host name for your droplet. Choose a size and region.&lt;/p&gt;
&lt;p&gt;The smallest size plan is big enough for most simple applications and the static server we’re making works great on this plan.&lt;/p&gt;
&lt;p&gt;It’s probably smart to choose a region that is close to you or where the application is mostly used.&lt;/p&gt;
&lt;p&gt;Now select the predefined Node.js image. It runs on Ubuntu 14.04 at the time of writing.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/simple-node-js-web-server-digitalocean/select-node-js-image-digital-ocean.jpg&quot; alt=&quot;Select the Node.js image&quot;&gt;
&lt;em&gt;Select the Node.js image&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Hit ‘create droplet’ at the bottom of the page and your droplet will be created.&lt;/p&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;Install a Node.js web server on your droplet&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;When DigitalOcean is done creating your droplet, you should receive an email with the ip address of the droplet, the username and the password. These are used to login to your droplet using ssh.&lt;/p&gt;
&lt;p&gt;Open up terminal or something similar that enables terminal access to external server through ssh.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Connect to the server by executing the following line&lt;/em&gt;, replace &lt;code&gt;username&lt;/code&gt; and &lt;code&gt;ipaddress&lt;/code&gt; with the credentials in the email you got.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ssh username@ipaddress&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Enter the password you got in the email. You should now be logged in to your droplet through ssh.&lt;/p&gt;
&lt;p&gt;We need to make a place for the Node.js application and the folder with files that will be served. Create a folder called &lt;code&gt;/var/www/&lt;/code&gt; and navigate to that folder.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mkdir /var/www
cd /var/www&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The application will be using npm for its dependencies. The application will essentially be a Node.js app which listens to incoming requests to the server while it’s running.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/senchalabs/connect&quot; title=&quot;Connect for Node.js&quot;&gt;Connect&lt;/a&gt; is a perfectly fine middleware to handle those requests. We can add other middleware to connect so that it does more for us. In the example in the GitHub readme of connect you can see they use &lt;code&gt;compression&lt;/code&gt; to compress the response. This is used as a middleware in connect. &lt;code&gt;serve-static&lt;/code&gt; is the middleware that handles static file requests. We’ll use these packages in this example.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Init the project&lt;/em&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm init&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;em&gt;Answer the questions and then install the dependencies.&lt;/em&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install --save compression connect http serve-static&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following simple server application script is based on connect’s readme, but stripped down for our needs.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Place to following code in a file&lt;/em&gt; called &lt;code&gt;server.js&lt;/code&gt;. (By doing &lt;code&gt;vim server.js&lt;/code&gt;)&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; connect = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'connect'&lt;/span&gt;);
&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; http = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'http'&lt;/span&gt;);
&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; app = connect();

&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; compression = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'compression'&lt;/span&gt;)
app.use(compression())

&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;static&lt;/span&gt; = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'serve-static'&lt;/span&gt;);
app.use(&lt;span class=&quot;keyword&quot;&gt;static&lt;/span&gt;(__dirname + &lt;span class=&quot;string&quot;&gt;&quot;/httpdocs&quot;&lt;/span&gt;));

http.createServer(app).listen(process.env.PORT || &lt;span class=&quot;number&quot;&gt;80&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To start the web server, execute the script using Node.js.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;node server.js&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;All the files that are in &lt;code&gt;/var/www/httpdocs&lt;/code&gt; will now be available publicly. You can adjust the folder name by adjusting it in the script. You can also put in an absolute path to a folder if you’d like.&lt;/p&gt;
&lt;p&gt;To stop running the server (do so for the purpose of this tutorial) press &lt;code&gt;ctrl + c&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Next up is making the server execute the script on startup or reboot. So when something goes wrong you don’t have to manually rerun the Node.js script.&lt;/p&gt;
&lt;ol start=&quot;4&quot;&gt;
&lt;li&gt;Create startup script to run your application as a service&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;To run the Node.js powered web server as a service, we can use &lt;a href=&quot;http://upstart.ubuntu.com/&quot;&gt;Upstart&lt;/a&gt;. Upstart provides an easy and scriptable way to add your own daemons.&lt;/p&gt;
&lt;p&gt;It will run commands on startup and power down of the server, which will be perfect in this situation.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Create a file called&lt;/em&gt; &lt;code&gt;node-server.conf&lt;/code&gt; &lt;em&gt;in&lt;/em&gt; &lt;code&gt;/etc/init/&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;vim /etc/init/node-server.conf&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following script is an adjustment of &lt;a href=&quot;http://kvz.io/blog/2009/12/15/run-nodejs-as-a-service-on-ubuntu-karmic/&quot;&gt;Kevin van Zonneveld’s Upstart script&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Place the contents in the file that you just opened in vim.&lt;/em&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;description &amp;quot;node.js server&amp;quot;
author      &amp;quot;Your name&amp;quot;

# used to be: start on startup
# until we found some mounts weren&amp;#39;t ready yet while booting:
start on started mountall
stop on shutdown

# Automatically Respawn:
respawn
respawn limit 99 5

script
    # Not sure why $HOME is needed, but we found that it is:
    export HOME=&amp;quot;/root&amp;quot;

    exec /usr/local/bin/node /var/www/server.js &amp;gt;&amp;gt; /var/log/node.log 2&amp;gt;&amp;amp;1
end script&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Note that at the end of the script &lt;code&gt;/var/www/server.js&lt;/code&gt; is executed by Node.js. If you saved the file on a different location, you can change the path.&lt;/p&gt;
&lt;p&gt;To start the service that was just created &lt;em&gt;type the following command&lt;/em&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;start node-server&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That’s it!&lt;/p&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;You now know how to create your own droplet using DigitalOcean and how to run a simple HTTP server on it. To access the files through your Internet browser you can go to the ip address of your droplet directly.&lt;/p&gt;
&lt;p&gt;Suggestions for a better, safer solution are welcome. &lt;a href=&quot;http://twitter.com/GayaKessler&quot;&gt;Reach out on Twitter&lt;/a&gt; or &lt;a href=&quot;https://gaya.pizza/contact/&quot;&gt;use my contact form&lt;/a&gt;.&lt;/p&gt;
</description></item><item><title>MarkPress: Markdown powered journal for WordPress</title><link>https://gaya.pizza/articles/markpress-markdown-powered-journal-wordpress/</link><pubDate>Tue, 05  Aug 2014 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/markpress-markdown-powered-journal-wordpress/</guid><author></author><description>&lt;p&gt;Markdown is used to quickly write a styled document with a simple syntax, great for taking notes or writing journals. MarkPress allows you to turn your WordPress install into an App to easily write and store Markdown notes.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/markpress-markdown-powered-journal-wordpress/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/markpress-markdown-powered-journal-wordpress/markpress-markdown-powered-journal-wordpress1.jpg&quot; alt=&quot;MarkPress: Markdown powered journal for WordPress&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;what-is-markpress-&quot;&gt;What is MarkPress?&lt;/h2&gt;
&lt;p&gt;Starting as an idea by &lt;a href=&quot;http://coenjacobs.me/&quot;&gt;Coen Jacobs&lt;/a&gt;, and me wanting to do something with WordPress again, I started writing this little app.&lt;/p&gt;
&lt;p&gt;Its requirements were simple:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Write some notes on findings you made.&lt;/li&gt;
&lt;li&gt;Automatically save them somewhere&lt;/li&gt;
&lt;li&gt;Enable tagging&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://daringfireball.net/projects/markdown/syntax&quot;&gt;Make it nice with Markdown&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Available everywhere on every device&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;There were not a lot of apps that do all this, so the easiest thing was to quickly write a web app and let WordPress store the data.&lt;/p&gt;
&lt;p&gt;And then, MarkPress was born.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/markpress-markdown-powered-journal-wordpress/screenshot-1.jpg&quot; alt=&quot;Example of how you&amp;#39;d write a journal note.&quot;&gt; &lt;em&gt;Example of how you’d write a journal note.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;how-to-install-&quot;&gt;How to install:&lt;/h2&gt;
&lt;p&gt;You can install MarkPress by searching for ‘MarkPress’ when adding a new plugin to your WordPress install.&lt;/p&gt;
&lt;p&gt;The plugin is also available for download on WordPress.org’s Plugin Directory: &lt;a href=&quot;http://wordpress.org/plugins/markpress/&quot;&gt;http://wordpress.org/plugins/markpress/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Or download on GitHub:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/Gaya/MarkPress/releases&quot;&gt;Download the latest version&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Upload contents of &lt;code&gt;markpress&lt;/code&gt; to &lt;code&gt;wp-content/plugins/&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Activate plugin in &lt;code&gt;wp-admin&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;how-to-use-&quot;&gt;How to use:&lt;/h2&gt;
&lt;p&gt;The app is really easy to use. Go to your WordPress install’s frontpage (not &lt;code&gt;wp-admin&lt;/code&gt;), fill some Markdown content in the editor on the left and see the content marked up on the right.&lt;/p&gt;
&lt;p&gt;Every 10 seconds the content of the post is automatically saved to the server, so no need to worry about that.&lt;/p&gt;
&lt;p&gt;Hit the big ‘+’ button to add a new note.&lt;/p&gt;
&lt;h2 id=&quot;contributing&quot;&gt;Contributing&lt;/h2&gt;
&lt;p&gt;More information about how to contribute to this plugin can be found on GitHub:&lt;br&gt;&lt;a href=&quot;https://github.com/Gaya/MarkPress&quot;&gt;https://github.com/Gaya/MarkPress&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;having-trouble-&quot;&gt;Having trouble?&lt;/h2&gt;
&lt;p&gt;You can shoot me an email with any questions on: &lt;a href=&quot;mailto:hi@gaya.pizza&quot;&gt;hi@gaya.pizza&lt;/a&gt; or you can file issues on GitHub via: &lt;a href=&quot;https://github.com/Gaya/MarkPress/issues&quot;&gt;https://github.com/Gaya/MarkPress/issues&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Better JavaScript Dependency Management with Browserify</title><link>https://gaya.pizza/articles/better-javascript-dependency-management-with-browserify/</link><pubDate>Wed, 23 Jul 2014 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/better-javascript-dependency-management-with-browserify/</guid><author></author><description>&lt;p&gt;Writing bundled JavaScript code for the browser tends to become a mess rather soon. We spend a lot of time arranging the code that has to be concatenated in the right order so every dependency gets loaded correctly.&lt;/p&gt;
&lt;p&gt;Browserify can require dependencies for JavaScript like modules in node.js. This brings a lot of advantages to the way we can handle our required libraries.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/better-javascript-dependency-management-with-browserify/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/better-javascript-dependency-management-with-browserify/better-javascript-dependency-management-with-browserify.jpg&quot; alt=&quot;better-javascript-dependency-management-with-browserify&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;what-is-wrong-with-plain-javascript-concatenation-&quot;&gt;What is wrong with plain JavaScript concatenation?&lt;/h2&gt;
&lt;p&gt;Most of the time when concatenating JavaScript files we’d list them all before running a concatenation task, making sure all the files are loaded in the correct order. We’d have to write out every single dependency by hand, especially when it comes to external libraries.&lt;/p&gt;
&lt;p&gt;In a Gruntfile I’d first define a few paths to dependencies I got through Bower, npm or downloaded manually. Then I’d have to point to each file and make sure the order is correct.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;src: [
    &lt;span class=&quot;comment&quot;&gt;//libraries&lt;/span&gt;
    &lt;span class=&quot;string&quot;&gt;'bower_components/eventie/eventie.js'&lt;/span&gt;,
    &lt;span class=&quot;string&quot;&gt;'bower_components/eventEmitter/EventEmitter.js'&lt;/span&gt;,
    &lt;span class=&quot;string&quot;&gt;'bower_components/imagesloaded/imagesloaded.js'&lt;/span&gt;,
    &lt;span class=&quot;comment&quot;&gt;/* I DON'T LIKE DOING THIS! */&lt;/span&gt;

    &lt;span class=&quot;comment&quot;&gt;//other files&lt;/span&gt;
    &lt;span class=&quot;string&quot;&gt;'src/!(base).js'&lt;/span&gt;,

    &lt;span class=&quot;comment&quot;&gt;//the base has to be last&lt;/span&gt;
    &lt;span class=&quot;string&quot;&gt;'src/base.js'&lt;/span&gt;
]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This might not look like such a big problem, but can be a pretty tedious task when you have to get new dependencies or when a dependency updates. The paths tend to leave a mess since most repositories have a different way of pointing to the main JavaScript files to include.&lt;/p&gt;
&lt;p&gt;Another downside is that the files you want to include in your concatenation have to be “compiled” and include all the project’s code and its dependencies.&lt;/p&gt;
&lt;h2 id=&quot;requiring-javascript-modules-in-browsers-with-browserify&quot;&gt;Requiring JavaScript modules in browsers with Browserify&lt;/h2&gt;
&lt;p&gt;Node.js uses CommonJS to include modules in your code. We can install packages using npm and require them in our projects as modules. We can put these modules in an object to use and we don’t have to worry about loading the correct files.&lt;/p&gt;
&lt;p&gt;We can define which module the current file depends on so we can let CommonJS solve the rest. This, however, doesn’t work in the browser. Browsers can’t require files like node.js does.&lt;/p&gt;
&lt;p&gt;This is where &lt;a href=&quot;http://browserify.org/&quot; title=&quot;Browserify&quot;&gt;Browserify&lt;/a&gt; comes in and creates a wrapper around our required npm modules so we can use &lt;code&gt;require()&lt;/code&gt; in the browser versions of our JavaScript.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; _ = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'underscore'&lt;/span&gt;); &lt;span class=&quot;comment&quot;&gt;// &amp;gt; node_modules/underscore/underscore.js&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; picturefill = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'picturefill'&lt;/span&gt;); &lt;span class=&quot;comment&quot;&gt;// &amp;gt; node_modules/picturefill/picturefill.js&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;/* We can now use both objects as modules */&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Browserify will bundle all the needed files into one and creates one output file.&lt;/p&gt;
&lt;h2 id=&quot;better-coding-through-dependency-management&quot;&gt;Better coding through dependency management&lt;/h2&gt;
&lt;p&gt;Using Browserify also means we can use npm modules in our browser. If we, for instance, would want to use the package uniq: all we need to do is to install the package into our project executing the following line in your terminal:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install uniq&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and place the following code in your JavaScript:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; uniq = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'uniq'&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can now use &lt;code&gt;uniq&lt;/code&gt; as an object in your script.&lt;/p&gt;
&lt;h2 id=&quot;using-browserify-from-command-line&quot;&gt;Using Browserify from command line&lt;/h2&gt;
&lt;p&gt;You can choose to run Browserify from your terminal, but you can also choose to run Browserify as a task in your favourite task runner.&lt;/p&gt;
&lt;p&gt;To use from CLI, install Browserify using npm:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install -g browserify&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and bundle your package using:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;browserify ./path/to/your/source.js -o ./destination/file.js&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;using-browserify-in-grunt&quot;&gt;Using Browserify in Grunt&lt;/h2&gt;
&lt;p&gt;Install the &lt;code&gt;grunt-browserify&lt;/code&gt; package.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install grunt-browserify&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and setup the correct source and destination in the grunt config:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;browserify: {
  &lt;span class=&quot;attr&quot;&gt;dist&lt;/span&gt;: {
    &lt;span class=&quot;attr&quot;&gt;files&lt;/span&gt;: {
      &lt;span class=&quot;string&quot;&gt;'destination/file.js'&lt;/span&gt;:  [&lt;span class=&quot;string&quot;&gt;'path/to/your/source.js'&lt;/span&gt;],
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;it-gets-even-better-using-browserify-in-gulp&quot;&gt;It gets even better using Browserify in Gulp&lt;/h2&gt;
&lt;p&gt;If you prefer to use Browserify in Gulp you can use the original package instead of a plugin. It’s even not advised to use the Gulp plugin for Browserify.&lt;/p&gt;
&lt;p&gt;Add Browserify as a dependency to your project:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install browserify --save-dev&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Require Browserify in your &lt;code&gt;gulpfile.js&lt;/code&gt; and use the following code to add a gulp task:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; gulp = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'gulp'&lt;/span&gt;),
    browserify = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'browserify'&lt;/span&gt;);

gulp.task(&lt;span class=&quot;string&quot;&gt;'browserify'&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; browserify(&lt;span class=&quot;string&quot;&gt;'./path/to/your/source.js'&lt;/span&gt;) &lt;span class=&quot;comment&quot;&gt;//read the main javascript file&lt;/span&gt;
        .bundle()
        .on(&lt;span class=&quot;string&quot;&gt;'error'&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;err&lt;/span&gt;) &lt;/span&gt;{
            &lt;span class=&quot;built_in&quot;&gt;console&lt;/span&gt;.log(err.toString());
            &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.emit(&lt;span class=&quot;string&quot;&gt;'end'&lt;/span&gt;);
        })
        .pipe(source(&lt;span class=&quot;string&quot;&gt;'output-name.js'&lt;/span&gt;)) &lt;span class=&quot;comment&quot;&gt;//name the file&lt;/span&gt;
        .pipe(gulp.dest(&lt;span class=&quot;string&quot;&gt;'./output/folder/'&lt;/span&gt;)); &lt;span class=&quot;comment&quot;&gt;//output directory&lt;/span&gt;
});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I added the &lt;code&gt;.on(&amp;#39;error&amp;#39;)&lt;/code&gt; callback so that Browserify won’t break the loop when you’re using the task inside of a watcher.&lt;/p&gt;
&lt;h2 id=&quot;creating-your-own-local-modules&quot;&gt;Creating your own (local) modules&lt;/h2&gt;
&lt;p&gt;Let’s say we have a file called &lt;code&gt;main.js&lt;/code&gt;. You can now include other files or packages with &lt;code&gt;var package = require(&amp;#39;name-of-module&amp;#39;)&lt;/code&gt;, but we can also include our own modules pointing to the file.&lt;/p&gt;
&lt;p&gt;If we’d have a module in a file called &lt;code&gt;sum.js&lt;/code&gt; in the same folder as &lt;code&gt;main.js&lt;/code&gt; we can require that module using &lt;code&gt;var sum = require(&amp;#39;./sum.js&amp;#39;);&lt;/code&gt;. Note the &lt;code&gt;./&lt;/code&gt; at the start of the path which is necessary for &lt;code&gt;require()&lt;/code&gt; to know it’s a file and not a package which resides in &lt;code&gt;node_packages&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We can make our object or function available as a module by using &lt;code&gt;module.exports&lt;/code&gt; in our code. Here is an example of what &lt;code&gt;sum.js&lt;/code&gt; would look like:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;Sum&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;a, b&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.a = a;
    &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.b = b;
}

Sum.prototype.calculate = &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.a + &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.b;
};

&lt;span class=&quot;built_in&quot;&gt;module&lt;/span&gt;.exports = Sum;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can now use it in &lt;code&gt;main.js&lt;/code&gt; like so:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; Sum = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'./sum.js'&lt;/span&gt;);

&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; calculation = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; Sum(&lt;span class=&quot;number&quot;&gt;400&lt;/span&gt;, &lt;span class=&quot;number&quot;&gt;20&lt;/span&gt;).calculate();&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This makes creating your own npm packages a lot easier and makes them available for Browserify use instantly.&lt;/p&gt;
&lt;p&gt;It makes our code way more manageable and makes the writing of it a lot more structured.&lt;/p&gt;
&lt;h2 id=&quot;a-lot-of-libraries-are-also-available-through-npm&quot;&gt;A lot of libraries are also available through npm&lt;/h2&gt;
&lt;p&gt;Since the use of Browserify over Require.js or other methods is gaining a lot of ground, a lot of JavaScript libraries are also becoming available on npm. This is great news if you want to use Browserify, since it will improve our dependency management dramatically.&lt;/p&gt;
&lt;p&gt;I am currently rewriting a few of my libraries to be available as modules through npm. Consider doing this too.&lt;/p&gt;
&lt;h2 id=&quot;wrapping-up&quot;&gt;Wrapping up&lt;/h2&gt;
&lt;p&gt;With Ecmascript 6 around the corner and front-end development moving forward very fast, this way of dependency management is finally something to hold on to.&lt;/p&gt;
&lt;p&gt;If you want to share your experience about creating npm packages and using Browserify for your module requiring in browsers, feel free to comment below.&lt;/p&gt;
</description></item><item><title>Static Mockup Data for your Endpoints with Connect</title><link>https://gaya.pizza/articles/static-mockup-data-endpoints-connect/</link><pubDate>Sat, 10 May 2014 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/static-mockup-data-endpoints-connect/</guid><author></author><description>&lt;p&gt;While working on a frontend project you’ll easily come to a point where you need data from a webserver that will be retrieved through an Ajax call. Serving mockup data from those endpoints is a tricky thing when you don’t run your frontend project on a webserver.&lt;/p&gt;
&lt;p&gt;Luckily there is a way to easily write middleware using Connect for NodeJS. Other great thing: works with task-runners!&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/static-mockup-data-endpoints-connect/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/static-mockup-data-endpoints-connect/static-mockup-data-endpoints-connect.jpg&quot; alt=&quot;Static Mockup Data for your Endpoints with Connect&quot;&gt;&lt;/a&gt;
&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Separation between front and back-end development becomes more important every day. We see projects grow bigger and tasks are assigned a lot better in development teams. While one developer can focus mainly on the front-end part of the project, the back-end developer will handle all the server requests.&lt;/p&gt;
&lt;h2 id=&quot;we-need-mockup-data-for-ajax-responses&quot;&gt;We need mockup data for Ajax responses&lt;/h2&gt;
&lt;p&gt;When working on a front-end project which does a lot of Ajax calls to the server you might get stuck for needing mockup data.&lt;/p&gt;
&lt;p&gt;We need a JSON response if we request information from an endpoint. Let’s say we need some user information when we do a &lt;code&gt;GET&lt;/code&gt; request to &lt;code&gt;/user/get/username&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We can write a script on our local development server to handle these requests for us, but we can also use NodeJS and Connect for this.&lt;/p&gt;
&lt;h2 id=&quot;using-connect-as-middleware-to-catch-urls&quot;&gt;Using Connect as middleware to catch URLs&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;http://www.senchalabs.org/connect/&quot; title=&quot;Connect&quot;&gt;Connect&lt;/a&gt; can be used to intercept HTTP requests and give responses to the client. The great thing about this is that we don’t need to write a lot of code to intercept these requests.&lt;/p&gt;
&lt;p&gt;We can use different task runners to run Connect and handle the middleware section for us. For the purpose of this tutorial I’ll be using Grunt.&lt;/p&gt;
&lt;h2 id=&quot;setting-up-grunt&quot;&gt;Setting up Grunt&lt;/h2&gt;
&lt;p&gt;First &lt;a href=&quot;https://gaya.pizza/articles/javascript-development-workflow-using-grunt/&quot; title=&quot;Automating your JavaScript workflow using Grunt&quot;&gt;you need to install Grunt&lt;/a&gt;. After that you must add &lt;code&gt;grunt-contrib-connect&lt;/code&gt; as a dependency to your project.&lt;/p&gt;
&lt;p&gt;Run in the terminal:  &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install grunt-contrib-connect --save-dev&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Init a Gruntfile.js file. Now we can configure Grunt and use Connect.&lt;/p&gt;
&lt;p&gt;Now we need to make it possible for Grunt to run Connect. The Connect task will start a webserver and serve your files through HTTP to your browser.&lt;/p&gt;
&lt;p&gt;Load the task in Grunt using:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;grunt.loadNpmTasks(&lt;span class=&quot;string&quot;&gt;'grunt-contrib-connect'&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we can use the Connect task. Enter the following basic configuration to make it work.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;connect: {
    &lt;span class=&quot;attr&quot;&gt;server&lt;/span&gt;: {
        &lt;span class=&quot;attr&quot;&gt;options&lt;/span&gt;: {
            &lt;span class=&quot;attr&quot;&gt;port&lt;/span&gt;: grunt.option(&lt;span class=&quot;string&quot;&gt;'port'&lt;/span&gt;) || &lt;span class=&quot;number&quot;&gt;8000&lt;/span&gt;,
            &lt;span class=&quot;attr&quot;&gt;hostname&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;localhost&quot;&lt;/span&gt;
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;serving-the-server&quot;&gt;Serving the server&lt;/h2&gt;
&lt;p&gt;When you let Grunt start Connect it will run the server as long as the Grunt task persists. So if we’d call Connect directly in the state we’ve set it up it will create a webserver and immediately ends it as well.&lt;/p&gt;
&lt;p&gt;We can add a &lt;code&gt;keepalive&lt;/code&gt; flag to the Connect task options, but we can also create our own Grunt task which starts the server and then starts a watch task. This will make sure the Grunt task keeps itself alive.&lt;/p&gt;
&lt;p&gt;The reason I use &lt;code&gt;watch&lt;/code&gt; instead of the &lt;code&gt;keepalive&lt;/code&gt; flag is because I want to run the server as long as I am developing and changing the source.&lt;/p&gt;
&lt;p&gt;By default Connect will serve the project root and its files as a webserver would. You can easily add &lt;code&gt;dest: &amp;#39;dist/&amp;#39;&lt;/code&gt; as an option value to serve the folder &lt;code&gt;dist&lt;/code&gt; as the root for example. This will allows you to separate your source and distribution much better.&lt;/p&gt;
&lt;h2 id=&quot;creating-the-middleware&quot;&gt;Creating the middleware&lt;/h2&gt;
&lt;p&gt;When you determine the endpoints to which your application can send Ajax calls to you can write a small middleware that will catch those endpoint URLs and serve static data. I choose to serve &lt;code&gt;.json&lt;/code&gt; files from my disk, but I want to use endpoints like &lt;code&gt;/user/get/1/&lt;/code&gt; and &lt;code&gt;/product/get/1/&lt;/code&gt; and not put the files there.&lt;/p&gt;
&lt;p&gt;It’s better for testing and separating front from back-end code to use the same endpoints in this stage as the ones your backend developer will implement. It’s also because I tend to forget to adjust the URLs later on.&lt;/p&gt;
&lt;p&gt;Add the following template to handle middleware with Connect:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;options: {
    &lt;span class=&quot;attr&quot;&gt;port&lt;/span&gt;: grunt.option(&lt;span class=&quot;string&quot;&gt;'port'&lt;/span&gt;) || &lt;span class=&quot;number&quot;&gt;8000&lt;/span&gt;,
    &lt;span class=&quot;attr&quot;&gt;hostname&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;localhost&quot;&lt;/span&gt;,
    &lt;span class=&quot;attr&quot;&gt;middleware&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;connect, options, middlewares&lt;/span&gt;) &lt;/span&gt;{
        middlewares.push(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;req, res, next&lt;/span&gt;) &lt;/span&gt;{
            &lt;span class=&quot;comment&quot;&gt;//stuff will go here&lt;/span&gt;
        }

        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; middlewares;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Connect will loop through a collection of middleware functions and handle then one by one. Before a middleware function has ended the developer can choose to either continue the chain or end it and give a response back to the client.&lt;/p&gt;
&lt;p&gt;We’re pushing our own middleware function to the middlewares list. We get three parameters to work with: &lt;code&gt;request&lt;/code&gt;, &lt;code&gt;response&lt;/code&gt; and &lt;code&gt;next&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;catching-your-endpoints&quot;&gt;Catching your endpoints&lt;/h2&gt;
&lt;p&gt;The only thing we have to do now is to read the &lt;code&gt;response&lt;/code&gt; and act accordingly. We can get the requested url by reading &lt;code&gt;req.url&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When the url is not an endpoint you want to catch you can let Connect continue in the middleware collection by returning &lt;code&gt;next&lt;/code&gt;. That’s the last parameter Connect gives to your middleware function we pushed earlier.&lt;/p&gt;
&lt;p&gt;Using &lt;code&gt;res.end()&lt;/code&gt; we can give a response to the requesting client. The only thing you have to keep in mind is that you don’t return the &lt;code&gt;next&lt;/code&gt; object.&lt;/p&gt;
&lt;p&gt;I like to keep mockup data outside of my middleware code so I created JSON files that contain the data I want the webserver to serve. We can use &lt;code&gt;grunt.file.read(&amp;quot;/path/to/file.json&amp;quot;)&lt;/code&gt; to get a file of your project as a string.&lt;/p&gt;
&lt;p&gt;This all comes together to something in the line of this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;middleware: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;connect, options, middlewares&lt;/span&gt;) &lt;/span&gt;{
    middlewares.push(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;req, res, next&lt;/span&gt;) &lt;/span&gt;{
        &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; endpoints = {
            &lt;span class=&quot;string&quot;&gt;&quot;/user/&quot;&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;json-files/user.json&quot;&lt;/span&gt;,
            &lt;span class=&quot;string&quot;&gt;&quot;/product/&quot;&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;json-files/product.json&quot;&lt;/span&gt;
        };
        &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; match = &lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt;;
        &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; fileToRead = &lt;span class=&quot;string&quot;&gt;&quot;&quot;&lt;/span&gt;;

        &lt;span class=&quot;built_in&quot;&gt;Object&lt;/span&gt;.keys(endpoints).forEach(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;url&lt;/span&gt;) &lt;/span&gt;{
            &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (req.url.indexOf(url) == &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;) {
                match = &lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;;
                fileToRead = endpoints[url];
            }
        });

        &lt;span class=&quot;comment&quot;&gt;//no match with the url, move along&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (match == &lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt;) {
            &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; next();
        }

        res.end(grunt.file.read(fileToRead));
    });

    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; middlewares;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can clone &lt;a href=&quot;https://github.com/Gaya/mockup-data-middleware-with-connect&quot;&gt;the example project I put on GitHub&lt;/a&gt; so you can run the webserver by entering the following command in the terminal:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;grunt serve&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;save-time-rewriting-endpoints&quot;&gt;Save time rewriting endpoints&lt;/h2&gt;
&lt;p&gt;With this example you can easily create your own endpoints and link JSON file responses to them. I hope this will give you a boost into trying more with Grunt and Connect.&lt;/p&gt;
&lt;p&gt;Mocking up your data is a great way to start testing more easily and create a nice way to combine front with back-end later.&lt;/p&gt;
</description></item><item><title>Compound Selectors for Better Class Names in Sass</title><link>https://gaya.pizza/articles/compound-selectors-for-better-class-names-in-sass/</link><pubDate>Fri, 04 Apr 2014 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/compound-selectors-for-better-class-names-in-sass/</guid><author></author><description>&lt;p&gt;There are a few class naming conventions you can live by, the problem with most of them is writing long class names that tend to give your CSS a messy look without compound selectors.&lt;/p&gt;
&lt;p&gt;Luckily Sass now supports compound selectors which will make our stylesheets a lot easier and better to maintain.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/compound-selectors-for-better-class-names-in-sass/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/compound-selectors-for-better-class-names-in-sass/better-class-names-sass-compound-selectors.jpg&quot; alt=&quot;Better Class Names with Sass Compound Selectors&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;naming-conventions&quot;&gt;Naming conventions&lt;/h2&gt;
&lt;p&gt;Web developers are always looking for a better way to create maintainable CSS for their projects. Giving class names to HTML elements can really get out of hand and reusable classes don’t always have the best names.&lt;/p&gt;
&lt;p&gt;Semantics are just as important in HTML as they are in CSS. Making the CSS not dependent on the HTML structure, or at least as little as possible, is desirable.&lt;/p&gt;
&lt;p&gt;Whatever convention you’re following, a structured one like &lt;a href=&quot;http://www.integralist.co.uk/posts/maintainable-css-with-bem/&quot; title=&quot;Maintainable CSS with BEM&quot;&gt;BEM for example&lt;/a&gt;, really helps you in this process. Whether you like to construct class name by appending more segments, or following a pattern: Sass can now help you make your code even better.&lt;/p&gt;
&lt;h2 id=&quot;compound-selectors-in-sass&quot;&gt;Compound Selectors in Sass&lt;/h2&gt;
&lt;p&gt;Sass has the ability to compound selectors for your CSS. You probably already knew that &lt;a href=&quot;http://sass-lang.com/documentation/file.SASS_REFERENCE.html#parent-selector&quot;&gt;you can append another class to a selector or a pseudo-element using the ampersand sign&lt;/a&gt;. Now we can also append parts of a class name.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.portfolio-items&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1.5em&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0px&lt;/span&gt;;

    &amp;amp;-item {
        &lt;span class=&quot;attribute&quot;&gt;border&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1px&lt;/span&gt; solid black;

        &amp;amp;-name {
            &lt;span class=&quot;attribute&quot;&gt;font-weight&lt;/span&gt;: bold;
        }
    }

    &amp;amp;-close-&lt;span class=&quot;selector-tag&quot;&gt;button&lt;/span&gt; {
        &lt;span class=&quot;keyword&quot;&gt;@extend&lt;/span&gt; .close-button;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Will now become the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.portfolio-items&lt;/span&gt; { &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1.5em&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0px&lt;/span&gt;; }
&lt;span class=&quot;selector-class&quot;&gt;.portfolio-items-item&lt;/span&gt; { &lt;span class=&quot;attribute&quot;&gt;border&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1px&lt;/span&gt; solid black; }
&lt;span class=&quot;selector-class&quot;&gt;.portfolio-items-item-name&lt;/span&gt; { &lt;span class=&quot;attribute&quot;&gt;font-weight&lt;/span&gt;: bold; }
&lt;span class=&quot;selector-class&quot;&gt;.button&lt;/span&gt;, &lt;span class=&quot;selector-class&quot;&gt;.portfolio-items-close-button&lt;/span&gt; { &lt;span class=&quot;comment&quot;&gt;/* styling */&lt;/span&gt; }&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This gives use the power of nesting our selectors without long selectors to match for the browser. It helps us maintain a modular approach to our styling without making a lot of clashing or duplicate style.&lt;/p&gt;
&lt;h2 id=&quot;nesting-problem-solved&quot;&gt;Nesting problem solved&lt;/h2&gt;
&lt;p&gt;Using this method we solve the problem of nesting to much in our Sass projects making long and a bit too specific selectors.&lt;/p&gt;
&lt;p&gt;I hope you’ll start using this functionality more often. I have a lot of old code to refactor now!&lt;/p&gt;
</description></item><item><title>Automating your JavaScript workflow using Grunt</title><link>https://gaya.pizza/articles/javascript-development-workflow-using-grunt/</link><pubDate>Sun, 17 Nov 2013 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/javascript-development-workflow-using-grunt/</guid><author></author><description>&lt;p&gt;Using tools like Grunt to improve your JavaScript development has been popular for quite a while. It’s not a surprise since it will truly improve your workflow and takes care of pesky tasks we so hate to do.&lt;/p&gt;
&lt;p&gt;This article will go into detail about the way I like to use Grunt to improve my workflow and make it way easier to maintain and test my JavaScript projects.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/javascript-development-workflow-using-grunt/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/javascript-development-workflow-using-grunt/Automating-your-JavaScript-workflow-using-Grunt.png&quot; alt=&quot;Automating your JavaScript workflow using Grunt&quot; title=&quot;Automating your JavaScript workflow using Grunt&quot;&gt;&lt;/a&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Grunt manages tasks automatically which we would otherwise do ourselves with separate tools. Think in the lines of concatenation, minification and other tasks which can become a drag if we have to do them yourself. Grunt will solves this for us.&lt;/p&gt;
&lt;p&gt;If you’re not familiar with using Grunt, there is a really &lt;a href=&quot;http://gruntjs.com/getting-started&quot; title=&quot;Getting started with Grunt&quot;&gt;good getting started guide on their site&lt;/a&gt; to get you going. It will immediately give you some insights.&lt;/p&gt;
&lt;h2 id=&quot;what-my-workflow-does-&quot;&gt;What my workflow does.&lt;/h2&gt;
&lt;p&gt;It’s basically a way to separate my development and production versions of my script while not changing the source for either of them. There will be two versions of our JavaScript file in the end, one I include in the development version of the website, one for the production version.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/javascript-development-workflow-using-grunt/grunt-logo.png&quot; alt=&quot;Grunt logo&quot;&gt;&lt;/p&gt;
&lt;p&gt;While in development I want my script to give me as many debugging info as possible, run a few unit tests and is easy to debug when the console gives me an error.&lt;/p&gt;
&lt;p&gt;I production I want the script to be reduced to minimal bytes, stripped of console.log messages but with the same complete functionality as the development version.&lt;/p&gt;
&lt;p&gt;I’ll tell Grunt to watch my project. So it automatically concatenates my source scripts and runs a few unit tests every time something changes in my source files. Now I won’t have to tell Grunt to run each time I want to check the website if it’s working.&lt;/p&gt;
&lt;p&gt;In the end, if I am happy with the result I’ll tell Grunt to build my project for production (and maybe even deploy it for me).&lt;/p&gt;
&lt;h2 id=&quot;setting-up-grunt-for-development&quot;&gt;Setting up Grunt for development&lt;/h2&gt;
&lt;p&gt;In the development phase I only need to use concatenation and a tool which allows Grunt to watch my project.&lt;/p&gt;
&lt;p&gt;I like to keep all my website’s assets in an “assets” folder. The following folder structure is used for this article:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;assets/
    css/
    images/
    js/
    src/
        js/&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the root of your assets folder create a &lt;code&gt;package.json&lt;/code&gt; file and a &lt;code&gt;Gruntfile.js&lt;/code&gt; file. Grunt needs these to work. Put the following in the &lt;code&gt;package.json&lt;/code&gt; file:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;{
    &lt;span class=&quot;string&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;project-name&quot;&lt;/span&gt;,
    &lt;span class=&quot;string&quot;&gt;&quot;version&quot;&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;0.1.0&quot;&lt;/span&gt;,
    &lt;span class=&quot;string&quot;&gt;&quot;devDependencies&quot;&lt;/span&gt;: {
        &lt;span class=&quot;string&quot;&gt;&quot;grunt&quot;&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;~0.4.1&quot;&lt;/span&gt;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For the development part we only need two grunt packages: &lt;a href=&quot;https://github.com/gruntjs/grunt-contrib-concat&quot;&gt;grunt-contrib-concat&lt;/a&gt; and &lt;a href=&quot;https://github.com/gruntjs/grunt-contrib-watch&quot;&gt;grunt-contrib-watch&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Go to your assets folder in command line. Run the following commands to install these packages:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install grunt-contrib-concat --save-dev
npm install grunt-contrib-watch --save-dev&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You’ll see &lt;code&gt;npm&lt;/code&gt; install all the dependancies of these packages. Great.&lt;/p&gt;
&lt;h2 id=&quot;concat-setup-in-gruntfile-js&quot;&gt;Concat setup in Gruntfile.js&lt;/h2&gt;
&lt;p&gt;Now we can move on to the &lt;code&gt;Gruntfile.js&lt;/code&gt;. Place the following basics in the file:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;built_in&quot;&gt;module&lt;/span&gt;.exports = &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;grunt&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;comment&quot;&gt;// Project configuration.&lt;/span&gt;
    grunt.initConfig({
        &lt;span class=&quot;attr&quot;&gt;pkg&lt;/span&gt;: grunt.file.readJSON(&lt;span class=&quot;string&quot;&gt;'package.json'&lt;/span&gt;)
    });
};&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This file is just basic JavaScript which is used as a configuration file. Let’s make Grunt load the tasks we need first.&lt;/p&gt;
&lt;p&gt;Before the end of the modules.export function we need to include the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;grunt.loadNpmTasks(&lt;span class=&quot;string&quot;&gt;'grunt-contrib-concat'&lt;/span&gt;);
grunt.loadNpmTasks(&lt;span class=&quot;string&quot;&gt;'grunt-contrib-watch'&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we can setup the tasks and how Grunt will be using them. First we’ll setup the concatenation. We’ll add configs to the object that is passed to the &lt;code&gt;grunt.initConfig&lt;/code&gt; method. Add following configs after &lt;code&gt;pkg: grunt.file.readJSON(&amp;#39;package.json&amp;#39;),&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;concat: {
    &lt;span class=&quot;attr&quot;&gt;options&lt;/span&gt;: {
        &lt;span class=&quot;attr&quot;&gt;separator&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;\n&quot;&lt;/span&gt;, &lt;span class=&quot;comment&quot;&gt;//add a new line after each file&lt;/span&gt;
        &lt;span class=&quot;attr&quot;&gt;banner&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;&quot;&lt;/span&gt;, &lt;span class=&quot;comment&quot;&gt;//added before everything&lt;/span&gt;
        &lt;span class=&quot;attr&quot;&gt;footer&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;&quot;&lt;/span&gt; &lt;span class=&quot;comment&quot;&gt;//added after everything&lt;/span&gt;
    },
    &lt;span class=&quot;attr&quot;&gt;dist&lt;/span&gt;: {
        &lt;span class=&quot;comment&quot;&gt;// the files to concatenate&lt;/span&gt;
        &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;: [
            &lt;span class=&quot;comment&quot;&gt;//include libs&lt;/span&gt;
            &lt;span class=&quot;string&quot;&gt;'libs/somelib/somelib.js'&lt;/span&gt;,
            &lt;span class=&quot;string&quot;&gt;'libs/otherlib/otherlib.js'&lt;/span&gt;,

            &lt;span class=&quot;comment&quot;&gt;//own classes and files&lt;/span&gt;
            &lt;span class=&quot;string&quot;&gt;'src/**/!(base).js'&lt;/span&gt;,

            &lt;span class=&quot;comment&quot;&gt;//the last script I need&lt;/span&gt;
            &lt;span class=&quot;string&quot;&gt;'src/base.js'&lt;/span&gt;
        ],
        &lt;span class=&quot;comment&quot;&gt;// the location of the resulting JS file&lt;/span&gt;
        &lt;span class=&quot;attr&quot;&gt;dest&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;'js/&amp;lt;%= pkg.name %&amp;gt;.js'&lt;/span&gt;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What I like to do is to leave the options open but at least add a new line in between all the scripts which I want to concatenate. Banner and footer can become very useful, especially when creating jQuery plugins and you want to add noConflict compatibility.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Protip: Set banner to &lt;code&gt;(function($){&lt;/code&gt; and footer to &lt;code&gt;})(jQuery);&lt;/code&gt; in grunt-contrib-concat to wrap your script with jQuery noConflict mode.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In &lt;code&gt;dist&lt;/code&gt; we define the scripts which concat will combine for us and the path to where the script has to be distributed.&lt;/p&gt;
&lt;p&gt;First I like to include all libraries I want to include in my script, then I include every file in my &lt;code&gt;src&lt;/code&gt; folder except for the &lt;code&gt;base.js&lt;/code&gt; file. I want this file to be included at the end since it handles my object creations and inits. You can easily adjust this to your liking.&lt;/p&gt;
&lt;p&gt;When it’s ready the file will be compiled to &lt;code&gt;js/project-name.js&lt;/code&gt;. &lt;code&gt;&amp;lt;%= pkg.name %&amp;gt;&lt;/code&gt; will get the information we put in the &lt;code&gt;package.json&lt;/code&gt; file for &lt;code&gt;npm&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;watching-the-src-folder&quot;&gt;Watching the src folder&lt;/h2&gt;
&lt;p&gt;Like SASS and Compass, you can watch projects with Grunt. You can let Grunt perform tasks automatically for you when your source files change.&lt;/p&gt;
&lt;p&gt;Add the following settings after the &lt;code&gt;concat&lt;/code&gt; object we just added.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;watch: {
    &lt;span class=&quot;attr&quot;&gt;scripts&lt;/span&gt;: {
        &lt;span class=&quot;attr&quot;&gt;files&lt;/span&gt;: [&lt;span class=&quot;string&quot;&gt;'src/**/*.js'&lt;/span&gt;],
        &lt;span class=&quot;attr&quot;&gt;tasks&lt;/span&gt;: [&lt;span class=&quot;string&quot;&gt;'dev-watch'&lt;/span&gt;],
        &lt;span class=&quot;attr&quot;&gt;options&lt;/span&gt;: {
            &lt;span class=&quot;attr&quot;&gt;interrupt&lt;/span&gt;: &lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You’re telling the watch package that it needs to watch for changes in all .js files in the src folder. If there is a change: execute the &lt;code&gt;dev-watch&lt;/code&gt; task.&lt;/p&gt;
&lt;p&gt;Note that we haven’t created the &lt;code&gt;dev-watch&lt;/code&gt; task yet. So after loading the npm tasks at the end of the function register a new Grunt task:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//register the task&lt;/span&gt;
grunt.registerTask(&lt;span class=&quot;string&quot;&gt;'dev-watch'&lt;/span&gt;, [&lt;span class=&quot;string&quot;&gt;'concat:dist'&lt;/span&gt;]);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The Gruntfile.js file &lt;a href=&quot;https://gist.github.com/Gaya/7498780#file-watch-gruntfile-js&quot;&gt;should be looking like this&lt;/a&gt; by now. Check your file against this one.&lt;/p&gt;
&lt;p&gt;Now, go back to your command line and run &lt;code&gt;grunt watch&lt;/code&gt;. Adjust a file in your src folder. If you get something like this, you’re done with the first phase.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/javascript-development-workflow-using-grunt/grunt-watch-concat.gif&quot; alt=&quot;Grunt watch in terminal example&quot;&gt;
&lt;em&gt;Example terminal output for &lt;code&gt;grunt watch&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;If you want to can also add unit testing tasks to your watch task set. It’s a great time to run these so you immediately know if you messed up your scripts.&lt;/p&gt;
&lt;h2 id=&quot;optimizing-the-output-for-production&quot;&gt;Optimizing the output for production&lt;/h2&gt;
&lt;p&gt;Once we’re ready with our development tasks we’ll move on to the production output. We want to combine and minimize our JavaScript files (also our external libs). You can read why &lt;a href=&quot;https://developers.google.com/speed/docs/best-practices/rtt#CombineExternalJS&quot; title=&quot;Minimize round-trip times&quot;&gt;minimizing round-trip times is a good practice&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We’re going to remove all the &lt;code&gt;console.log&lt;/code&gt; since we don’t want those messages in our production version. After that we’re going to minimize the script and output it as the famous &lt;code&gt;*.min.js&lt;/code&gt; file. We’re going to use &lt;a href=&quot;https://npmjs.org/package/grunt-remove-logging&quot; title=&quot;Grunt Remove Loggin&quot;&gt;grunt-remove-logging&lt;/a&gt; and &lt;a href=&quot;https://github.com/gruntjs/grunt-contrib-uglify&quot; title=&quot;Grunt UglifyJS&quot;&gt;grunt-contrib-uglify&lt;/a&gt; for this.&lt;/p&gt;
&lt;p&gt;Execute these commands in the assets folder to install the packages:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install grunt-remove-logging --save-dev
npm install grunt-contrib-uglify --save-dev&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;removing-console-log-messages&quot;&gt;Removing console.log messages&lt;/h2&gt;
&lt;p&gt;Sometimes we log messages in the console we don’t want the end user to read or there might be a certain browser which stops working when it comes across a console.log command. So let’s just remove them all in the production version of our script.&lt;/p&gt;
&lt;p&gt;Let’s put remove-logging’s configuration in &lt;code&gt;Gruntfile.js&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;removelogging: {
    &lt;span class=&quot;attr&quot;&gt;dist&lt;/span&gt;: {
        &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;js/&amp;lt;%= pkg.name %&amp;gt;.js&quot;&lt;/span&gt;,
        &lt;span class=&quot;attr&quot;&gt;dest&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;build/&amp;lt;%= pkg.name %&amp;gt;.js&quot;&lt;/span&gt;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We’re telling the task to pick our development version of the script and remove all the log messages and save the outcome to &lt;code&gt;build/project-name.js&lt;/code&gt;. I am using a separate folder for my output so I can easily ignore this folder on deployment.&lt;/p&gt;
&lt;h2 id=&quot;uglifing-the-script&quot;&gt;Uglifing the script&lt;/h2&gt;
&lt;p&gt;When all is ready we’re going to minimize the filesize and crop the script to it’s optimal size. We’re using UglifyJS for this. If you want to read more about how it works, check out the &lt;a href=&quot;https://github.com/mishoo/UglifyJS&quot; title=&quot;UglifyJS on GitHub&quot;&gt;UglifyJS GitHub page&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Put the following in your configuration:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;uglify: {
    &lt;span class=&quot;attr&quot;&gt;options&lt;/span&gt;: {
        &lt;span class=&quot;attr&quot;&gt;banner&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;&quot;&lt;/span&gt;
    },
    &lt;span class=&quot;attr&quot;&gt;build&lt;/span&gt;: {
        &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;'build/&amp;lt;%= pkg.name %&amp;gt;.js'&lt;/span&gt;,
        &lt;span class=&quot;attr&quot;&gt;dest&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;'js/&amp;lt;%= pkg.name %&amp;gt;.min.js'&lt;/span&gt;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It tells UglifyJS to pick the file which has the &lt;code&gt;console.log&lt;/code&gt; messages stripped and then save the outcome to &lt;code&gt;js/project-name.min.js&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;combine-it-all-in-a-new-build-task&quot;&gt;Combine it all in a new “build” task&lt;/h2&gt;
&lt;p&gt;First we need to load the newly used packages in Grunt:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;grunt.loadNpmTasks(&lt;span class=&quot;string&quot;&gt;'grunt-remove-logging'&lt;/span&gt;);
grunt.loadNpmTasks(&lt;span class=&quot;string&quot;&gt;'grunt-contrib-uglify'&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Finish it of by registering a new task at the end:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;grunt.registerTask(&lt;span class=&quot;string&quot;&gt;'build'&lt;/span&gt;, [&lt;span class=&quot;string&quot;&gt;'concat'&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;'removelogging'&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;'uglify'&lt;/span&gt;]);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Go back to command line and let Grunt execute your newly created task.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;grunt build&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/javascript-development-workflow-using-grunt/grunt-build.gif&quot; alt=&quot;grunt-build&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gist.github.com/Gaya/7498780#file-build-gruntfile-js&quot; title=&quot;The complete Gruntfile.js&quot;&gt;The complete file outcome can be found as a Gist&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;further-improvement&quot;&gt;Further improvement&lt;/h2&gt;
&lt;p&gt;From here you can start optimizing your front-end workflow. You can also add tasks for automatic image optimalisation, copying files, parsing SASS / Compass etc etc. There are &lt;a href=&quot;http://gruntjs.com/plugins&quot; title=&quot;Grunt Plugins&quot;&gt;a lot of great plugins&lt;/a&gt; available to use.&lt;/p&gt;
&lt;p&gt;If you have your own workflow, or if you want to share your thoughts: leave them in the comments.&lt;/p&gt;
&lt;p&gt;Happy Grunting!&lt;/p&gt;
</description></item><item><title>Curse of the Open Source libraries and frameworks</title><link>https://gaya.pizza/articles/curse-of-the-open-source-libraries-frameworks/</link><pubDate>Wed, 30 Oct 2013 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/curse-of-the-open-source-libraries-frameworks/</guid><author></author><description>&lt;p&gt;The web development population has grown significantly over the past years. A lot of people are choosing development as their trade and make a good living out of it.&lt;/p&gt;
&lt;p&gt;The number of people using frameworks or libraries to speed up their development, or solve the parts of development they can’t do themselves has increased as well.&lt;/p&gt;
&lt;p&gt;Is it a good thing, or are we shooting ourselves in the foot? I will share my view on the matter in this article.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/curse-of-the-open-source-libraries-frameworks/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/curse-of-the-open-source-libraries-frameworks/curse-of-the-open-source-libraries-frameworks1.jpg&quot; alt=&quot;Curse of the Open Source libraries and frameworks&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;learning-to-code&quot;&gt;Learning to code&lt;/h2&gt;
&lt;p&gt;More and more students are choosing to go into development, but also people from other fields of work are switching to writing code. Webdesigners in particular are switching to be frontend-developer more and more.&lt;/p&gt;
&lt;p&gt;Most good webdesigners know how to write HTML and CSS, so that’s a great foundation. The problem (in my eyes) is when people dive into learning Javascript by using jQuery immediately.&lt;/p&gt;
&lt;p&gt;To me learning to code Javascript doesn’t work well when you start by using jQuery. jQuery helps you with a lot of cross-browser compatibility and will make coding Javascript a lot easier, but you’ll have to go back to plain Javascript some time in the learning process.&lt;/p&gt;
&lt;p&gt;Go to Google and search for a Javascript question. Now replace the word “Javascript” with “jQuery”. People are clearly asking the wrong thing because they don’t know the fundamentals.&lt;/p&gt;
&lt;h2 id=&quot;missing-out-on-the-fundamentals&quot;&gt;Missing out on the fundamentals&lt;/h2&gt;
&lt;p&gt;Learning through a library or framework brings with it a problem that arises a lot of the time; the separation between the foundation of the language they’re writing in and the library / framework they’re using seems to disappears.&lt;/p&gt;
&lt;p&gt;You are, for instance, still writing Javascript when you’re using jQuery, and using jQuery’s way might not be the answer you’re looking for. In PHP we can say the same thing for the CMS’s and frameworks that encourage a certain way of working.&lt;/p&gt;
&lt;p&gt;To me it’s important to understand how a website is build from the ground up. I tend to go deeper and deeper into web development technology to grasp the concepts of which our websites are build. This improves my understanding of what I am doing without just doing something and hoping it doesn’t break later.&lt;/p&gt;
&lt;p&gt;When I started making websites I started from the beginning: writing HTML only pages, moving on to CSS, then PHP and from there I learned all the knowledge needed to create my own dynamic website. Much later in the process I started learning to use frameworks. For me this improved the understanding of what the frameworks do apart from the language and platform you’re writing in.&lt;/p&gt;
&lt;p&gt;You can start learning through frameworks or libraries if you’d like, but at some point you’re forced to go back to the beginning and learn the true principles of programming.&lt;/p&gt;
&lt;p&gt;Don’t get me wrong. Starting out learning using established frameworks like Symfony, Laravel and Grails will teach you some great principles. You’d have to know how to code before you dig into these frameworks.&lt;/p&gt;
&lt;h2 id=&quot;adding-plugins-to-destroy-your-project&quot;&gt;Adding plugins to destroy your project&lt;/h2&gt;
&lt;p&gt;Before jQuery and similar libraries (which have been forgotten) we had to write most of our Javascript bottom up. This made it harder for webdesigners to get into coding Javascript next to their HTML and CSS. jQuery spawned a whole new group of coders who created their own Javascript powered pages.&lt;/p&gt;
&lt;p&gt;This also unleashed a storm of plugins to the world. I too have released a few. These can help people with pieces of code they don’t know how to or have no time to solve. It’s very tempting to use them to solve your problem, but at the same time you don’t really know what the impact on your site is.&lt;/p&gt;
&lt;p&gt;I am not only aiming at jQuery in this case, but also at software like WordPress, which has a large resource of plugins whom users can install. This gives the unexperienced user and builder the change to improve their site with a piece of code they don’t have to write themselves.&lt;/p&gt;
&lt;p&gt;This means that you’ll most likely add some code and functionality to your site you don’t really need to have. This could make your site slower, bigger and break in some cases.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/curse-of-the-open-source-libraries-frameworks/script-overload.jpg&quot; alt=&quot;Very bad practice&quot;&gt;
&lt;em&gt;One of the worst cases I’ve come across.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This webpage loads 88 resources, counting 37 scripts. That’s an insanely large number. These guys have no clue what they’re doing.&lt;/p&gt;
&lt;p&gt;Staying clear from them is better in some cases. It just gets hard to filter the good from the bad these days.&lt;/p&gt;
&lt;h2 id=&quot;paid-themes-and-plugin-overkill&quot;&gt;Paid themes and plugin overkill&lt;/h2&gt;
&lt;p&gt;I’ve bought templates on the internet to speed up the development process of a website. There are a lot of great ones out there. There is one problem though I run into every time, and that’s jQuery plugins overkill.&lt;/p&gt;
&lt;p&gt;One of the themes loaded 15 (!) different jQuery plugins to empower the site. Ranging from menu / dropdown behavior plugins to table sorting plugins. They seemed to fix the problems at hand, but included way too much clutter and unneeded code to the webpage, making it very slow and heavy to load.&lt;/p&gt;
&lt;p&gt;It also made the site hard to manage and adjust because it was very dependent on these libraries. And I am not even talking about updates that break the site.&lt;/p&gt;
&lt;h2 id=&quot;sticking-with-a-library&quot;&gt;Sticking with a library&lt;/h2&gt;
&lt;p&gt;The library or framework you’re working with may feel very safe and you know your way around it. Any problem you face you’ll reflect on the tools you’re used to working with. This doesn’t mean that it’s the best solution.&lt;/p&gt;
&lt;p&gt;Take WordPress for instance. It’s a great tool for creating websites and has great plugins (also a lot of bad ones). It is however not the best solution for some projects I’ve heard about. I understand that a developer can get used to using a single CMS for everything, but there is really a lot more out there.&lt;/p&gt;
&lt;h2 id=&quot;cursing-yourself&quot;&gt;Cursing yourself&lt;/h2&gt;
&lt;p&gt;Plugins, development tools and everything alike have one common curse: a user base. People who will be using your product and apply it to their project. The problem here of course is that you’ll have to try and catch as many situations and exceptions as possible. This also makes it harder to improve your product when your users are not improving theirs.&lt;/p&gt;
&lt;p&gt;You’ll see a handful of great products out there that I for one can not live without. The problem with some of them is that the people who use the package are not as experienced programmers as the rest. This might lead to the problem that the people behind the software product are holding themselves back for the sake of those inexperienced people. Backwards compatible is not the best choice here.&lt;/p&gt;
&lt;p&gt;I understand that you can increase your user base by targeting the less experienced coders and providing them with support for all the previous applications, but how are you so supposed to improve your own product when you can’t get rid of the parts which are not as good?&lt;/p&gt;
&lt;h2 id=&quot;some-closing-words&quot;&gt;Some closing words&lt;/h2&gt;
&lt;p&gt;I am not trying to tell you not to use frameworks and libraries. In fact: they can be super powerful if used correctly. Just use them wisely and do not go for a solution that might not be the best idea.&lt;/p&gt;
&lt;p&gt;Go back to the basics and rethink your solutions so we can grow to become a better developers.&lt;/p&gt;
</description></item><item><title>Using WordPress plugins as Symbolic Links</title><link>https://gaya.pizza/articles/using-wordpress-plugins-as-symbolic-links/</link><pubDate>Thu, 10 Oct 2013 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/using-wordpress-plugins-as-symbolic-links/</guid><author></author><description>&lt;p&gt;If you want to use a single plugin on different WordPress installs you might want to go for a symlinked plugin folder. That way we can have one codebase and apply it on multiple installs.&lt;/p&gt;
&lt;p&gt;That would be great right? Sadly, WordPress doesn’t support this (yet). In this post I’ll explain how I got WordPress to accept my plugins as symbolic links.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/using-wordpress-plugins-as-symbolic-links&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/using-wordpress-plugins-as-symbolic-links/using-wordpress-plugins-as-symbolic-links.jpg&quot; alt=&quot;Using WordPress plugins as Symbolic Links&quot; title=&quot;Using WordPress plugins as Symbolic Links&quot;&gt;&lt;/a&gt;
&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The Problem&lt;/h2&gt;
&lt;p&gt;There are a few functions we use in WordPress when it comes to plugin development. The ones that are causing the problems we run into when using symbolic links are &lt;code&gt;plugins_url&lt;/code&gt;, &lt;code&gt;plugin_basename&lt;/code&gt;, &lt;code&gt;register_activation_hook&lt;/code&gt;, &lt;code&gt;register_deactivation_hook&lt;/code&gt; and &lt;code&gt;register_uninstall_hook&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;These functions break because they assume all the plugin files are physically in the plugin folder defined in WordPress. It will remove the path to the WordPress plugins directory from the file path we pass to above functions. &lt;code&gt;__FILE__&lt;/code&gt; is in a different folder physically on your system when you’re using symbolic links.&lt;/p&gt;
&lt;p&gt;In the future we’ll surely see this solved in the core. You can &lt;a href=&quot;http://core.trac.wordpress.org/ticket/16953&quot; title=&quot;Ticket #16953 on WordPress Trac&quot;&gt;follow ticket #16953&lt;/a&gt; on Trac to see it’s progress. For now, you can use my solution.&lt;/p&gt;
&lt;h2 id=&quot;when-to-use-symbolic-links&quot;&gt;When to Use Symbolic Links&lt;/h2&gt;
&lt;p&gt;Plugin development in WordPress can be a pain when it comes to testing. I like to have a single place to work on my plugin, but testing it on multiple installs at the same time.&lt;/p&gt;
&lt;p&gt;Using symlinks can be the solution when you want to use one codebase and use it in different places.&lt;/p&gt;
&lt;p&gt;In this case we’ve got a plugin in &lt;code&gt;/Users/gaya/Git/awesome-plugin/&lt;/code&gt; and want it available in &lt;code&gt;/Users/gaya/Sites/wordpress-test/wp-content/plugins/&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Open up terminal and run the following command (Mac OSX and Unix):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ln -s /User/gaya/Git/awesome-plugin/ /Users/gaya/Sites/wordpress-test/wp-content/plugins/awesome-plugin&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Note that the target path has no trailing slash. Also change the paths to your situation.&lt;/p&gt;
&lt;h2 id=&quot;the-solution-symbolic-press&quot;&gt;The Solution: Symbolic Press&lt;/h2&gt;
&lt;p&gt;Download the &lt;a href=&quot;https://gist.github.com/Gaya/6918966&quot; title=&quot;Symbolic Press Class Gist on GitHub&quot;&gt;Symbolic Press helper class on GitHub&lt;/a&gt; and place it somewhere in your plugin directory. I like to keep my external classes in a seperate folder from my own classes. Save the file as &lt;code&gt;class-symbolic-press.php&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In this case my plugin is called &lt;code&gt;awesome-plugin&lt;/code&gt; so I can assume a file called &lt;code&gt;awesome-plugin.php&lt;/code&gt; is in this directory.&lt;/p&gt;
&lt;p&gt;Include the Symbolic Press class in this file and create a new instance of the class passing &lt;code&gt;__FILE__&lt;/code&gt; as a parameter like so:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&quot;libs/class-symbolic-press.php&quot;&lt;/span&gt;;
&lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; Symbolic_Press(&lt;span class=&quot;keyword&quot;&gt;__FILE__&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Every time you use &lt;code&gt;plugins_url()&lt;/code&gt; it won’t include the path to your symlinked plugin folder. So first problem fixed!&lt;/p&gt;
&lt;p&gt;What it does is this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;add_filter( &lt;span class=&quot;string&quot;&gt;'plugins_url'&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;'plugins_symbolic_filter'&lt;/span&gt; );

&lt;span class=&quot;keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;plugins_symbolic_filter&lt;/span&gt;&lt;span class=&quot;params&quot;&gt;( $url )&lt;/span&gt; &lt;/span&gt;{
    &lt;span class=&quot;comment&quot;&gt;//set the path to the plugin file&lt;/span&gt;
    $path = dirname( &lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;plugin_path );

    &lt;span class=&quot;comment&quot;&gt;//get the basename of the path&lt;/span&gt;
    $basename = basename( $path );

    &lt;span class=&quot;comment&quot;&gt;//check if this plugin is in the basename that is checked&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; ( preg_match( &lt;span class=&quot;string&quot;&gt;'/'&lt;/span&gt; . &lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;plugin_name . &lt;span class=&quot;string&quot;&gt;'$/'&lt;/span&gt;, $basename ) ) {
        $path = dirname( $path );
    }

    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; str_replace( $path, &lt;span class=&quot;string&quot;&gt;&quot;&quot;&lt;/span&gt;, $url );
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It will check if the plugin name is found in the path and remove the file path (which won’t be removed by WordPress) from the URL. So now your assets will work again.&lt;/p&gt;
&lt;h2 id=&quot;what-about-registration-deregistration-and-uninstall-hooks-&quot;&gt;What about registration, deregistration and uninstall hooks?&lt;/h2&gt;
&lt;p&gt;Registration hooks in WordPress bind actions on it’s filenames. Since it uses the function &lt;code&gt;plugin_basename&lt;/code&gt; it will bind it’s action on a filename which doesn’t exist.&lt;/p&gt;
&lt;p&gt;What happens is that &lt;code&gt;plugin_basename&lt;/code&gt; only removes the &lt;code&gt;WP_PLUGIN_DIR&lt;/code&gt; and &lt;code&gt;WPMU_PLUGIN_DIR&lt;/code&gt; from the file path, but since our plugin is not physically in either folders the path wont get stripped.&lt;/p&gt;
&lt;p&gt;For this I created a small function in Symbolic Press: &lt;code&gt;plugin_basename&lt;/code&gt;. Which can be called by using &lt;code&gt;Symbolic_Press::plugin_basename()&lt;/code&gt;. Easy peasy.&lt;/p&gt;
&lt;p&gt;The solution is a copy of the original &lt;code&gt;plugin_basename&lt;/code&gt; but with two lines added before the &lt;code&gt;preg_replace&lt;/code&gt; and a replacement for the &lt;code&gt;preg_replace&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;$sp_plugin_dir = dirname( dirname( $sp_plugin_dir ) );
$sp_plugin_dir = preg_replace( &lt;span class=&quot;string&quot;&gt;'|/+|'&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;'/'&lt;/span&gt;, $sp_plugin_dir ); &lt;span class=&quot;comment&quot;&gt;// remove any duplicate slash&lt;/span&gt;
$file          = preg_replace( &lt;span class=&quot;string&quot;&gt;'#^'&lt;/span&gt; . preg_quote( $sp_plugin_dir, &lt;span class=&quot;string&quot;&gt;'#'&lt;/span&gt; ) . &lt;span class=&quot;string&quot;&gt;'/|^'&lt;/span&gt; . preg_quote( $plugin_dir, &lt;span class=&quot;string&quot;&gt;'#'&lt;/span&gt; ) . &lt;span class=&quot;string&quot;&gt;'/|^'&lt;/span&gt; . preg_quote( $mu_plugin_dir, &lt;span class=&quot;string&quot;&gt;'#'&lt;/span&gt; ) . &lt;span class=&quot;string&quot;&gt;'/#'&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;''&lt;/span&gt;, $file ); &lt;span class=&quot;comment&quot;&gt;// get relative path from plugins dir&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;how-do-i-use-the-registration-deregistration-and-uninstall-hooks-&quot;&gt;How do I use the registration, deregistration and uninstall hooks?&lt;/h2&gt;
&lt;p&gt;When you’re using a registration or deregistration hook WordPress does no more than:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;add_action( &lt;span class=&quot;string&quot;&gt;'activate_awesome-plugin/awesome-plugin.php'&lt;/span&gt;, $function );&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For this you can use:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;$plugin_basename = Symbolic_Press::plugin_basename( $file );

&lt;span class=&quot;comment&quot;&gt;//bind the activation action&lt;/span&gt;
add_action( &lt;span class=&quot;string&quot;&gt;'activate_'&lt;/span&gt; . $plugin_basename, $function );&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or the respectable static functions you can use to register these hooks.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;Symbolic_Press::register_activation_hook( $filepath, $function ); Symbolic_Press::register_deactivation_hook( $filepath, $function );
Symbolic_Press::register_uninstall_hook( $filepath, $function );&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;It’s a workaround, but it works very good. Now you can go and test your plugins agains multiple installs without any problems.&lt;/p&gt;
&lt;p&gt;You can also create a single place to update and maintain your plugins on your production environment. That might get a bit tricky, but that’s a completely different story.&lt;/p&gt;
&lt;p&gt;Let me know what you think in the comments.&lt;/p&gt;
</description></item><item><title>Looking back at WordCamp Europe 2013</title><link>https://gaya.pizza/articles/looking-back-at-wordcamp-europe-2013/</link><pubDate>Tue, 08 Oct 2013 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/looking-back-at-wordcamp-europe-2013/</guid><author></author><description>&lt;p&gt;Last weekend I went to WordCamp Europe in Leiden. It was my first WordCamp and I have to say; it was very awesome. Can’t believe I’ve never been to an event like this before and I should really start doing it more in the future.&lt;/p&gt;
&lt;p&gt;I’ll fill you in on the experience, the speakers and give you my two cents of what I thought about the talks.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/looking-back-at-wordcamp-europe-2013/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/looking-back-at-wordcamp-europe-2013/looking-back-at-wordcamp-europe-2013.jpg&quot; alt=&quot;Looking back at WordCamp Europe 2013&quot; title=&quot;Looking back at WordCamp Europe 2013&quot;&gt;&lt;/a&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;how-i-got-into-wordpress-and-going-to-wordcamp&quot;&gt;How I got into WordPress and going to WordCamp&lt;/h2&gt;
&lt;p&gt;When I started working at &lt;a href=&quot;http://www.merchandise.nl&quot; title=&quot;Merchandise.nl&quot;&gt;Merchandise.nl&lt;/a&gt; a while ago this conference was one of the things Richard (my boss) talked to me about. He encouraged me to go for the whole weekend and contributors day, even if I just wanted to go for the experience.&lt;/p&gt;
&lt;p&gt;I didn’t know what to expect since the only things I had done with WordPress back then were a few themes, managing my blog and writing a few plugins here and there. Most of my experience was based of personal projects.&lt;/p&gt;
&lt;p&gt;Since we have a lot of sites running on WordPress at Merchandise.nl it was quite logical for me to attend this kind of conference. So last friday, it was time to leave for &lt;a href=&quot;http://2013.europe.wordcamp.org/&quot; title=&quot;WordCamp Europe 2013 Leiden&quot;&gt;WordCamp Europe in Leiden&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;day-0-woo-ping-dinner-and-whooping-pubs&quot;&gt;Day 0: Woo Ping dinner and whooping pubs&lt;/h2&gt;
&lt;p&gt;Friday was a little warmup for all that was to come. Headed out for some drinks at the English pub and for Chinese food at the Sponsor/Speaker/Volunteers dinner. It was a good lot of fun and I got to talk to a lot of interesting people from the WordPress community.&lt;/p&gt;
&lt;p&gt;Of course we ended up at the English pub again and I stumbled back to the hotel at the end of the night. What a great start of the weekend!&lt;/p&gt;
&lt;h2 id=&quot;day-1-the-talks&quot;&gt;Day 1: The Talks&lt;/h2&gt;
&lt;p&gt;After waking up with a huge headache and walking to the conference with Richard it was time to pickup our t-shirts (which we made in case you’re wondering). I decided that most talks in the “build” section would be most fit for me.&lt;/p&gt;
&lt;h3 id=&quot;unit-testing-like-a-pirate-ptah-dunbar&quot;&gt;Unit Testing Like a Pirate - &lt;a href=&quot;https://twitter.com/ptahdunbar/&quot; title=&quot;Ptah Dunbar on Twitter&quot;&gt;Ptah Dunbar&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The first talk I joined was about unit testing in PHP like the title would suggest. It was a nice intro into unit testing in general but also how you could go about and write your own tests. Very interesting and important to people who are not doing it.&lt;/p&gt;
&lt;p&gt;I’d like to see even more unit tests in my own projects, not only on WordPress projects. TDD is something that takes getting used to, but it’s important for the quality control of your product (if you have any).&lt;/p&gt;
&lt;p&gt;For those who are interested here are &lt;a href=&quot;http://ptahdunbar.com/resources-for-unit-testing-like-a-pirate-talk-wceu/&quot; title=&quot;Resources for Unit testing like a Pirate talk&quot;&gt;the slides and resources to Ptah’s talk&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;the-life-of-a-theme-tammie-lister&quot;&gt;The Life of a Theme - Tammie Lister&lt;/h3&gt;
&lt;p&gt;A pretty straightforward talk from a designer’s perspective on how to take on a website project. She talked about the most logical waterfall approach to creating a website and it’s design.&lt;/p&gt;
&lt;p&gt;Pretty good for people who don’t have a clue how to handle such projects. I expected a different approach though, but this method works for a lot of people.&lt;/p&gt;
&lt;h3 id=&quot;perfect-your-images-using-wordpress-marko-heijnen-mike-schroder&quot;&gt;Perfect Your Images Using WordPress - &lt;a href=&quot;https://twitter.com/markoheijnen&quot; title=&quot;Marko Heijnen on Twitter&quot;&gt;Marko Heijnen&lt;/a&gt; &amp;amp; &lt;a href=&quot;https://twitter.com/GetSource&quot; title=&quot;Mike Schroder on Twitter&quot;&gt;Mike Schroder&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Since WordPress 3.5 the image editor has been made into separate classes to encapsulate all the functionality. Two of those are specifically for the use of GD and Image Magick.&lt;/p&gt;
&lt;p&gt;It makes resizing, cropping or manipulating images in your code just a bit easier. The great thing here is that it has integrated WordPress specific features like saving.&lt;/p&gt;
&lt;p&gt;It was pretty interesting for me to see how they handled this because I am using Image Magick in one of our projects to gather the user’s input and create output images we can use to print on different products we sell. I’ll sure to be writing about that soon.&lt;/p&gt;
&lt;p&gt;You can find the &lt;a href=&quot;http://www.getsource.net/2013/10/wordcamp-europe-2013-perfect-images-using-wordpress/&quot; title=&quot;Slides for Perfect Your Images Using WordPress&quot;&gt;slides to perfecting image manipulation in WordPress&lt;/a&gt; on Mike’s blog.&lt;/p&gt;
&lt;h3 id=&quot;writing-secure-wordpress-code-brad-williams&quot;&gt;Writing Secure WordPress Code - &lt;a href=&quot;https://twitter.com/williamsba&quot; title=&quot;Brad Williams on Twitter&quot;&gt;Brad Williams&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Brad took us through the process of writing secure WordPress plugins and themes. He showed us the importance of sanitising input and escaping output in your themes / plugins.&lt;/p&gt;
&lt;p&gt;I think stuff like this should be mandatory when writing plugins and I believe a lot of plugin developers are missing this kind of professionalism. As much as I knew most of the stuff Brad was telling us, I felt like it was the best talk of the day.&lt;/p&gt;
&lt;p&gt;If we want to improve WordPress we should keep stuff like this and testing like Ptah explained in our workflows. The web is a scary place, we have to improve it so the foundation we stand on will be stronger.&lt;/p&gt;
&lt;p&gt;You can find &lt;a href=&quot;http://www.slideshare.net/williamsba/writing-secure-wordpress-code&quot; title=&quot;Slides to Writing Secure WordPress code&quot;&gt;the slides to Writing Secure WordPress code&lt;/a&gt; here.&lt;/p&gt;
&lt;h2 id=&quot;the-after-and-in-between-party&quot;&gt;The after (and in between) party&lt;/h2&gt;
&lt;p&gt;WordCamp is a great place to meet people, which I did throughout the first day. I didn’t fill my time with going to all the talks, but I went to grab a beer now and then. It’s great to see so many people from different countries come together with a similar interest and have such a good time doing just that.&lt;/p&gt;
&lt;p&gt;Had a lot of nice interesting conversations with people at the after party, but the music was kind of shitty and way too loud to have a normal conversation. The atmosphere was great though.&lt;/p&gt;
&lt;h2 id=&quot;day-2-the-speakers&quot;&gt;Day 2: The Speakers&lt;/h2&gt;
&lt;p&gt;Waking up the day after the after party was a lot easier than I had expected. I was ready for day two of WordCamp.&lt;/p&gt;
&lt;h3 id=&quot;wordpress-3-7-foundations-andrew-nacin&quot;&gt;WordPress 3.7: Foundations - &lt;a href=&quot;https://twitter.com/nacin&quot; title=&quot;Andrew Nacin on Twitter&quot;&gt;Andrew Nacin&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Andrew is the lead developer of WordPress and was going through the changes that are going to talk place in the next release of WordPress.&lt;/p&gt;
&lt;p&gt;One of the most interesting things Andrew told us about was that WordPress is going to have automatic updates. I am very glad security patches are getting pushed to some people’s websites, but I for one like to stage my projects before putting them on my production server. An update might just break a site, we’ve all been there.&lt;/p&gt;
&lt;p&gt;We run over 30 WordPress websites at Merchandise.nl, so it’s not really an option for us to stage all our updates. So an auto updater might come in handy. Although I like how &lt;a href=&quot;http://infinitewp.com/&quot; title=&quot;Infinite WordPress&quot;&gt;Infinite WordPress&lt;/a&gt; updates all our websites so I can instantly tell when one of the sites breaks.&lt;/p&gt;
&lt;h3 id=&quot;practical-wordpress-accessibility-bram-duvigneau&quot;&gt;Practical WordPress Accessibility - &lt;a href=&quot;https://twitter.com/bramduvigneau&quot; title=&quot;Bram Duvigneau on Twitter&quot;&gt;Bram Duvigneau&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;We tend to forget how important accessibility is on the web. Bram showed us the struggle he has to go through browsing the web. Bram was born blind and showed us how he uses his screenreader and let us actually see what he sees.&lt;/p&gt;
&lt;p&gt;It’s hard to comprehend this part of the web for a lot of us. The best we can do is keep ourselves to coding clean and semantic HTML.&lt;/p&gt;
&lt;p&gt;Bram didn’t have any slides (of course) and showed us what he talked about throughout the talk. It surely was one the most interesting talks to have attended this WordCamp.&lt;/p&gt;
&lt;h3 id=&quot;to-oop-or-not-to-oop-nikolay-bachiyski&quot;&gt;To OOP or not to OOP - &lt;a href=&quot;https://twitter.com/nikolayb&quot; title=&quot;Nikolay Bachiyski on Twitter&quot;&gt;Nikolay Bachiyski&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;A great discussion, which has been going on for a long time. I tend to agree with Nikolay on this one.&lt;/p&gt;
&lt;p&gt;A project can get out of hand pretty quickly and if you have been putting your functions over different files and try to get any logic in them things tend to get a bit messy and hard to follow. Everything gets named improperly with prefixes and data doesn’t really have a scope.&lt;/p&gt;
&lt;p&gt;I don’t know if the WordPress development community is ready to elevate to a higher level of programming, but there are a lot of plugins (my older ones have the same problem) out there that are not meeting those standards.&lt;/p&gt;
&lt;p&gt;View &lt;a href=&quot;https://speakerdeck.com/nb/wordpress-to-oop-or-not-to-oop&quot; title=&quot;To OOP or not to OOP&quot;&gt;the slides to To OOP or not to OOP&lt;/a&gt; here.&lt;/p&gt;
&lt;h3 id=&quot;q-a-matt-mullenweg&quot;&gt;Q &amp;amp; A - &lt;a href=&quot;https://twitter.com/photomatt&quot; title=&quot;Matt Mullenweg&quot;&gt;Matt Mullenweg&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;It was time for a round of questions to ask Matt Mullenweg who is the co-founder of WordPress.&lt;/p&gt;
&lt;p&gt;Matt is a charismatic guy on stage and answered the questions very nice. It’s a pity the questions weren’t as good. I’d wish he had prepared a talk himself, but it was nice to hear the philosophy behind some discussions that were made.&lt;/p&gt;
&lt;h3 id=&quot;less-is-more-the-journey-of-happytables-as-a-wordpress-saas-noel-tock&quot;&gt;Less is More: The Journey of happytables as a WordPress SaaS - &lt;a href=&quot;https://twitter.com/noeltock&quot; title=&quot;Noel Tock on Twitter&quot;&gt;Noel Tock&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Noel Tock is the founder Happy Tables. A service that provides a way for restaurant owners to easily create a website specifically aimed for their audience with ease.&lt;/p&gt;
&lt;p&gt;It’s interesting to see how they managed for change the looks and contenting process on WordPress in such way that it’s focused on the tasks of the restaurant owner. Very valuable information.&lt;/p&gt;
&lt;h3 id=&quot;real-wordpress-security-kill-the-noise-dre-armeda&quot;&gt;Real WordPress Security – Kill the Noise! - &lt;a href=&quot;https://twitter.com/dremeda&quot; title=&quot;Dre Armeda on Twitter&quot;&gt;Dre Armeda&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Dre went over some pointers on how you can increase the security of your website with just some simple techniques. He told us how important things like strong passwords, being careful with our information and updating your software are.&lt;/p&gt;
&lt;p&gt;He also explained how some attacks go about and how we as WordPress users can prevent them, or at least make it harder to gain access to our websites.&lt;/p&gt;
&lt;p&gt;It’s all pretty basic, but still very important. I found this talk very entertaining.&lt;/p&gt;
&lt;h3 id=&quot;the-victory-of-the-commons-joost-de-valk&quot;&gt;The Victory of the Commons - &lt;a href=&quot;https://twitter.com/yoast&quot; title=&quot;Joost de Valk on Twitter&quot;&gt;Joost de Valk&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Joost ended WordCamp with a talk about keeping the open-source community a healthy place to live in.&lt;/p&gt;
&lt;p&gt;It’s sad to see so many great developers contributing to the open-source community but not getting anything back. We give stuff away for free and we can’t make a living with it.&lt;/p&gt;
&lt;p&gt;Joost presented us a way to change our strategy to make money off it while still providing to the open-source community.&lt;/p&gt;
&lt;p&gt;Read more about &lt;a href=&quot;http://yoast.com/victory-commons/&quot; title=&quot;Victory of the Commons&quot;&gt;the victory of the commons&lt;/a&gt; on his blog.&lt;/p&gt;
&lt;h2 id=&quot;day-3-contributors-day&quot;&gt;Day 3: Contributors day&lt;/h2&gt;
&lt;p&gt;On contributors day all the nerds got together to contribute to the WordPress project. What I mainly learned here was how to contribute and got some insights from the lead developers.&lt;/p&gt;
&lt;p&gt;It’s great to see such a vibrant community and how we work to make the product better every day.&lt;/p&gt;
&lt;h2 id=&quot;closing-words&quot;&gt;Closing words&lt;/h2&gt;
&lt;p&gt;I am so glad I went and I am sure I’ll be attending a lot more conferences in the future. It’s great that Richard is giving me the opportunity to go to events like this.&lt;/p&gt;
&lt;p&gt;It was great meeting the speakers, crew, contributors and other attendees. You made this experience that much better.&lt;/p&gt;
</description></item><item><title>How to start using Sass and Compass in 10 minutes</title><link>https://gaya.pizza/articles/how-to-start-using-sass-and-compass-in-10-minutes/</link><pubDate>Fri, 20 Sep 2013 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/how-to-start-using-sass-and-compass-in-10-minutes/</guid><author></author><description>&lt;p&gt;Lately I’ve been getting a lot of questions from people how to begin using Sass and Compass. Even though it’s pretty easy, a little push in the right direction is all you need to quickly start utilising Sass and Compass in your next project.&lt;/p&gt;
&lt;p&gt;I’ll give you installing instructions, a bit of information on what happens and a sample project setup I use myself to get you started quickly.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/how-to-start-using-sass-and-compass-in-10-minutes/&quot; title=&quot;How to start using Sass and Compass in 10 minutes&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/how-to-start-using-sass-and-compass-in-10-minutes/how-to-sass-compass.jpg&quot; alt=&quot;How to start using Sass and Compass in 10 minutes&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;what-will-sass-and-compass-do-for-me-&quot;&gt;What will Sass and Compass do for me?&lt;/h2&gt;
&lt;p&gt;With Sass and Compass you can generate optimised css output to use on your webprojects. It will take your &lt;code&gt;.sass&lt;/code&gt; or &lt;code&gt;.scss&lt;/code&gt; source files and compile browser readable CSS for you.&lt;/p&gt;
&lt;p&gt;Since Compass helps a lot with handling other assets than just CSS, we’ll be using it to generate our CSS.&lt;/p&gt;
&lt;h2 id=&quot;how-does-compass-work-&quot;&gt;How does Compass work?&lt;/h2&gt;
&lt;p&gt;Most projects I’ve worked on have their images, CSS and other assets separated in different folders. Compass will help us organise our &lt;code&gt;.sass&lt;/code&gt; or &lt;code&gt;.scss&lt;/code&gt; code to work better with our other assets.&lt;/p&gt;
&lt;p&gt;In a Compass project we’ll have a config file called &lt;code&gt;config.rb&lt;/code&gt; in which the settings of the project are defined. Compass will read this and use the settings when compiling your css.&lt;/p&gt;
&lt;h2 id=&quot;the-difference-between-sass-and-scss&quot;&gt;The difference between .sass and .scss&lt;/h2&gt;
&lt;p&gt;Only thing different about the two is the syntax. Both will be parsed by Compass. In this tutorial we’ll use &lt;code&gt;.scss&lt;/code&gt;. A more in-depth article of which syntax to pick can be found here: &lt;a href=&quot;http://thesassway.com/articles/sass-vs-scss-which-syntax-is-better&quot; title=&quot;Sass vs Scss&quot;&gt;http://thesassway.com/articles/sass-vs-scss-which-syntax-is-better&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;what-will-we-be-doing-&quot;&gt;What will we be doing?&lt;/h2&gt;
&lt;p&gt;This tutorial will take you through the following steps in understanding and setting up your project:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Install Compass on your computer&lt;/li&gt;
&lt;li&gt;Use the test project&lt;/li&gt;
&lt;li&gt;Watch Compass do its magic&lt;/li&gt;
&lt;li&gt;Your first .scss&lt;/li&gt;
&lt;li&gt;Trying out Compass’ helpers&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;##1. Install Compass on your computer&lt;/p&gt;
&lt;p&gt;First we’re going to install Ruby. If you’re on OS X; Ruby is already installed (great!). If you’re working on a Windows machine you can grab &lt;a href=&quot;http://rubyinstaller.org/&quot; title=&quot;RubyInstaller&quot;&gt;RubyInstaller for Windows&lt;/a&gt;. Be sure to check the “export Ruby executables to PATH” box when installing.&lt;/p&gt;
&lt;p&gt;More detailed instructions can be found in &lt;a href=&quot;http://net.tutsplus.com/tutorials/ruby/ruby-for-newbies-installing-ruby-and-getting-started/&quot; title=&quot;Ruby for Newbies: Installing Ruby and Getting Started&quot;&gt;“Ruby for Newbies: Installing Ruby and Getting Started”&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Now we can install Compass. So let’s open up a &lt;em&gt;Terminal&lt;/em&gt; (CMD on Windows).&lt;/p&gt;
&lt;h3 id=&quot;on-windows-&quot;&gt;On Windows:&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;gem install compass&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;on-os-x&quot;&gt;On OS X&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;sudo gem install compass&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;Use the test project&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;Compass is installed and we can start using it to watch our projects.&lt;/p&gt;
&lt;p&gt;Let’s create a folder somewhere on your computer. We’ll call it &lt;code&gt;compass-demo&lt;/code&gt; for the purpose of this demo.&lt;/p&gt;
&lt;p&gt;Download the &lt;a href=&quot;https://github.com/Gaya/Compass-Boilerplate/archive/master.zip&quot; title=&quot;Compass Boilerplate&quot;&gt;Compass Boilerplate I created&lt;/a&gt;  from Github and extract it in your &lt;code&gt;compass-demo&lt;/code&gt; folder.&lt;/p&gt;
&lt;p&gt;The folder structure of the project should look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;- compass-demo
    - assets
        - compass
            - sass
                style.scss
            config.rb
        - css
            style.css
        - images
            gaya-design-logo.png&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;assets&lt;/code&gt; is the root folder of all our assets. Later on you can for example add a Javascripts directory. &lt;code&gt;compass&lt;/code&gt; is the directory we will be ‘watching’ for changes. Notice the &lt;code&gt;config.rb&lt;/code&gt; file. That file holds all the settings Compass needs to compile the CSS correctly.&lt;/p&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;Watch Compass do its magic&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;We need to tell Compass to ‘watch’ our &lt;code&gt;compass&lt;/code&gt; folder. This will make Compass look for changes to the files in the &lt;code&gt;sass&lt;/code&gt; folder of the project. In this case we have a &lt;code&gt;style.scss&lt;/code&gt; file.&lt;/p&gt;
&lt;p&gt;Go to the &lt;code&gt;compass-demo/assets/compass&lt;/code&gt; folder in your *Terminal *(or cmd). From here run the following command:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;compass watch&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It should say: &lt;code&gt;&amp;gt;&amp;gt;&amp;gt; Compass is polling for changes. Press Ctrl-C to Stop.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Good, we’re now watching the &lt;code&gt;compass&lt;/code&gt; folder because the &lt;code&gt;config.rb&lt;/code&gt; file is in there. It’s contents look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# Require any additional compass plugins here.

#Folder settings
relative_assets = true      #because we&amp;#39;re not working from the root
css_dir = &amp;quot;../css&amp;quot;          #where the CSS will saved
sass_dir = &amp;quot;sass&amp;quot;           #where our .scss files are
images_dir = &amp;quot;../images&amp;quot;    #the folder with your images

# You can select your preferred output style here (can be overridden via the command line):
output_style = :expanded # After dev :compressed

# To disable debugging comments that display the original location of your selectors. Uncomment:
line_comments = true

# Obviously
preferred_syntax = :scss&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can see all the references to the different directories Compass will need in order to compile your CSS.&lt;/p&gt;
&lt;ol start=&quot;4&quot;&gt;
&lt;li&gt;Your first .scss&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;Let’s open up the &lt;code&gt;sass/style.scss&lt;/code&gt; file and add the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;'compass/css3'&lt;/span&gt;;

&lt;span class=&quot;selector-class&quot;&gt;.shadow&lt;/span&gt; {
    &lt;span class=&quot;keyword&quot;&gt;@include&lt;/span&gt; box-shadow(&lt;span class=&quot;number&quot;&gt;#000&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;5px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;5px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;5px&lt;/span&gt;);
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;First we import Compass’ CSS3 mixins and then give the selector &lt;code&gt;.shadow&lt;/code&gt; a nice box-shadow.&lt;/p&gt;
&lt;p&gt;Now open the compiled css file in &lt;code&gt;assets/css/style.css&lt;/code&gt;. You can see that Compass magically added all the CSS3 vendor prefixes for you.&lt;/p&gt;
&lt;ol start=&quot;5&quot;&gt;
&lt;li&gt;Trying out Compass’ helpers&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;In the &lt;code&gt;config.rb&lt;/code&gt; we also pointed out where our images are saved. This is because we can use Compass to get the url to our image, but also the width and the height. Pretty neat, right?&lt;/p&gt;
&lt;p&gt;Add the following code to your &lt;code&gt;style.scss&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.logo&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;background-image&lt;/span&gt;: image-url(&lt;span class=&quot;string&quot;&gt;&quot;gaya-design-logo.png&quot;&lt;/span&gt;);
    &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: image-width(&lt;span class=&quot;string&quot;&gt;&quot;gaya-design-logo.png&quot;&lt;/span&gt;);
    &lt;span class=&quot;attribute&quot;&gt;height&lt;/span&gt;: image-height(&lt;span class=&quot;string&quot;&gt;&quot;gaya-design-logo.png&quot;&lt;/span&gt;);
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You’ll see that the compiled CSS will point to the right image file and filled in the width and height in pixels.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.logo&lt;/span&gt; {
  &lt;span class=&quot;attribute&quot;&gt;background-image&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;url&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'../images/gaya-design-logo.png?1364137770'&lt;/span&gt;);
  &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;102px&lt;/span&gt;;
  &lt;span class=&quot;attribute&quot;&gt;height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;87px&lt;/span&gt;;
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;just-start-using-compass-&quot;&gt;Just start using Compass!&lt;/h2&gt;
&lt;p&gt;From here all I can tell you is to start using Compass and &lt;a href=&quot;http://compass-style.org/reference/compass/&quot; title=&quot;Compass Reference&quot;&gt;dig into Compass’ features&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It might be a good start to look for some in-dept tutorials, but you can also ask someone you know is great with Sass and Compass to fill you in.&lt;/p&gt;
&lt;p&gt;I hope this quick tutorial made your Compass working environment possible.&lt;/p&gt;
</description></item><item><title>An inspirational day at Yoast</title><link>https://gaya.pizza/articles/an-inspirational-day-at-yoast/</link><pubDate>Sat, 14 Sep 2013 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/an-inspirational-day-at-yoast/</guid><author></author><description>&lt;p&gt;Yesterday, friday the 13th, I went to &lt;a href=&quot;http://yoast.com&quot; title=&quot;Yoast&quot;&gt;Yoast&lt;/a&gt; for a day of coding, sharing knowledge and good old fun. It’s great to see that a company like Yoast can thrive when it’s most know for its WordPress plugin.&lt;/p&gt;
&lt;p&gt;Let me tell you the impressions I got from Yoast, its people and a non standard environment.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/an-inspirational-day-at-yoast/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/an-inspirational-day-at-yoast/an-inspirational-day-at-yoast.jpg&quot; alt=&quot;An inspirational day at Yoast&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;who-is-yoast-&quot;&gt;Who is Yoast?&lt;/h2&gt;
&lt;p&gt;If you’ve ever made a website using WordPress it’s most likely that you’ve heard of the name Yoast. Joost is best known for his plugin &lt;a href=&quot;http://yoast.com/wordpress/seo/&quot; title=&quot;WordPress SEO Plugin&quot;&gt;WordPress SEO plugin&lt;/a&gt;. As the name suggests it’s a plugin that helps you have kick-ass SEO support on your WordPress website.&lt;/p&gt;
&lt;p&gt;Yoast has grown to be a company that provides a lot of plugins for WordPress and started selling premium plugins a while ago. They also do website reviews and are working on releasing a lot of cool stuff later on.&lt;/p&gt;
&lt;h2 id=&quot;what-i-did-do-there-&quot;&gt;What I did do there?&lt;/h2&gt;
&lt;p&gt;When I came in I was presented with a place to plug in my laptop (which is starting to feel older being from 2009) so I could start showing some projects I’ve been working on at &lt;a href=&quot;http://www.merchandise.nl&quot; title=&quot;The place I work at: Merchandise.nl&quot;&gt;Merchandise.nl&lt;/a&gt;. I showed Joost and his crew a WordPress plugin I had working on for a few days. More information on that pretty soon.&lt;/p&gt;
&lt;p&gt;After a bit of talking we came to the subject of Sass and Compass. The developers at Yoast are coding stylesheets, but they’re not using enough Sass and Compass awesomeness to enhance their workflow.&lt;/p&gt;
&lt;h2 id=&quot;mini-sass-and-compass-workshop&quot;&gt;Mini Sass and Compass workshop&lt;/h2&gt;
&lt;p&gt;Joost and his crew gathered around while I showed them some tricks and awesome Compass features. This really opened their eyes as to what is possible and I could see ideas pop up in their heads, which was a great thing to see.&lt;/p&gt;
&lt;p&gt;After showing the great advantages of using Sass and Compass I did a hands-on part where showed them how to set up their development machines for Sass and Compass usage. What made it different was that I tried to solve an other developers’ use-case rather than the problems I face on my own.&lt;/p&gt;
&lt;p&gt;It gave me room to try out some new tricks and show the developers how to go ahead and improve their CSS development using Sass and Compass.&lt;/p&gt;
&lt;h2 id=&quot;codeception-try-outs&quot;&gt;Codeception try-outs&lt;/h2&gt;
&lt;p&gt;After that we got around to try &lt;a href=&quot;http://codeception.com/&quot; title=&quot;Codeception&quot;&gt;Codeception&lt;/a&gt; for testing of websites. It helps you create acceptance tests, functional tests and unit tests.&lt;/p&gt;
&lt;p&gt;We didn’t really have a lot of time to try it out, but it looks really promising. Can’t wait to get my hands dirty with it later. I bet I can make way better products using tests like these, not to mention updates on existing sites.&lt;/p&gt;
&lt;h2 id=&quot;wrapping-up&quot;&gt;Wrapping up&lt;/h2&gt;
&lt;p&gt;At four ‘o clock it was time for a beer and reflect on the day. This surely is not the last time I’m visiting and I am sure to be collaborating with Joost on projects in the future.&lt;/p&gt;
&lt;h2 id=&quot;sass-and-compass-workshops&quot;&gt;Sass and Compass workshops&lt;/h2&gt;
&lt;p&gt;Returning home I got really excited thinking back about the short improvised workshop I gave earlier. I’d love to hold workshops for other development teams in the future.&lt;br&gt; Get in touch with me if you’re interested in such workshop.&lt;/p&gt;
</description></item><item><title>Good design is not just the pretty picture</title><link>https://gaya.pizza/articles/good-design-just-pretty-picture/</link><pubDate>Wed, 28  Aug 2013 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/good-design-just-pretty-picture/</guid><author></author><description>&lt;p&gt;In the time I spend working in web development I had the chance to work on some great looking designs which were fun to work with most of the time. There is however a problem with many designs I see lately and that’s that they miss the fundamentals.&lt;/p&gt;
&lt;p&gt;Maybe it’s weird to hear a design lecture from a developer, but I really think it’s good to see things from a different direction. I’ll give you my view on designs and how they lack some important things a lot of the time.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/good-design-just-pretty-picture/&quot; title=&quot;Good design is not just the pretty picture&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/good-design-just-pretty-picture/poster-good-design-pretty-picture.jpg&quot; alt=&quot;Good design is not just the pretty picture&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;let-s-do-the-same-thing-the-crowd-does-&quot;&gt;Let’s do the same thing the crowd does!&lt;/h2&gt;
&lt;p&gt;People tend to feel more comfortable in crowds and will act the same when they are together. This means that a lot of cultural elements we see every day are the same in some way.&lt;/p&gt;
&lt;p&gt;Music sounds pretty much the same on every mainstream station. Fashion looks the same in different groups of people, making them easy to identify.&lt;/p&gt;
&lt;p&gt;I’ve been seeing the same behaviour as far as design goes. Someone will create some new concept and it will get done a million of times over, one worse than the other. Choosing to copy someone is not bad, but just for the sake of it being “the latest thing”, that’s bad.&lt;/p&gt;
&lt;p&gt;What I am aiming at are sites like dribbble and Awwwards. You’ll see a trend growing popularity on either of them and after that you’ll see a ton of websites with the same look and functionality without even considering if it will work properly for the target audience.&lt;/p&gt;
&lt;h2 id=&quot;you-ll-not-be-the-one-using-the-site&quot;&gt;You’ll not be the one using the site&lt;/h2&gt;
&lt;p&gt;And your client is also not the target audience. Your client’s clients are the target audience. So whatever you might consider “useable” or “the way to go” may not apply to the end user. You’re not here to impress yourself, your designer buddies or the client. You’re here to impress and work your magic for the end user.&lt;/p&gt;
&lt;p&gt;A lot of stuff that we come across on a daily basis might be very logical to use web makers, but not for the end user. A super large header carousel or a huge picture with a little caption on top of it has no function at all to the end user. You might impress some hip web making kids, but the end user won’t get it most of the time. He might even get confused and skip the website he just visited, just because he doesn’t know what he has to do with it.&lt;/p&gt;
&lt;p&gt;The best working websites are the ones that are adjusted to their end users, not their creators. Design seems to loose focus on the target audience a lot of the time.&lt;/p&gt;
&lt;h2 id=&quot;stop-overcomplicating-things&quot;&gt;Stop overcomplicating things&lt;/h2&gt;
&lt;p&gt;Just because something looks better doesn’t mean that it’s better. Just because an important element looks better in a certain part of the page doesn’t mean it’s logical to put it there.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/good-design-just-pretty-picture/a-complicated-maze.jpg&quot; alt=&quot;A very &amp;quot;complicated&amp;quot; maze&quot;&gt;&lt;/p&gt;
&lt;p&gt;A good design always starts with some sort of wireframe where the layout and structure of the website is put together. In this layout you can see where the important parts of the page will be. You’ll also get a feeling of what the user will be drawn to. Huge headers and useless elements will not help the end user is most of the cases.&lt;/p&gt;
&lt;p&gt;Something I also see happen a lot is changing the way people have to input information in a form. Users are used to filling out forms and picking choices in some ways that you just don’t want to change.&lt;/p&gt;
&lt;p&gt;A form should be clear and all the elements should be clear at a glance. When an end user will struggle with a slider to pick an amount or if the user has problems filling the form out in any way there is a great chance that you lost that sale, and that’s not what you want.&lt;/p&gt;
&lt;p&gt;Changing the user interface is fine, as long as it’s not too far from what they are used to. It shouldn’t be a puzzle how to use a website or app, it should be understandable just by looking at it.&lt;/p&gt;
&lt;h2 id=&quot;measure-your-design&quot;&gt;Measure your design&lt;/h2&gt;
&lt;p&gt;There are tons of ways to see if your design works. One example are heat maps which track how many times users click on a part of the page. This will give a lot of insight in the importance of buttons and might bring parts to your attention that shouldn’t be clicked on as many.&lt;/p&gt;
&lt;p&gt;Another way is to measure the path that users follow to get to the desired end you want them to go. This will help you understand how users find what you’d like them to find. If you want users to put products in their shopping cart, then you’ll have to track how users get to the point of adding the product to their carts. This will give you insights in how the design and structure flows.&lt;/p&gt;
&lt;p&gt;Once you find a great way to measure your design you can start to improve it on functionality. Now you can test and feel the improvements you can make for your end users and see the visitors and sales rise instead of not getting your product of the ground at all.&lt;/p&gt;
&lt;h2 id=&quot;closing&quot;&gt;Closing&lt;/h2&gt;
&lt;p&gt;A good design doesn’t need a pretty picture, but it will sure improve it if the fundamentals are good. It’s a shame when great artists make such nice elements but don’t put them to great use.&lt;/p&gt;
&lt;p&gt;I am testing out multiple ways to measure design and website performance and will share my findings with you later.&lt;/p&gt;
&lt;p&gt;Let me know what you think on what I wrote in the comments below the article.&lt;/p&gt;
</description></item><item><title>Stuck at your web development job? Break your routine</title><link>https://gaya.pizza/articles/stuck-at-your-web-development-job-break-your-routine/</link><pubDate>Sat, 15 Jun 2013 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/stuck-at-your-web-development-job-break-your-routine/</guid><author></author><description>&lt;p&gt;Getting stuck in the same cycle at work can be fatal for your creativity and motivation to go on. If you’re doing the same trick over and over again, project after project, you will find yourself out of energy pretty soon. I’ll try to explain what might be going wrong and what to do about it in this article.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/stuck-at-your-web-development-job-break-your-routine/&quot; title=&quot;Stuck at your web development job? Break your routine&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/stuck-at-your-web-development-job-break-your-routine/poster-stuck.jpg&quot; alt=&quot;Stuck at your web development job? Break your routine&quot; title=&quot;Stuck at your web development job? Break your routine&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;sailing-in-the-comfort-zone&quot;&gt;Sailing in the comfort zone&lt;/h2&gt;
&lt;p&gt;Back when you started your web development job everything was exciting and new. All kinds of new problems and challenges arose when you got projects to work on. This feeling of challenge will last for a few years until a point where you feel you’ve established your workflow.&lt;/p&gt;
&lt;p&gt;When this happens you’ll feel good about doing projects and will probably deliver great stuff to your clients. I found that projects were even beginning to get dull and thought there was nothing left for me to improve or figure out. The challenge was gone, but the products were good.&lt;/p&gt;
&lt;p&gt;The problem here is that you might have the feeling that you hit the ceiling when it comes to knowledge, and don’t know what you can do to improve your products.&lt;/p&gt;
&lt;h2 id=&quot;stop-the-routine-try-something-different&quot;&gt;Stop the routine, try something different&lt;/h2&gt;
&lt;p&gt;What most people do when they get the same kind of project that makes you go “Time to reinvent the wheel again.” is to read web development blogs that discuss the latest and greatest.&lt;/p&gt;
&lt;p&gt;It’s a good thing to fool around with the demos that are available everywhere and get your hands on the code yourself. This doesn’t take away the fact that there are still projects on your to-do that you have no interest in doing, but you kind of have to. It does take away the edge.&lt;/p&gt;
&lt;p&gt;If the company your work for allows it, you could try to get a completely different project from time to time.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/stuck-at-your-web-development-job-break-your-routine/werken-bij-twisted.jpg&quot; alt=&quot;Working at a dead end job&quot;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Try to make a mashup of services, or try to make a service yourself.&lt;/li&gt;
&lt;li&gt;Create a completely different website for once.&lt;/li&gt;
&lt;li&gt;Start a blog and write down your thoughts and ideas to share them with the world.&lt;/li&gt;
&lt;li&gt;Creating apps for devices and other applications can be a great step away from your routine too.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Is the company you work for only creating websites for clients with a CMS to back it and your only task is to convert design to code? Then you might be in trouble.&lt;/p&gt;
&lt;p&gt;Is the company not willing to give you space for making your own stuff aside from what you normally do? Ugh.&lt;/p&gt;
&lt;p&gt;From what I’ve experienced before is that it will kill your creativity massively. Your motivation will go down the drain as well. You’ll become a tool for the company, not an inspirator or activator you’d want to be.&lt;/p&gt;
&lt;h2 id=&quot;talk-about-being-stuck&quot;&gt;Talk about being stuck&lt;/h2&gt;
&lt;p&gt;The hardest part for some to accomplish is to talk about what you’re feeling and doing. It will relieve you from the stress of worrying about stuff that bothers you at work. Talk to your co-workers on what you think is killing your creativity and that you want to try something new.&lt;/p&gt;
&lt;p&gt;The most important people here are the ones that make the decisions about projects and what will be done. Most of the time this will be your boss(es) or project manager (if you have any.)&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/stuck-at-your-web-development-job-break-your-routine/twisted-in-eindhoven.jpg&quot; alt=&quot;Stuck in a cycle&quot;&gt;&lt;/p&gt;
&lt;p&gt;Trying to convince them you have to break the cycle shouldn’t be too hard if they know what is best for their company. It’s practically impossible to give a person the same thing to do every single time and expect them to be happy and motivated about it. If we wanted that, we probably would have chosen a different field to work in. For some people it works, but you can’t expect everyone to be like that.&lt;/p&gt;
&lt;p&gt;Some will try to look for different project for you to work on, some will give you room to explore new trends / techniques around web development. Others will not see the problem and make you do your job the same as always, in that case they’re just idiots who refuse to listen.&lt;/p&gt;
&lt;h2 id=&quot;have-meetings-about-projects&quot;&gt;Have meetings about projects&lt;/h2&gt;
&lt;p&gt;Like talking about being stuck, it’s oh so important to have meetings about the projects you’re working on. Especially when you’re working with a team that involves more than two people.&lt;/p&gt;
&lt;p&gt;Plan meetings, or just walk over to each other and talk about what you’re doing. The best way to look for new solutions,  tackle new problems and think about great new features is to talk and discuss a project with the whole team.&lt;/p&gt;
&lt;p&gt;It’s no use when one part of the team is left out of meetings, especially in the beginning. Sure, when a meeting is about the design details a developer is less necessary, but when talking about solutions to the client’s wishes it’s more than usual to be part of the process.&lt;/p&gt;
&lt;p&gt;Try and get things as clear as possible before even making a mockup, wireframe of design. A developer can help you see things from a different perspective and might even tell you a thing or two you never knew about. We can inspire designers to create something new, thus creating something new and exciting for the developer to do too. This also makes your work as a company stand out.&lt;/p&gt;
&lt;h2 id=&quot;if-you-need-to-change-jobs&quot;&gt;If you need to, change jobs&lt;/h2&gt;
&lt;p&gt;You feel you’ve tried everything and nothing is working to improve the diversity of your job, there is always one thing you can do: change jobs. A while ago I had to change jobs, which at the time I was really bummed about. Even though I was stuck and didn’t feel like I could get away from it I felt I could hang in there.&lt;/p&gt;
&lt;p&gt;Change gives you room explore and try new things. The grass is always greener on the other side for sure, but it’s the truth when you feel like you’re stuck at your current job and nobody wants to listen or do something about it.&lt;/p&gt;
&lt;p&gt;There are enough companies around that want to hire web developers, and not only agencies that create websites. Keep that in mind: you’re valuable.&lt;/p&gt;
</description></item><item><title>Faking a top-level domain name for local development with Apache</title><link>https://gaya.pizza/articles/faking-a-top-level-domain-name-for-local-development-with-apache/</link><pubDate>Tue, 09 Apr 2013 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/faking-a-top-level-domain-name-for-local-development-with-apache/</guid><author></author><description>&lt;p&gt;Developing a website on your local webserver environment can become complicated when it comes to URLs. Not every CMS (looking at you Wordpress!) has relative paths to their content. These full paths get placed in the database, which makes it harder to test and create content with pointers to wrong URLs.&lt;/p&gt;
&lt;p&gt;This guide will tell you how to fake a top-level domain name so you can redirect any domain name to your local development environment and keep your source code in separate folders.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/faking-a-top-level-domain-name-for-local-development-with-apache/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/faking-a-top-level-domain-name-for-local-development-with-apache/poster-top-level-domain-dev.jpg&quot; alt=&quot;Faking a top level domain name for local development with Apache&quot; title=&quot;Faking a top level domain name for local development with Apache&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;what-we-will-be-doing-&quot;&gt;What we will be doing:&lt;/h2&gt;
&lt;p&gt;It’s actually easier than I thought. There are a few things we need to do:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;line-height: 13px;&quot;&gt;Have a folder where our source code is in. Basically the root of your website.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Have the virtual hosts file of your Apache installation point to these folders with a few rewrites.&lt;/li&gt;
&lt;li&gt;Redirect a top-level domain name to your testing webserver’s ip address.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;before-we-start-get-a-local-development-environment-&quot;&gt;Before we start. Get a local development environment.&lt;/h2&gt;
&lt;p&gt;You’ll have to have a working local web development environment. An Apache environment in this case. Be it your native Apache on your machine, &lt;a href=&quot;http://www.mamp.info/en/index.html&quot; title=&quot;MAMP&quot;&gt;MAMP&lt;/a&gt; or &lt;a href=&quot;http://www.wampserver.com/&quot; title=&quot;WAMP&quot;&gt;WAMP&lt;/a&gt;. Just install one and have a development environment running.&lt;/p&gt;
&lt;h2 id=&quot;create-a-folder-with-the-source-&quot;&gt;Create a folder with the source.&lt;/h2&gt;
&lt;p&gt;I personally like to create a folder with all my web projects in a root folder. On OS X I went for: &lt;code&gt;~/Sites/www.domainname.com&lt;/code&gt;. This can be any domain name you want it to be. Let’s stick with this name for this example.&lt;/p&gt;
&lt;p&gt;The name of the folder with the source will be the HTTP address later on. So; making a folder called: &lt;code&gt;thisisawesome&lt;/code&gt; will be &lt;code&gt;http://thisisawesome&lt;/code&gt; later on.&lt;/p&gt;
&lt;p&gt;Let’s continue shall we. Put an HTML file in the source folder called &lt;code&gt;index.html&lt;/code&gt;. I created a sample HTML file:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;html&lt;/span&gt;&amp;gt;&lt;/span&gt;Hi, I work!&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;html&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;adjusting-the-virtual-hosts-&quot;&gt;Adjusting the virtual hosts.&lt;/h2&gt;
&lt;p&gt;First we have to find the &lt;code&gt;httpd.conf&lt;/code&gt; file of your Apache installation. On Mac OS X &lt;code&gt;/etc/apache2/httpd.conf&lt;/code&gt; using MAMP it’s typically &lt;code&gt;/Applications/MAMP/conf/apache/httpd.conf&lt;/code&gt;, with WAMP it should be in the installation folder too. Open that file in a text editor.&lt;/p&gt;
&lt;p&gt;Find this line: &lt;code&gt;# Virtual hosts&lt;/code&gt; and remove the # at the beginning of &lt;strong&gt;the next line&lt;/strong&gt; so it says something like:&lt;br&gt; &lt;code&gt;Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf&lt;/code&gt; (this is obviously for the MAMP version)&lt;/p&gt;
&lt;p&gt;Now open and edit the file in the line you just uncommented.&lt;/p&gt;
&lt;p&gt;Replace the content for the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;NameVirtualHost *:&lt;span class=&quot;number&quot;&gt;80&lt;/span&gt;

&amp;lt;Directory &lt;span class=&quot;string&quot;&gt;&quot;/Users/username/Sites/*&quot;&lt;/span&gt;&amp;gt;
    Options Indexes MultiViews FollowSymLinks Includes
    AllowOverride All
    Order allow,deny
    Allow from all
&amp;lt;/Directory&amp;gt;
&amp;lt;VirtualHost *:&lt;span class=&quot;number&quot;&gt;80&lt;/span&gt;&amp;gt;
    UseCanonicalName off
    VirtualDocumentRoot &lt;span class=&quot;string&quot;&gt;&quot;/Users/username/Sites/%0&quot;&lt;/span&gt;
    ServerName %&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Fix the folder paths if you went with a different structure. Don’t forget Windows uses different slashes in folder paths!&lt;/p&gt;
&lt;p&gt;Make sure you restart Apache after this so it can start using the vhosts configuration.&lt;/p&gt;
&lt;h2 id=&quot;if-you-re-using-mamp-preventing-port-8888-in-urls-&quot;&gt;If you’re using MAMP; preventing port 8888 in URLs.&lt;/h2&gt;
&lt;p&gt;As you might have seen it says we’re listening to port 80 in the vhosts configuration, this is not by default in MAMP. So we’re going to map MAMP to port 80.&lt;/p&gt;
&lt;p&gt;If you have a native install of apache running; open &lt;code&gt;terminal&lt;/code&gt; and type: &lt;code&gt;sudo apachectl -k stop&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now open MAMP and click on “preferences”. Go to the “ports” tab and change the the port number to 80.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/faking-a-top-level-domain-name-for-local-development-with-apache/mampport801.png&quot; alt=&quot;Change Apache port to 80 in MAMP&quot;&gt; Change Apache port to 80 in MAMP&lt;/p&gt;
&lt;p&gt;Save and restart MAMP. No more port 8888 in your URLs.&lt;/p&gt;
&lt;h2 id=&quot;making-your-computer-redirect-domain-names-in-the-hosts-file-&quot;&gt;Making your computer redirect domain names in the hosts file.&lt;/h2&gt;
&lt;p&gt;There are a lot of ways you can change the DNS to think any domain name belongs to another ip-address, but in this example we’re going to use the good old hosts file.&lt;/p&gt;
&lt;p&gt;Open up your hosts file in a text editor.&lt;/p&gt;
&lt;p&gt;On Mac: &lt;code&gt;/etc/hosts&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;On Windows: &lt;code&gt;%SystemRoot%\system32\drivers\etc\hosts&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Add this line at the bottom:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-plain&quot;&gt;127.0.0.1        www.domainname.com&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;now-open-your-browser-and-go-to-www-domainname-com&quot;&gt;Now open your browser and go to “&lt;a href=&quot;http://www.domainname.com&amp;quot;&quot;&gt;www.domainname.com&amp;quot;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;When you have Apache running you should see this now:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/faking-a-top-level-domain-name-for-local-development-with-apache/browsertest.png&quot; alt=&quot;Result in the browser&quot; title=&quot;Result in the browser&quot;&gt;&lt;/p&gt;
&lt;p&gt;And that’s it! Easy and effective. Hope you enjoyed my method of local development for top level domains.&lt;/p&gt;
</description></item><item><title>Vertical rhythm on DOM elements with dynamic heights – Keep the Rhythm</title><link>https://gaya.pizza/articles/keep-the-rhythm-vertical-rhythm-on-objects-having-dynamic-heights/</link><pubDate>Tue, 02 Apr 2013 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/keep-the-rhythm-vertical-rhythm-on-objects-having-dynamic-heights/</guid><author></author><description>&lt;p&gt;That is a lot in one sentence, but basically it explains it all. Maintaining a vertical rhythm is hard enough by itself and takes a lot of time and thinking to accomplish.&lt;/p&gt;
&lt;p&gt;The problem with maintaining a proper rhythm are objects (like images) that have dynamic heights. Like the images on this blog, or when you have clients uploading their content which isn’t perfectly resized / cropped to your line-height.&lt;/p&gt;
&lt;p&gt;For this I created a jQuery plugin that fixes the rhythm: Keep the Rhythm.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/keep-the-rhythm-vertical-rhythm-on-objects-having-dynamic-heights/&quot; title=&quot;Keep the Rhythm: Vertical rhythm on objects having dynamic heights&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/keep-the-rhythm-vertical-rhythm-on-objects-having-dynamic-heights/keep-the-rhythm.jpg&quot; alt=&quot;Keep the Rhythm: Vertical rhythm on objects having dynamic heights&quot; title=&quot;Keep the Rhythm: Vertical rhythm on objects having dynamic heights&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Rhythms are sexy and make the web a better place. It makes it way easier to read the page and it will look very balanced at the same time. It might be a bit of extra work to create a vertical rhythm, but it’s really worth the time.&lt;/p&gt;
&lt;h2 id=&quot;what-is-a-vertical-rhythm-&quot;&gt;What is a vertical rhythm?&lt;/h2&gt;
&lt;p&gt;Vertical rhythms make sure the text and elements on your page are aligned to a baseline rhythm. Look at it as if you had a notebook with line, these are the guides we write on.&lt;/p&gt;
&lt;p&gt;You can get the concept of vertical alignment pretty quick when you &lt;a href=&quot;http://gaya.github.io/scripts/keeptherhythm/&quot;&gt;take a look at the example&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;how-can-i-create-a-vertical-rhythm-&quot;&gt;How can I create a vertical rhythm?&lt;/h2&gt;
&lt;p&gt;There are tons of &lt;a href=&quot;http://drewish.com/tools/vertical-rhythm&quot;&gt;website where you can generate your vertical rhythm CSS&lt;/a&gt; so it does all the calculation for you. What I like to use is &lt;a href=&quot;http://compass-style.org/reference/compass/typography/vertical_rhythm/&quot;&gt;Compass’ vertical rhythm mixins&lt;/a&gt;. Still not using Compass? This might be a great opportunity to. Vertical rhythms are a breeze when you use Compass.&lt;/p&gt;
&lt;h2 id=&quot;what-does-keep-the-rhythm-do-&quot;&gt;What does Keep the Rhythm do?&lt;/h2&gt;
&lt;p&gt;Maintaining a vertical rhythm using line-heights is pretty doable, but there are also inline and block elements that don’t have their heights set to a rhythm. Of course the most pesky ones in this case are images.&lt;/p&gt;
&lt;p&gt;Imagine you have a baseline of 24 pixels and the image is 50 pixels tall, this means your image is 2 pixel too tall, or 22 pixels too short. Keep the Rhythm will fill this gap for you with paddings (or margins) so the elements has a perfect rhythmic height.&lt;/p&gt;
&lt;h3 id=&quot;it-fixes-this-&quot;&gt;It fixes this:&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/keep-the-rhythm-vertical-rhythm-on-objects-having-dynamic-heights/incorrect-rhythm.jpg&quot; alt=&quot;Incorrect Rhythm&quot;&gt; &lt;em&gt;Incorrect Rhythm, overlap marked in red.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;to-this-&quot;&gt;To this:&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/keep-the-rhythm-vertical-rhythm-on-objects-having-dynamic-heights/perfect-rhythm.jpg&quot; alt=&quot;Perfect Rhythm&quot;&gt;&lt;/p&gt;
&lt;p&gt;It does not only fix images, it also fixes block elements like &lt;code&gt;iframes&lt;/code&gt;. Which will come in handy when embedding media from Youtube or Vimeo.&lt;/p&gt;
&lt;h2 id=&quot;responsive-&quot;&gt;Responsive.&lt;/h2&gt;
&lt;p&gt;This script fixes the vertical alignment of elements that get resized because of a responsive layout too. This will work on very object that changes size on the window’s &lt;code&gt;resize()&lt;/code&gt; event.&lt;/p&gt;
&lt;h2 id=&quot;how-to-use-&quot;&gt;How to use?&lt;/h2&gt;
&lt;p&gt;First thing you want to do is to include jQuery and Keep the Rhythm in your webpage. Place the following code in your &lt;code&gt;tag or before the end of your&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;path/to/js/jquery-1.9.1.min.js&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;path/to/js/jquery.keeptherhythm.js&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, on &lt;code&gt;$(document).ready();&lt;/code&gt; or &lt;code&gt;$(window).load();&lt;/code&gt; call the function using a selector. Define the baseline in the options.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;$(&lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;).ready(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    $(&lt;span class=&quot;string&quot;&gt;&quot;div.rhythm&quot;&lt;/span&gt;).keepTheRhythm({
        &lt;span class=&quot;attr&quot;&gt;baseLine&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;20&lt;/span&gt;
    });
});

$(&lt;span class=&quot;built_in&quot;&gt;window&lt;/span&gt;).load(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    $(&lt;span class=&quot;string&quot;&gt;&quot;article img&quot;&lt;/span&gt;).keepTheRhythm({
        &lt;span class=&quot;attr&quot;&gt;baseLine&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;20&lt;/span&gt;
    });
});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That’s basically it! The padding will now be added automatically.&lt;/p&gt;
&lt;h2 id=&quot;use-window-load-event-for-images&quot;&gt;Use window.load event for images&lt;/h2&gt;
&lt;p&gt;Because images get their height and width set after they have been loaded it’s best if you use the &lt;code&gt;.load()&lt;/code&gt; event of the &lt;code&gt;window&lt;/code&gt;. It’s best to always perform the rhythm fixes after this event so you can be sure that the images have their heights set.&lt;/p&gt;
&lt;h2 id=&quot;i-want-to-use-margin-instead-of-padding&quot;&gt;I want to use margin instead of padding&lt;/h2&gt;
&lt;p&gt;Well, you can. Just pass an extra option value to the function call:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;$(&lt;span class=&quot;string&quot;&gt;&quot;element&quot;&lt;/span&gt;).keepTheRhythm({
    &lt;span class=&quot;attr&quot;&gt;spacing&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;margin&quot;&lt;/span&gt;
});&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;the-element-shouldn-t-be-aligned-to-the-center&quot;&gt;The element shouldn’t be aligned to the center&lt;/h2&gt;
&lt;p&gt;There is also an option for that, it can be “top”, “center” or “bottom”:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;$(&lt;span class=&quot;string&quot;&gt;&quot;element&quot;&lt;/span&gt;).keepTheRhythm({
    &lt;span class=&quot;attr&quot;&gt;verticalAlignment&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;top&quot;&lt;/span&gt;
});&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Hopefully this little plugin will help you maintain a perfect rhythm and keeps your readers happy. Let me know what you think and &lt;a href=&quot;https://github.com/Gaya/jQuery--Keep-the-Rhythm/issues&quot; title=&quot;issues on Github&quot;&gt;contribute on GitHub&lt;/a&gt; if anything is wrong with the script.&lt;/p&gt;
&lt;h2 id=&quot;documentation-reference&quot;&gt;Documentation reference&lt;/h2&gt;
</description></item><item><title>A new life for Gaya Design, the redesign part 2</title><link>https://gaya.pizza/articles/a-new-life-for-gaya-design-the-redesign-part-2/</link><pubDate>Wed, 27 Mar 2013 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/a-new-life-for-gaya-design-the-redesign-part-2/</guid><author></author><description>&lt;p&gt;Since my blog is based around web development and I don’t want to be behind on things I decided it has time to kick new life into my blog. I needed a new format which would allow short posts and have a blog that loads fast.&lt;/p&gt;
&lt;p&gt;I needed a redo of the website. From the ground up.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/a-new-life-for-gaya-design-the-redesign-part-2/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/a-new-life-for-gaya-design-the-redesign-part-2/a-new-life.jpg&quot; alt=&quot;A new life for Gaya Design, the redesign part 2&quot; title=&quot;A new life for Gaya Design, the redesign part 2&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;A while ago I started to regret the fact that there are so little posts on Gaya Design lately and realised I never got / made the time to create content for this blog. It takes a lot of time researching new stuff and getting to know cool new findings around web development.&lt;/p&gt;
&lt;p&gt;As some of you might have already heard, &lt;a href=&quot;https://www.brandmerchandise.nl/2013/02/25/hello-merchandise-nl/&quot;&gt;I switched jobs&lt;/a&gt; and so far it has been awesome. Working here makes me realise just more and more how important it is to inspire myself to get to know new stuff about web development. You can get stuck in a pace at your job where you just do the same trick over and over again. It’s time to step out of that comfort zone.&lt;/p&gt;
&lt;p&gt;Gaya Design has been a great escape from that before, and will be again, but I needed a different approach since I also learned a thing or two the last couple of years as a web developer. I will get back on the subject of getting stuck in your comfort zone in a later post.&lt;/p&gt;
&lt;h2 id=&quot;time-for-something-fresh-&quot;&gt;Time for something fresh.&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/a-new-life-for-gaya-design-the-redesign-part-2/the-signature-chimneys.jpg&quot; alt=&quot;The signature chimneys&quot;&gt; The signature chimneys of the old design&lt;/p&gt;
&lt;p&gt;The previous design was made in a time when I wanted to show off what I could accomplish with CSS styling a few funky ideas. I really went all the way with cool gadgets and images not thinking about the main point of the website, which was the content. I am not a designer as profession, but I like to do it as a hobby, and that’s what the website portrayed.&lt;/p&gt;
&lt;p&gt;I got a lot of great feedback at the time and make some changes along the way. Implemented some easter eggs (&lt;a href=&quot;https://en.wikipedia.org/wiki/Konami_Code&quot; title=&quot;Konami code&quot;&gt;Konami code&lt;/a&gt; anyone?), included some third party api streams and fixed some styling along the way.&lt;/p&gt;
&lt;p&gt;Since I’ve been working in this business I came across various trends and saw what worked and what did not. I summed up the good and the bad trends before creating my new website and came with a list of requirements:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;line-height: 13px;&quot;&gt;No clutter.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Focus on the article, the rest is not so important.&lt;/li&gt;
&lt;li&gt;Has to be very clean and subtle.&lt;/li&gt;
&lt;li&gt;Needs good to read typography.&lt;/li&gt;
&lt;li&gt;Must be responsive and adjust to screen sizes.&lt;/li&gt;
&lt;li&gt;Retina optimized.&lt;/li&gt;
&lt;li&gt;Need to be aligned to perfection.&lt;/li&gt;
&lt;li&gt;Oh, and a new logo / style.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;where-to-start-a-redesign-&quot;&gt;Where to start a redesign?&lt;/h2&gt;
&lt;p&gt;It was clear that I had to really take the time and dive into what makes a website work and what makes it clean and good to read. Just a while before starting on my redesign I got sucked into responsive webdesign (way too late!), but it immediately made it clear that I have been doing stuff the wrong way all along.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/a-new-life-for-gaya-design-the-redesign-part-2/mandala.jpg&quot; alt=&quot;Mandala&quot;&gt;The one thing I learned was that &lt;a href=&quot;http://24ways.org/2006/compose-to-a-vertical-rhythm/&quot; title=&quot;Compose to a Vertical Rhythm&quot;&gt;composing to a vertical rhythm&lt;/a&gt; was one of the best things I could be doing to get a readable blog.&lt;/p&gt;
&lt;p&gt;It became clear to me that it makes developing a responsive layout a lot easier. So I set a baseline grid on my new Photoshop document and started drawing some ideas for how the content would come to look like.&lt;/p&gt;
&lt;p&gt;When I was done with typography and layout of posts I had to think of a theme for the blog. Since I’ve been into geometric patterns for a while I thought it would look great in a clean design. I started testing out some cool patterns I came across and my logo on accident when I was drawing patterns to test out. I quickly made a vectorized version to test it out in various sizes and positions. I love how simple and beautiful geometric shapes can be and choose to go with this style.&lt;/p&gt;
&lt;h2 id=&quot;switching-to-design-in-browser-&quot;&gt;Switching to “design in browser”.&lt;/h2&gt;
&lt;p&gt;While Photoshop and any similar tool are great for drawing websites and making static content it also leaves a lot to the imagination when you consider it has to become a website some day. Photoshop doesn’t know what an element is in your web browser, it doesn’t know it can scale, it doesn’t know about paddings and margins and surely doesn’t know anything about viewports.&lt;/p&gt;
&lt;p&gt;These tools are basically not made to do this, it has been used for this purpose though, thus creating layouts that work really great with the content used for the design, but get crappy 8 out of 10 times once the real content starts to fill the website. Best case scenario designs are easily made and look awesome, but sometimes the real functionality of a web browser is forgotten and contents end up being different in different settings.&lt;/p&gt;
&lt;p&gt;If you keep these problems in mind while designing in Photoshop it’s fine, but you really have to find a way to illustrate how the design should react to the browser. I got to a point that made it kind of useless to align my designed content to the baseline over and over again when I changed an element or if I wanted to shift some content in-between elements. Why not design in a tool which knows all about the behaviour of browsers, the browser itself?&lt;/p&gt;
&lt;h2 id=&quot;the-perfect-design-companion-&quot;&gt;The perfect design companion.&lt;/h2&gt;
&lt;p&gt;Think about it. The browser knows about line-heights, stacking of elements, border, paddings and margins. The browser knows it’s limits and has the behaviour you are designing for.&lt;/p&gt;
&lt;p&gt;I got to writing some simple HTML and started to structure my document one section at the time, making a flat and blank canvas for me to paint the ideas I made in Photoshop in the browser.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/a-new-life-for-gaya-design-the-redesign-part-2/responsive-devices.png&quot; alt=&quot;REsponsive layout on devices&quot;&gt;&lt;/p&gt;
&lt;p&gt;The layout and styling all happened through the &lt;a href=&quot;http://mobile.smashingmagazine.com/2011/05/02/a-user-centered-approach-to-mobile-design/&quot; title=&quot;Mobile first&quot;&gt;mobile first principle&lt;/a&gt;, first making everything work in the smallest version (which is everything smaller than 420px in this case) and then scale it up one step at the time. For viewport sizes I picked an iPhone in portrait mode, one in landscape, an iPad in portrait and iPad in landscape. I set the start and endpoints around those widths, and maybe they’re not perfect, but I thought those were great points to scale the layout to another version.&lt;/p&gt;
&lt;p&gt;I styled the elements one by one and ended up with a design that was already defined in my Sass files compiled to CSS. So that was covered. No double work here.&lt;/p&gt;
&lt;h2 id=&quot;javascript-goods-&quot;&gt;Javascript goods.&lt;/h2&gt;
&lt;p&gt;The new installation had to be smaller and better. I choose to use jQuery because a lot of Wordpress plugins choose to use it too, and why include another library if jQuery will be included anyway?&lt;/p&gt;
&lt;p&gt;Things I know I would need to do in Javascript:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;line-height: 13px;&quot;&gt;Fire events on breakpoints; let’s call this “responsive javascript”.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;A slider that works on touch.&lt;/li&gt;
&lt;li&gt;A syntax highlighter.&lt;/li&gt;
&lt;li&gt;Something to maintain my vertical rhythm.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For the breakpoints callbacks I used &lt;a href=&quot;https://github.com/ten1seven/jRespond&quot; title=&quot;jRespond&quot;&gt;jRespond&lt;/a&gt;. It allows you to register breakpoints and fire events once you enter or exit the width range. Will handle your Javascript events nicely.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/a-new-life-for-gaya-design-the-redesign-part-2/prism.jpg&quot; alt=&quot;Prism JS&quot; title=&quot;Prism JS&quot;&gt;&lt;/p&gt;
&lt;p&gt;As a slider I picked &lt;a href=&quot;http://iosscripts.com/iosslider/&quot; title=&quot;iosSlider&quot;&gt;iosSlider&lt;/a&gt;. It works perfectly on all devices and does exactly what I need it to do. If you’re making sliders on your website, give this slider a try. It is one of the best ones out there and really worth the money.&lt;/p&gt;
&lt;p&gt;The syntax highlighter I found was &lt;a href=&quot;http://prismjs.com/&quot; title=&quot;Prism&quot;&gt;Prism&lt;/a&gt;. It’s really lightweight and was a nice way of styling. I also found a nice Monokai colourscheme to go with it.&lt;/p&gt;
&lt;p&gt;For the vertical rhythm I needed something that fixed the breaking of vertical rhythm and but the elements that had the wrong height back in position. For this I wrote my own solution, which I am going to share with you very soon.&lt;/p&gt;
&lt;h2 id=&quot;redoing-my-wordpress-installation-from-the-ground-up-&quot;&gt;Redoing my Wordpress installation, from the ground up.&lt;/h2&gt;
&lt;p&gt;Because I made my old theme / website when I wasn’t as familiar with web development and Wordpress development as I am now I wanted to start over. I mean, start from the beginning with a totally new install.&lt;/p&gt;
&lt;p&gt;I had some plugins running on my old install that I could easily do myself with some hooks and filters, but there are a few ones that I used in the new installation.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://yoast.com/wordpress/seo/&quot; title=&quot;Yoast Wordpress SEO plugin&quot;&gt;Yoast’s SEO plugin&lt;/a&gt;, &lt;a href=&quot;http://www.gravityforms.com/&quot; title=&quot;Gravity Forms&quot;&gt;Gravity Forms&lt;/a&gt; for my forms, &lt;a href=&quot;http://wp-types.com/&quot; title=&quot;WP Types&quot;&gt;WP Types&lt;/a&gt; for my custom posttypes and fields.&lt;/p&gt;
&lt;h2 id=&quot;the-future&quot;&gt;The future&lt;/h2&gt;
&lt;p&gt;I hope to have given you a closer look at how I solved the problems that go with creating a new blog. I also hope this new theme and total redo will breathe new life into my blogging and makes me write a lot more articles to share with you.&lt;/p&gt;
&lt;p&gt;Let me know what you think about this layout and how I solved things.&lt;/p&gt;
</description></item><item><title>Retina Sprites for Compass</title><link>https://gaya.pizza/articles/retina-sprites-for-compass/</link><pubDate>Mon, 14 Jan 2013 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/retina-sprites-for-compass/</guid><author></author><description>&lt;p&gt;Creating CSS rules for retina sprites and background images can be a drag. I wrote a quick mixin that will help you with this. It allows you to use sprites in Compass with added retina variants. Works just like the normal sprites helpers, but has been made a lot easier with these mixins.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/retina-sprites-for-compass/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/retina-sprites-for-compass/post-image.jpg&quot; alt=&quot;&quot; title=&quot;Retina Sprites for Compass&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Take a look at the example to see the results.&lt;/p&gt;
&lt;h2 id=&quot;the-problem-&quot;&gt;The problem:&lt;/h2&gt;
&lt;p&gt;You want your site to serve retina images to retina displays, but not to non-retina ones. This mixin / solution will make it very easy for you to use sprites and let Compass generate the mappings of the two different sizes.&lt;/p&gt;
&lt;p&gt;Since we have to develop sites that serve retina images and background-images our sprites and background-image approaches might get a bit cluttered in our CSS. Using just one call, this mixin will know which image has to be served to the browser and will also resize it to show as if it was in your normal image dimentions.&lt;/p&gt;
&lt;h2 id=&quot;how-to-use-&quot;&gt;How to use:&lt;/h2&gt;
&lt;p&gt;First thing you’ll need to do is to download the mixins and put them where your scss / sass files are located. Notice the underscore at the start of the filenames, this will prevent Compass from compiling these files to CSS.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Include the mixin in your SASS/SCSS file using:&lt;br&gt;&lt;code&gt;@import &amp;quot;retina-sprites&amp;quot;;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Create two folders in your images folder of your Compass project. By default there are &lt;code&gt;icons&lt;/code&gt; and &lt;code&gt;icons-2x&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Save your sprite images in the folders. The pixel-ratio 1 variant in &lt;code&gt;./icons&lt;/code&gt; and the retina variant in &lt;code&gt;./icons-2x&lt;/code&gt;. Make sure there have the same filename.&lt;/li&gt;
&lt;li&gt;Use the sprite in your SASS/SCSS using: &lt;code&gt;@include use-sprite(filename)&lt;/code&gt;. (Note the missing .png, this is not needed.)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It’s really that easy!&lt;/p&gt;
&lt;h2 id=&quot;what-it-does-&quot;&gt;What it does:&lt;/h2&gt;
&lt;p&gt;Compass will create a nice sprite image from the images you put in the folders. Make sure you only use PNG files for the best result.&lt;/p&gt;
&lt;p&gt;Using just the name of the file Compass will know where the image is located in the huge sprite image it will generate. The mixin will also get the retina variant if the browser is running in a pixel-ratio 2 environment.&lt;/p&gt;
&lt;p&gt;This is the generated CSS from the example:&lt;/p&gt;
&lt;p&gt;SCSS:  &lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.sprite2&lt;/span&gt; {
    &lt;span class=&quot;keyword&quot;&gt;@include&lt;/span&gt; use-sprite(&lt;span class=&quot;string&quot;&gt;&quot;sprite2&quot;&lt;/span&gt;);
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Becomes, CSS:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.sprite2&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;background-image&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;url&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;../images/icons-s44ec97e90e.png&quot;&lt;/span&gt;);
    &lt;span class=&quot;attribute&quot;&gt;background-position&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt; -&lt;span class=&quot;number&quot;&gt;25px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;background-repeat&lt;/span&gt;: no-repeat;
    &lt;span class=&quot;attribute&quot;&gt;overflow&lt;/span&gt;: hidden;
    &lt;span class=&quot;attribute&quot;&gt;display&lt;/span&gt;: block;
    &lt;span class=&quot;attribute&quot;&gt;height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;25px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;25px&lt;/span&gt;;
}

&lt;span class=&quot;keyword&quot;&gt;@media&lt;/span&gt; (&lt;span class=&quot;attribute&quot;&gt;-webkit-min-device-pixel-ratio:&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;), (&lt;span class=&quot;attribute&quot;&gt;-o-min-device-pixel-ratio:&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;3&lt;/span&gt; / &lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;), (&lt;span class=&quot;attribute&quot;&gt;min-device-pixel-ratio:&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;) {
    &lt;span class=&quot;selector-class&quot;&gt;.sprite2&lt;/span&gt; {
        &lt;span class=&quot;attribute&quot;&gt;background-image&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;url&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;../images/icons-2x-s93dce01c9d.png&quot;&lt;/span&gt;);
        &lt;span class=&quot;attribute&quot;&gt;background-position&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt; -&lt;span class=&quot;number&quot;&gt;25px&lt;/span&gt;;
        &lt;span class=&quot;attribute&quot;&gt;background-size&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;45px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;95px&lt;/span&gt;;
        &lt;span class=&quot;attribute&quot;&gt;height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;25px&lt;/span&gt;;
        &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;25px&lt;/span&gt;;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The nice thing about this is that the browser will only get the sprite image it needs:&lt;/p&gt;
&lt;h3 id=&quot;non-retina-&quot;&gt;Non-retina:&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/retina-sprites-for-compass/network-non-retina.jpg&quot; alt=&quot;Network on non retina device&quot; title=&quot;Network on non retina device&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;retina-&quot;&gt;&lt;strong&gt;Retina:&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/retina-sprites-for-compass/network-retina.jpg&quot; alt=&quot;Network on retina device&quot; title=&quot;Network on retina device&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;bonus-retina-background-images&quot;&gt;Bonus: retina background-images&lt;/h2&gt;
&lt;p&gt;With the same principles of the sprites I created a mixin that sets the background-image and it’s retina version.&lt;/p&gt;
&lt;h2 id=&quot;how-to-use-retina-background-images-&quot;&gt;How to use retina background-images:&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Include the mixin in your SASS/SCSS file using: &lt;code&gt;@import &amp;quot;retina-background-image&amp;quot;;&lt;/code&gt;**&lt;br&gt;**&lt;/li&gt;
&lt;li&gt;Put a pixel-ratio 1 version and a retina version anywhere in your images folder.&lt;/li&gt;
&lt;li&gt;Apply the style using: &lt;code&gt;@include background-retina(file-normal.png, file-retina.png);&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The following code will generate:&lt;/p&gt;
&lt;p&gt;SCSS:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.background&lt;/span&gt; {
    &lt;span class=&quot;keyword&quot;&gt;@include&lt;/span&gt; background-retina(&lt;span class=&quot;string&quot;&gt;&quot;background.gif&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;background-2x.gif&quot;&lt;/span&gt;);
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Becomes, CSS:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.background&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;background-image&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;url&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'../images/background.gif'&lt;/span&gt;);
}
&lt;span class=&quot;keyword&quot;&gt;@media&lt;/span&gt; (&lt;span class=&quot;attribute&quot;&gt;-webkit-min-device-pixel-ratio:&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;),
(&lt;span class=&quot;attribute&quot;&gt;-o-min-device-pixel-ratio:&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;3&lt;/span&gt; / &lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;),
(&lt;span class=&quot;attribute&quot;&gt;min-device-pixel-ratio:&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;) {
    &lt;span class=&quot;selector-class&quot;&gt;.background&lt;/span&gt; {
        &lt;span class=&quot;attribute&quot;&gt;background-image&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;url&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'../images/background-2x.gif'&lt;/span&gt;);
        &lt;span class=&quot;attribute&quot;&gt;background-size&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;25px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;25px&lt;/span&gt;;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;conclusion-&quot;&gt;Conclusion:&lt;/h2&gt;
&lt;p&gt;Let me know what you think about the mixins and if they are useful to you.&lt;/p&gt;
&lt;p&gt;If you have anything to add, put it in the comments or let me know on Github.&lt;/p&gt;
&lt;p&gt;Happy Sassing, and tell people to stop using LESS ;)&lt;/p&gt;
&lt;p&gt;Gaya&lt;/p&gt;
</description></item><item><title>jQuery plugin: Fullscreen Background</title><link>https://gaya.pizza/articles/jquery-plugin-fullscreen-background/</link><pubDate>Wed, 25 Apr 2012 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/jquery-plugin-fullscreen-background/</guid><author></author><description>&lt;p&gt;If you’re a webdeveloper or designer I am pretty sure you’ve run into the problem of people wanting to have “fullscreen content” or just background images that will stretch in the most optimal way to the users screen.&lt;br&gt; Lately I found that a lot of people are asking for fullscreen backgrounds, videos and other types on stuff. So to prevent myself from reinventing the wheel over and over again I made a small jQuery plugin, and thought you guys might like it too.&lt;/p&gt;
&lt;p&gt;So here it is: Fullscreen Background for jQuery.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/jquery-plugin-fullscreen-background/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/jquery-plugin-fullscreen-background/fullscreengdpost.jpg&quot; alt=&quot;jQuery plugin: Fullscreen Background&quot; title=&quot;jQuery plugin: Fullscreen Background&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;how-to-use-&quot;&gt;How to use.&lt;/h2&gt;
&lt;p&gt;And using it is so easy; anyone can do it!&lt;/p&gt;
&lt;p&gt;Oh, and it works in every browser I could test it in. (IE7 and higher, Firefox, Opera, Safari and Chrome)&lt;/p&gt;
&lt;p&gt;Here’s a short step by step installation guide:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Put the following code in the  section of your webpage: &lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;jquery.js&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;jquery.fullscreenBackground.js&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Have the following structure in your HTML (or something similar): &lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;content&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
 Content goes here
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;background-image&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
 &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;path/to/img.jpg&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;alt&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;width&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;800&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;height&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;600&quot;&lt;/span&gt; /&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remember to define the width and height of the images! This is important.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then, in your CSS. Make sure the content (not the background image container) is absolute and has a higher z-index than 1.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally add this in a piece of Javascript, preferably in &lt;span class=&quot;code&quot;&gt;&lt;span class=&quot;code&quot;&gt;$(document).ready();&lt;br&gt;&lt;/span&gt;&lt;/span&gt;  &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;$(&lt;span class=&quot;string&quot;&gt;&quot;#background-image&quot;&lt;/span&gt;).fullscreenBackground();&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;conclusion-&quot;&gt;Conclusion:&lt;/h2&gt;
&lt;p&gt;Quick and easy: it really does the trick here.&lt;/p&gt;
&lt;p&gt;Absolutely no rocket science, but it will prevent you from coding it again in the future.&lt;/p&gt;
&lt;p&gt;Let me know what you think!&lt;/p&gt;
</description></item><item><title>Kickstart app development for Spotify</title><link>https://gaya.pizza/articles/kickstart-app-development-for-spotify/</link><pubDate>Thu, 26 Jan 2012 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/kickstart-app-development-for-spotify/</guid><author></author><description>&lt;p&gt;So you’ve decided to go ahead and develop an app for Spotify. Great! Starting off might be a pain though if you’re not well informed.&lt;br&gt; In this article I’ll give you a boost in developing for Spotify and warn you for common mistakes I’ve made.&lt;/p&gt;
&lt;p&gt;App development for Spotify is not hard! It’s mainly HTML, CSS and Javascript, which you are probably already familiar with.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/kickstart-app-development-for-spotify&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/kickstart-app-development-for-spotify/spotify.jpg&quot; alt=&quot;Kickstart app development for Spotify&quot; title=&quot;Kickstart app development for Spotify&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Here’s a list of things I will discuss in this article:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;#before&quot;&gt;Before creating an app&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#yourfirstpage&quot;&gt;Your first page&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#debug&quot;&gt;Debug!&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#manifestjson&quot;&gt;manifest.json&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#api&quot;&gt;The API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#storage&quot;&gt;Store the info&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#wheretogofromhere&quot;&gt;Where to go from here&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;before-creating-an-app&quot;&gt;Before creating an app&lt;/h2&gt;
&lt;p&gt;When you decide to create an app for Spotify you’ll have to sign-up for a developers account. You can do that on this page: &lt;a href=&quot;http://developer.spotify.com/en/spotify-apps-api/developer-signup/&quot;&gt;http://developer.spotify.com/en/spotify-apps-api/developer-signup/&lt;/a&gt;. If you already own a developers account you can move on to point 2.&lt;/p&gt;
&lt;p&gt;If you &lt;strong&gt;don’t&lt;/strong&gt; have an account yet you’ll have to wait until it has been activated. There’s no point to go on from here now, your application simply will not load in Spotify. &lt;strong&gt;&lt;em&gt;Just be patient&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Spotify offers a special client for developers that has the latest API build in. It is useful to develop on this build since there might be some differences with the original client as to API calls etc, so get it here: &lt;a href=&quot;http://developer.spotify.com/en/spotify-apps-api/preview/&quot;&gt;http://developer.spotify.com/en/spotify-apps-api/preview/&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Oh, and since you’re probably designing the app in Photoshop or something first, &lt;a href=&quot;http://developer.spotify.com/download/spotify-apps-api/design_resources.zip&quot;&gt;this design resource&lt;/a&gt; might be of great help.&lt;/p&gt;
&lt;h3 id=&quot;your-first-page&quot;&gt;Your first page&lt;/h3&gt;
&lt;p&gt;Got your account activated? GOOD! You can now finally start working on stuff.&lt;/p&gt;
&lt;p&gt;As the &lt;a href=&quot;http://developer.spotify.com/download/spotify-apps-api/guidelines/&quot;&gt;integration guidelines&lt;/a&gt; point out, you’ll have to create a folder in your home directory called **”Spotify”. **&lt;code&gt;~/Spotify&lt;/code&gt; on Mac OS X and &lt;code&gt;My Documents\Spotify&lt;/code&gt; on Windows.&lt;br&gt; In this folder we will create another folder with your app’s name.&lt;/p&gt;
&lt;p&gt;The only thing you really need to create now is an &lt;code&gt;index.html&lt;/code&gt; file which will load once you open up the app in Spotify. But since we’re creating an app that looks a lot like your typical web-app (technically speaking), we’re going to create the folders for all our assets.&lt;br&gt; What I like to do is just to create a folder for my javascript, images, and stylesheets. You know the drill.&lt;/p&gt;
&lt;p&gt;Now put something funny in your &lt;code&gt;index.html&lt;/code&gt; file. Go original and put &lt;strong&gt;“Hello World”&lt;/strong&gt; in there! (no HTML needed! Whoop)&lt;/p&gt;
&lt;p&gt;Now we can bring up the app in Spotify (have you already rebooted Spotify when you became a developer? If not: do it now.)&lt;/p&gt;
&lt;p&gt;First: Go to the search field in Spotify&lt;br&gt; Type: &lt;code&gt;spotify:app:your_apps_folder_name&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You should see something similar to this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/kickstart-app-development-for-spotify/spotify01.jpg&quot; alt=&quot;Hello world in Spotify&quot; title=&quot;Hello world in Spotify&quot;&gt; &lt;em&gt;You just included your app in Spotify. Nice.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The “add application to sidebar” button will put it in the sidebar until you close Spotify again. This will come in handy when you’re debugging the app.&lt;/p&gt;
&lt;p&gt;Keep in mind that next time you’ll open up Spotify the app is not in the sidebar anymore. You’ll have to search for it again.&lt;/p&gt;
&lt;h2 id=&quot;debug-&quot;&gt;Debug!&lt;/h2&gt;
&lt;p&gt;The great thing about developing apps for Spotify is that it renders it’s pages with Chromium, so it kind of feels like you’re developing for Chrome. To quote the integration guidelines:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Spotify currently uses the Chromium rendering engine to run and display your applications. However, this is an implementation detail and may change in the future. Please do not assume anything about the browser other than it is WebKit based (so WebKit-only CSS attributes can be used).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This means that you can finally forget about Internet Explorer and get your HTML5 and CSS3 socks on! Isn’t that just nice. Keep in mind that there are a few HTML5 elements and functions that are not added out of security reasons.&lt;br&gt; To view the list of things that are available go to &lt;strong&gt;“Develop”&lt;/strong&gt; in the taskbar and choose &lt;strong&gt;“Show HTML5 Support”&lt;/strong&gt; and check if what you want to use is in there.&lt;/p&gt;
&lt;p&gt;To open up the inspector just right-click anywhere on the app and choose &lt;strong&gt;“Show Inspector”&lt;/strong&gt;. The familiar inspector pops up and gives you all the functionality we are used to use when developing websites in Chrome. The inspector will save your life.&lt;/p&gt;
&lt;h2 id=&quot;manifest-json&quot;&gt;manifest.json&lt;/h2&gt;
&lt;p&gt;This file contains important information about your app Spotify needs to know. It’s a JSON file which contains an object filled with variables.&lt;/p&gt;
&lt;p&gt;Just create a new file in the root of your app’s folder called: &lt;code&gt;manifest.json&lt;/code&gt;. The basic layout looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;{
    &lt;span class=&quot;string&quot;&gt;&quot;BundleType&quot;&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;Application&quot;&lt;/span&gt;,
    &lt;span class=&quot;string&quot;&gt;&quot;AppIcon&quot;&lt;/span&gt;: {
    &lt;span class=&quot;string&quot;&gt;&quot;36x18&quot;&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;tutorial.png&quot;&lt;/span&gt;
},
    &lt;span class=&quot;string&quot;&gt;&quot;AppName&quot;&lt;/span&gt;: {
    &lt;span class=&quot;string&quot;&gt;&quot;en&quot;&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;Tutorial&quot;&lt;/span&gt;
},
    &lt;span class=&quot;string&quot;&gt;&quot;SupportedLanguages&quot;&lt;/span&gt;: [
        &lt;span class=&quot;string&quot;&gt;&quot;en&quot;&lt;/span&gt;
    ]
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;http://developer.spotify.com/download/spotify-apps-api/guidelines/#applicationmanifest&quot;&gt;A full list of variables&lt;/a&gt; you can set are available in the integration guidelines.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;IMPORTANT:&lt;/strong&gt; if you change anything to this file a simple “Reload Application” is not enough. You’ll have to restart Spotify and do a search for your app again. Keep this in mind.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;If you’re going to include external resources (like doing an Ajax call or including images from a website) you’ll have to add the &lt;code&gt;RequiredPermissions&lt;/code&gt; variable like so:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;string&quot;&gt;&quot;RequiredPermissions&quot;&lt;/span&gt;: [ 
    &lt;span class=&quot;string&quot;&gt;&quot;http://*.gayadesign.com&quot;&lt;/span&gt;,
    &lt;span class=&quot;string&quot;&gt;&quot;http://gayadesign.com&quot;&lt;/span&gt;,
    &lt;span class=&quot;string&quot;&gt;&quot;http://ws.audioscrobbler.com&quot;&lt;/span&gt; 
]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Remember to restart Spotify and adjust the &lt;code&gt;RequiredPermissions&lt;/code&gt; variable if Spotify won’t load the resource. It might not have been included in the permissions yet. You’ll just get 404 content.&lt;/p&gt;
&lt;h2 id=&quot;the-api&quot;&gt;The API&lt;/h2&gt;
&lt;p&gt;All interactivity in the app can be done in Javascript. You can even add jQuery to your app if you feel more comfortable using that. The Spotify API is just plain Javascript, so some might feel that this is a step too far, but people: it’s not hard.&lt;/p&gt;
&lt;p&gt;To include the API you’ll only need to do this in your script (that you’ll include in the index.html file obviously):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; sp = getSpotifyApi(&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;);
&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; models = sp.require(&lt;span class=&quot;string&quot;&gt;&quot;sp://import/scripts/api/models&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will first load the API and then require a Javascript file “models” that lets you create Spotify related objects in Javascript.&lt;br&gt; In the &lt;a href=&quot;http://developer.spotify.com/download/spotify-apps-api/reference/&quot;&gt;JSDoc of Spotify&lt;/a&gt; you can see which object you can create and what you can do with them.&lt;/p&gt;
&lt;p&gt;You can control the player, get information about artists, tracks and albums, and configure the users’ library for example.&lt;/p&gt;
&lt;p&gt;If you want to add searches to your app you can refer to &lt;a href=&quot;http://developer.spotify.com/en/metadata-api/overview/&quot;&gt;Spotify’s Meta-data API&lt;/a&gt;. Remember to add &lt;code&gt;http://ws.spotify.com&lt;/code&gt; to your &lt;code&gt;RequiredPermissions&lt;/code&gt; array in &lt;strong&gt;&lt;strong&gt;`manifest.json&lt;/strong&gt;&lt;/strong&gt;`.&lt;/p&gt;
&lt;p&gt;You can easily get the information you need using this API and do plain AJAX calls to retrieve XML files with information. Couldn’t be easier right?&lt;/p&gt;
&lt;h2 id=&quot;store-the-info&quot;&gt;Store the info&lt;/h2&gt;
&lt;p&gt;You can save settings of you app in HTML 5’s Locale Storage. A brief explanation is available here: &lt;a href=&quot;http://www.webmonkey.com/2011/04/how-to-use-html5s-local-storage-tools-today/&quot;&gt;http://www.webmonkey.com/2011/04/how-to-use-html5s-local-storage-tools-today/&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The biggest problem with this is that it can only store strings. I made a little script that takes care of this problem and allows you to also save arrays and objects. You can download it from GitHub here:&lt;br&gt;&lt;a href=&quot;http://github.com/Gaya/Locale-Storager&quot;&gt;http://github.com/Gaya/Locale-Storager&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;where-to-go-from-here&quot;&gt;Where to go from here&lt;/h2&gt;
&lt;p&gt;Now that you’ve got your app ready to be build; just go for it! It’s not harder than building your regular website, you’ll just have to look at the possibilities Spotify gives you with their API’s and go from there.&lt;/p&gt;
&lt;p&gt;You can follow &lt;a href=&quot;http://www.twitter.com/spotifyplatform&quot;&gt;@SpotifyPlatform&lt;/a&gt; for updates concerning the API and go to &lt;a href=&quot;http://stackoverflow.com/questions/tagged/spotify&quot;&gt;Stack Overflow’s Spotify section&lt;/a&gt; to ask your questions or hop into the conversations.&lt;/p&gt;
&lt;p&gt;I hope I tackled the start up problems and made everything a bit more clear.&lt;/p&gt;
&lt;p&gt;If you have anything good going on: Let me know! I’ll be releasing an app myself. When it comes, you’ll know.&lt;/p&gt;
</description></item><item><title>WordPress Plugin: Complete Language Switcher</title><link>https://gaya.pizza/articles/wordpress-plugin-complete-language-switcher/</link><pubDate>Wed, 04 Jan 2012 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/wordpress-plugin-complete-language-switcher/</guid><author></author><description>&lt;p&gt;A while ago I uploaded a new plugin to the Wordpress plugin directory called Complete Language Switcher. Using this plugin enables you to easily make a multilingual blog with Wordpress to give the user the best experience in a language you provide.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/wordpress-plugin-complete-language-switcher/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/wordpress-plugin-complete-language-switcher/completelangswitcher.jpg&quot; alt=&quot;Wordpress Plugin: Complete Language Switcher&quot; title=&quot;Wordpress Plugin: Complete Language Switcher&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Complete Language Switcher provides an easy way to filter out posts in a certain language. It will only display content in the set language and also view the template in the language set by the user. If there is no language set the plugin will pick the standard language set in the config of your Wordpress blog.&lt;/p&gt;
&lt;h2 id=&quot;what-do-i-need-&quot;&gt;What do I need?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;A Wordpress blog (obviously.)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://wordpress.org/extend/plugins/xili-language/&quot;&gt;Xili-language&lt;/a&gt;, this is a very nice plugin which can separate posts into different languages. Use this in order to set languages to posts and link other versions of the post to itself.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codex.wordpress.org/WordPress_in_Your_Language&quot;&gt;Language files for Wordpress&lt;/a&gt; and your theme installed.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://wordpress.org/extend/plugins/complete-language-switch/&quot;&gt;Complete Language Switcher&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;how-do-i-install-it-&quot;&gt;How do I install it?&lt;/h2&gt;
&lt;p&gt;Installing this plugin is easy.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Install and activate the xili-language plugin.&lt;/li&gt;
&lt;li&gt;Upload the complete-language-switch folder to the &lt;code&gt;/wp-content/plugins/&lt;/code&gt; directory&lt;/li&gt;
&lt;li&gt;Activate the plugin through the ‘Plugins’ menu in WordPress&lt;/li&gt;
&lt;li&gt;Place &lt;code&gt;&amp;lt;?php cls_langs_html(); ?&amp;gt;&lt;/code&gt; anywhere in your templates or hook it in your template using &lt;code&gt;&amp;lt;?php add_action(&amp;#39;hook_name&amp;#39;, &amp;#39;cls_langs_html&amp;#39;); ?&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You are done and can use the plugin now!&lt;/p&gt;
&lt;h2 id=&quot;a-few-notes-&quot;&gt;A few notes:&lt;/h2&gt;
&lt;p&gt;Make sure you put &lt;code&gt;en_US.mo&lt;/code&gt; files in the language folders when you use the default English language of Wordpress.&lt;/p&gt;
&lt;p&gt;Check the &lt;code&gt;/flags/&lt;/code&gt; directory in the plugin folder to see if your flag is in there. Naming is the 2 last characters of the locale (eg. en_US) in lowercase in PNG format. So en_US would be: us.png&lt;/p&gt;
&lt;h2 id=&quot;future-&quot;&gt;Future:&lt;/h2&gt;
&lt;p&gt;Got in contact with the creator of Xili-language to improve the functionality of my plugin. This will involve better overall taxonomy filtering and also filtering out standard functions such as &lt;code&gt;wp_list_categories()&lt;/code&gt;.&lt;br&gt; More on this soon.&lt;/p&gt;
&lt;h2 id=&quot;questions-&quot;&gt;Questions?&lt;/h2&gt;
&lt;p&gt;Let me know what you think in the comments.&lt;/p&gt;
&lt;p&gt;If you have any questions you can let me know.&lt;/p&gt;
&lt;p&gt;You can also file issues in the Wordpress Plugin directory.&lt;/p&gt;
</description></item><item><title>Why SASS and Compass should be in your workflow</title><link>https://gaya.pizza/articles/why-sass-and-compass-should-be-in-your-workflow/</link><pubDate>Thu, 17 Nov 2011 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/why-sass-and-compass-should-be-in-your-workflow/</guid><author></author><description>&lt;p&gt;Admit it: CSS is awesome, but it’s default syntax is insanely stupid. Are you tired of the way CSS is written and proves to be quite useless and cluttered once the project grows and gets more styling? It just takes up way too much of our time to organize and it’s plain stupid if we stick with this kind of workflow.&lt;/p&gt;
&lt;p&gt;That’s when CSS compilers came around, and it will change your life. This post will describe the benefits of CSS compiling and in which possible ways you can use it.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/why-sass-and-compass-should-be-in-your-workflow/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/why-sass-and-compass-should-be-in-your-workflow/sassworkflow.jpg&quot; alt=&quot;Why SASS and Compass should be in your workflow&quot; title=&quot;Why SASS and Compass should be in your workflow&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;time-to-keep-it-simple-no-time-for-the-stupid-&quot;&gt;Time to keep it simple, no time for the stupid!&lt;/h2&gt;
&lt;p&gt;How many times have you done this?&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-tag&quot;&gt;ul&lt;/span&gt; { &lt;span class=&quot;attribute&quot;&gt;padding&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0px&lt;/span&gt;; &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0px&lt;/span&gt;; }
&lt;span class=&quot;selector-tag&quot;&gt;ul&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;li&lt;/span&gt; { &lt;span class=&quot;attribute&quot;&gt;padding&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;5px&lt;/span&gt;; }
&lt;span class=&quot;selector-tag&quot;&gt;ul&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;li&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;a&lt;/span&gt; { &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#335345&lt;/span&gt;; }
&lt;span class=&quot;selector-tag&quot;&gt;ul&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;li&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;span&lt;/span&gt; { &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#434343&lt;/span&gt;; }&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then sighed and thought: &lt;em&gt;Why the hell I am retyping “ul li” the whole time? IT’S JUST STUPID!&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Yes it is. Let me go on.&lt;/p&gt;
&lt;p&gt;What about colors that are used in a project or just font-sizes / line-heights / margins that are recurrent and appear all over your CSS file. Imagine that you want to change that and realize it’s all over your CSS file. Indeed, this is a pain.&lt;/p&gt;
&lt;p&gt;How about styles that appear all over your stylesheet? Getting tired of reusing the same styles over and over again? And “oh oops!” There is a style change. Now the pain begins of changing that piece of style to a amount of times that it will make your stylesheet more cluttered and inuseable.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;This is CSS hell.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;For these problems. &lt;a href=&quot;http://sass-lang.com/&quot; title=&quot;SASS - Syntactically Awesome Stylesheets&quot;&gt;SASS&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;compiling-css-now-what-&quot;&gt;Compiling CSS now? What?&lt;/h2&gt;
&lt;p&gt;Don’t be scared if you are not a developer that knows his around the terminal (or Windows’ ugly CMD.) There are a lot of solutions that prevent you from having to use the terminal to start watching projects, but let me take a step back.&lt;/p&gt;
&lt;p&gt;SASS will give you the opportunity to change the way you code your CSS and generate the “real” CSS file for you. What it basically does is look at the SASS file and generate the correct CSS representation from it.&lt;/p&gt;
&lt;p&gt;The thing is though, that once you want your CSS files to be generated you have to command SASS to “watch” your folder containing the SASS files. So once you save the SASS file, it won’t have the CSS ready instantaneously, sadly. But a few seconds later, it will be ready. This will take a few minutes to get used to, but you sure will.&lt;/p&gt;
&lt;h2 id=&quot;style-nesting&quot;&gt;Style nesting&lt;/h2&gt;
&lt;p&gt;The first thing I loved about SASS and SCSS as it’s syntax has nesting of the styles. This makes it way easier to work with your stylesheets. Imagine having this HTML:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;ul&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;#&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;link 1&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;last&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;#&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;link 2&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;ul&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In SASS, you would be able to style this the following way:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;selector-tag&quot;&gt;ul&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;padding&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;210px&lt;/span&gt;;

    &lt;span class=&quot;selector-tag&quot;&gt;li&lt;/span&gt; {
        &lt;span class=&quot;attribute&quot;&gt;float&lt;/span&gt;: left;
        &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;100px&lt;/span&gt;;
        &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;10px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0px&lt;/span&gt;;

        &amp;amp;&lt;span class=&quot;selector-class&quot;&gt;.last&lt;/span&gt; {
            &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0px&lt;/span&gt;;
        }

        &lt;span class=&quot;selector-tag&quot;&gt;a&lt;/span&gt; {
            &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#232323&lt;/span&gt;;

            &amp;amp;&lt;span class=&quot;selector-pseudo&quot;&gt;:hover&lt;/span&gt; {
                &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#121212&lt;/span&gt;;
            }
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Isn’t that just pretty? Finally you can nest your CSS the way you would in HTML. You can use any CSS selector to make the process even easier.&lt;/p&gt;
&lt;p&gt;I also put in a nice little feature which I use a lot in SASS: the &lt;code&gt;&amp;amp;&lt;/code&gt; notation. This tells SASS to set an extra rule for the element you’re in. So the &lt;code&gt;li&lt;/code&gt; element with class &lt;code&gt;.last&lt;/code&gt; is targeted through this method. Not having to create a new rule in the nesting for it.&lt;br&gt; The hover on the anchor tag is also targeted through this method. Very handy!&lt;/p&gt;
&lt;h2 id=&quot;variables-mixins-and-selector-inheritance&quot;&gt;Variables, Mixins and Selector Inheritance&lt;/h2&gt;
&lt;p&gt;The reuse of pieces of styling and making the CSS dynamic, that is what SASS is good at.&lt;/p&gt;
&lt;p&gt;Variables are simple. Define it and use it throughout your SASS file:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;variable&quot;&gt;$background&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#040404&lt;/span&gt;;
&lt;span class=&quot;variable&quot;&gt;$text-color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#fefefe&lt;/span&gt;;
&lt;span class=&quot;variable&quot;&gt;$standard-margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;16px&lt;/span&gt;;

&lt;span class=&quot;selector-tag&quot;&gt;body&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;background-color&lt;/span&gt;: &lt;span class=&quot;variable&quot;&gt;$background&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;variable&quot;&gt;$text-color&lt;/span&gt;;

    &lt;span class=&quot;selector-tag&quot;&gt;input&lt;/span&gt; {
        &lt;span class=&quot;attribute&quot;&gt;background-color&lt;/span&gt;: &lt;span class=&quot;variable&quot;&gt;$background&lt;/span&gt;;
        &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;variable&quot;&gt;$text-color&lt;/span&gt;;
        &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;variable&quot;&gt;$standard-margin&lt;/span&gt;;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It’s simple. Define a variable using &lt;code&gt;$varname: value&lt;/code&gt; and use it throughout with: &lt;code&gt;$varname&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Mixins are like variables but for peaces of styling. You can just tell SASS to reuse a piece of code you wrote and include it in the style. You can even give parameters when including to make them dynamic. It’s almost as if you’re writing functions for your CSS.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;@mixin&lt;/span&gt; ptsans {
    &lt;span class=&quot;attribute&quot;&gt;font-family&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;'PT Sans'&lt;/span&gt;, sans-serif;
}

&lt;span class=&quot;keyword&quot;&gt;@mixin&lt;/span&gt; absolute-positioned(&lt;span class=&quot;variable&quot;&gt;$top&lt;/span&gt;, &lt;span class=&quot;variable&quot;&gt;$left&lt;/span&gt;) {
    &lt;span class=&quot;attribute&quot;&gt;position&lt;/span&gt;: absolute;
    &lt;span class=&quot;attribute&quot;&gt;top&lt;/span&gt;: &lt;span class=&quot;variable&quot;&gt;$top&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;left&lt;/span&gt;: &lt;span class=&quot;variable&quot;&gt;$left&lt;/span&gt;;
}

&lt;span class=&quot;selector-tag&quot;&gt;body&lt;/span&gt; {
    &lt;span class=&quot;keyword&quot;&gt;@include&lt;/span&gt; ptsans;
    &lt;span class=&quot;attribute&quot;&gt;position&lt;/span&gt;: relative;

    &lt;span class=&quot;selector-id&quot;&gt;#notifier&lt;/span&gt; {
        &lt;span class=&quot;keyword&quot;&gt;@include&lt;/span&gt; absolute-positioned(&lt;span class=&quot;number&quot;&gt;20px&lt;/span&gt;, &lt;span class=&quot;number&quot;&gt;100px&lt;/span&gt;);
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Defining a mixin with &lt;code&gt;@mixin mixinname { styling in here }&lt;/code&gt; or &lt;code&gt;@mixin mixinname ($parameter1) { anystyle: $parameter1; }&lt;/code&gt;. That is it. It is great for defining recurring styles and CSS3 fallback stuff. You can put a lot of styling in mixins and reuse it with very little effort.&lt;/p&gt;
&lt;p&gt;Last but not least is selector inheritance. This allows you to grab a piece of styling like you would in a mixin, but just extending the style. So you’re putting the same CSS in the actual file but extending the CSS rules. Let me explain this through an example:&lt;/p&gt;
&lt;h3 id=&quot;plain-css-&quot;&gt;Plain CSS:&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.error&lt;/span&gt;, &lt;span class=&quot;selector-class&quot;&gt;.succes&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;border&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1px&lt;/span&gt; solid black;
    &lt;span class=&quot;attribute&quot;&gt;padding&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;5px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: red;
}

&lt;span class=&quot;selector-class&quot;&gt;.succes&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: green;
    &lt;span class=&quot;attribute&quot;&gt;border-color&lt;/span&gt;: green;
}&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;scss-&quot;&gt;&lt;strong&gt;SCSS:&lt;/strong&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.error&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;border&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1px&lt;/span&gt; solid black;
    &lt;span class=&quot;attribute&quot;&gt;padding&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;5px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: red;
}

&lt;span class=&quot;selector-class&quot;&gt;.succes&lt;/span&gt; {
    &lt;span class=&quot;selector-class&quot;&gt;.error&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: green;
    &lt;span class=&quot;attribute&quot;&gt;border-color&lt;/span&gt;: green;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Beautiful.&lt;/p&gt;
&lt;p&gt;For an extended tutorial on how to use SASS and use ruby to compile your files I point you to SASS’ tutorial: &lt;a href=&quot;http://sass-lang.com/tutorial.html&quot;&gt;http://sass-lang.com/tutorial.html&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;and-now-to-make-it-even-more-awesome-compass&quot;&gt;And now to make it even more awesome: Compass&lt;/h2&gt;
&lt;p&gt;The reason I didn’t explain how to compile SASS is because I recently found &lt;a href=&quot;http://compass-style.org/&quot;&gt;Compass&lt;/a&gt; to do this for me. And I have to say: I am sold.&lt;/p&gt;
&lt;p&gt;As if SASS isn’t awesome enough on it’s own, Compass comes with an extra set of awesomeness. It’s a layer on top of SASS which has some extra nifty tricks inside of it. Compass will also compile your SASS files and has a lot of options.&lt;/p&gt;
&lt;p&gt;To install Compass you can &lt;a href=&quot;http://compass-style.org/install/&quot;&gt;read their install page&lt;/a&gt;. And if you, like me, are too lazy to bother with the command line stuff, try this app: &lt;a href=&quot;http://compass.handlino.com/&quot;&gt;http://compass.handlino.com/&lt;/a&gt;. It’s just $7 or you can build the project yourself to save some money.&lt;/p&gt;
&lt;h2 id=&quot;why-compass-&quot;&gt;Why Compass?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;It has build-in CSS3 mixins.&lt;/li&gt;
&lt;li&gt;A lot of handly CSS workarounds included.&lt;/li&gt;
&lt;li&gt;Lots of helpers to save work.&lt;/li&gt;
&lt;li&gt;Option to output SASS file as compressed CSS.&lt;/li&gt;
&lt;li&gt;Great docs.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There is a lot to Compass, and I learn more and more every day. There are a few things that sold me immediately.&lt;/p&gt;
&lt;h2 id=&quot;project-workflow&quot;&gt;Project workflow&lt;/h2&gt;
&lt;p&gt;When you start up a Compass project, it will create a few folders for you. According to your config file, it will generate the output that you desire.&lt;/p&gt;
&lt;p&gt;In the config you can define the folder where the SASS files (.scss) are stored, it will then automatically watch that folder for changes. You can also define which folder contains your CSS images and where to output the generated CSS files. These can all be in different places.&lt;/p&gt;
&lt;p&gt;The great thing about this is the &lt;code&gt;image-url&lt;/code&gt; helper for example. Don’t you just hate stuff like this?&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-tag&quot;&gt;div&lt;/span&gt; { &lt;span class=&quot;attribute&quot;&gt;background&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;url&lt;/span&gt;(../../images/backgrounds/&lt;span class=&quot;number&quot;&gt;01&lt;/span&gt;.jpg); };&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With Compass (and the right settings) it will turn into this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;selector-tag&quot;&gt;div&lt;/span&gt; { &lt;span class=&quot;attribute&quot;&gt;background&lt;/span&gt;: image-url(&lt;span class=&quot;string&quot;&gt;&quot;backgrounds/01.jpg&quot;&lt;/span&gt;); };&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now THAT is convenient! The generated CSS will be the same as above though, but your SASS files will be way more organized.&lt;/p&gt;
&lt;p&gt;Stuff like &lt;code&gt;image-width&lt;/code&gt; and &lt;code&gt;image-height&lt;/code&gt; to get the width and height of an image in pixels, &lt;a href=&quot;http://compass-style.org/reference/compass/utilities/sprites/&quot;&gt;support for Sprites&lt;/a&gt; and an &lt;a href=&quot;http://compass-style.org/reference/compass/layout/sticky_footer/&quot;&gt;out-of-box sticky footer&lt;/a&gt; make our lives so much easier.&lt;/p&gt;
&lt;h2 id=&quot;css3-mixins-no-more-webkit-moz-and-all-that-crap-&quot;&gt;CSS3 mixins, no more -webkit -moz and all that crap!&lt;/h2&gt;
&lt;p&gt;The reason I hated CSS3 at first was the fact that a lot of times it involved having to set the properties for each browser using -webkit, -moz etc. This is a serious pain in the ass for us coders and always held me from using it.&lt;/p&gt;
&lt;p&gt;Using SASS’ mixins and some parameters you can save yourself a lot of time when setting CSS3 properties. Compass has &lt;a href=&quot;http://compass-style.org/reference/compass/css3/&quot;&gt;all of these CSS3 mixins&lt;/a&gt; ready.&lt;/p&gt;
&lt;p&gt;This in particular convinced me to use Compass aside SASS. Imagine doing this from now on:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-scss&quot;&gt;&lt;span class=&quot;selector-tag&quot;&gt;div&lt;/span&gt; { &lt;span class=&quot;keyword&quot;&gt;@include&lt;/span&gt; border-radius(&lt;span class=&quot;number&quot;&gt;4px&lt;/span&gt;); }&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The way it supposed to if you ask me. Well it should have been in CSS in the first place. Luckily, SASS and Compass fix these problems for us.&lt;/p&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;
&lt;p&gt;A nice presentation that goes into the functionality of SASS and Compass by &lt;a href=&quot;http://brandonmathis.com/&quot;&gt;Brandon Mathis&lt;/a&gt; can be found here: &lt;a href=&quot;http://speakerdeck.com/u/imathis/p/sass-compass-the-future-of-stylesheets-now&quot;&gt;http://speakerdeck.com/u/imathis/p/sass-compass-the-future-of-stylesheets-now&lt;/a&gt;. It’s really worth the skipping through.&lt;/p&gt;
&lt;p&gt;The leasons by Jeffrey Way on Nettuts are great too:&lt;br&gt;&lt;a href=&quot;http://net.tutsplus.com/tutorials/other/mastering-sass-lesson-1/&quot;&gt;http://net.tutsplus.com/tutorials/other/mastering-sass-lesson-1/&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;There is a lot to say about SASS and Compass, and there is &lt;a href=&quot;http://compass-style.org/reference/compass/&quot;&gt;a lot more to Compass&lt;/a&gt; than explained in this post.&lt;/p&gt;
&lt;p&gt;Using these compilers will save you a lot of work and make coding CSS fun again. Better syntax, managed code, dynamic parts, it’s all better now.&lt;/p&gt;
&lt;p&gt;I hope to have convinced you into using SASS and Compass. Tell me what you think in the comments.&lt;/p&gt;
&lt;p&gt;Cheers.&lt;/p&gt;
</description></item><item><title>QueryLoader2 – Preload your images with ease</title><link>https://gaya.pizza/articles/queryloader2-preload-your-images-with-ease/</link><pubDate>Wed, 26 Oct 2011 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/queryloader2-preload-your-images-with-ease/</guid><author></author><description>&lt;p&gt;Gaya Design is back in business and hitting hard with a redo of the 2009 script QueryLoader. I kept getting e-mails and comments about it and thought I had left it just hanging there for way too long. It had become very outdated. So here it is: version 2 of QueryLoader!&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/queryloader2-preload-your-images-with-ease/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/queryloader2-preload-your-images-with-ease/ql2header.jpg&quot; alt=&quot;QueryLoader2 - Preload your images with ease&quot; title=&quot;QueryLoader2 - Preload your images with ease&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;A direct link to the zipfile:&lt;br&gt;&lt;a href=&quot;https://github.com/Gaya/QueryLoader2/zipball/master&quot;&gt;https://github.com/Gaya/QueryLoader2/zipball/master&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;View the example here:&lt;br&gt;&lt;a href=&quot;http://gaya.github.io/scripts/queryLoader2/&quot;&gt;http://gaya.github.io/scripts/queryLoader2/&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;reason-behind-v2&quot;&gt;Reason behind v2&lt;/h2&gt;
&lt;p&gt;QueryLoader2 is a better version of the old script posted in 2009. It serves the main purpose of preloading the images on your website by showing an overlay and a loading bar. It automatically fetches all your images and background images and preloads them before showing the webpage.&lt;/p&gt;
&lt;h2 id=&quot;compatibility&quot;&gt;Compatibility&lt;/h2&gt;
&lt;p&gt;QueryLoader currently works in IE version 9+, Chrome, Safari and Firefox.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;No dependencies&lt;/strong&gt;, so &lt;em&gt;no&lt;/em&gt; jQuery / Zepto / MooTools needed.&lt;/p&gt;
&lt;h2 id=&quot;example-usage-&quot;&gt;Example usage:&lt;/h2&gt;
&lt;p&gt;Include the queryloader2.min.js script in the head section of your webpage.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;queryloader2.min.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Create a QueryLoader2 object like this for example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&amp;lt;script type=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;
    &lt;span class=&quot;built_in&quot;&gt;window&lt;/span&gt;.addEventListener(&lt;span class=&quot;string&quot;&gt;'DOMContentLoaded'&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
        &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; QueryLoader2(&lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;.querySelector(&lt;span class=&quot;string&quot;&gt;&quot;body&quot;&lt;/span&gt;), {
            &lt;span class=&quot;attr&quot;&gt;barColor&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;#efefef&quot;&lt;/span&gt;,
            &lt;span class=&quot;attr&quot;&gt;backgroundColor&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;#111&quot;&lt;/span&gt;,
            &lt;span class=&quot;attr&quot;&gt;percentage&lt;/span&gt;: &lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;,
            &lt;span class=&quot;attr&quot;&gt;barHeight&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;,
            &lt;span class=&quot;attr&quot;&gt;minimumTime&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;200&lt;/span&gt;,
            &lt;span class=&quot;attr&quot;&gt;fadeOutTime&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1000&lt;/span&gt;
        });
    });
&amp;lt;&lt;span class=&quot;regexp&quot;&gt;/script&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;use-with-npm-browserify&quot;&gt;Use with NPM / Browserify&lt;/h2&gt;
&lt;p&gt;First install QueryLoader as a dependency in your project:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install queryloader2 --save-dev&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use it in a node / browserify project:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; QueryLoader2 = &lt;span class=&quot;built_in&quot;&gt;require&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;queryloader2&quot;&lt;/span&gt;);

&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; loader = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; QueryLoader2(&lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;.querySelector(&lt;span class=&quot;string&quot;&gt;&quot;body&quot;&lt;/span&gt;), {
    &lt;span class=&quot;attr&quot;&gt;barColor&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;#efefef&quot;&lt;/span&gt;,
    &lt;span class=&quot;attr&quot;&gt;backgroundColor&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;#111&quot;&lt;/span&gt;,
    &lt;span class=&quot;attr&quot;&gt;percentage&lt;/span&gt;: &lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;,
    &lt;span class=&quot;attr&quot;&gt;barHeight&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;,
    &lt;span class=&quot;attr&quot;&gt;minimumTime&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;200&lt;/span&gt;,
    &lt;span class=&quot;attr&quot;&gt;fadeOutTime&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1000&lt;/span&gt;
});&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;jquery-usage&quot;&gt;jQuery usage&lt;/h2&gt;
&lt;p&gt;Include jQuery and &lt;code&gt;queryloader2.min.js&lt;/code&gt; scripts in the header.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;https://code.jquery.com/jquery-1.11.1.min.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;queryloader2.min.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Call QueryLoader in &lt;code&gt;$(document).ready()&lt;/code&gt; like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;$(&lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;).ready(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; (&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    $(&lt;span class=&quot;string&quot;&gt;&quot;body&quot;&lt;/span&gt;).queryLoader2();
});&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;install-using-bower&quot;&gt;Install using Bower&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;bower install queryloader2&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;github&quot;&gt;GitHub&lt;/h2&gt;
&lt;p&gt;As you might have noticed &lt;a href=&quot;https://github.com/Gaya/QueryLoader2&quot;&gt;I put my code on GitHub&lt;/a&gt;. This makes it easier for me to manage my code and give you updates if you or me find any bugs.&lt;br&gt;You can also &lt;a href=&quot;https://github.com/Gaya/QueryLoader2/issues&quot;&gt;file issues&lt;/a&gt; with the script here and fork it to make changes / fix bugs. If you send me pull requests I will take a look as to what you have changed and commit it if it is an addition.&lt;/p&gt;
</description></item><item><title>Working on Siebstudio</title><link>https://gaya.pizza/articles/working-on-siebstudio/</link><pubDate>Thu, 10 Feb 2011 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/working-on-siebstudio/</guid><author></author><description>&lt;p&gt;Last week a friend of mine, &lt;a href=&quot;http://www.siebstudio.com&quot;&gt;Sieb&lt;/a&gt;, launched his new website for his design company called &lt;a href=&quot;http://www.siebstudio.com&quot;&gt;Siebstudio&lt;/a&gt;.&lt;br&gt; The website got mentioned on &lt;a href=&quot;http://creattica.com/css/siebstudio/52315&quot;&gt;creattica&lt;/a&gt; and got some nice exposure through it.&lt;br&gt; This article will explain my part in the development and what we did to create a site like this.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/working-on-siebstudio/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/working-on-siebstudio/ssworkingon.jpg&quot; alt=&quot;&quot; title=&quot;Working on Siebstudio&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;As some of you might know, me and Sieb work &lt;a href=&quot;http://www.cybox.nl&quot;&gt;at the same place&lt;/a&gt; and we get together from time to time.&lt;br&gt; We’ve created quite a lot of website in our time and I always like when we have to collaborate to make an awesome looking website that pops.&lt;/p&gt;
&lt;p&gt;So a couple of weeks ago I got to see the new and in progress Siebstudio website which instantaneously blew my mind.&lt;br&gt; The one thing that wasn’t done yet (because it’s not Sieb’s specialty) was the advanced code behind the site. Sieb did get a nice base for me too work on and got the effects ready as he wanted it.&lt;br&gt; There were a couple of things missing though, and that’s where I came in, using my jQuery / javascript magic.&lt;/p&gt;
&lt;p&gt;Let me just point out a few features of the site:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Sorting elements on screen using &lt;a href=&quot;http://desandro.com/resources/jquery-masonry/&quot;&gt;Masonry&lt;/a&gt; (animated)&lt;/li&gt;
&lt;li&gt;Displaying different artwork and slides using &lt;a href=&quot;http://jquery.malsup.com/cycle/&quot;&gt;Cycle&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Loading the clicked items through AJAX&lt;/li&gt;
&lt;li&gt;Dynamically change the visiting url with Javascript making it possible to share / like / tweet links even though the content is loaded dynamically without a new HTTP request&lt;/li&gt;
&lt;li&gt;Different types of blocks so the content is not set to one layout&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;After hours of coding, having fun, drinking beers and having smokes the website was finally done. Most annoying stuff I encountered was obviously getting it to work in Internet Explorer (that freaking browser!) and getting that twitter/facebook like urls to work. But it works now.&lt;/p&gt;
&lt;p&gt;Hope you like the website. I really think Sieb outdid himself again. My compliments.&lt;/p&gt;
&lt;p&gt;Drop any comments below, much appreciated.&lt;/p&gt;
&lt;p&gt;Take care,&lt;br&gt; Gaya&lt;/p&gt;
</description></item><item><title>Text with Moving Backgrounds with jQuery</title><link>https://gaya.pizza/articles/text-with-moving-backgrounds-with-jquery/</link><pubDate>Fri, 08 Jan 2010 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/text-with-moving-backgrounds-with-jquery/</guid><author></author><description>&lt;p&gt;Personally, I am a huge fan of negative space in design. This got me thinking while I was trying to accomplish something different. Normally a textual caption would be positioned above a background, but I wanted to do it the other way around: place the background in the letters.&lt;br&gt; I also wanted to add some nice dynamic effects to enhance the effect. This was amazingly easy to accomplish in jQuery with the use of a little creativity.&lt;/p&gt;
&lt;p&gt;This article will explain what you need to do create an effect like this yourself.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/text-with-moving-backgrounds-with-jquery/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/text-with-moving-backgrounds-with-jquery/movingbgcover.jpg&quot; alt=&quot;Text with Moving Backgrounds with jQuery&quot; title=&quot;Text with Moving Backgrounds with jQuery&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;what-are-we-going-to-do-&quot;&gt;What are we going to do?&lt;/h2&gt;
&lt;p&gt;We are going to create a container which has a moving background, but only a set of letters will be visible of the background. It will be as if there are holes in your container.&lt;/p&gt;
&lt;p&gt;To do this we need just a few things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A nice background pattern or image&lt;/li&gt;
&lt;li&gt;Letters punched out of an image&lt;/li&gt;
&lt;li&gt;Just a little jQuery code&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Normally you would create a PNG file containing anti-aliased letters and place it inside some container on top of a background. What we are going to do is place a full image over a background, covering parts that shouldn’t be seen. Just like a mask!&lt;/p&gt;
&lt;p&gt;Then we’re going to make the background of the container move around to create a nice looking effect.&lt;/p&gt;
&lt;h2 id=&quot;step-1-creating-the-mask-&quot;&gt;Step 1: Creating the “mask”&lt;/h2&gt;
&lt;p&gt;To create the overlaying mask I am going to use Photoshop. You can do this with any other image manipulation application, but I am going to explain what I did using screenshots of Photoshop.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;*&lt;em&gt;First create a new image and fill the background with the foreground of the mask. *&lt;/em&gt;This is the part that will be visible for the users. I used a black solid fill for this, so it stays clean.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Create a new text layer on the fill you just made.&lt;/strong&gt;&lt;br&gt;&lt;img src=&quot;https://gaya.pizza/articles/text-with-moving-backgrounds-with-jquery/movingbgpost_1.jpg&quot; alt=&quot;Mask in Photoshop&quot; title=&quot;Mask in Photoshop&quot;&gt;&lt;br&gt;This gives us the right impression, and we just have to imagine that the white letters will be punched out later.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hold CMD / CTRL and click on the text layer icon&lt;/strong&gt;&lt;br&gt;&lt;img src=&quot;https://gaya.pizza/articles/text-with-moving-backgrounds-with-jquery/movingbgpost_2.jpg&quot; alt=&quot;Select the text&quot; title=&quot;Select the text&quot;&gt;&lt;br&gt;Doing this the text will get a selection around it which should look like this:&lt;br&gt;&lt;img src=&quot;https://gaya.pizza/articles/text-with-moving-backgrounds-with-jquery/movingbgpost_3.jpg&quot; alt=&quot;Selected text in Photoshop&quot; title=&quot;Selected text in Photoshop&quot;&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Click: Select &amp;gt; Inverse&lt;/strong&gt;&lt;br&gt;&lt;img src=&quot;https://gaya.pizza/articles/text-with-moving-backgrounds-with-jquery/movingbgpost_5.jpg&quot; alt=&quot;Inverse selection&quot; title=&quot;Inverse selection&quot;&gt;&lt;br&gt;Now the area that will be visible on the mask image is selected. It will look like this:&lt;br&gt;&lt;img src=&quot;https://gaya.pizza/articles/text-with-moving-backgrounds-with-jquery/movingbgpost_6.jpg&quot; alt=&quot;Inversed text selection in Photoshop&quot; title=&quot;Inversed text selection in Photoshop&quot;&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Select the fill layer and click on “Add mask”&lt;/strong&gt;&lt;br&gt;&lt;img src=&quot;https://gaya.pizza/articles/text-with-moving-backgrounds-with-jquery/movingbgpost_4.jpg&quot; alt=&quot;Add layer mask&quot; title=&quot;Add layer mask&quot;&gt;&lt;br&gt;This will create a mask for the fill and the letters have been punched out.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hide the text layer&lt;/strong&gt;&lt;br&gt;&lt;img src=&quot;https://gaya.pizza/articles/text-with-moving-backgrounds-with-jquery/movingbgpost_7.jpg&quot; alt=&quot;Hide text layer&quot; title=&quot;Hide text layer&quot;&gt;&lt;br&gt;You have now punched out the letters of the fill!&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Save as .png!&lt;/strong&gt;&lt;br&gt;PNG handles transparency very well and looks right in almost all current browsers (nope, not IE6). It also support opacity per pixel, so it’s not like the the GIF transparency.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;step-2-a-little-documenting-and-styling&quot;&gt;Step 2: A little documenting and styling&lt;/h2&gt;
&lt;p&gt;Now that you’ve got your own mask image, it’s time to create the HTML page for it to end up in.&lt;/p&gt;
&lt;p&gt;Just for basics, use something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;meta&quot;&gt;&amp;lt;!DOCTYPE &lt;span class=&quot;meta-keyword&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;meta-keyword&quot;&gt;PUBLIC&lt;/span&gt; &lt;span class=&quot;meta-string&quot;&gt;&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;&lt;/span&gt; &lt;span class=&quot;meta-string&quot;&gt;&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;xmlns&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;http://www.w3.org/1999/xhtml&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;xml:lang&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;nl&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;lang&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;nl&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;meta&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;http-equiv&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;content-type&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;content&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/html; charset=UTF-8&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;title&lt;/span&gt;&amp;gt;&lt;/span&gt;Some title&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;title&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;style.css&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;body&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'scrollBg'&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'overlay.png'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;alt&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;''&lt;/span&gt; /&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;body&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;html&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We created a simple HTML page containing just two elements; the container “scrollBg” and the image that serves as the mask.&lt;/p&gt;
&lt;p&gt;Make sure to fix the &lt;em&gt;src&lt;/em&gt; of the image and the &lt;em&gt;href&lt;/em&gt; to your stylesheet.&lt;/p&gt;
&lt;p&gt;In the stylesheet we just need a little bit of styling:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-tag&quot;&gt;body&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;background-color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#000000&lt;/span&gt;;
}

&lt;span class=&quot;selector-class&quot;&gt;.scrollBg&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;background-image&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;url&lt;/span&gt;(background.jpg);
    &lt;span class=&quot;attribute&quot;&gt;background-color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#000000&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;487px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;83px&lt;/span&gt;;
}

&lt;span class=&quot;selector-class&quot;&gt;.scrollBg&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;img&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;display&lt;/span&gt;: block;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You’ll have to fix the width and height of the scrollBg container. Adjust it to the width and height of the mask you created. This will prevent the background image from showing outside of the mask.&lt;/p&gt;
&lt;p&gt;Also change the URL of the background image.&lt;/p&gt;
&lt;h2 id=&quot;step-3-go-jquery-crazy-&quot;&gt;Step 3: Go jQuery crazy!&lt;/h2&gt;
&lt;p&gt;In the Javascript part of this tutorial we are going to make the background image shift in position at random.&lt;/p&gt;
&lt;p&gt;To make jQuery able to move the background image, we need a plugin, since it’s not in the default behavior.&lt;/p&gt;
&lt;p&gt;Go download this plugin: &lt;a href=&quot;http://plugins.jquery.com/project/backgroundPosition-Effect&quot;&gt;http://plugins.jquery.com/project/backgroundPosition-Effect&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Include this script in on your page using:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;url_to_moving_background.js&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we can use backgroundPosition as a parameter in the jQuery animate effect! Pretty neat!&lt;/p&gt;
&lt;p&gt;The following jQuery code will move the background around at random (put it in the  part of the HTML page):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;javascript&quot;&gt;
$(&lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;).ready(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{

    moveBgAround();

});

&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;moveBgAround&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;comment&quot;&gt;//give a random value from 0 to 400 for the X axis and the Y axis&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; x = &lt;span class=&quot;built_in&quot;&gt;Math&lt;/span&gt;.floor(&lt;span class=&quot;built_in&quot;&gt;Math&lt;/span&gt;.random()*&lt;span class=&quot;number&quot;&gt;401&lt;/span&gt;);
    &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; y = &lt;span class=&quot;built_in&quot;&gt;Math&lt;/span&gt;.floor(&lt;span class=&quot;built_in&quot;&gt;Math&lt;/span&gt;.random()*&lt;span class=&quot;number&quot;&gt;401&lt;/span&gt;);

    &lt;span class=&quot;comment&quot;&gt;//random generated time it takes to move&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; time = &lt;span class=&quot;built_in&quot;&gt;Math&lt;/span&gt;.floor(&lt;span class=&quot;built_in&quot;&gt;Math&lt;/span&gt;.random()*&lt;span class=&quot;number&quot;&gt;1001&lt;/span&gt;) + &lt;span class=&quot;number&quot;&gt;2000&lt;/span&gt;;

    &lt;span class=&quot;comment&quot;&gt;//make the background image move!&lt;/span&gt;
    $(&lt;span class=&quot;string&quot;&gt;'.scrollBg'&lt;/span&gt;).animate({
        &lt;span class=&quot;attr&quot;&gt;backgroundPosition&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;'('&lt;/span&gt; + (x * &lt;span class=&quot;number&quot;&gt;-1&lt;/span&gt;) + &lt;span class=&quot;string&quot;&gt;'px '&lt;/span&gt; + (y * &lt;span class=&quot;number&quot;&gt;-1&lt;/span&gt;) + &lt;span class=&quot;string&quot;&gt;'px)'&lt;/span&gt;
    }, time, &lt;span class=&quot;string&quot;&gt;&quot;swing&quot;&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
        moveBgAround();
    });
}
&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It’s that simple! You are now ready to experiment with the code I just created.&lt;/p&gt;
&lt;p&gt;The X and Y values are the amount of pixels the background image will shift. He will not move that amount in pixel, but he will move to the generated coordinates.&lt;/p&gt;
&lt;p&gt;If you would like to make it move more you can increase the number stated here:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; x = &lt;span class=&quot;built_in&quot;&gt;Math&lt;/span&gt;.floor(&lt;span class=&quot;built_in&quot;&gt;Math&lt;/span&gt;.random()*&lt;span class=&quot;number&quot;&gt;401&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you want to create a background image that is not a pattern but rather just a large texture, you have to an image with the following width and height: Take the number that you entered in the script (amount after &lt;em&gt;random()&lt;/em&gt;) and add the width of the mask to it: that is your width. Same goes with the height.&lt;br&gt; This will allow the background to move around without being repeated.&lt;/p&gt;
&lt;h2 id=&quot;done-&quot;&gt;Done!&lt;/h2&gt;
&lt;p&gt;If you have any questions or was inspirited to create different crazy effects: let me know in the comments below.&lt;/p&gt;
&lt;p&gt;Happy developing!&lt;/p&gt;
</description></item><item><title>One year of Gaya Design</title><link>https://gaya.pizza/articles/one-year-of-gaya-design/</link><pubDate>Mon, 28 Dec 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/one-year-of-gaya-design/</guid><author></author><description>&lt;p&gt;On this day, but about 365 days ago, I published &lt;a href=&quot;https://gaya.pizza/articles/garagedoor-effect-using-javascript/&quot;&gt;my first article&lt;/a&gt;. From that day I devoted quite a lot of my free time to this weblog, and still doing it with a smile!
 It’s great to know where my little blog is after a year and I am very thankful for the people who made this possible.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/one-year-of-gaya-design/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/one-year-of-gaya-design/oneyear.jpg&quot; alt=&quot;One year of Gaya Design&quot; title=&quot;One year of Gaya Design&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-start&quot;&gt;The start&lt;/h2&gt;
&lt;p&gt;In the beginning I didn’t know anything about blogging, but I’ve always had the urge to go and spread the stuff that I made and share my knowledge with other people.&lt;br&gt; And as we know, the Internet is a great medium to do that, so I started this blog.&lt;br&gt; The idea to start a blog came from Marco of &lt;a href=&quot;http://www.marcofolio.net&quot;&gt;Marcofolio.net&lt;/a&gt; (at the time a classmate). He kind of made me want to do a blog myself. Seeing that his blog was a success, I wanted to start something myself. Thanks Marco for inspiring me!&lt;/p&gt;
&lt;p&gt;After a few months of running my blog on a self made system (which was enough at the time), it was time to boost the action and convert the whole blog into a &lt;a href=&quot;http://wordpress.org/&quot;&gt;Wordpress&lt;/a&gt; blog, and then it started. Such a great platform to run a blog on, if you’re not yet running Wordpress: do it now!&lt;/p&gt;
&lt;h2 id=&quot;traffic-boom&quot;&gt;Traffic boom&lt;/h2&gt;
&lt;p&gt;A few months in I saw that a lot of new comments appeared on my blog. I must have had a mention somewhere nice. And it was, not just somewhere! In &lt;a href=&quot;http://net.tutsplus.com/articles/web-roundups/best-of-the-web-january/&quot;&gt;an article on Nettuts&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;I want to once again thank &lt;a href=&quot;http://dev-tips.com/&quot;&gt;Drew Douglass&lt;/a&gt; for this. I believe he gave me a big boost into the developers community on the Internet, even though I wrote script.aculo.us scripts back then. He’s an awesome dude who like me just has a passion for web development and wants to share it with the world.&lt;/p&gt;
&lt;h2 id=&quot;few-other-thank-yous&quot;&gt;Few other thank yous&lt;/h2&gt;
&lt;p&gt;I want to thank everyone at &lt;a href=&quot;http://www.cybox.nl/&quot;&gt;Cybox&lt;/a&gt; (the place I work) for their support for what I do and giving me the opportunity to host this weblog on their servers.&lt;/p&gt;
&lt;p&gt;We’ve experienced some crazy stuff thanks to this blog, but the servers will always survive!&lt;br&gt; Check out the websites of my co-workers: &lt;a href=&quot;http://siebdesign.com/&quot;&gt;Sieb&lt;/a&gt;, &lt;a href=&quot;http://hypekid.com&quot;&gt;Pim&lt;/a&gt;, &lt;a href=&quot;http://www.bashendriks.nl/&quot;&gt;Bas&lt;/a&gt;, &lt;a href=&quot;http://www.nando.nl/&quot;&gt;Nando&lt;/a&gt;, &lt;a href=&quot;http://www.rutgerdragstra.com/&quot;&gt;Rutger&lt;/a&gt;.&lt;br&gt;&lt;strong&gt;You guys ROCK!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Also a HUGE thank you to YOU, my readers, you make this all happen! If it weren’t for you, I’d be eating some crisps and play Nintendo games in all the time I’ve spend in the social networks of this wonderful community.&lt;br&gt; I really love how a lot of people from all around the world are contacting me and talk about stuff I’ve written on my website. A lot of this conversing goes on &lt;a href=&quot;http://twitter.com/GayaKessler&quot;&gt;on Twitter&lt;/a&gt;. Really love how fast stuff goes over there and the ease of just starting a conversation. Thank you all readers, followers and subscribers!&lt;/p&gt;
&lt;p&gt;I’d also like to thank the people at FUEL for giving me the opportunity to write for one of their blogs. As some of you may know, I was an editor at &lt;a href=&quot;http://fuelyourcoding.com/&quot;&gt;FUEL Your Coding&lt;/a&gt; for a while and let them use my articles to give the website a kick start. Since it started to take up way too much of my time I had to stop, which was a bummer.&lt;br&gt; But as you can see, mister &lt;a href=&quot;http://dougneiner.com/&quot;&gt;Douglass Neiner&lt;/a&gt; is doing a great job keeping that site alive!&lt;/p&gt;
&lt;p&gt;Thank you &lt;a href=&quot;http://adellecharles.com/&quot;&gt;Adelle&lt;/a&gt;, &lt;a href=&quot;http://dougneiner.com/&quot;&gt;Doug&lt;/a&gt;, &lt;a href=&quot;http://joshuasmibert.com/&quot;&gt;Josh&lt;/a&gt;, &lt;a href=&quot;http://michellekrasniak.com/&quot;&gt;Michelle&lt;/a&gt; and all the other FUEL people for the great time at FUEL. You enlighten the community.&lt;/p&gt;
&lt;h2 id=&quot;a-look-at-2010&quot;&gt;A look at 2010&lt;/h2&gt;
&lt;p&gt;In 2010 I want to bring you a lot of jQuery madness and I am planning on doing another blog along with some friends, but that’s just another surprise waiting for you in 2010.&lt;br&gt; Thank you all for reading my blog and I hope to make next year a great one!&lt;/p&gt;
</description></item><item><title>How to start writing your own sweet jQuery scripts</title><link>https://gaya.pizza/articles/how-to-start-writing-your-own-sweet-jquery-scripts/</link><pubDate>Mon, 30 Nov 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/how-to-start-writing-your-own-sweet-jquery-scripts/</guid><author></author><description>&lt;p&gt;Sometimes it can be hard to start writing a Javascript script when you don’t know what to do instantaneously. But luckily there is the Internet right?&lt;br&gt; Just go to Google and type in what you want in a script. Good chance some jQuery or Javascript solution will show in the results, and you are basically done.&lt;/p&gt;
&lt;p&gt;The problem is that you still don’t know how to do such things.&lt;/p&gt;
&lt;p&gt;In this article I’ll discuss the viral points of planning out a Javascript / jQuery script with ease.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/how-to-start-writing-your-own-sweet-jquery-scripts/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/how-to-start-writing-your-own-sweet-jquery-scripts/startjquery.jpg&quot; alt=&quot;How to start writing your own sweet jQuery scripts&quot; title=&quot;How to start writing your own sweet jQuery scripts&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Before I start talking about Javascript and jQuery I want to take the time to do some shameless self-promotion.&lt;br&gt; A few weeks ago I opened up &lt;a href=&quot;http://micro.gayadesign.com&quot;&gt;a small blog on tumblr&lt;/a&gt;. I will be posting inspiration I’ve come by on the Internet, just to support the sharing of awesomeness on the web!&lt;/p&gt;
&lt;p&gt;The url is: &lt;a href=&quot;http://micro.gayadesign.com&quot;&gt;http://micro.gayadesign.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now on with the article!&lt;/p&gt;
&lt;h2 id=&quot;good-to-know&quot;&gt;Good to know&lt;/h2&gt;
&lt;p&gt;Before you start working with jQuery, it’s best you first understand Javascript and the difference with it and plain HTML and CSS.&lt;br&gt; Most HTML elements are static, they don’t move, they just sit there. A document (without any flash objects or gif images) looks like a still life. The only change you’ll probably get is when you hover over links. You can’t change the content of the page without generating a new document.&lt;br&gt; This is where Javascript (in this case in addition jQuery) steps in, which you probably already know.&lt;/p&gt;
&lt;p&gt;The first thing I would like to advise is to start by learning basic Javascript and doing calculations in it. This will also help you experience the differences between browsers. But don’t worry; jQuery solves a lot of these problems!&lt;br&gt; I think that the following tutorials give you a great start in developing in Javascript: &lt;a href=&quot;http://www.w3schools.com/JS/js_intro.asp&quot;&gt;http://www.w3schools.com/JS/&lt;/a&gt;. For people who prefer books; I found that “Professional JavaScript for Web Developers (Wrox Professional Guides)” is a pretty neat book to understand the basics of Javascript.&lt;/p&gt;
&lt;p&gt;If you’re already into Javascripting, the previous steps would be out of the question. So we’ll move on to jQuery.&lt;br&gt; Go to the &lt;a href=&quot;http://docs.jquery.com/Main_Page&quot;&gt;jQuery website for the documentation&lt;/a&gt;. There is a lot of information about how jQuery works and which functionality is available.&lt;/p&gt;
&lt;p&gt;In the next section I’ll explain what to do before starting to write your own script.&lt;/p&gt;
&lt;h2 id=&quot;before-creating-a-script&quot;&gt;Before creating a script&lt;/h2&gt;
&lt;p&gt;The first thing you need (this is kind of a no-brainer) is a good idea. An idea for a nice effect, some sort of enhancement for your web page or effect of any kind.&lt;br&gt; Most of the scripts I wrote were made because there was functionality I wanted, but wasn’t available in plain HTML and CSS. Most of the things you’ll create with jQuery would have never been possible without the use of Javascript.&lt;/p&gt;
&lt;p&gt;Once you’ve got an overall idea of what you want to achieve and which elements you want to adjust, you can start to create a layout in HTML and CSS.&lt;br&gt; It is important that you give the right classes and ids to the elements, this will benefit in the jQuery development process.&lt;/p&gt;
&lt;p&gt;Elements that will be visible after a certain action can already be included in the document, but make sure to hide them from the user. A simple &lt;em&gt;display: none&lt;/em&gt; in the CSS will suffice.&lt;br&gt; It is a lot easier to use HTML that is already generated rather than generating it all in jQuery.&lt;br&gt; I also like to keep “ghost elements” ready in the HTML, so I can copy a whole element and append / prepend the copied element with ease. This will minimize the jQuery scripting code.&lt;/p&gt;
&lt;p&gt;Now that you have the layout ready and have a basic idea of what you want, you can start to map out everything the script will do to your page.&lt;br&gt; The basic idea is to list all events and happenings. I like to make short lists of different functions which the script will contain.&lt;br&gt; I’ll give an example of a very basic script; It displays thumbnails. When a user clicks on a thumbnail, the larger version is displayed. When a user hovers over a thumbnail some styling is added.&lt;br&gt; This example can be divided into separate function with ease, but separating the events first is the easiest. We’ll have an *onhover *and an *onclick *event which we have to lay out.&lt;br&gt; Now that we know which events will take place we can write what these events should do, eg:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Hover&lt;/strong&gt;: Element should get a border and disposition a bit to the top. It should reset when the cursor leaves the element.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Click&lt;/strong&gt;: Get the source to the larger version and append this image to the display element.&lt;/p&gt;
&lt;p&gt;The actions can be easily scripted as functions. So that you’d only have to bind a function to the event.&lt;/p&gt;
&lt;p&gt;Now we can create the code layout for this example. I like to keep all my scripts clean, and to achieve this I put the whole script inside a new Javascript array. The following code will serve as the template for this script:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; ScriptName = {

    &lt;span class=&quot;attr&quot;&gt;init&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;comment&quot;&gt;//function that will initialize the script and do all the bindings&lt;/span&gt;

    },

    &lt;span class=&quot;attr&quot;&gt;openLargeVersion&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;obj&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;comment&quot;&gt;//when a thumbnail is clicked, this will be executed, given the clicked element&lt;/span&gt;

    },

    &lt;span class=&quot;attr&quot;&gt;hoverThumb&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;obj&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;comment&quot;&gt;//given the object, we'll manipulate the css&lt;/span&gt;

    },

    &lt;span class=&quot;attr&quot;&gt;mouseoutThumb&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;obj&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;comment&quot;&gt;//given the object, we'll reset the styling here&lt;/span&gt;

    }

}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using script layouts like these will really help in the development process. It gives a good idea of what every function should contain and will separate all the action (rather than putting all the Javascript in a file and summing up all functions and bindings.)&lt;/p&gt;
&lt;h2 id=&quot;keep-it-simple&quot;&gt;Keep it simple&lt;/h2&gt;
&lt;p&gt;Really! Keep it simple! Javascript can be used to adjust the presentation of the website, but please, please don’t overdo it. It won’t do any good on the experience, performance and goal of the script. On top of that the development process will probably be a killer. Just keep it simple (stupid!).&lt;/p&gt;
&lt;p&gt;It’s good to plan out the different animations you want to achieve in the script. First move the element a bit and then change the colour and then and then… It’s important to keep animations and actions in line with what you expect.&lt;/p&gt;
&lt;p&gt;Using the *init *function I created in the sample template code can really help you in separating different snippets of jQuery code. A simple&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;$(&lt;span class=&quot;string&quot;&gt;&quot;#element-id img.thumb&quot;&lt;/span&gt;).click(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{ ScriptName.openLargeVersion($(&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;)) });&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;would be enough to bind the &lt;code&gt;openLargeVersion&lt;/code&gt; function to every &lt;code&gt;img&lt;/code&gt; element with the class &lt;code&gt;thumb&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When using functionality like .animate using callbacks can be really useful for chaining animations and keeping everything in line.&lt;/p&gt;
&lt;p&gt;Another thing I started to like is the use of cheat sheets. They save a lot of time clicking around in the jQuery docs. They list all the functionality which jQuery contains and gives you a small example of how you should write the code.&lt;br&gt; I found the following cheat sheet very helpful: &lt;a href=&quot;http://woork.blogspot.com/2009/09/jquery-visual-cheat-sheet.html&quot;&gt;Visual Cheat Sheet by Woork&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Think of how you want to adjust your document’s layout. A lot can be achieved by only adjusting the CSS presentation. The *animate *function in jQuery enables you to make changes over an amount of time. Imagine increasing the padding, it will look as if the element is growing. Same can be said about margins, but then the element would move around.&lt;/p&gt;
&lt;p&gt;Another little something: use &lt;a href=&quot;https://addons.mozilla.org/en-US/firefox/addon/1843&quot;&gt;Firebug&lt;/a&gt; in Firefox!&lt;br&gt;&lt;a href=&quot;https://addons.mozilla.org/en-US/firefox/addon/1843&quot;&gt;Firebug&lt;/a&gt; will help you in the development process and gives you a lot of handy options to keep an eye on your HTML. It is very interesting to see the style of an element change thanks to jQuery.&lt;br&gt; The possibility to execute Javascript code on the fly is also a really nice feature when writing Javascript code. It’s the easiest way to do trail and error coding without having to upload a file and refreshing the page.&lt;br&gt; This is a tool you cannot miss!&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I hope this is a nice step into creating your own jQuery scripts with a few things to keep in mind. It really isn’t hard, just let your imagination run wild and try to translate it into logical steps.&lt;/p&gt;
&lt;p&gt;If you have something to add, please let me know in the comments below!&lt;/p&gt;
</description></item><item><title>Presentation Cycle: Cycle with a progressbar</title><link>https://gaya.pizza/articles/presentation-cycle-cycle-with-a-progressbar/</link><pubDate>Tue, 03 Nov 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/presentation-cycle-cycle-with-a-progressbar/</guid><author></author><description>&lt;p&gt;&lt;a href=&quot;http://www.malsup.com/jquery/cycle/&quot;&gt;Cycle&lt;/a&gt; is a script that supports image presentations to easily display multiple images. This script supports a lot of effects and the cycling of html elements.&lt;/p&gt;
&lt;p&gt;Presentation Cycle is a variation on the functionality of Cycle. Instead of generating a list of numbers that are clickable Presentation Cycle generates a progress bar that shows when the new slide will appear.&lt;/p&gt;
&lt;p&gt;In this article I’ll explain how to implement this on your web page and give you some tips on how to adjust the looks of the cycle elements and progress bar.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/presentation-cycle-cycle-with-a-progressbar&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/presentation-cycle-cycle-with-a-progressbar/presentationCycle.jpg&quot; alt=&quot;Presentation Cycle: Cycle with a progressbar&quot; title=&quot;Presentation Cycle: Cycle with a progressbar&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Download the source code here:&lt;br&gt;&lt;a href=&quot;http://gaya.github.io/scripts/presentationCycle/presentationCycle.zip&quot;&gt;http://gaya.github.io/scripts/presentationCycle/presentationCycle.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;View the example here:&lt;br&gt;&lt;a href=&quot;http://gaya.github.io/scripts/presentationCycle/&quot;&gt;http://gaya.github.io/scripts/presentationCycle/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As shown on the &lt;a href=&quot;http://gaya.github.io/scripts/presentationCycle/&quot;&gt;example page&lt;/a&gt;, this script generates a progress bar automatically instead of the developer adding some html.
 Depending on the settings of the script, it dynamically generates a progress bar adjusted to the number of slides in the Cycle container.&lt;/p&gt;
&lt;h2 id=&quot;features&quot;&gt;Features&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Cycle through elements&lt;/li&gt;
&lt;li&gt;Adjustable animation times&lt;/li&gt;
&lt;li&gt;Generates a navigation bar that also shows the progress&lt;/li&gt;
&lt;li&gt;Works in modern browsers&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;implementing-the-script&quot;&gt;Implementing the script&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&quot;http://gaya.github.io/scripts/presentationCycle/presentationCycle.zip&quot;&gt;zip archive&lt;/a&gt; contains an example page to see how to get things to work, but the following steps will tell you how to make your own.&lt;/p&gt;
&lt;p&gt;First we need to upload the contents of the &lt;a href=&quot;http://gaya.github.io/scripts/presentationCycle/presentationCycle.zip&quot;&gt;zip archive&lt;/a&gt; to your web server (or local for testing).&lt;/p&gt;
&lt;p&gt;Create a new html page and include the following code in the `` section:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;&amp;lt;!-- Stylesheets--&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;css/presentationCycle.css&quot;&lt;/span&gt; /&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;comment&quot;&gt;&amp;lt;!-- Scripts --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/javascript'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/javascript'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'js/jquery.cycle.all.min.js'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/javascript'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'js/presentationCycle.js'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It’s time to create the container that will contain the html elements for the Cycle:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;presentation_container&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;pc_container&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;pc_item&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;desc&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;h1&lt;/span&gt;&amp;gt;&lt;/span&gt;Description title&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;h1&lt;/span&gt;&amp;gt;&lt;/span&gt;
            You can put your description in here.
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;images/slide1.jpg&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;alt&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;slide1&quot;&lt;/span&gt; /&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;comment&quot;&gt;&amp;lt;!-- ... repeat the previous item --&amp;gt;&lt;/span&gt;

&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The container of the cycle elements has a default &lt;strong&gt;id&lt;/strong&gt; of “&lt;code&gt;#presentation_container&lt;/code&gt;“. This corresponds to the default settings of the script and the stylesheet.&lt;/p&gt;
&lt;p&gt;The child elements have a class of “&lt;code&gt;pc_item&lt;/code&gt;“, this also corresponds to the default settings in the stylesheet.&lt;/p&gt;
&lt;p&gt;Have you uploaded all the files and images? Then you are ready to initialize the script.&lt;/p&gt;
&lt;p&gt;Put the following below the Cycle container:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
presentationCycle.init();
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is all you need to do to get the default look going!&lt;/p&gt;
&lt;p&gt;In the following section I will talk about how to configure the script to adjust the looks to your likings.&lt;/p&gt;
&lt;h2 id=&quot;adjusting-the-looks&quot;&gt;Adjusting the looks&lt;/h2&gt;
&lt;p&gt;The first thing I’ll explain is how to adjust the images that are used to generate the progress bar.&lt;/p&gt;
&lt;p&gt;The Javascript file of Presentation Cycle contains the following code regarding images the script uses (&lt;em&gt;line 18&lt;/em&gt;):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//progressbar options&lt;/span&gt;
&lt;span class=&quot;attr&quot;&gt;barHeight&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;14&lt;/span&gt;,
&lt;span class=&quot;attr&quot;&gt;barDisplacement&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;20&lt;/span&gt;,
&lt;span class=&quot;attr&quot;&gt;barImgLeft&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;images/pc_item_left.gif&quot;&lt;/span&gt;,
&lt;span class=&quot;attr&quot;&gt;barImgRight&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;images/pc_item_right.gif&quot;&lt;/span&gt;,
&lt;span class=&quot;attr&quot;&gt;barImgCenter&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;images/pc_item_center.gif&quot;&lt;/span&gt;,
&lt;span class=&quot;attr&quot;&gt;barImgBarEmpty&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;images/pc_bar_empty.gif&quot;&lt;/span&gt;,
&lt;span class=&quot;attr&quot;&gt;barImgBarFull&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;images/pc_bar_full.gif&quot;&lt;/span&gt;,&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The bar height is defined in pixels, this is required for the script to work properly. The height is the same as the images that are contained in the &lt;strong&gt;images&lt;/strong&gt; folder. As you can see the images are sprites. I’ve included the active and inactive version of the image in one image to reduce loading time and it makes the script work better.&lt;/p&gt;
&lt;p&gt;To adjust the images you need to have two square images next to each other. Making the left part the inactive one and the right the active one.&lt;/p&gt;
&lt;p&gt;The only requirement is that all the images have the same height, this is to position the bar the right way. Also make sure that you set the height in the script too.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;barDisplacement&lt;/code&gt; is the combined value of padding + margin the bar has.&lt;/p&gt;
&lt;p&gt;To change settings the following code might help; there is no need to change the Javascript file. This code is executed after the Cycle container defined.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;presentationCycle.barHeight = &lt;span class=&quot;number&quot;&gt;10&lt;/span&gt;; &lt;span class=&quot;comment&quot;&gt;//different from the default&lt;/span&gt;
presentationCycle.barImgLeft = &lt;span class=&quot;string&quot;&gt;&quot;images/pc_item_left_custom.gif&quot;&lt;/span&gt;; &lt;span class=&quot;comment&quot;&gt;//using a different image&lt;/span&gt;

presentationCycle.init(); &lt;span class=&quot;comment&quot;&gt;//start the script&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To adjust the settings of the cycle you can adjust the following settings:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//slide options&lt;/span&gt;
&lt;span class=&quot;attr&quot;&gt;slideTimeout&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;8000&lt;/span&gt;,
&lt;span class=&quot;attr&quot;&gt;containerId&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;presentation_container&quot;&lt;/span&gt;,

&lt;span class=&quot;comment&quot;&gt;//cycle options&lt;/span&gt;
&lt;span class=&quot;attr&quot;&gt;cycleFx&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;'scrollHorz'&lt;/span&gt;,
&lt;span class=&quot;attr&quot;&gt;cycleSpeed&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;600&lt;/span&gt;,&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;slideTimeout&lt;/code&gt; is the time it takes for a slide to go to the next one.&lt;br&gt; &lt;code&gt;containerId&lt;/code&gt; is the container of the cycle elements.&lt;br&gt; &lt;code&gt;cycleFx&lt;/code&gt; is the effect of cycle the script will be using, for all the effects visit &lt;a href=&quot;http://www.malsup.com/jquery/cycle/browser.html&quot;&gt;the effect browser&lt;/a&gt;.&lt;br&gt; &lt;code&gt;cycleSpeed&lt;/code&gt; is the speed of the animation.&lt;/p&gt;
&lt;p&gt;I used &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; elements to add text to the slides, you can play around with the elements to make them fit your needs, that’s the great thing about Cycle!&lt;/p&gt;
&lt;p&gt;For &lt;a href=&quot;http://gaya.github.io/scripts/presentationCycle/index.php?style=1&quot;&gt;more examples&lt;/a&gt; on how to adjust the script you can take a look at the source of the &lt;a href=&quot;http://gaya.github.io/scripts/presentationCycle/index.php?style=2&quot;&gt;different examples&lt;/a&gt; on the example page.&lt;/p&gt;
&lt;p&gt;Good luck!&lt;/p&gt;
</description></item><item><title>Notifications: the other approach</title><link>https://gaya.pizza/articles/notifications-the-other-approach/</link><pubDate>Tue, 20 Oct 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/notifications-the-other-approach/</guid><author></author><description>&lt;p&gt;A normal problem: notifications or updates that have to be displayed on a website, but it’s kind of overloading the backend. But as long as the page is open: please update the status dynamically (if necessary) without reloading the page.&lt;/p&gt;
&lt;p&gt;I can hear you think: AJAX! Yes, I’ll use AJAX for sure. But there is a little problem when it comes to how up-to-date you want these notifications to be without overloading the backend of the website.&lt;/p&gt;
&lt;p&gt;In this article I’ll approach pushing notifications from another perspective, regulating them in the backend rather than the frontend.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/notifications-the-other-approach/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/notifications-the-other-approach/notifications.jpg&quot; alt=&quot;Notifications: the other approach&quot; title=&quot;Notifications: the other approach&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Most of the applications that use AJAX to update the information that is on the screen use a simple request that fire every once in a while. This doesn’t really make the notification instant and can cause the Javascript to make more calls than necessary to the server.&lt;/p&gt;
&lt;p&gt;Expanding the interval time of the calls would lessen the requests, but that would take away a bit of the notification functionality don’t you think? When there is something to notify: notify me!&lt;/p&gt;
&lt;p&gt;With these problems in mind, there might be various solutions. A solution someone told me about got me interested; rather than letting Javascript determine whether to make a call to the server, let the server do it.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works-&quot;&gt;How it works:&lt;/h2&gt;
&lt;p&gt;How are we going to make the backend (in this case PHP) say when the frontend has to update?&lt;/p&gt;
&lt;p&gt;The solution is quick and easy: only return information if PHP has some, and let PHP tell the frontend to reload. Simply put: if there is an answer: go and reload.&lt;br&gt; To make this a bit more clear, I’ve put together the following work flow:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Frontend notifies the backend that it wants information.&lt;/li&gt;
&lt;li&gt;The backend goes in a loop waiting for information to give back to the frontend.&lt;/li&gt;
&lt;li&gt;If in the meantime information is available: return the results.&lt;/li&gt;
&lt;li&gt;The backend gives his answer (if available) and tells the frontend to do another request.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This approach is a bit different from letting Javascript interval the requests and making it load PHP the whole time.&lt;/p&gt;
&lt;h2 id=&quot;getting-started-&quot;&gt;Getting started:&lt;/h2&gt;
&lt;p&gt;In this example I am going to make a simple page that shows text from a txt file on the server and changes the text once changes are made on the server.&lt;/p&gt;
&lt;p&gt;First we need a bit of code to get everything off the ground.&lt;/p&gt;
&lt;p&gt;Start with this super easy HTML:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;meta&quot;&gt;&amp;lt;!DOCTYPE &lt;span class=&quot;meta-keyword&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;meta-keyword&quot;&gt;PUBLIC&lt;/span&gt; &lt;span class=&quot;meta-string&quot;&gt;&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&lt;/span&gt; &lt;span class=&quot;meta-string&quot;&gt;&quot;http://www.w3.org/TR/html4/loose.dtd&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;html&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;meta&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;http-equiv&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;Content-Type&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;content&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/html; charset=ISO-8859-1&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;title&lt;/span&gt;&amp;gt;&lt;/span&gt;Notification test&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;title&lt;/span&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/javascript'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;notification/notification.js&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;body&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'content'&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;h1&lt;/span&gt;&amp;gt;&lt;/span&gt;Notification test&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;h1&lt;/span&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;p&lt;/span&gt;&amp;gt;&lt;/span&gt;
        This example will notify the user when changes have been made to updates.txt.
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;p&lt;/span&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'notify'&lt;/span&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;body&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;html&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nothing too complicated right? I won’t go into details what I did here.&lt;/p&gt;
&lt;p&gt;We are going to use jQuery for its AJAX functions (which are so convenient and make clean code.)&lt;/p&gt;
&lt;p&gt;The next step would be to output information in the &lt;code&gt;#notify&lt;/code&gt; element.&lt;/p&gt;
&lt;h2 id=&quot;the-javascript-code-&quot;&gt;The Javascript code:&lt;/h2&gt;
&lt;p&gt;What do we need in the Javascript:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A function to make a request to the backend.&lt;/li&gt;
&lt;li&gt;In the callback of the jQuest AJAX function we need to load the notifications and output them if they exist.&lt;/li&gt;
&lt;li&gt;When callback is called: repeat the cycle.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Create a folder called &lt;code&gt;notification&lt;/code&gt; and in that folder create the file: &lt;code&gt;notification.js&lt;/code&gt;. From the root where the HTML file is in it would be: &lt;code&gt;notification/notification.js&lt;/code&gt;. We’ll use this folder to add other files too.&lt;/p&gt;
&lt;p&gt;The basic Javascript I got is:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; notification = {

    &lt;span class=&quot;attr&quot;&gt;request_url&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&quot;notification/notification_request.php&quot;&lt;/span&gt;,

    &lt;span class=&quot;attr&quot;&gt;do_request&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{

    }

}

notification.do_request();&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice that I separated the request URL from the actual AJAX call that will be the next step. I always to this so I can change this URL with ease, without changing all the code. Request URL change some times, and you don’t want to have to mess around in the code too much.&lt;/p&gt;
&lt;p&gt;Now to fill the &lt;code&gt;do_request&lt;/code&gt; function, we’ll make a post request to the URL and expect JSON back as its output. Also create a callback function that will be handling the output given by the server.&lt;/p&gt;
&lt;p&gt;Now to fill &lt;code&gt;do_request&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;do_request: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    $.post(notification.request_url, {},
        &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;data&lt;/span&gt;) &lt;/span&gt;{
            &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;typeof&lt;/span&gt;(data.updates) != &lt;span class=&quot;string&quot;&gt;'undefined'&lt;/span&gt;) {
                $(&lt;span class=&quot;string&quot;&gt;&quot;#notify&quot;&lt;/span&gt;).html(data.updates);
            }
            notification.do_request();
        }, &lt;span class=&quot;string&quot;&gt;&quot;json&quot;&lt;/span&gt;);
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It requests the file given in the URL. Waits for it. Looks if there are updates in the answer and then call the function again (recursive loop.)&lt;/p&gt;
&lt;p&gt;That was all the frontend code there is. Pretty small don’t you think? That’s why we are going to put all the logic in the backend.&lt;/p&gt;
&lt;h2 id=&quot;the-backend-&quot;&gt;The backend:&lt;/h2&gt;
&lt;p&gt;To make the backend work I created a small (not that great) update condition: if a certain file on the server contains text; output it and empty the file again.&lt;/p&gt;
&lt;p&gt;Your updates would probably be stored in a database and marked if the user has received them, but that’s up to you. I’ll use this simple case to show you a quick result.&lt;/p&gt;
&lt;p&gt;Create two files in the &lt;code&gt;notification&lt;/code&gt; folder: &lt;code&gt;notification_request.php&lt;/code&gt; and &lt;code&gt;updates.txt&lt;/code&gt;. Also make &lt;code&gt;updates.txt&lt;/code&gt; &lt;em&gt;chmod 777&lt;/em&gt; so PHP can edit that file.&lt;/p&gt;
&lt;p&gt;The PHP script has to do the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Determine the time the script can be put on hold.&lt;/li&gt;
&lt;li&gt;Constantly check if there are changes. If there are any, output the result.&lt;/li&gt;
&lt;li&gt;Wait a short while and check again. If the max time as been reach output an empty result.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The basic code will look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//determine the starting time and the max execution time&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;//set default response&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;while&lt;/span&gt;(&lt;span class=&quot;comment&quot;&gt;/* max time has not been reached */&lt;/span&gt;) {

    &lt;span class=&quot;comment&quot;&gt;//check and determine update&lt;/span&gt;

    &lt;span class=&quot;comment&quot;&gt;//if update is available; output and break script&lt;/span&gt;

    &lt;span class=&quot;comment&quot;&gt;//if not: wait a little and clear the output&lt;/span&gt;
}

&lt;span class=&quot;comment&quot;&gt;//output the default result if there is no update&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To determine the maximum execution time of a PHP script you can get this information from the PHP settings using &lt;code&gt;ini_get&lt;/code&gt;, which can get a lot of information found in &lt;code&gt;phpinfo()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The first part of the script would look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//determine the starting time and the max timeout&lt;/span&gt;
$start_time = time();
$max_timeout = ini_get(&lt;span class=&quot;string&quot;&gt;'max_execution_time'&lt;/span&gt;);

&lt;span class=&quot;comment&quot;&gt;//set default data&lt;/span&gt;
$data = &lt;span class=&quot;keyword&quot;&gt;array&lt;/span&gt;();&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It determines the start time of the request and the maximum time PHP can put the script on hold. Also the default ouput is set (an empty array.)&lt;/p&gt;
&lt;p&gt;Next part contains a bit more code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//go into the loop&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;while&lt;/span&gt;((time() - $start_time) &amp;lt; $max_timeout) {

    &lt;span class=&quot;comment&quot;&gt;//set the updates available to false&lt;/span&gt;
    $update_available = &lt;span class=&quot;keyword&quot;&gt;false&lt;/span&gt;;

    &lt;span class=&quot;comment&quot;&gt;//open the file and get its contents&lt;/span&gt;
    $updates = file_get_contents(&lt;span class=&quot;string&quot;&gt;&quot;updates.txt&quot;&lt;/span&gt;);

    &lt;span class=&quot;comment&quot;&gt;//if there is any content, put it in the output&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (strlen($updates) &amp;gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;) {
        &lt;span class=&quot;comment&quot;&gt;//set update available&lt;/span&gt;
        $update_available = &lt;span class=&quot;keyword&quot;&gt;true&lt;/span&gt;;

        &lt;span class=&quot;comment&quot;&gt;//set updates&lt;/span&gt;
        $data[&lt;span class=&quot;string&quot;&gt;'updates'&lt;/span&gt;] = $updates;

        &lt;span class=&quot;comment&quot;&gt;//empty file&lt;/span&gt;
        file_put_contents(&lt;span class=&quot;string&quot;&gt;&quot;updates.txt&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;&quot;&lt;/span&gt;);
    }

    &lt;span class=&quot;comment&quot;&gt;//if there was an update output it and exit the script&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; ($update_available) {
        &lt;span class=&quot;keyword&quot;&gt;echo&lt;/span&gt; json_encode($data);
        &lt;span class=&quot;keyword&quot;&gt;exit&lt;/span&gt;();
    }

    &lt;span class=&quot;comment&quot;&gt;//go into sleep for a little while and try again&lt;/span&gt;
    sleep(&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;);
    flush();
}

&lt;span class=&quot;comment&quot;&gt;//if there are no updates within the set time: echo the empty result&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;echo&lt;/span&gt; json_encode($data);&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (iam &amp;gt; you &amp;amp;&amp;amp; you &amp;lt; iam) {

}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Simply put, this script will return an update once the the file on the server (“updates.txt”) has contents and gives this to the frontend.&lt;br&gt; If there is no update, it will give the frontend an empty response and the script will do the same request again.&lt;/p&gt;
&lt;p&gt;The frontend script will output the contents of the file once it has been changed on the server, almost instantaneously!&lt;/p&gt;
&lt;p&gt;The following clip will show you this functionality:&lt;/p&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;375&quot; src=&quot;https://player.vimeo.com/video/7160768&quot; width=&quot;500&quot;&gt;&lt;/iframe&gt;

&lt;h2 id=&quot;future-&quot;&gt;Future:&lt;/h2&gt;
&lt;p&gt;Now it’s time to customize the script to meet your needs, not reading a file on the server, but rather getting updates from your database and creating a better output on the frontend side.&lt;/p&gt;
&lt;p&gt;I didn’t make this too fancy because I only wanted to show you another approach to the problem of pushing notifications to the frontend.&lt;br&gt; This example would work perfectly in cooperation with &lt;a href=&quot;https://gaya.pizza/articles/snotify-easy-notifications-in-jquery/&quot;&gt;sNotify, which I made a while ago&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you have any ideas, suggestions and like to discuss this solution, please comment below.&lt;/p&gt;
&lt;p&gt;I hope this helped you in developing an application with notifications and made you look at updating information in another way.&lt;/p&gt;
</description></item><item><title>QueryLoader – preload your website in style</title><link>https://gaya.pizza/articles/queryloader-preload-your-website-in-style/</link><pubDate>Thu, 01 Oct 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/queryloader-preload-your-website-in-style/</guid><author></author><description>&lt;p&gt;There is always a minor problem when it comes to preloading image on a website. Nobody really has a full solution for it. There are a lot of preloaders available, but most of the time they only display the words: “Loading page” or have an animated image that spins. Why can’t there be a nice loading bar of some kind?&lt;br&gt; I’ve gotten a few request on how to make a preloader, or people asking me how to get all the images of a web page and preload them (even the images in CSS).&lt;/p&gt;
&lt;p&gt;This preloader has it all. Loading bar, custom animations and getting all images included in the web page.&lt;/p&gt;
&lt;div style=&quot;background-color: #fcf8bb; text-align: center; margin-bottom: 1.5em; padding: 0.75em;&quot;&gt;[ There is a new version of QueryLoader. Consider this one obselete!](/articles/queryloader2-preload-your-images-with-ease/)&lt;/div&gt;[![QueryLoader - preload your website in style](/articles/queryloader-preload-your-website-in-style/qloader.jpg &quot;QueryLoader - preload your website in style&quot;)](/articles/queryloader-preload-your-website-in-style/)

&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div style=&quot;background-color: #fcf8bb; text-align: center; margin-bottom: 1.5em; padding: 0.75em;&quot;&gt;[ There is a new version of QueryLoader. Consider this one obselete!](/articles/queryloader2-preload-your-images-with-ease/)&lt;/div&gt;(a special shout out goes to Sieb of [Siebdesign](http://www.siebdesign.nl) for coming up with the animation and the idea of building a preloader)

&lt;p&gt;Download the source code here:&lt;br&gt;&lt;a href=&quot;http://gaya.github.io/scripts/queryLoader/queryLoader.zip&quot;&gt;http://gaya.github.io/scripts/queryLoader/queryLoader.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;View the example here:&lt;br&gt;&lt;a href=&quot;http://gaya.github.io/scripts/queryLoader/&quot;&gt;http://gaya.github.io/scripts/queryLoader/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Example with percentage visible:&lt;br&gt;&lt;a href=&quot;http://gaya.github.io/scripts/queryLoaderPercentage/&quot;&gt;http://gaya.github.io/scripts/queryLoaderPercentage/&lt;/a&gt; or download: &lt;a href=&quot;http://gaya.github.io/scripts/queryLoaderPercentage/qL2.zip&quot;&gt;http://gaya.github.io/scripts/queryLoader2/qL2.zip&lt;/a&gt; (thanks to Olivier Dumetz)&lt;/p&gt;
&lt;h2 id=&quot;features-&quot;&gt;Features:&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Preload a whole web page.&lt;/li&gt;
&lt;li&gt;Preload a part of the page.&lt;/li&gt;
&lt;li&gt;Gets all images, &lt;img&gt; tags and background-image of your CSS&lt;/li&gt;
&lt;li&gt;Easy to implement.&lt;/li&gt;
&lt;li&gt;Adjustable loading bar.&lt;/li&gt;
&lt;li&gt;Tested in Firefox, Safari, Opera, Chrome, IE7, IE8 and IE6 (script will be ignored in IE6 though).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;implementation-&quot;&gt;Implementation:&lt;/h2&gt;
&lt;p&gt;To implement this script you don’t need any Javascript experience. Just follow these easy steps:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Download &lt;a href=&quot;http://gaya.github.io/scripts/queryLoader/queryLoader.zip&quot;&gt;the zipped archive&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Upload the contents to your webserver.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; Place the following code in thepart of your page:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/javascript'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;css/queryLoader.css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/css&quot;&lt;/span&gt; /&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/javascript'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'js/queryLoader.js'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Remove the jQuery part if you have already included the file.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt; Place this code at the bottom of your page:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/javascript'&lt;/span&gt;&amp;gt;&lt;/span&gt;
QueryLoader.init();
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You are now done!&lt;/p&gt;
&lt;h2 id=&quot;customization-&quot;&gt;Customization:&lt;/h2&gt;
&lt;p&gt;If you only want one element / container to be preloaded you can setup a jQuery selector to only preload what you want.&lt;/p&gt;
&lt;p&gt;Let’s say you have an element with an id. You only want the images inside that element to be preloaded. You can use the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/javascript'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;actionscript&quot;&gt;
QueryLoader.selectorPreload = &lt;span class=&quot;string&quot;&gt;&quot;#idOfTheElement&quot;&lt;/span&gt;;
QueryLoader.init();
&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Be aware that you can only preload a single element. So using a class selector could cause some problems.&lt;br&gt; To read more about selectors in jQuery you can read &lt;a href=&quot;http://docs.jquery.com/Selectors&quot;&gt;this page in the jQuery docs&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To adjust the animations of the loading bar, you can take a look in the following functions:&lt;br&gt; &lt;code&gt;QueryLoader.animateLoader()&lt;/code&gt; and &lt;code&gt;QueryLoader.doneLoad()&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Adjusting these functions requires a bit of jQuery knowledge.&lt;/p&gt;
&lt;p&gt;Any questions about QueryLoader and implementations can be posted in the comments below.&lt;/p&gt;
&lt;p&gt;Good luck and happy developing.&lt;/p&gt;
</description></item><item><title>Circular InterAction menu</title><link>https://gaya.pizza/articles/circular-interaction-menu/</link><pubDate>Fri, 04 Sep 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/circular-interaction-menu/</guid><author></author><description>&lt;p&gt;It’s time for another jQuery script from Gaya Design. This time I created an interactive menu, which can be used in CMSes, applications or just on your own website.&lt;br&gt; This post will show you how this script works and how to apply it in your own environment.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/circular-interaction-menu/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/circular-interaction-menu/interactionpost.jpg&quot; alt=&quot;Circular InterAction menu&quot; title=&quot;Circular InterAction menu&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Download the source code here: &lt;a href=&quot;http://gaya.github.io/scripts/interaction/interaction.zip&quot;&gt;http://gaya.github.io/scripts/interaction/interaction.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;View the examples here: &lt;a href=&quot;http://gaya.github.io/scripts/interaction/&quot;&gt;http://gaya.github.io/scripts/interaction/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Have you ever run into this problem? You have a nice CMS with a list of items a client can edit, delete, move etc etc. The page becomes kind of cluttered with icons, problem!&lt;br&gt; Not anymore. This script offers a minor solution to that problem. It is a menu that opens once you click on an object of your choice. It loads the options and shows them in a circular way around the center of the object.&lt;br&gt; It took some math and a lot of thinking time, but the menu items seem to be positioning quite well.&lt;/p&gt;
&lt;p&gt;If you take a look at the example, you see that I applied the InterAction script inside a small mini game. It shows that an object can have menu items, that the items can fire actions and that objects can get new sets of actions if needed.&lt;/p&gt;
&lt;h2 id=&quot;getting-started-&quot;&gt;Getting started:&lt;/h2&gt;
&lt;p&gt;First we have to include a few stuff scripts and CSS in the `` tag:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'css/interaction.css'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'stylesheet'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/css'&lt;/span&gt; /&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/javascript'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/interaction.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can leave out the jQuery part if you have it included in your html already.&lt;/p&gt;
&lt;p&gt;Now you need an object on which you to add the menu. I’ll use a sample object:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;plant&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'images/flower.png'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;alt&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;''&lt;/span&gt; /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will serve as our object in this tutorial. Note that you have to have an image &lt;code&gt;flower.png&lt;/code&gt; ready for use ;-)&lt;/p&gt;
&lt;p&gt;To add a menu to this object you’ll only need to execute the following Javascript code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;InterAction.init(&lt;span class=&quot;string&quot;&gt;&quot;#plant&quot;&lt;/span&gt;, &lt;span class=&quot;built_in&quot;&gt;Array&lt;/span&gt;(&lt;span class=&quot;built_in&quot;&gt;Array&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;test option&quot;&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{})));&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These are the method + parameters you have to perform to add a menu to the object. The object is now clickable and there is one menu option with an empty action.&lt;/p&gt;
&lt;p&gt;The first parameter is the selector (use id) you’d use in jQuery. The second parameter is a multidimensional array filled with arrays that contain menu options + their actions.&lt;br&gt; Where the first item in the array is the text in the menu item and the second item the action itself. It is a callback for the menu item once it is clicked.&lt;/p&gt;
&lt;p&gt;To prevent the code from getting cluttered, the second parameter can be set before the &lt;code&gt;InterAction.init()&lt;/code&gt; method is called.&lt;br&gt; I like to separate both this way:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; plantMenu = &lt;span class=&quot;built_in&quot;&gt;Array&lt;/span&gt;(
    &lt;span class=&quot;built_in&quot;&gt;Array&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;Test option&quot;&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
        &lt;span class=&quot;comment&quot;&gt;//you can enter js code here&lt;/span&gt;
    }),
    &lt;span class=&quot;built_in&quot;&gt;Array&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;Test option 2&quot;&lt;/span&gt;, &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
        &lt;span class=&quot;comment&quot;&gt;//you can enter js code here&lt;/span&gt;
    })
);

InterAction.init(&lt;span class=&quot;string&quot;&gt;&quot;#plant&quot;&lt;/span&gt;, plantMenu);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These are the basics of creating a menu with the InterAction script.&lt;/p&gt;
&lt;h2 id=&quot;filling-it-in-&quot;&gt;Filling it in:&lt;/h2&gt;
&lt;p&gt;Have you already noticed that empty actions will not automatically the menu once you’ve clicked on an item?&lt;br&gt; InterAction supports has a few options you can use in the action to make the development process a bit easier.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//this will close the menu&lt;/span&gt;
InterAction.forceClose();

&lt;span class=&quot;comment&quot;&gt;//this contains the html object of the item you just clicked&lt;/span&gt;
InterAction.clickedElement;
&lt;span class=&quot;comment&quot;&gt;//for jQuery:&lt;/span&gt;
$(InterAction.clickedElement);

&lt;span class=&quot;comment&quot;&gt;//dynamically create a new menu for an object:&lt;/span&gt;
InterAction.init(&lt;span class=&quot;string&quot;&gt;&quot;#plant&quot;&lt;/span&gt;, nameOfActionArray); &lt;span class=&quot;comment&quot;&gt;//will replace old menu if one exists&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To change the looks of the menu, you can take a look in the CSS and replace the images of the menu if you want. They are also set in the InterAction.js file.&lt;/p&gt;
&lt;h2 id=&quot;a-quick-example-&quot;&gt;A quick example:&lt;/h2&gt;
&lt;p&gt;The following code will show you how to create an easy InterAction menu:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; plantMenu = &lt;span class=&quot;built_in&quot;&gt;Array&lt;/span&gt;(
    &lt;span class=&quot;built_in&quot;&gt;Array&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;Close menu&quot;&lt;/span&gt;), &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
        InterAction.forceClose();
    },
    &lt;span class=&quot;built_in&quot;&gt;Array&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;Hide me&quot;&lt;/span&gt;), &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
        $(InterAction.clickedElement).fadeOut();
    },
    &lt;span class=&quot;built_in&quot;&gt;Array&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;Create new&quot;&lt;/span&gt;), &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
        InterAction.init(&lt;span class=&quot;string&quot;&gt;&quot;#&quot;&lt;/span&gt; + $(InterAction.clickedElement).attr(&lt;span class=&quot;string&quot;&gt;&quot;id&quot;&lt;/span&gt;), plantMenu);
    }
);

InterAction.init(&lt;span class=&quot;string&quot;&gt;&quot;#plant&quot;&lt;/span&gt;, plantMenu);&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;future-&quot;&gt;Future:&lt;/h2&gt;
&lt;p&gt;I am already creating a standard Javascript file containing actions which are widely used in applications (such as going to an url and manipulating html). If you are creating actions yourself I’d be happy to hear what your ideas are, so I can use them in the future.&lt;/p&gt;
&lt;p&gt;Drop any questions you have in the comments. Happy developing!&lt;/p&gt;
</description></item><item><title>sNotify: Easy notifications in jQuery</title><link>https://gaya.pizza/articles/snotify-easy-notifications-in-jquery/</link><pubDate>Wed, 19  Aug 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/snotify-easy-notifications-in-jquery/</guid><author></author><description>&lt;p&gt;There hasn’t been a jQuery tutorial / script on Gaya Design for a while. This is because I’ve been working on this particular script for a while and have a lot of other scripts in development.&lt;/p&gt;
&lt;p&gt;sNotify is a script which is particularly handy for people who are developing web applications. sNotify allows the developer to display notifications in a fast and easy way.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/snotify-easy-notifications-in-jquery/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/snotify-easy-notifications-in-jquery/snotify.jpg&quot; alt=&quot;sNotify: Easy notifications in jQuery&quot; title=&quot;sNotify: Easy notifications in jQuery&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Download the source code here: &lt;a href=&quot;http://gaya.github.io/scripts/sNotify/sNotify.zip&quot;&gt;http://gaya.github.io/scripts/sNotify/sNotify.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;View the examples here: &lt;a href=&quot;http://gaya.github.io/scripts/sNotify/&quot;&gt;http://gaya.github.io/scripts/sNotify/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The idea for sNotify struck me when I was playing the Sims 3. Its way of notifying the user of important events looked simple but effective. A message box slides in screen from the top right, containing just a small bit of information.&lt;br&gt; The thing I liked most was the way it sorted notifications and displayed them in an orderly way. By this I mean: When there is more than one notification, it displays them one after another.&lt;/p&gt;
&lt;h2 id=&quot;features-&quot;&gt;Features:&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Display notifications in the top right corner of the screen&lt;/li&gt;
&lt;li&gt;Close the message with a click on a button&lt;/li&gt;
&lt;li&gt;Automatically closes messages after 10 seconds (or whatever you’d like)&lt;/li&gt;
&lt;li&gt;Disables auto close when you are hovering over a message&lt;/li&gt;
&lt;li&gt;Puts messages in a queue to display them one after another&lt;/li&gt;
&lt;li&gt;Easy to implement&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;getting-it-to-work-&quot;&gt;Getting it to work:&lt;/h2&gt;
&lt;p&gt;First thing we need to do is to include the script on your web page. Upload the contents of the script somewhere, preferably in the folders you use for CSS and JS.&lt;/p&gt;
&lt;p&gt;Put the following code in the `` section of the page:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'css/sNotify.css'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'stylesheet'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/css'&lt;/span&gt; /&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/javascript'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/sNotify.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can remove the jQuery part if you already included it.&lt;/p&gt;
&lt;p&gt;Now that you’ve included sNotify, you can start to test out the script.&lt;br&gt; Use the following Javascript code to display a message:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/javascript'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;actionscript&quot;&gt;
sNotify.addToQueue(&lt;span class=&quot;string&quot;&gt;&quot;You can add your message here.&quot;&lt;/span&gt;);
&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will display the notification in the first possible cycle of the queue. You are basically putting the message in a queue so that messages won’t get mixed up.&lt;/p&gt;
&lt;p&gt;By doing a simple &lt;code&gt;sNotify.addToQueue&lt;/code&gt; call you can add your messages to the queue, so it is possible to add multiple messages at the same time but it won’t clutter the page:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;sNotify.addToQueue(&lt;span class=&quot;string&quot;&gt;&quot;The first message.&quot;&lt;/span&gt;);
sNotify.addToQueue(&lt;span class=&quot;string&quot;&gt;&quot;The second message.&quot;&lt;/span&gt;);
sNotify.addToQueue(&lt;span class=&quot;string&quot;&gt;&quot;The third message.&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To change the amount of time a message a message stays on screen, use the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;sNotify.timeOpen = &lt;span class=&quot;number&quot;&gt;10&lt;/span&gt;; &lt;span class=&quot;comment&quot;&gt;//change this number to the amount of second you want&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;conclusion-&quot;&gt;Conclusion:&lt;/h2&gt;
&lt;p&gt;It’s that easy!&lt;br&gt; You can edit the CSS to adjust the looks (I guess this is required) according to the looks of your web page. You can also add HTML in the messages to add links or other elements.&lt;/p&gt;
&lt;p&gt;Have fun!&lt;/p&gt;
</description></item><item><title>PHP ORM: Models and PHP Object Generator</title><link>https://gaya.pizza/articles/php-orm-models-and-php-object-generator/</link><pubDate>Mon, 27 Jul 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/php-orm-models-and-php-object-generator/</guid><author></author><description>&lt;p&gt;If you are a developer, especially in the object orientated parts, you must heard of the Model View Controller design pattern.&lt;br&gt; This post will tell you a bit about models and how you can use them to lift your code to a higher level and safe a lot of time in the development process.&lt;br&gt; I will also tell you about &lt;a href=&quot;http://www.phpobjectgenerator.com/&quot;&gt;PHP Object Generator&lt;/a&gt; (POG) to use for implementing your models.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/php-orm-models-and-php-object-generator&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/php-orm-models-and-php-object-generator/postimgpost.jpg&quot; alt=&quot;PHP ORM: Models and PHP Object Generator&quot; title=&quot;PHP ORM: Models and PHP Object Generator&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Models are the application’s place for storing information. If you have your model right, the application tends to work out better than applications without models.&lt;br&gt; In the model you can store properties of all your objects (tables) and apply rules to them.&lt;/p&gt;
&lt;h2 id=&quot;making-the-model&quot;&gt;Making the model&lt;/h2&gt;
&lt;p&gt;To make a model all you need is some paper and a pen. But if you prefer software, there are a lot of tools around that enable you to make your own Physical Data Model. These tools also have some reverse engineering options and code generation possibilities. I use: &lt;a href=&quot;http://www.sybase.nl/products/modelingdevelopment/powerdesigner&quot;&gt;PowerDesigner&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The good thing about models is that you can use them to implement ORM in your PHP application. Models are also needed if you want to develop an application in a framework like CakePHP. ORM has been made to decouple the controller and model, so it doesn’t really matter where the information is saved, but rather that it will be saved. ORM will create the connection to the database and persist the object with the data source of choice.&lt;/p&gt;
&lt;p&gt;Let’s say we want to make a small web application for a client to save some information. We will create a small application for a small real estate company who offers homes in the region.&lt;br&gt; The client explains the following: “We offer homes in a certain region to our visitors. A home has information about its sizes and price etc. A home is inside a town, and the town is inside a region.”&lt;br&gt; This information is enough to start drawing your first model. We don’t know very much, but the basics of the model can now be made. I got the following with only the information given above:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/php-orm-models-and-php-object-generator/pogimg1.jpg&quot; alt=&quot;pogimg1&quot; title=&quot;pogimg1&quot;&gt;&lt;/p&gt;
&lt;p&gt;What it basically says is: “There is a region, it contains a town. A town contains a home.”&lt;/p&gt;
&lt;p&gt;We also know there can be more towns in a region, and that a town has zero or more homes. Let’s add that in the model:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/php-orm-models-and-php-object-generator/pogimg2.jpg&quot; alt=&quot;pogimg2&quot; title=&quot;pogimg2&quot;&gt;&lt;/p&gt;
&lt;p&gt;You are now thinking object oriented, so this makes it quiet easier for developers to understand how their application will work.&lt;/p&gt;
&lt;p&gt;As you might note, there are no properties for these objects yet. Let’s say a region has a name and a description, the town and homes too. The only thing different is that the homes hold a lot more information like: the price, lot size, object size, build year etc.&lt;/p&gt;
&lt;p&gt;With a few properties included, the model looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/php-orm-models-and-php-object-generator/pogimg3.jpg&quot; alt=&quot;pogimg3&quot; title=&quot;pogimg3&quot;&gt;&lt;/p&gt;
&lt;p&gt;I hope this gives a clear view of what a model is to people who’ve never heard of them.&lt;/p&gt;
&lt;p&gt;As you can see I already wrote the data types of the properties of the objects, this is to make sure you remember what goes in the field and you can also put a few restraints on the fields by doing this.&lt;br&gt; I used the {objectname}Id field because POG will generate objects with that field as the key. You don’t have to do this, but it makes your model look better and the software modeling tools might require you to do this.&lt;/p&gt;
&lt;p&gt;Let’s move on to implementing the model inside your PHP application.&lt;/p&gt;
&lt;h2 id=&quot;implementing-models-inside-php&quot;&gt;Implementing models inside PHP&lt;/h2&gt;
&lt;p&gt;I was looking for an easy way to implement ORM inside a PHP application without using a very large framework. I only needed a solution that knew what my model was and does the persistence with the database at the same time.&lt;br&gt; That’s when I found PHP Object Generator (&lt;a href=&quot;http://www.phpobjectgenerator.com/&quot;&gt;http://www.phpobjectgenerator.com/&lt;/a&gt;), a project which is easy to use and easy to implement.&lt;br&gt; It’s not recommended to use this for super huge projects, but POG is quiet scalable, clean, contains CRUD methods (Create, Read, Update and Delete) for the objects, extensible with plugins and open source.&lt;/p&gt;
&lt;p&gt;First thing you need to do is to create the objects we have just defined in our model. Take a look at the following image:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/php-orm-models-and-php-object-generator/Picture-2.png&quot; alt=&quot;Picture 2&quot; title=&quot;Picture 2&quot;&gt;&lt;/p&gt;
&lt;p&gt;This will generate the code for the region object. Note that I set “Town” as its child, this is also defined in the model, so don’t forget this! Click submit and wait until the next screen comes.&lt;/p&gt;
&lt;p&gt;Choose to download the zip, this contains the POG code base and the object you just generated. Unzip and upload the contents to your server.&lt;/p&gt;
&lt;p&gt;Now it’s time to make an object for “Town”.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/php-orm-models-and-php-object-generator/Picture-3.png&quot; alt=&quot;Picture 3&quot; title=&quot;Picture 3&quot;&gt;&lt;/p&gt;
&lt;p&gt;I’ve set “Region” as its parent and added “Home” as its child. Click submit again.&lt;/p&gt;
&lt;p&gt;All you need to do is create a new file in a text editor and copy paste the code that in the text area that just came up.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/php-orm-models-and-php-object-generator/Picture-4.png&quot; alt=&quot;Picture 4&quot; title=&quot;Picture 4&quot;&gt;&lt;/p&gt;
&lt;p&gt;Save the file as “class.town.php” inside the &lt;em&gt;/objects/&lt;/em&gt; folder.&lt;/p&gt;
&lt;p&gt;Do the same for the “Home” object:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/php-orm-models-and-php-object-generator/Picture-6.png&quot; alt=&quot;Picture 6&quot; title=&quot;Picture 6&quot;&gt;&lt;/p&gt;
&lt;p&gt;Now that we’ve got our objects ready it’s time to use POG and do some actions.&lt;/p&gt;
&lt;h2 id=&quot;using-pog-in-php&quot;&gt;Using POG in PHP&lt;/h2&gt;
&lt;p&gt;If you have all your files uploaded the folder structure should look something like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/php-orm-models-and-php-object-generator/Picture-7.png&quot; alt=&quot;Picture 7&quot; title=&quot;Picture 7&quot;&gt;&lt;/p&gt;
&lt;p&gt;Now it’s time to change the configuration of POG, this contains the database connection.&lt;br&gt; Open &lt;em&gt;configuration.example.php&lt;/em&gt; and edit the following information:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;$configuration[&lt;span class=&quot;string&quot;&gt;'db'&lt;/span&gt;] = &lt;span class=&quot;string&quot;&gt;'test'&lt;/span&gt;; &lt;span class=&quot;comment&quot;&gt;// database name&lt;/span&gt;
$configuration[&lt;span class=&quot;string&quot;&gt;'host'&lt;/span&gt;] = &lt;span class=&quot;string&quot;&gt;'localhost'&lt;/span&gt;; &lt;span class=&quot;comment&quot;&gt;// database host&lt;/span&gt;
$configuration[&lt;span class=&quot;string&quot;&gt;'user'&lt;/span&gt;] = &lt;span class=&quot;string&quot;&gt;'root'&lt;/span&gt;; &lt;span class=&quot;comment&quot;&gt;// database user&lt;/span&gt;
$configuration[&lt;span class=&quot;string&quot;&gt;'pass'&lt;/span&gt;] = &lt;span class=&quot;string&quot;&gt;'pass'&lt;/span&gt;; &lt;span class=&quot;comment&quot;&gt;// database password&lt;/span&gt;
$configuration[&lt;span class=&quot;string&quot;&gt;'port'&lt;/span&gt;] = &lt;span class=&quot;string&quot;&gt;'3306'&lt;/span&gt;; &lt;span class=&quot;comment&quot;&gt;// database port&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and also:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//plugin settings&lt;/span&gt;
$configuration[&lt;span class=&quot;string&quot;&gt;'plugins_path'&lt;/span&gt;] = &lt;span class=&quot;string&quot;&gt;''&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you don’t know the full path to the plugins folder, you can try &lt;code&gt;phpinfo()&lt;/code&gt; and search for “document_root”. Add “/plugins” to this variable (without a slash at the end.)&lt;/p&gt;
&lt;p&gt;Save this file as “configuration.php” and upload it to the server.&lt;/p&gt;
&lt;p&gt;Next thing we need to do is use POG to create our tables in the database. In your web browser; go to the root of the application and add /setup at the end of the URL. Click on “POG me up!” and you should see the following:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://gaya.pizza/articles/php-orm-models-and-php-object-generator/Picture-8-300x251.png&quot; alt=&quot;Picture 8&quot; title=&quot;Picture 8&quot;&gt;&lt;/p&gt;
&lt;p&gt;Yay! It worked! Basically, we can now start to use POG in our application, so let’s do that.&lt;/p&gt;
&lt;p&gt;Let’s create a small test script to see how POG works and what it can do.&lt;br&gt; Create a file in the root called “test.php”. Add the following lines of code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;include&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'configuration.php'&lt;/span&gt;);
&lt;span class=&quot;keyword&quot;&gt;include&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'objects/class.database.php'&lt;/span&gt;);

&lt;span class=&quot;keyword&quot;&gt;include&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'objects/class.region.php'&lt;/span&gt;);
&lt;span class=&quot;keyword&quot;&gt;include&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'objects/class.town.php'&lt;/span&gt;);
&lt;span class=&quot;keyword&quot;&gt;include&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'objects/class.home.php'&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will include all the necessary files needed to make POG work and include the classes we’ve made.&lt;/p&gt;
&lt;p&gt;In the next piece of code I am going to create a region, give it a name and a description, create a town that belongs to that region and put a home inside the town.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//create a region&lt;/span&gt;
$region = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; Region();

$region-&amp;gt;name = &lt;span class=&quot;string&quot;&gt;'Super region'&lt;/span&gt;;
$region-&amp;gt;description = &lt;span class=&quot;string&quot;&gt;'We are in love with this region!'&lt;/span&gt;;

$region-&amp;gt;Save();

&lt;span class=&quot;comment&quot;&gt;//create a town&lt;/span&gt;
$town = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; Town();

$town-&amp;gt;name = &lt;span class=&quot;string&quot;&gt;'Townsville'&lt;/span&gt;;
$town-&amp;gt;description = &lt;span class=&quot;string&quot;&gt;'We don'&lt;/span&gt;t need a description.&lt;span class=&quot;string&quot;&gt;';
$town-&amp;gt;SetRegion($region);

$town-&amp;gt;Save();

//create a home
$home = new Home();

$home-&amp;gt;name = '&lt;/span&gt;Superstreet &lt;span class=&quot;number&quot;&gt;29&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;';
$home-&amp;gt;description = '&lt;/span&gt;A house with a lot of windows.&lt;span class=&quot;string&quot;&gt;';
$home-&amp;gt;objectSize = '&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;';
$home-&amp;gt;lotSize = '&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;120&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;';
$home-&amp;gt;price = '&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;100000&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;';
$home-&amp;gt;buildYear = '&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;2008&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;';
$home-&amp;gt;SetTown($town);

$home-&amp;gt;Save();&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Take a look at your database. All the information has been saved and the objects have been linked to each other.&lt;br&gt; Neat isn’t it?&lt;/p&gt;
&lt;p&gt;In a later post I’ll explain how to use POG for getting information and build your own content management system around it. This article was an introduction to models and ORM. I hope you enjoyed it and if you have any thoughts or other frameworks / applications that do the same: let me know in the comments.&lt;/p&gt;
</description></item><item><title>WordPress Plugin: Mark as Read</title><link>https://gaya.pizza/articles/wordpress-plugin-mark-as-read/</link><pubDate>Tue, 09 Jun 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/wordpress-plugin-mark-as-read/</guid><author></author><description>&lt;p&gt;For the first time ever I created my own plugin. Starting out as a hacking attempt, it quickly changed into a prototype plugin.&lt;/p&gt;
&lt;p&gt;What it basically does is list the articles that haven’t been read yet by a logged in user. Whenever a change to the post is made or a new comment is posted, the post moves to the top of the unread list.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/wordpress-plugin-mark-as-read/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/wordpress-plugin-mark-as-read/markasread.jpg&quot; alt=&quot;WordPress Plugin: Mark as Read&quot; title=&quot;WordPress Plugin: Mark as Read&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;functionality-&quot;&gt;Functionality:&lt;/h2&gt;
&lt;p&gt;Mark as Read makes it easy for your users to keep track of changes on your blog. Whenever a post is published or updated the post will show up in this list. When a new comment is posted, the post will also go up in this list and will be marked as “unread”.&lt;/p&gt;
&lt;h2 id=&quot;features-&quot;&gt;Features:&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Keeps track of which articles a logged in user has read.&lt;/li&gt;
&lt;li&gt;Posts bump on new comments&lt;/li&gt;
&lt;li&gt;Posts bump on published / updates&lt;/li&gt;
&lt;li&gt;Customizable output&lt;/li&gt;
&lt;li&gt;Lists per category or all categories&lt;/li&gt;
&lt;li&gt;Usable non-output functions&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;installation-&quot;&gt;Installation:&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Download the plugin&lt;/li&gt;
&lt;li&gt;Upload contents of the zip-archive (the folder) to the plugin directory of your WordPress installation (default: wp-content/plugins/)&lt;/li&gt;
&lt;li&gt;Enable the plugin through the plugin admin panel&lt;/li&gt;
&lt;li&gt;Paste code inside template file&lt;/li&gt;
&lt;li&gt;Enjoy!&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;usage-&quot;&gt;Usage:&lt;/h2&gt;
&lt;p&gt;To output the list all you need to do is to put the following code inside a template file of your theme:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&amp;lt;ul&amp;gt;
    &lt;span class=&quot;meta&quot;&gt;&amp;lt;?php&lt;/span&gt; the_unread_posts(); &lt;span class=&quot;meta&quot;&gt;?&amp;gt;&lt;/span&gt;
&amp;lt;/ul&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will output all the unread content of &lt;strong&gt;all&lt;/strong&gt; categories.&lt;/p&gt;
&lt;p&gt;The following parameters are accepted:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;the_unread_posts($categoryID, $noPostsMessage, $updateText, $rowStyle);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;$categoryID&lt;/strong&gt; (Optional, default: *”all”*):&lt;br&gt; Supply this parameter if you want to show unread messages from one category only. Give the string “all” if you want to display all categories.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;$noPostsMessage&lt;/strong&gt; (Optional, default: *”&lt;li&gt;No unread posts&lt;/li&gt;“*):&lt;br&gt; Sets the output of an empty list.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;$updateText&lt;/strong&gt; (Optional, default: &lt;em&gt;array(“New comment(s) and changes”, “Changes”, “New comment(s)”)&lt;/em&gt;):&lt;br&gt; Sets the output of the different types. Give an array with 3 values; first one being the output when a post has new comments and is updated, second for updates only and third for new comments only.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;$rowStyle&lt;/strong&gt; (Optional, default: *”&lt;li&gt;&lt;a href='%link%'&gt;%type% on: %title%&lt;/a&gt;&lt;/li&gt;“&lt;em&gt;):&lt;br&gt; The HTML in which each post has to be shown. Use *&lt;/em&gt;%link%** to insert a permalink to the post, &lt;strong&gt;%title%&lt;/strong&gt; for the post title and &lt;strong&gt;%type%&lt;/strong&gt; for the type of change.&lt;/p&gt;
</description></item><item><title>Puffing Smoke Effect in jQuery</title><link>https://gaya.pizza/articles/puffing-smoke-effect-in-jquery/</link><pubDate>Tue, 26 May 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/puffing-smoke-effect-in-jquery/</guid><author></author><description>&lt;p&gt;Since the launch of the new looks, I’ve been getting some requests on how to make the puffing smoke effect that you can see in the header.&lt;/p&gt;
&lt;p&gt;Thinking it might be a funny effect, I’d like to take this opportunity to discuss this effect.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/puffing-smoke-effect-in-jquery/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/puffing-smoke-effect-in-jquery/puffingsmoke.jpg&quot; alt=&quot;Puffing Smoke Effect in jQuery&quot; title=&quot;Puffing Smoke Effect in jQuery&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Download the source code here: &lt;a href=&quot;http://gaya.github.io/scripts/smokeeffect/smokeEffect.zip&quot;&gt;http://gaya.github.io/scripts/smokeeffect/smokeEffect.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;View the examples here: &lt;a href=&quot;http://gaya.github.io/scripts/smokeeffect/&quot;&gt;http://gaya.github.io/scripts/smokeeffect/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As you can see on the example page, you can selected different types of smoke that will adjust the effect while keeping the code intact.&lt;/p&gt;
&lt;p&gt;Creating this fun jQuery effect doesn’t take too much effort. I am going to quickly go through the steps of using this effect to show you how easy it can be.&lt;/p&gt;
&lt;h2 id=&quot;usage&quot;&gt;Usage&lt;/h2&gt;
&lt;p&gt;Using this script takes just a few small steps. Enter the following code in the  section of your HTML page (remove jQuery if you already included that):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'css/smokePuff.css'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'stylesheet'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/css'&lt;/span&gt; /&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/javascript'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/smokeEffect.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next up is to put something in the page that will puff the smoke, I used the chimney from my home page. Include the following in your HTML:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;smokeSpawnPoint&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'uri to your image'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;alt&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'chimney'&lt;/span&gt; /&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now it’s time to make the Javascript call and set up the smoke.&lt;/p&gt;
&lt;p&gt;First we’re going to set the URI to the smoke / cloud image and the size in pixels.&lt;br&gt; Place this after the HTML from above:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/javascript'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;actionscript&quot;&gt;
    SmokeEffect.imgLocation = &lt;span class=&quot;string&quot;&gt;&quot;http://www.yoursite.com/images/smoke.png&quot;&lt;/span&gt;;
    SmokeEffect.smokeWidth = &lt;span class=&quot;number&quot;&gt;100&lt;/span&gt;;
    SmokeEffect.smokeHeight = &lt;span class=&quot;number&quot;&gt;100&lt;/span&gt;;
&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Make sure the values match your smoke image. The smoke image is preferably a PNG image to make the effect look better and to be able to see the background. If you have a solid colour background, you can also use other formats.&lt;/p&gt;
&lt;p&gt;Now start up the script by including the following code in the same &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;SmokeEffect.makeEffect(&lt;span class=&quot;string&quot;&gt;&quot;smokeSpawnPoint&quot;&lt;/span&gt;, &lt;span class=&quot;number&quot;&gt;24&lt;/span&gt;, &lt;span class=&quot;number&quot;&gt;12&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first parameter is the id of the element the smoke has to come from. The next 2 are the position from the top-left of the element where the smoke has to start. First is X then Y.&lt;/p&gt;
&lt;p&gt;So if you have an image of a chimney like me, the starting point is 24px to the right and 12px down from the top-left. Play with the values to get it right.&lt;/p&gt;
&lt;p&gt;And that’s it! Another easy effect on your web page!&lt;/p&gt;
&lt;h2 id=&quot;extra-&quot;&gt;Extra!&lt;/h2&gt;
&lt;p&gt;If you want to change the kind of smoke coming out of the spawn point you can use this code to change it into another image:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;SmokeEffect.imgLocation = &lt;span class=&quot;string&quot;&gt;&quot;http://www.yoursite.com/images/otherSmoke.png&quot;&lt;/span&gt;;
SmokeEffect.smokeWidth = &lt;span class=&quot;number&quot;&gt;90&lt;/span&gt;;
SmokeEffect.smokeHeight = &lt;span class=&quot;number&quot;&gt;70&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can change this dynamically whenever you want.&lt;/p&gt;
&lt;p&gt;Good luck!&lt;/p&gt;
</description></item><item><title>Caching external data in PHP</title><link>https://gaya.pizza/articles/caching-external-data-in-php/</link><pubDate>Thu, 14 May 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/caching-external-data-in-php/</guid><author></author><description>&lt;p&gt;Caching data. If you are a developer you must have heard about it somewhere. Is it really that important? There is only one thing I can say to that: yes!&lt;br&gt; There are a lot of reasons why you should start caching data that has been calculated. The most common reason is to keep the owner of the data happy, saving him/her bandwidth and server capacity.&lt;/p&gt;
&lt;p&gt;In this article I will be telling you how to cache data given from an external service, but can also be used to save local results.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/caching-external-data-in-php/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/caching-external-data-in-php/cachingpost.jpg&quot; alt=&quot;Caching external data in PHP&quot; title=&quot;Caching external data in PHP&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Caching is also important for you! It can speed up your scripts and won’t bug your visitors with long loading times (which will get them walking.)&lt;br&gt; Imagine this: You have a very nice script which is very powerful but takes a while to load, since it calculates a whole lot of stuff. This action would take up about 4 seconds. Maybe it’s time to question if this action is really necessary every time a page is loaded, will this data fluctuate that much?&lt;/p&gt;
&lt;p&gt;A great example of this problem is getting when you are getting your data from an external service. This will always require an other server to respond to your needs, slowing down the script. Wouldn’t it be better to get the information you need and save it on your server for the times you need that data?&lt;/p&gt;
&lt;p&gt;There is also something else to keep in mind: How many times is the data updated and how many times do I need to refresh this data? If you are loading a list of things going on right at this moment, then you might not want to cache anything, for the information is real time. But if you want, let’s say, a weekly report on something. Then obviously you only need to update this data once a week.&lt;/p&gt;
&lt;p&gt;To explain how to create your own caching method I am going to use &lt;a href=&quot;http://www.last.fm/api/show?service=281&quot;&gt;another Last.fm API function&lt;/a&gt;. We are going to save last weeks favorite artist of a user and refresh this data once a week.&lt;/p&gt;
&lt;h2 id=&quot;getting-the-data-to-work-with&quot;&gt;Getting the data to work with&lt;/h2&gt;
&lt;p&gt;First things first: create a folder using any FTP application. Make sure this folder is writable. I put a folder called “cache” in the root of my script folder. Make sure this folder is writable and readable for PHP, most people just CHMOD the folder to 777.&lt;br&gt; We’ll be writing our cached data in this folder. Also create the file you’ll be caching too, I used an empty file called “lastfm.xml”. Be sure to make it read and writable.&lt;/p&gt;
&lt;p&gt;Next you want to go and grab any service you’d like. an XML provider, an RSS feed or even your own script. It doesn’t matter what you are caching. In this tutorial I am going to work with an XML providing service.&lt;/p&gt;
&lt;p&gt;Next up is to create a new PHP class which is going to handle our caching and the gathering of data. Let’s create the class to do this for us. I created a file called “Caching.php” for the class to go in.&lt;/p&gt;
&lt;p&gt;Take a look at this skeleton:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;meta&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;/*
* Caching A small PHP class to
*/&lt;/span&gt;

&lt;span class=&quot;class&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;Caching&lt;/span&gt; &lt;/span&gt;{

    &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; $filePath = &lt;span class=&quot;string&quot;&gt;&quot;&quot;&lt;/span&gt;;
    &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; $apiURI = &lt;span class=&quot;string&quot;&gt;&quot;&quot;&lt;/span&gt;;

    &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;__construct&lt;/span&gt;&lt;span class=&quot;params&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{

    }

    &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;checkForRenewal&lt;/span&gt;&lt;span class=&quot;params&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{

    }

    &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;getExternalInfo&lt;/span&gt;&lt;span class=&quot;params&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{

    }

    &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;stripAndSaveFile&lt;/span&gt;&lt;span class=&quot;params&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{

    }

}
&lt;span class=&quot;meta&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This piece of code will serve as the foundation of our class which will cache our information. We’ll be filling up each function step by step.&lt;/p&gt;
&lt;p&gt;First we need a constructor which will accept the path to the file and a URI to the API. In this case, the XML data can be requested by only calling an URL.&lt;br&gt; The constructor will be executed the moment you instantiate the class.&lt;br&gt; A few things we’ll be doing in this function are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Check the input variables.&lt;/li&gt;
&lt;li&gt;Check if the local file needs to be updated.&lt;/li&gt;
&lt;li&gt;Get new data if refresh is needed and save it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I’ve set up the following piece of code for the constructor:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;__construct&lt;/span&gt;&lt;span class=&quot;params&quot;&gt;($filePath, $apiURI)&lt;/span&gt; &lt;/span&gt;{
    &lt;span class=&quot;comment&quot;&gt;//check if the file path and api URI are specified, if not: break out of construct.&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (strlen($filePath) &amp;gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; strlen($apiURI) &amp;gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;) {
        &lt;span class=&quot;comment&quot;&gt;//set the local file path and api path&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;filePath = $filePath;
        &lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;apiURI = $apiURI;

        &lt;span class=&quot;comment&quot;&gt;//does the file need to be updated?&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;checkForRenewal()) {

            &lt;span class=&quot;comment&quot;&gt;//get the data you need&lt;/span&gt;
            $xml = &lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;getExternalInfo();

            &lt;span class=&quot;comment&quot;&gt;//save the data to your file&lt;/span&gt;
            &lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;stripAndSaveFile($xml);

        } &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; {
            &lt;span class=&quot;comment&quot;&gt;//no need to update the file&lt;/span&gt;
            &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;true&lt;/span&gt;;
        }

    } &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; {
        &lt;span class=&quot;keyword&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&quot;No file path and / or api URI specified.&quot;&lt;/span&gt;;
        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;false&lt;/span&gt;;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The process of this function is quiet self explanatory. So now we need to go and enable all the function calls within the constructor.&lt;/p&gt;
&lt;h2 id=&quot;making-the-functions-work&quot;&gt;Making the functions work&lt;/h2&gt;
&lt;p&gt;First up is the time check called “checkForRenewal”. In this function we’ll be checking the file that has been set in the constructor and see if the last adjusted time has been a week ago. To accomplish this, we are going to compare the times using time() and filemtime(). These methods are extremely easy to use and can add any given amount of seconds to the time, which we need to check whether the file is a week old.&lt;/p&gt;
&lt;p&gt;Use the following code for the “checkForRenewal” function:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;checkForRenewal&lt;/span&gt;&lt;span class=&quot;params&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
    &lt;span class=&quot;comment&quot;&gt;//set the caching time (in seconds)&lt;/span&gt;
    $cachetime = (&lt;span class=&quot;number&quot;&gt;60&lt;/span&gt; * &lt;span class=&quot;number&quot;&gt;60&lt;/span&gt; * &lt;span class=&quot;number&quot;&gt;24&lt;/span&gt; * &lt;span class=&quot;number&quot;&gt;7&lt;/span&gt;); &lt;span class=&quot;comment&quot;&gt;//one week&lt;/span&gt;

    &lt;span class=&quot;comment&quot;&gt;//get the file time&lt;/span&gt;
    $filetimemod = filemtime(&lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;filePath) + $cachetime;

    &lt;span class=&quot;comment&quot;&gt;//if the renewal date is smaller than now, return true; else false (no need for update)&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; ($filetimemod &amp;lt; time()) {
        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;true&lt;/span&gt;;
    } &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; {
        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;false&lt;/span&gt;;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What this function does is get the time which the file was last modified and add the set seconds to it and see if that time is smaller than now. The cache time is defined in second, so 60 seconds * 60 minutes * 24 hours * 7 days would make a week worth of seconds. You can adjust this to any given time you want. &lt;em&gt;For debugging I suggest setting the time to only 60 seconds.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The next function will be how to get the external of the URI we specified in the constructor. I’ve written a post about &lt;a href=&quot;https://gaya.pizza/articles/reading-xml-with-php/&quot;&gt;how to read XML in PHP&lt;/a&gt; before, so I’ll go over this function very briefly.&lt;/p&gt;
&lt;h2 id=&quot;reading-the-xml-and-saving-it&quot;&gt;Reading the XML and saving it&lt;/h2&gt;
&lt;p&gt;In getExternalInfo() we are going to make the API call and just return the result as an XML set.&lt;/p&gt;
&lt;p&gt;Take a look at the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;getExternalInfo&lt;/span&gt;&lt;span class=&quot;params&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; ($xml = @simplexml_load_file(&lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;apiURI)) {
        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; $xml;
    } &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; {
        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;false&lt;/span&gt;;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This must have been one of the shortest PHP function I ever wrote, this is all you need to do in order to get the XML you want (if the service provides XML through just doing simple URI calls.)&lt;/p&gt;
&lt;p&gt;Next up is going through the XML and only keeping parts you want to save in your XML file.&lt;/p&gt;
&lt;p&gt;Again: going to skip through some parts of the next function because you can &lt;a href=&quot;https://gaya.pizza/articles/reading-xml-with-php/&quot;&gt;read more about reading xml in an older article&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Looking at &lt;a href=&quot;http://ws.audioscrobbler.com/2.0/?method=user.getweeklyartistchart&amp;amp;user=xgayax&amp;amp;api_key=b25b959554ed76058ac220b7b2e0a026&quot;&gt;the XML returned by Last.fm&lt;/a&gt; I saw the first problem: unnecessary information. The name of the artist and play count are the only things I am interested in. Mbid? Don’t need that. Url? Not this time!&lt;br&gt; So the next function, “stripAndSaveFile”, will make us read XML, create our own and save it to a file. Sounds simple enough right?&lt;/p&gt;
&lt;p&gt;Take a look at what I wrote:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;stripAndSaveFile&lt;/span&gt;&lt;span class=&quot;params&quot;&gt;($xml)&lt;/span&gt; &lt;/span&gt;{
    &lt;span class=&quot;comment&quot;&gt;//put the artists in an array&lt;/span&gt;
    $artists = $xml-&amp;gt;weeklyartistchart-&amp;gt;artist;

    &lt;span class=&quot;comment&quot;&gt;//building the xml object for SimpleXML&lt;/span&gt;
    $output = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; SimpleXMLElement(&lt;span class=&quot;string&quot;&gt;&quot;&amp;lt;artists&amp;gt;&amp;lt;/artists&amp;gt;&quot;&lt;/span&gt;);

    &lt;span class=&quot;comment&quot;&gt;//get only the top 10&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; ($i = &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;; $i &amp;lt; &lt;span class=&quot;number&quot;&gt;10&lt;/span&gt;; $i++) {

        &lt;span class=&quot;comment&quot;&gt;//create a new artist&lt;/span&gt;
        $insert = $output-&amp;gt;addChild(&lt;span class=&quot;string&quot;&gt;&quot;artist&quot;&lt;/span&gt;);

        &lt;span class=&quot;comment&quot;&gt;//insert name and playcount childs to the artist&lt;/span&gt;
        $insert-&amp;gt;addChild(&lt;span class=&quot;string&quot;&gt;&quot;name&quot;&lt;/span&gt;, $artists[$i]-&amp;gt;name);
        $insert-&amp;gt;addChild(&lt;span class=&quot;string&quot;&gt;&quot;playcount&quot;&lt;/span&gt;, $artists[$i]-&amp;gt;playcount);
    }

    &lt;span class=&quot;comment&quot;&gt;//save the xml in the cache&lt;/span&gt;
    file_put_contents(&lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;filePath, $output-&amp;gt;asXML());
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;First thing it does is put the node inside a new variable to keep everything readable. The next lines are to create a new SimpleXML object you can work with.&lt;br&gt; new SimpleXMLElement(“”) means that I just created an XML document with as the root element. We’ll be filling up this element with elements. Sounds logical? It sure does!&lt;/p&gt;
&lt;p&gt;In the the loop that comes next we’re looping through the first ten entries and create a new artist for every time you are in the loop.&lt;/p&gt;
&lt;p&gt;$insert is a new node that will be inserted into the root. The and nodes are also inserted into the node with the information we got from the XML.&lt;/p&gt;
&lt;p&gt;Pfew! Now it’s time to save the file on your file system! Which is the last line in this function. It will export the XML as a string and save it in the file.&lt;/p&gt;
&lt;h2 id=&quot;making-the-call-&quot;&gt;Making the call!&lt;/h2&gt;
&lt;p&gt;Up until now we haven’t called the function once. So create a new script and put the following code in it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;meta&quot;&gt;&amp;lt;?php&lt;/span&gt;
ini_set(&lt;span class=&quot;string&quot;&gt;'display_errors'&lt;/span&gt;, &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;);
error_reporting(E_ALL);

&lt;span class=&quot;keyword&quot;&gt;include&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'Caching.php'&lt;/span&gt;);
$caching = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; Caching(&lt;span class=&quot;string&quot;&gt;&quot;cache/lastfm.xml&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;http://ws.audioscrobbler.com/2.0/?method=user.getweeklyartistchart&amp;amp;user=xgayax&amp;amp;api_key=b25b959554ed76058ac220b7b2e0a026&quot;&lt;/span&gt;);
&lt;span class=&quot;meta&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I’ve put the first two lines in to ensure errors will be shown. If you have that by default; feel free to remove these lines.&lt;br&gt; Next is including the class file and then make a new instance of the class, giving the two required parameters: The path to the cache XML and the URL to the Last.fm API.&lt;/p&gt;
&lt;p&gt;You won’t see anything if it’s correct. Now check out your cache to see if your XML is saved.&lt;/p&gt;
&lt;p&gt;Congratulations! You just cached some information.&lt;/p&gt;
&lt;h3 id=&quot;the-source&quot;&gt;The source&lt;/h3&gt;
&lt;p&gt;Missed anything? Here is the source in it’s full galore!&lt;/p&gt;
&lt;p&gt;The Caching class:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;meta&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;/*
* Caching A small PHP class to get data from Last.fm and cache it
* Author: Gaya Kessler
* URL: http://www.gayadesign.com/
*/&lt;/span&gt;

&lt;span class=&quot;class&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;Caching&lt;/span&gt; &lt;/span&gt;{

    &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; $filePath = &lt;span class=&quot;string&quot;&gt;&quot;&quot;&lt;/span&gt;;
    &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; $apiURI = &lt;span class=&quot;string&quot;&gt;&quot;&quot;&lt;/span&gt;;

    &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;__construct&lt;/span&gt;&lt;span class=&quot;params&quot;&gt;($filePath, $apiURI)&lt;/span&gt; &lt;/span&gt;{
        &lt;span class=&quot;comment&quot;&gt;//check if the file path and api URI are specified, if not: break out of construct.&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (strlen($filePath) &amp;gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; strlen($apiURI) &amp;gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;) {
            &lt;span class=&quot;comment&quot;&gt;//set the local file path and api path&lt;/span&gt;
            &lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;filePath = $filePath;
            &lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;apiURI = $apiURI;

            &lt;span class=&quot;comment&quot;&gt;//does the file need to be updated?&lt;/span&gt;
            &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;checkForRenewal()) {

                &lt;span class=&quot;comment&quot;&gt;//get the data you need&lt;/span&gt;
                $xml = &lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;getExternalInfo();

                &lt;span class=&quot;comment&quot;&gt;//save the data to your file&lt;/span&gt;
                &lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;stripAndSaveFile($xml);

                &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;true&lt;/span&gt;;
            } &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; {
                &lt;span class=&quot;comment&quot;&gt;//no need to update the file&lt;/span&gt;
                &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;true&lt;/span&gt;;
            }

        } &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; {
            &lt;span class=&quot;keyword&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&quot;No file path and / or api URI specified.&quot;&lt;/span&gt;;
            &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;false&lt;/span&gt;;
        }
    }

    &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;checkForRenewal&lt;/span&gt;&lt;span class=&quot;params&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
        &lt;span class=&quot;comment&quot;&gt;//set the caching time (in seconds)&lt;/span&gt;
        $cachetime = (&lt;span class=&quot;number&quot;&gt;60&lt;/span&gt; * &lt;span class=&quot;number&quot;&gt;60&lt;/span&gt; * &lt;span class=&quot;number&quot;&gt;24&lt;/span&gt; * &lt;span class=&quot;number&quot;&gt;7&lt;/span&gt;); &lt;span class=&quot;comment&quot;&gt;//one week&lt;/span&gt;

        &lt;span class=&quot;comment&quot;&gt;//get the file time&lt;/span&gt;
        $filetimemod = filemtime(&lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;filePath) + $cachetime;

        &lt;span class=&quot;comment&quot;&gt;//if the renewal date is smaller than now, return true; else false (no need for update)&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; ($filetimemod &amp;lt; time()) {
            &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;true&lt;/span&gt;;
        } &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; {
            &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;false&lt;/span&gt;;
        }
    }

    &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;getExternalInfo&lt;/span&gt;&lt;span class=&quot;params&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; ($xml = @simplexml_load_file(&lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;apiURI)) {
            &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; $xml;
        } &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; {
            &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;false&lt;/span&gt;;
        }
    }

    &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;stripAndSaveFile&lt;/span&gt;&lt;span class=&quot;params&quot;&gt;($xml)&lt;/span&gt; &lt;/span&gt;{
        &lt;span class=&quot;comment&quot;&gt;//put the artists in an array&lt;/span&gt;
        $artists = $xml-&amp;gt;weeklyartistchart-&amp;gt;artist;

        &lt;span class=&quot;comment&quot;&gt;//building the xml object for SimpleXML&lt;/span&gt;
        $output = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; SimpleXMLElement(&lt;span class=&quot;string&quot;&gt;&quot;&amp;lt;artists&amp;gt;&amp;lt;/artists&amp;gt;&quot;&lt;/span&gt;);

        &lt;span class=&quot;comment&quot;&gt;//get only the top 10&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; ($i = &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;; $i &amp;lt; &lt;span class=&quot;number&quot;&gt;10&lt;/span&gt;; $i++) {

            &lt;span class=&quot;comment&quot;&gt;//create a new artist&lt;/span&gt;
            $insert = $output-&amp;gt;addChild(&lt;span class=&quot;string&quot;&gt;&quot;artist&quot;&lt;/span&gt;);

            &lt;span class=&quot;comment&quot;&gt;//insert name and playcount childs to the artist&lt;/span&gt;
            $insert-&amp;gt;addChild(&lt;span class=&quot;string&quot;&gt;&quot;name&quot;&lt;/span&gt;, $artists[$i]-&amp;gt;name);
            $insert-&amp;gt;addChild(&lt;span class=&quot;string&quot;&gt;&quot;playcount&quot;&lt;/span&gt;, $artists[$i]-&amp;gt;playcount);

        }

        &lt;span class=&quot;comment&quot;&gt;//save the xml in the cache&lt;/span&gt;
        file_put_contents(&lt;span class=&quot;keyword&quot;&gt;$this&lt;/span&gt;-&amp;gt;filePath, $output-&amp;gt;asXML());
    }

}

&lt;span class=&quot;meta&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Calling the scripts:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;meta&quot;&gt;&amp;lt;?php&lt;/span&gt;
ini_set(&lt;span class=&quot;string&quot;&gt;'display_errors'&lt;/span&gt;, &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;);
error_reporting(E_ALL);

&lt;span class=&quot;keyword&quot;&gt;include&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'Caching.php'&lt;/span&gt;);
$caching = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; Caching(&lt;span class=&quot;string&quot;&gt;&quot;cache/lastfm.xml&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;http://ws.audioscrobbler.com/2.0/?method=user.getweeklyartistchart&amp;amp;user=xgayax&amp;amp;api_key=b25b959554ed76058ac220b7b2e0a026&quot;&lt;/span&gt;);
&lt;span class=&quot;meta&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</description></item><item><title>New design for Gaya Design</title><link>https://gaya.pizza/articles/new-design-for-gaya-design/</link><pubDate>Tue, 12 May 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/new-design-for-gaya-design/</guid><author></author><description>&lt;p&gt;Yesterday I finally launched my new layout for the world to see! There are even new things to be done on the site now.&lt;/p&gt;
&lt;p&gt;After about a month of hard work it’s done, ready to be shown in public.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/new-design-for-gaya-design/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/new-design-for-gaya-design/newlayout.jpg&quot; alt=&quot;New design for Gaya Design&quot; title=&quot;New design for Gaya Design&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I wanted to go for a retro, colourful and playful layout. With these things in mind I got working on an idea of the layout. I really like out of the box and semi 3D effects in web designs, looks different and so simple at the same time.&lt;/p&gt;
&lt;p&gt;That’s why this layout looks like it does right now. After a few weeks of designing, coding the layout, designing again and coding again &lt;a href=&quot;https://gaya.pizza/articles/new-looks-coming-your-way/&quot;&gt;it was time to put the layout to the test&lt;/a&gt;. I got a lot of feedback from you guys and I am very thankful for that! You guys seriously rock!&lt;/p&gt;
&lt;p&gt;A few things about the new design:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.gayadesign.com/advertise/&quot;&gt;Advertisement spots are now available&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Chimneys on the roof that are smoking.&lt;/li&gt;
&lt;li&gt;Oh, try and pick the chimneys up!&lt;/li&gt;
&lt;li&gt;A few jQuery effects to give power to the design.&lt;/li&gt;
&lt;li&gt;Tabbed content in the sidebar to see my top reads.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://feedburner.google.com/fb/a/mailverify?uri=GayaDesign&quot;&gt;E-mail subscription&lt;/a&gt; on Feedburner.&lt;/li&gt;
&lt;li&gt;Some navigational and page changes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thanks to everyone on Twitter too! You guys are amazing and gave me a lot of feedback! Thanks again!&lt;/p&gt;
</description></item><item><title>Gaya Kessler, editor of Fuel Your Coding</title><link>https://gaya.pizza/articles/gaya-kessler-editor-of-fuel-your-coding/</link><pubDate>Sat, 09 May 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/gaya-kessler-editor-of-fuel-your-coding/</guid><author></author><description>&lt;p&gt;You might have noticed, but for the ones that haven’t already read: I am now the editor of &lt;a href=&quot;http://fuelyourcoding.com/&quot; title=&quot;Fuel Your Coding&quot;&gt;Fuel Your Coding&lt;/a&gt;; a new website by the &lt;a href=&quot;http://www.fuelbrandgroup.com/&quot; title=&quot;Fuel Brand Group&quot;&gt;Fuel Brand Group&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.fuelyourcoding.com&quot;&gt;Visit the site&lt;/a&gt; for tutorials, tips, freebies and interview about coding, coders and tools! Along with the articles on this site, I’ll be posting development articles for you to read.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/gaya-kessler-editor-of-fuel-your-coding/&quot; title=&quot;Fuel Your Coding&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/gaya-kessler-editor-of-fuel-your-coding/fuelcodingheader.jpg&quot; alt=&quot;Gaya Kessler, editor of Fuel Your Coding&quot; title=&quot;Gaya Kessler, editor of Fuel Your Coding&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Website is located at &lt;a href=&quot;http://www.fuelyourcoding.com&quot;&gt;http://www.fuelyourcoding.com&lt;/a&gt; and you can &lt;a href=&quot;http://twitter.com/fuelyourcoding&quot; title=&quot;Follow on Twitter&quot;&gt;follow us on Twitter&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;Subscribe to &lt;a href=&quot;http://feeds2.feedburner.com/fuelyourcoding&quot;&gt;Fuel Your Coding&lt;/a&gt; via &lt;a href=&quot;http://feeds2.feedburner.com/fuelyourcoding&quot;&gt;RSS&lt;/a&gt; for coding and dev tutorials, tips (inspiration as always), freebies and awesome interviews with amazing Front end &amp;amp; Back end developers. If you’d like to subscribe and get articles delivered to your &lt;a href=&quot;http://feedburner.google.com/fb/a/mailverify?uri=fuelyourcoding&amp;amp;loc=en_US&quot;&gt;email inbox&lt;/a&gt; as they are written, sign up&lt;a href=&quot;http://feedburner.google.com/fb/a/mailverify?uri=fuelyourcoding&amp;amp;loc=en_US&quot;&gt; here.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I want to thank everyone at Fuel Brand Group for letting me join their team!&lt;/p&gt;
</description></item><item><title>Now in The Woods: Simulate Gravity with jQuery</title><link>https://gaya.pizza/articles/now-in-the-woods-simulate-gravity-with-jquery/</link><pubDate>Mon, 04 May 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/now-in-the-woods-simulate-gravity-with-jquery/</guid><author></author><description>&lt;p&gt;I wrote a post a while ago about gravity in jQuery. Thinking it was a rather funny effect, I thought I’d submit this article to a famous weblog to see if they would accept it. And what do you know: it’s now on ThemeForest’s blog &lt;a href=&quot;http://blog.themeforest.net/&quot;&gt;In The Woods&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;The article will show you how to fake gravity using jQuery, creating real life simulation of objects falling.&lt;/p&gt;
&lt;p&gt;Read the post here:&lt;br&gt;&lt;a href=&quot;http://blog.themeforest.net/tutorials/simulate-gravity-with-jquery/&quot;&gt;http://blog.themeforest.net/tutorials/simulate-gravity-with-jquery/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/now-in-the-woods-simulate-gravity-with-jquery&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/now-in-the-woods-simulate-gravity-with-jquery/gravitythemeforest.jpg&quot; alt=&quot;Now in The Woods: Simulate Gravity with jQuery&quot; title=&quot;Now in The Woods: Simulate Gravity with jQuery&quot;&gt;&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Animated tabbed content with jQuery</title><link>https://gaya.pizza/articles/animated-tabbed-content-with-jquery/</link><pubDate>Sun, 26 Apr 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/animated-tabbed-content-with-jquery/</guid><author></author><description>&lt;p&gt;A lot of websites on the Internet have tabbed content now a days. The problem I find with most of them is that most of the time they can be quite dull. For my new looks I created a container which has the ability to switch content through tabs, but with an animation. This tutorial will show you how to create your own tabbed content step by step.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/animated-tabbed-content-with-jquery/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/animated-tabbed-content-with-jquery/tabbedpost.jpg&quot; alt=&quot;Animated tabbed content with jQuery&quot; title=&quot;Animated tabbed content with jQuery&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In this tutorial I am going to show you some web development techniques that can be used in your next projects. This will cover some CSS, HTML and jQuery tricks.&lt;/p&gt;
&lt;p&gt;The sources of this tutorial are downloadable here: &lt;a href=&quot;http://gaya.github.io/scripts/tabbed/tabbedContent.zip&quot;&gt;http://gaya.github.io/scripts/tabbed/tabbedContent.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Example of the outcome is found here: &lt;a href=&quot;http://gaya.github.io/scripts/tabbed/&quot;&gt;http://gaya.github.io/scripts/tabbed/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First thing we need is some basic HTML layout to fit what we are going to make.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;meta&quot;&gt;&amp;lt;!DOCTYPE &lt;span class=&quot;meta-keyword&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;meta-keyword&quot;&gt;PUBLIC&lt;/span&gt; &lt;span class=&quot;meta-string&quot;&gt;&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;&lt;/span&gt; &lt;span class=&quot;meta-string&quot;&gt;&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;xmlns&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;http://www.w3.org/1999/xhtml&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;xml:lang&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;en&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;lang&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;en&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;title&lt;/span&gt;&amp;gt;&lt;/span&gt;Tabbed content&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;title&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;meta&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;http-equiv&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'Content-Type'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;content&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/html; charset=iso-8859-1'&lt;/span&gt; /&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/javascript'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'css/tabbedContent.css'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'stylesheet'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/css'&lt;/span&gt; /&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/tabbedContent.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;body&lt;/span&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;body&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;html&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I already included jQuery and other files in the head section. We’ll be making these files step by step in the next few minutes.&lt;/p&gt;
&lt;p&gt;Next thing we need to do is create the structure of the document. What we need is a container with the tabs and a container which the content will that switch if we change tabs.&lt;br&gt; As a nice feature to enhance this all we’ll use a tab background that will move to the choice the user makes. While this tab moves, the content will also change to the selected tab.&lt;/p&gt;
&lt;p&gt;For this we need a container containing the tabs and the background, a container containing the content and container that prevents the content to be shown prematurely.&lt;/p&gt;
&lt;p&gt;Take a look at the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'tabbed_content'&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'tabs'&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'moving_bg'&lt;/span&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;symbol&quot;&gt;&amp;amp;nbsp;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;span&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'tab_item'&lt;/span&gt;&amp;gt;&lt;/span&gt;
        Tab one
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;span&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;span&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'tab_item'&lt;/span&gt;&amp;gt;&lt;/span&gt;
        Tab two
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;span&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;span&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'tab_item'&lt;/span&gt;&amp;gt;&lt;/span&gt;
        Tab three
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;span&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;span&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'tab_item'&lt;/span&gt;&amp;gt;&lt;/span&gt;
        Tab four
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;span&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'slide_content'&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'tabslider'&lt;/span&gt;&amp;gt;&lt;/span&gt;

            &lt;span class=&quot;comment&quot;&gt;&amp;lt;!-- content goes here --&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It’s time to do a little styling to the tabs section and the overall container. Note that in the next part I am going to use an image which is included in &lt;a href=&quot;http://gaya.github.io/scripts/tabbed/tabbedContent.zip&quot;&gt;the source archive&lt;/a&gt;. This will enhance the looks of the tabbed container.&lt;/p&gt;
&lt;p&gt;This following CSS will make the tabs appear as tabs:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.tabbed_content&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;background-color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#000000&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;620px&lt;/span&gt;;
}

&lt;span class=&quot;selector-class&quot;&gt;.tabs&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;62px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;position&lt;/span&gt;: relative;
}

&lt;span class=&quot;selector-class&quot;&gt;.tabs&lt;/span&gt; &lt;span class=&quot;selector-class&quot;&gt;.moving_bg&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;background-color&lt;/span&gt;:&lt;span class=&quot;number&quot;&gt;#7F822A&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;background-image&lt;/span&gt;:&lt;span class=&quot;built_in&quot;&gt;url&lt;/span&gt;(../images/arrow_down_green.gif);
    &lt;span class=&quot;attribute&quot;&gt;background-position&lt;/span&gt;: bottom left;
    &lt;span class=&quot;attribute&quot;&gt;background-repeat&lt;/span&gt;: no-repeat;
    &lt;span class=&quot;attribute&quot;&gt;left&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;padding&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;15px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;padding-bottom&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;29px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;position&lt;/span&gt;: absolute;
    &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;125px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;z-index&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;190&lt;/span&gt;;
}

&lt;span class=&quot;selector-class&quot;&gt;.tabs&lt;/span&gt; &lt;span class=&quot;selector-class&quot;&gt;.tab_item&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;display&lt;/span&gt;: block;
    &lt;span class=&quot;attribute&quot;&gt;float&lt;/span&gt;: left;
    &lt;span class=&quot;attribute&quot;&gt;padding&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;15px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;125px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#ffffff&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;text-align&lt;/span&gt;: center;
    &lt;span class=&quot;attribute&quot;&gt;z-index&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;200&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;position&lt;/span&gt;: relative;
    &lt;span class=&quot;attribute&quot;&gt;cursor&lt;/span&gt;: pointer;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the tab container has a position of &lt;em&gt;relative&lt;/em&gt; to make the moving background position to it. Now we can easily move the moving background using the *left *property.&lt;/p&gt;
&lt;p&gt;In the next part we are going to add the first few lines of Javascript to the tabbedContent.js file to create a mouseover effect on the tab items.&lt;/p&gt;
&lt;p&gt;Use this code as a skeleton:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; TabbedContent = {
    &lt;span class=&quot;attr&quot;&gt;init&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{

    },

    &lt;span class=&quot;attr&quot;&gt;slideContent&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;obj&lt;/span&gt;) &lt;/span&gt;{

    }
}

$(&lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;).ready(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    TabbedContent.init();
});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This code is will execute the init function once the page is loaded.&lt;/p&gt;
&lt;p&gt;Now we need to make is so that the moving background moves to the tab item which is hovered on. Implement the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;$(&lt;span class=&quot;string&quot;&gt;&quot;.tab_item&quot;&lt;/span&gt;).mouseover(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{

    &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; background = $(&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;).parent().find(&lt;span class=&quot;string&quot;&gt;&quot;.moving_bg&quot;&lt;/span&gt;);

    $(background).stop().animate({
        &lt;span class=&quot;attr&quot;&gt;left&lt;/span&gt;: $(&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;).position()[&lt;span class=&quot;string&quot;&gt;'left'&lt;/span&gt;]
    }, {
        &lt;span class=&quot;attr&quot;&gt;duration&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;300&lt;/span&gt;
    });

    TabbedContent.slideContent($(&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;));

});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will make all the items with the class &lt;strong&gt;tab_item&lt;/strong&gt; behave as if it was a tab. It also moves the moving background to the right position, matching the *left *property with that of the tab.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;TabbedContent.slideContent($(this));&lt;/code&gt; will make the content switch in a few steps. We’ll get to that.&lt;/p&gt;
&lt;p&gt;Next up is creating the content and it’s CSS. The content goes in the place we put **.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;ul&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt;&amp;gt;&lt;/span&gt;
        This matches the first tab
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;ul&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;ul&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt;&amp;gt;&lt;/span&gt;
        This matches the second tab
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;ul&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;ul&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt;&amp;gt;&lt;/span&gt;
        This matches the third tab
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;ul&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;ul&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt;&amp;gt;&lt;/span&gt;
        This matches the fourth tab
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;ul&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the matching CSS:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.tabbed_content&lt;/span&gt; &lt;span class=&quot;selector-class&quot;&gt;.slide_content&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;overflow&lt;/span&gt;: hidden;
    &lt;span class=&quot;attribute&quot;&gt;background-color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#000000&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;padding&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;20px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;20px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;20px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;position&lt;/span&gt;: relative;
    &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;600px&lt;/span&gt;;
}

&lt;span class=&quot;selector-class&quot;&gt;.tabslider&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;5000px&lt;/span&gt;;
}

&lt;span class=&quot;selector-class&quot;&gt;.tabslider&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;ul&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;float&lt;/span&gt;: left;
    &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;560px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;padding&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;margin-right&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;40px&lt;/span&gt;;
}

&lt;span class=&quot;selector-class&quot;&gt;.tabslider&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;ul&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;a&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#ffffff&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;text-decoration&lt;/span&gt;: none;
}

&lt;span class=&quot;selector-class&quot;&gt;.tabslider&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;ul&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;selector-pseudo&quot;&gt;:hover&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#aaaaaa&lt;/span&gt;;
}

&lt;span class=&quot;selector-class&quot;&gt;.tabslider&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;ul&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;li&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;padding-bottom&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;7px&lt;/span&gt;;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the content has two containers. One is for the overall wrapping and the other for making the content move as we hover over the items.&lt;/p&gt;
&lt;p&gt;The top container has an overflow of hidden, which makes any content that goes out of it’s limits hidden. The container below that will hold the content that will be hidden.&lt;/p&gt;
&lt;p&gt;Now we are going to make the content scroll to the right position as we did with the tabs.&lt;/p&gt;
&lt;p&gt;It’s time to fill up the *&lt;em&gt;slideContent *&lt;/em&gt;function:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; margin = $(obj).parent().parent().find(&lt;span class=&quot;string&quot;&gt;&quot;.slide_content&quot;&lt;/span&gt;).width();
margin = margin * ($(obj).prevAll().size() - &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;);
margin = margin * &lt;span class=&quot;number&quot;&gt;-1&lt;/span&gt;;

$(obj).parent().parent().find(&lt;span class=&quot;string&quot;&gt;&quot;.tabslider&quot;&lt;/span&gt;).stop().animate({
    &lt;span class=&quot;attr&quot;&gt;marginLeft&lt;/span&gt;: margin + &lt;span class=&quot;string&quot;&gt;&quot;px&quot;&lt;/span&gt;
}, {
    &lt;span class=&quot;attr&quot;&gt;duration&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;300&lt;/span&gt;
});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The margin needed for the slider to move is calculated in this function. It has been made so that you can change the widths of several containers in the result, it will scroll to the right position automatically.&lt;/p&gt;
&lt;p&gt;Take another looks at the source for references.&lt;/p&gt;
&lt;p&gt;Good luck with making your own tabbed content in your future projects.&lt;/p&gt;
</description></item><item><title>New looks coming your way</title><link>https://gaya.pizza/articles/new-looks-coming-your-way/</link><pubDate>Wed, 22 Apr 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/new-looks-coming-your-way/</guid><author></author><description>&lt;p&gt;The current design has been around for almost five months now. When I made that design, I didn’t really aim for it to be a weblog and didn’t pay much attention to its functionallity. I must say that in that time the design was kind of growing out of me and thought I needed a new one.&lt;/p&gt;
&lt;p&gt;After a few days of thinking and many drafts I created a version suited better for my blogging needs. Read the post to see a large preview.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/new-looks-coming-your-way/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/new-looks-coming-your-way/prevgdpost.jpg&quot; alt=&quot;New looks coming your way&quot; title=&quot;New looks coming your way&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Tell me what you think about this concept. It’s not fully done yet, but it gives an idea of what the looks will be.&lt;br&gt; Thanks for watching!&lt;/p&gt;
</description></item><item><title>jQuery convertion: Panoramic Photoviewer in Javascript</title><link>https://gaya.pizza/articles/jquery-convertion-panoramic-photoviewer-in-javascript/</link><pubDate>Thu, 09 Apr 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/jquery-convertion-panoramic-photoviewer-in-javascript/</guid><author></author><description>&lt;p&gt;This is part two of my script convertions. From &lt;a href=&quot;http://script.aculo.us/&quot;&gt;scriptaculous&lt;/a&gt; to &lt;a href=&quot;http://jquery.com&quot;&gt;jQuery&lt;/a&gt; in just a few minutes of work. This time it’s the &lt;a href=&quot;https://gaya.pizza/articles/panoramic-photoviewer-in-javascript/&quot;&gt;Panoramic Photoviewer&lt;/a&gt; to get a &lt;a href=&quot;https://gaya.pizza/articles/jquery-convertion-panoramic-photoviewer-in-javascript/&quot;&gt;jQuery makeover&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A few highlights:&lt;/strong&gt;&lt;br&gt; From 200 to 80 lines of code (wow).&lt;br&gt; Works in more browsers.&lt;br&gt; Lightweight due to jQuery usage.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;For all the jQuery lovers: Here is the Panoramic Photoviewer. Now in jQuery!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/jquery-convertion-panoramic-photoviewer-in-javascript/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/jquery-convertion-panoramic-photoviewer-in-javascript/jqueryphotonav.jpg&quot; alt=&quot;jQuery convertion: Panoramic Photoviewer in Javascript&quot; title=&quot;jQuery convertion: Panoramic Photoviewer in Javascript&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Since this article is a redo of &lt;a href=&quot;https://gaya.pizza/articles/panoramic-photoviewer-in-javascript/&quot;&gt;Panoramic Photoviewer in Javascript&lt;/a&gt; I’ll just make it so that it fits jQuery.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;example page&lt;/em&gt; is located here:&lt;br&gt;&lt;a href=&quot;http://gaya.github.io/scripts/jqueryphotonav/&quot;&gt;http://gaya.github.io/scripts/jqueryphotonav/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And the &lt;em&gt;archive is downloadable&lt;/em&gt; here:&lt;br&gt;&lt;a href=&quot;http://gaya.github.io/scripts/jqueryphotonav/jqueryphotonav.zip&quot;&gt;http://gaya.github.io/scripts/jqueryphotonav/jqueryphotonav.zip&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;-what-is-it-&quot;&gt;*&lt;em&gt;What is it? *&lt;/em&gt;&lt;/h2&gt;
&lt;p&gt;This photo container has been adjusted to “move” with the cursor. To achieve this I used Javascript and a library called &lt;a href=&quot;http://jQuery.com&quot;&gt;jQuery&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;what-do-we-have-and-what-do-we-need-to-do-&quot;&gt;&lt;strong&gt;What do we have and what do we need to do?&lt;/strong&gt;&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Create a HTML layout for the picture to get in.&lt;/li&gt;
&lt;li&gt;Adjust the CSS.&lt;/li&gt;
&lt;li&gt;Make a call to PhotoNav in Javascript.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;1-create-a-html-layout&quot;&gt;&lt;strong&gt;1. Create a HTML layout&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;This is the easiest step. It might just as well be a copy paste of the code below. But be aware of three things.&lt;br&gt; First give the overall container an id (so Javascript can grab the object).&lt;br&gt; Then make sure the div with classname &lt;em&gt;fixed&lt;/em&gt; gets a second classname to correspond with the CSS (I used &lt;em&gt;opt1&lt;/em&gt; and &lt;em&gt;opt2&lt;/em&gt;).&lt;br&gt; Determine if you want to have links inside of the container, if not; you can leave the container empty.&lt;/p&gt;
&lt;p&gt;Take a look at the code below:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'photo'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;style&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'display: none;'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'navigate'&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'fixed opt1'&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;comment&quot;&gt;&amp;lt;!-- this is optional --&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://gayadesign.com/post/'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'button1'&lt;/span&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://gayadesign.com/portfolio/'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'button2'&lt;/span&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://gayadesign.com/about/'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'button3'&lt;/span&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://gayadesign.com/partners/'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'button4'&lt;/span&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://gayadesign.com/contact/'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'button5'&lt;/span&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The overall container “navigate” will always be hidden prior to the actual Javascript call. I also gave the &lt;em&gt;fixed&lt;/em&gt; div a second class. This classname will point to the options of the container; the height and the background image (the actual image that needs scrolling).&lt;br&gt; You can add &lt;em&gt;&lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tags&lt;/em&gt; to the &lt;em&gt;fixed&lt;/em&gt; container. I gave them all classnames so they can be positioned in the CSS. This part is optional.&lt;/p&gt;
&lt;p&gt;Remember to include the jQuery library and the PhotoNav Javascript files in the header. Also include the CSS file &lt;em&gt;photonav.css&lt;/em&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/jquery-1.3.2.min.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/photonavjQuery.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'css/photonav.css'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'stylesheet'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/css'&lt;/span&gt; /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;2-adjust-the-css&quot;&gt;&lt;strong&gt;2. Adjust the CSS&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;The top part of the CSS has to stay the way it is, do not adjust it if you don’t know what you are doing. I put a comment at the spot where you can start to edit the CSS.**&lt;br&gt;** I’ll describe what to do at each part of the CSS.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;.photonav .photo:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.photonav&lt;/span&gt; &lt;span class=&quot;selector-class&quot;&gt;.photo&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;400px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;10px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;border&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1px&lt;/span&gt; solid gray;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Adjust the width of the total container. This has to be a fixed width in order for it to work in IE6. I have no idea why, but if the &lt;em&gt;width&lt;/em&gt; was set to &lt;em&gt;100%&lt;/em&gt;, the height was 0px. You can do &lt;em&gt;100%&lt;/em&gt; in other browser with the &lt;em&gt;!important&lt;/em&gt; trick.&lt;br&gt; The margin and border are optional, just make it as you’d like.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;.photonav .photo .opt1:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.photonav&lt;/span&gt; &lt;span class=&quot;selector-class&quot;&gt;.photo&lt;/span&gt; &lt;span class=&quot;selector-class&quot;&gt;.opt1&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;100px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;background-image&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;url&lt;/span&gt;();
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is the height of the photo container, at least, the &lt;em&gt;fixed&lt;/em&gt; container. But notice the &lt;em&gt;.opt1&lt;/em&gt;, it is the second classname we added to the &lt;em&gt;fixed&lt;/em&gt; container in the HTML part.&lt;br&gt; The background image is the image that has to be viewed inside the container.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The next part is optional and only if you want buttons inside the container.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;a.button*:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-tag&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;selector-class&quot;&gt;.button1&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;margin-left&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;20px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;margin-top&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;30px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;100px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;90px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;background-image&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;url&lt;/span&gt;();
}

&lt;span class=&quot;selector-tag&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;selector-class&quot;&gt;.button1&lt;/span&gt;&lt;span class=&quot;selector-pseudo&quot;&gt;:hover&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;background-image&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;url&lt;/span&gt;();
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In order to create a menu navigation like I did on the preview page, you need to add &lt;em&gt;a tags&lt;/em&gt; with different classnames. Define the pixels from the left side and the top of the container in the margin values. State the width and height of the button and the background image (if needed).&lt;br&gt; To create an &lt;em&gt;onhover&lt;/em&gt; effect you can add an other image in the &lt;em&gt;:hover&lt;/em&gt; part.&lt;br&gt; If you want a second &lt;em&gt;a tag&lt;/em&gt; next to the other, subtract the *height *of the previous button from the margin-top.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Make a call to PhotoNav in Javascript&lt;/strong&gt;&lt;br&gt; Now that you’ve got all the necessary HTML and CSS set, you can call the PhotoNav functionality. The following code can be put in a js file or in a &lt;em&gt;strict&lt;/em&gt; tag.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;.getElementById(&lt;span class=&quot;string&quot;&gt;'navigate'&lt;/span&gt;).style.display = &lt;span class=&quot;string&quot;&gt;'block'&lt;/span&gt;;
PhotoNav.init(&lt;span class=&quot;string&quot;&gt;'navigate'&lt;/span&gt;, &lt;span class=&quot;number&quot;&gt;758&lt;/span&gt;, &lt;span class=&quot;number&quot;&gt;1412&lt;/span&gt;, &lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The specification is:&lt;br&gt;&lt;strong&gt;function **init(&lt;/strong&gt;String &lt;strong&gt;&lt;em&gt;id_of_container&lt;/em&gt;, **int *&lt;/strong&gt;width_of_container&lt;em&gt;, &lt;strong&gt;int *&lt;/strong&gt;width_of_panorama_picture&lt;/em&gt;, &lt;strong&gt;bool*&lt;/strong&gt;debugMode*);&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;String *&lt;/strong&gt;id_of_container*:&lt;br&gt; The id of the container.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;int *&lt;/strong&gt;width_of_container&lt;em&gt;:&lt;br&gt; Give the width in pixels of the *fixed&lt;/em&gt; container. For calculating reasons.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;int *&lt;/strong&gt;width_of_panorama_picture&lt;em&gt;:&lt;br&gt; Give the width in pixels of the &lt;span style=&quot;font-style: italic;&quot;&gt;panoramic &lt;/span&gt;&lt;/em&gt;picture*. For calculating reasons.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;bool*&lt;/strong&gt;debugMode&lt;em&gt;:&lt;br&gt; Enable debug mode. Outputting value to the HTML element with id *’status’&lt;/em&gt;. (default: false)&lt;/p&gt;
&lt;p&gt;If you want to enable debug mode, you have to insert the following code somewhere in your HTML:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'status'&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;symbol&quot;&gt;&amp;amp;nbsp;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that everything is set, you can fire the thing up! Enable the navigation on loading a page or by triggering an event in Javascript. If you have implementations of this script, post your examples in the comment section, I’d like to see them.&lt;/p&gt;
&lt;p&gt;I hope you like the second convertion to jQuery. Stay tuned for more!&lt;/p&gt;
&lt;p&gt;Good luck!&lt;/p&gt;
</description></item><item><title>jQuery convertion: Garagedoor effect using Javascript</title><link>https://gaya.pizza/articles/jquery-convertion-garagedoor-effect-using-javascript/</link><pubDate>Wed, 08 Apr 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/jquery-convertion-garagedoor-effect-using-javascript/</guid><author></author><description>&lt;p&gt;Today I finally found the courage to go and try &lt;a href=&quot;http://jquery.com/&quot; title=&quot;jQuery&quot;&gt;jQuery&lt;/a&gt;. After getting some people say: “You should use jQuery instead of scriptaculous.” I began thinking. What is the reason I choose script.aculo.us again? Must have been something I read in that time.&lt;br&gt; Anyway, today I found the time to look at jQuery a bit and thought: Let’s convert &lt;a href=&quot;https://gaya.pizza/articles/garagedoor-effect-using-javascript/&quot;&gt;my very first posted script&lt;/a&gt; to jQuery!&lt;/p&gt;
&lt;p&gt;After 5 minutes of reading about selectors in jQuery and 15 minutes of coding it was born. I am super amazed by the results! About 40%/50% less code and about 200% less time needed to write the script. I bet that in the future 400% less time is reachable!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;For all the jQuery lovers: Here is the Garage Door effect. Now in jQuery!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/jquery-convertion-garagedoor-effect-using-javascript/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/jquery-convertion-garagedoor-effect-using-javascript/jquerygarage.jpg&quot; alt=&quot;jQuery convertion: Garagedoor effect using Javascript&quot; title=&quot;jQuery convertion: Garagedoor effect using Javascript&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Since this article is a redo of &lt;a href=&quot;https://gaya.pizza/articles/garagedoor-effect-using-javascript/&quot;&gt;Garagedoor effect using Javascript&lt;/a&gt; I’ll just make it so that it fits jQuery.&lt;/p&gt;
&lt;p&gt;An example of the GarageDoor effect in work is found here: &lt;a href=&quot;http://gaya.github.io/scripts/jquerygaragedoor/&quot;&gt;http://gaya.github.io/scripts/jquerygaragedoor/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Download the following archive containing everything you need: &lt;a href=&quot;http://gaya.github.io/scripts/jquerygaragedoor/jquerygarage.zip&quot;&gt;http://gaya.github.io/scripts/jquerygaragedoor/jquerygarage.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;*Unzip *the contents of the archive and upload the contents to your server, the set folders can be adjusted to your needs.&lt;/p&gt;
&lt;p&gt;First we need to make the script ans style of the GarageDoor work. To make that happen, you’ll need jQuery. This library enables interface effects, so you don’t have to create it yourself. So &lt;a href=&quot;http://docs.jquery.com/Downloading_jQuery#Download_jQuery&quot;&gt;grab jQuery&lt;/a&gt; and upload it to your server.&lt;/p&gt;
&lt;p&gt;Add the following code in the **** tag of your page:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/jquery-1.3.2.min.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/garagedoorjQuery.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'css/garagedoor.css'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'stylesheet'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/css'&lt;/span&gt; /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will load the scripts and styles needed for the GarageDoor to work. *Adjust the paths where needed.&lt;br&gt;*&lt;/p&gt;
&lt;p&gt;The next thing you want to do is to create the HTML layout for the garagedoors. The following code shows the structure you need to create for your document:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'garagedoor'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'garagedoor'&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;title&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'linktofile'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'item'&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'underlay'&lt;/span&gt;&amp;gt;&lt;/span&gt;
            Caption text
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'uritooverlayimage'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'overlay'&lt;/span&gt; /&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'mouse'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'images/nothing.gif'&lt;/span&gt; /&amp;gt;&lt;/span&gt;&lt;span class=&quot;symbol&quot;&gt;&amp;amp;nbsp;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;title&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'linktofile'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'item'&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'underlay'&lt;/span&gt;&amp;gt;&lt;/span&gt;
            Caption text
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'uritooverlayimage'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'overlay'&lt;/span&gt; /&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'mouse'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'images/nothing.gif'&lt;/span&gt; /&amp;gt;&lt;/span&gt;&lt;span class=&quot;symbol&quot;&gt;&amp;amp;nbsp;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;his contains two items that will be the garagedoor. The keywords &lt;strong&gt;linktofile&lt;/strong&gt; and &lt;strong&gt;uritooverlayimage&lt;/strong&gt; have to be adjusted in order to make it work. &lt;strong&gt;Linktofile&lt;/strong&gt; is the URL of the page the button has to link to, might be confusing because it’s not an &lt;em&gt;a tag&lt;/em&gt;, but Javascript fixes it for you.&lt;/p&gt;
&lt;p&gt;The items have a default size of: &lt;strong&gt;100px width *&lt;em&gt;and *&lt;/em&gt;80px height&lt;/strong&gt;. &lt;em&gt;Create overlay images&lt;/em&gt; according to these dimensions. In order to change the size, take a look in the &lt;strong&gt;garagedoor.css&lt;/strong&gt; file and &lt;em&gt;adjust&lt;/em&gt; the &lt;strong&gt;width&lt;/strong&gt; and &lt;strong&gt;height&lt;/strong&gt; of several elements.&lt;/p&gt;
&lt;p&gt;All there is left to do is call the GarageDoor to enable the effect!&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;actionscript&quot;&gt;
    GarageDoor.scrollY = &lt;span class=&quot;number&quot;&gt;-55&lt;/span&gt;;
    GarageDoor.scrollX = &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;;
    GarageDoor.setBindings(&lt;span class=&quot;string&quot;&gt;'garagedoor'&lt;/span&gt;);
&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first line in the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag sets the amount of scrolling the overlay has to do when the cursor is floating over an item. In this example the overlay has to go 55 up, which means move -55px on the Y-axis.
 You can also make it scroll horizontal.&lt;/p&gt;
&lt;p&gt;Give the &lt;strong&gt;id&lt;/strong&gt; of the &lt;strong&gt;garagedoor container&lt;/strong&gt; to the &lt;strong&gt;setBindings&lt;/strong&gt; method and the GarageDoor effect will be initialized! Be sure to make the call &lt;strong&gt;after&lt;/strong&gt; creating the &lt;strong&gt;html&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Hope you liked this jQuery version of the Garage Door. &lt;strong&gt;No more prototype conflicts&lt;/strong&gt;!&lt;/p&gt;
&lt;p&gt;Stay tuned for more jQuery convertions!&lt;/p&gt;
</description></item><item><title>Image slider for displaying pictures or portfolios</title><link>https://gaya.pizza/articles/image-slider-for-displaying-pictures-or-portfolios/</link><pubDate>Tue, 07 Apr 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/image-slider-for-displaying-pictures-or-portfolios/</guid><author></author><description>&lt;p&gt;I love &lt;a href=&quot;http://www.noupe.com/javascript/30-javascriptajax-techniques-for-sliders-scrollers-and-scrollbars.html&quot;&gt;image slideshows&lt;/a&gt; and &lt;a href=&quot;http://www.siebdesign.nl/&quot; title=&quot;Sieb Design&quot;&gt;portfolios with an extra bit of interaction and effects&lt;/a&gt;. The problem I found when I wanted to make one of my own was that I always ran out of ideas how to display portfolio items / pictures in a special way. But then it hit me, and the idea for this image slider was born.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/image-slider-for-displaying-pictures-or-portfolios/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/image-slider-for-displaying-pictures-or-portfolios/imageslider.jpg&quot; alt=&quot;Image slider for displaying pictures or portfolios&quot; title=&quot;Image slider for displaying pictures or portfolios&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Example of the image slider is located at: &lt;a href=&quot;http://gaya.github.io/scripts/slider/&quot;&gt;http://gaya.github.io/scripts/slider/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The slider and all its files can be downloaded here: &lt;a href=&quot;http://gaya.github.io/scripts/slider/gdslider.zip&quot;&gt;http://gaya.github.io/scripts/slider/gdslider.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First I want to explain what this image slider does:&lt;br&gt; This image slider creates a slideshow of images and makes it look like the images have been cropped to only thin strokes. Once the user clicks on an image it will expand across the slideshow and show the picture in its full galore. Click of the left or the right side of the container to navigate to other pictures, the images will keep appearing as if there is an infinite loop of images. It also preloads the images that will be shown on the page.&lt;/p&gt;
&lt;p&gt;The pictures in the example are all pictures from &lt;a href=&quot;http://www.sxc.hu/&quot; title=&quot;Stock.xchng&quot;&gt;http://www.sxc.hu/&lt;/a&gt; a nice site with free stock photos.&lt;/p&gt;
&lt;p&gt;*&lt;em&gt;Please note that this script does not work in IE6.&lt;br&gt;*&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Implementing this script is fairly easy. &lt;a href=&quot;http://gaya.github.io/scripts/slider/gdslider.zip&quot;&gt;The zip-archive&lt;/a&gt; contains everything you need except from &lt;a href=&quot;http://script.aculo.us/&quot; title=&quot;Scriptaculous&quot;&gt;Scriptaculous and Prototype&lt;/a&gt;. So &lt;a href=&quot;http://script.aculo.us/downloads&quot; title=&quot;Download scriptaculous&quot;&gt;let’s download that&lt;/a&gt; first.&lt;/p&gt;
&lt;p&gt;Next, unzip the archive somewhere and upload the contents of the &lt;strong&gt;/src/&lt;/strong&gt; and &lt;strong&gt;/lib/&lt;/strong&gt; folders to you web server.&lt;/p&gt;
&lt;p&gt;Great! Now that you have Scriptaculous uploaded, &lt;a href=&quot;http://gaya.github.io/scripts/slider/gdslider.zip&quot;&gt;download the image slider&lt;/a&gt; and unzip it. Upload the contents to your web server (I used the &lt;strong&gt;js&lt;/strong&gt; folder to put the Scriptaculous files in to keep things separated).&lt;/p&gt;
&lt;p&gt;Now it’s time to make things work. Add the following code to your  tag. Adjust the following code to your preferences:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;comment&quot;&gt;&amp;lt;!-- include scriptaculous + prototype --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/scriptaculous/prototype.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/scriptaculous/scriptaculous.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/extraTransitions.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/slider.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can find the html code to put on your page in the &lt;strong&gt;example.html&lt;/strong&gt; file which is the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;items&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;loading&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;symbol&quot;&gt;&amp;amp;nbsp;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;pictureLoadContainer&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;caption&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;style&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;display: none&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;background&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;symbol&quot;&gt;&amp;amp;nbsp;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;captionContent&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;style&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;display: none&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;overflow&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;comment&quot;&gt;&amp;lt;!-- put images with alt attributes here --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;SlideLeft&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;nav left&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;images/arrow_left.png&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;alt&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;Click to move left&quot;&lt;/span&gt; /&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;SlideRight&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;nav right&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;images/arrow_right.png&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;alt&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;Click to move right&quot;&lt;/span&gt; /&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The images you want to load inside the slider have to be &lt;strong&gt;1000 x 620&lt;/strong&gt; by default. I’ll explain how adjust this later in the tutorial.&lt;/p&gt;
&lt;p&gt;Put the images you want to load in the &lt;div&gt; called *”overlay”*, just like a normal image on your webpage.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;uritoimage&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;alt&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;caption to go with the image&quot;&lt;/span&gt; /&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;uritoimage&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;alt&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;caption to go with the image&quot;&lt;/span&gt; /&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;uritoimage&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;alt&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;caption to go with the image&quot;&lt;/span&gt; /&amp;gt;&lt;/span&gt;
...&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You are basically done with adjusting the script if you like the default looks.&lt;/p&gt;
&lt;p&gt;To adjust the height and width of several elements take a look in the &lt;strong&gt;style.css&lt;/strong&gt; file.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Define the height and width of the item container in: &lt;strong&gt;#container #items&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Define the size of the navigation buttons in: &lt;strong&gt;#container #items .nav&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Define the size of the items in: &lt;strong&gt;#container .item&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;If you adjust the height also adjust it here: &lt;strong&gt;#container #items #overflow&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you adjust the widths of elements you also have to change the &lt;strong&gt;slider.js&lt;/strong&gt; file in the js folder. The code is at the top of the script:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;comment&quot;&gt;/* edit these options according to your CSS */&lt;/span&gt;
&lt;span class=&quot;attr&quot;&gt;itemWidth&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;250&lt;/span&gt;, &lt;span class=&quot;comment&quot;&gt;//width of an item&lt;/span&gt;
&lt;span class=&quot;attr&quot;&gt;totalWidth&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1000&lt;/span&gt;, &lt;span class=&quot;comment&quot;&gt;//total width of the container&lt;/span&gt;
&lt;span class=&quot;attr&quot;&gt;navWidth&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;112&lt;/span&gt;, &lt;span class=&quot;comment&quot;&gt;//width of the nav including padding&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;/* end edit options */&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;Adjust the number to the amount of pixels you had it changed into. Easy not?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The script will load automatically and will only start once all the images have been loaded.&lt;/p&gt;
&lt;p&gt;Have fun!&lt;/p&gt;
</description></item><item><title>AjaxTwits – Load Tweets on your website with AJAX</title><link>https://gaya.pizza/articles/ajaxtwits-load-tweets-on-your-website-with-ajax/</link><pubDate>Thu, 26 Mar 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/ajaxtwits-load-tweets-on-your-website-with-ajax/</guid><author></author><description>&lt;p&gt;&lt;a href=&quot;http://www.twitter.com&quot; title=&quot;Twitter&quot;&gt;Twitter&lt;/a&gt; is an amazing service to keep in touch with everyone on the Internet. It’s easy, fast and there are a lot of &lt;a href=&quot;http://twitter.com/downloads&quot; title=&quot;Twitter Applications&quot;&gt;Twitter applications&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I came up with the idea to Ajaxify (is that even a word?) the tweets on &lt;a href=&quot;http://www.gayadesign.com&quot; title=&quot;Gaya Design&quot;&gt;my website&lt;/a&gt;. As you can see, it’s on the right, below the last.fm recently played. It’s called &lt;a href=&quot;https://gaya.pizza/articles/ajaxtwits-load-tweets-on-your-website-with-ajax&quot; title=&quot;AjaxTwits&quot;&gt;AjaxTwits&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;This article will show you how to use AjaxTwits and how to install it on your website.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/ajaxtwits-load-tweets-on-your-website-with-ajax&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/ajaxtwits-load-tweets-on-your-website-with-ajax/ajaxtwits.jpg&quot; alt=&quot;AjaxTwits - Load Tweets on your website with AJAX&quot; title=&quot;AjaxTwits - Load Tweets on your website with AJAX&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Example of AjaxTwits is located at: &lt;a href=&quot;http://gaya.github.io/scripts/ajaxtwits/&quot;&gt;http://gaya.github.io/scripts/ajaxtwits/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;AjaxTwits and all it’s files can be downloaded here: &lt;a href=&quot;http://gaya.github.io/scripts/ajaxtwits/ajaxtwits.zip&quot;&gt;http://gaya.github.io/scripts/ajaxtwits/ajaxtwits.zip&lt;/a&gt; or the &lt;a href=&quot;http://gaya.github.io/scripts/ajaxtwits/ajaxtwits_old.zip&quot;&gt;old version&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;update-notice-&quot;&gt;Update notice:&lt;/h2&gt;
&lt;p&gt;There were a few things going from in the AjaxTwits class which have been fixed. Some tweets seems to make AjaxTwits stop working. I also included the date in the Javascript code.&lt;br&gt;&lt;a href=&quot;http://gaya.github.io/scripts/ajaxtwits/ajaxtwits.zip&quot;&gt;Download the new zip&lt;/a&gt; to gain access to the improved code.&lt;/p&gt;
&lt;p&gt;If you have an installation of AjaxTwits on your site you can replace the AjaxTwits.php class with the file from the &lt;a href=&quot;http://gaya.github.io/scripts/ajaxtwits/ajaxtwits.zip&quot;&gt;new zip&lt;/a&gt;. The Javascript has changed to, but it’s not necessary to change.&lt;/p&gt;
&lt;h2 id=&quot;what-does-ajaxtwits-do-&quot;&gt;What does AjaxTwits do?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Load a twitter timeline and / or the replies of a twitter account&lt;/li&gt;
&lt;li&gt;Cache the results so you don’t stress the twitter servers&lt;/li&gt;
&lt;li&gt;Avatar finder (auto update if user uploads a new one)&lt;/li&gt;
&lt;li&gt;Load multiple timelines / replies from different accounts&lt;/li&gt;
&lt;li&gt;AJAX support with JSON option or XML&lt;/li&gt;
&lt;li&gt;Front-end Javascript output&lt;/li&gt;
&lt;li&gt;Automatic hyperlink finder and @username linking&lt;/li&gt;
&lt;li&gt;Easy to adjust to your likings&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;why-ajaxtwits-&quot;&gt;Why AjaxTwits?&lt;/h2&gt;
&lt;p&gt;The problem with loading twitter on the server side part of your website is that it will slow down the load time massively. Which means your pages will load pretty slow.&lt;/p&gt;
&lt;p&gt;This is because of the use of external feeds and services, it takes some time to load them. The server will read the XML and RSS feeds very quickly, but PHP still has to load the files from the Twitter servers.&lt;/p&gt;
&lt;p&gt;AjaxTwits keeps the load time separate from your website, meaning it will load after your page is loaded and not effecting the user experience. Yes, the services still need to be loaded. But the loading is done afterward.&lt;/p&gt;
&lt;p&gt;The caching of results prevents the service to stop loading the feeds. Twitter has a build in limit of requests, so be gentle on their servers.&lt;br&gt; This also helps to load AjaxTwits very quickly and output tweets in a few milliseconds!&lt;/p&gt;
&lt;p&gt;The twitter timeline is also limited to only your tweets and not those of other people. That’s why AjaxTweets also supports search queries performed on &lt;a href=&quot;http://search.twitter.com/&quot;&gt;http://search.twitter.com/&lt;/a&gt;. AjaxTwits has an easy build-in option to get all the reply messages of a user and mix them into the timeline.&lt;/p&gt;
&lt;h2 id=&quot;what-do-i-need-&quot;&gt;What do I need?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;PHP with JSON and SimpleXML support (PHP 5.2.0 or greater)&lt;/li&gt;
&lt;li&gt;A &lt;a href=&quot;https://twitter.com/signup&quot;&gt;Twitter account&lt;/a&gt; to consume or a Twitter account of &lt;a href=&quot;https://twitter.com/gayadesign&quot;&gt;someone else&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;An FTP client to upload contents to the server&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;how-to-install-&quot;&gt;How to install:&lt;/h2&gt;
&lt;p&gt;AjaxTwits is fairly easy to install, the following steps will enable AjaxTwits on your website!&lt;/p&gt;
&lt;h2 id=&quot;step-1-download-and-upload-ajaxtwits&quot;&gt;Step 1: Download and upload AjaxTwits&lt;/h2&gt;
&lt;p&gt;Download AjaxTwits here: &lt;a href=&quot;http://gaya.github.io/scripts/ajaxtwits/ajaxtwits.zip&quot;&gt;http://gaya.github.io/scripts/ajaxtwits/ajaxtwits.zip&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Unzip the contents and upload them to your web server. Anywhere you’d like!&lt;/p&gt;
&lt;h2 id=&quot;step-2-adjust-the-request-file&quot;&gt;Step 2: Adjust the request file&lt;/h2&gt;
&lt;p&gt;In the “&lt;em&gt;AjaxTwits&lt;/em&gt;“ folder you just uploaded&lt;em&gt;***is a file called “&lt;/em&gt;AjaxTwitsRequest.php*” and “&lt;em&gt;AjaxTwitsUpdate.php&lt;/em&gt;“. Open this file in an editor.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//include AjaxTwits and create an object&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;include&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'AjaxTwits.php'&lt;/span&gt;);
$ajaxTwits = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; AjaxTwits;

&lt;span class=&quot;comment&quot;&gt;//set the cache to a writable folder, to save xml files&lt;/span&gt;
$ajaxTwits-&amp;gt;cachefolder = &lt;span class=&quot;string&quot;&gt;&quot;AjaxTwits/cache&quot;&lt;/span&gt;;
&lt;span class=&quot;comment&quot;&gt;//the amount of minutes the feed is cached&lt;/span&gt;
$ajaxTwits-&amp;gt;cacheTime = &lt;span class=&quot;number&quot;&gt;15&lt;/span&gt;;

&lt;span class=&quot;comment&quot;&gt;//the amount of items you'll show&lt;/span&gt;
$ajaxTwits-&amp;gt;itemCount = &lt;span class=&quot;number&quot;&gt;6&lt;/span&gt;;

&lt;span class=&quot;comment&quot;&gt;//add your twitter account feeds&lt;/span&gt;
$ajaxTwits-&amp;gt;addTimeline(&lt;span class=&quot;string&quot;&gt;&quot;gayadesign&quot;&lt;/span&gt;);
$ajaxTwits-&amp;gt;addReplies(&lt;span class=&quot;string&quot;&gt;&quot;gayadesign&quot;&lt;/span&gt;);

&lt;span class=&quot;comment&quot;&gt;//this will output the information, JSON is for the Javascript application&lt;/span&gt;
$ajaxTwits-&amp;gt;outputFeed(&lt;span class=&quot;string&quot;&gt;&quot;json&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Adjust the following line to your likings:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;*$ajaxTwits-&amp;gt;cachefolder = “AjaxTwits/cache”;&lt;/strong&gt;&lt;br&gt;&lt;em&gt;This is the folder where the XMLs will be cached. Enter the folder starting in the &lt;strong&gt;root&lt;/strong&gt; of your website. So if you have AjaxTwits installed in */blog/AjaxTwits/&lt;/em&gt; the cache folder should be &lt;em&gt;blog/AjaxTwits/cache.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;*$ajaxTwits-&amp;gt;cacheTime = 15;&lt;br&gt;*&lt;/strong&gt;The amount of minutes the XML should stay on your server before it will be refreshed.&lt;strong&gt;**&lt;/strong&gt;This means that every 15 minutes the timeline will be updated on your site. Adjust to your likings.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;$ajaxTwits-&amp;gt;itemCount = 6;&lt;/em&gt;&lt;/strong&gt;&lt;br&gt; The amount of items you want to output on your website.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;$ajaxTwits-&amp;gt;addTimeline(“gayadesign”);&lt;/em&gt;&lt;/strong&gt;&lt;br&gt; Load the public timeline of the given username.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;$ajaxTwits-&amp;gt;addReplies(“gayadesign”);&lt;/em&gt;&lt;/strong&gt;&lt;br&gt; Load the replies of the given user. Every tweet on Twitter containing &lt;a href=&quot;http://twitter.com/gayadesign&quot;&gt;@gayadesign&lt;/a&gt; in this case.&lt;/p&gt;
&lt;p&gt;Upload the adjusted file to your server if needed.&lt;/p&gt;
&lt;h2 id=&quot;step-3-make-the-cache-folder-writable&quot;&gt;Step 3: Make the cache folder writable&lt;/h2&gt;
&lt;p&gt;Explore the server contents with an FTP client and make the cache folder (default: AjaxTwits/cache) writable using &lt;em&gt;chmod&lt;/em&gt; 777.&lt;/p&gt;
&lt;p&gt;This is for saving XML on the server.&lt;/p&gt;
&lt;h2 id=&quot;step-4-include-ajaxtwits-on-your-webpage&quot;&gt;Step 4: Include AjaxTwits on your webpage&lt;/h2&gt;
&lt;p&gt;In the header () of your HTML add the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/AjaxTwits.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'css/AjaxTwits.css'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'stylesheet'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/css'&lt;/span&gt; /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will load the necessary Javascript + the styling of the widget.&lt;/p&gt;
&lt;h2 id=&quot;step-5-get-the-html-of-the-widget-ready&quot;&gt;Step 5: Get the HTML of the widget ready&lt;/h2&gt;
&lt;p&gt;Add this to your HTML on the place you want to include the widget:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;ul&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'AjaxTwits'&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'AjaxTwitsLoader'&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;em&lt;/span&gt;&amp;gt;&lt;/span&gt;Loading tweets&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;em&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;li&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;ul&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;actionscript&quot;&gt;
    getAjaxTwits(&lt;span class=&quot;string&quot;&gt;&quot;AjaxTwits/AjaxTwitsRequest.php&quot;&lt;/span&gt;, &lt;span class=&quot;number&quot;&gt;6&lt;/span&gt;);
&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The tweets that are loaded will be inserted into the unordered list with id &lt;em&gt;AjaxTwits&lt;/em&gt;. The list item *AjaxTwitsLoader *will be deleted.&lt;/p&gt;
&lt;p&gt;Adjust &lt;strong&gt;&lt;em&gt;getAjaxTwits(“AjaxTwits/AjaxTwitsRequest.php”, “AjaxTwits/AjaxTwitsUpdate.php”, 6);&lt;/em&gt;&lt;/strong&gt; to your preferences.&lt;/p&gt;
&lt;p&gt;The first parameter is the &lt;strong&gt;location of the AjaxTwitsRequest.php file&lt;/strong&gt;. The second parameter is the &lt;strong&gt;location of the AjaxTwitsUpdate.php file&lt;/strong&gt;. The third parameter is the &lt;strong&gt;amount of items to show&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&quot;conclusion-&quot;&gt;Conclusion:&lt;/h2&gt;
&lt;p&gt;That’s all you have to do! Not that much right?&lt;/p&gt;
&lt;p&gt;You can adjust the CSS and mess around with the Javascript if you like.&lt;/p&gt;
&lt;p&gt;Hope this will help you create a nice Twitter widget on your website.&lt;/p&gt;
</description></item><item><title>What to do with AJAX and what not to</title><link>https://gaya.pizza/articles/what-to-do-with-ajax-and-what-not-to/</link><pubDate>Fri, 20 Mar 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/what-to-do-with-ajax-and-what-not-to/</guid><author></author><description>&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Ajax_%28programming%29&quot;&gt;AJAX&lt;/a&gt; is one the nicest concept I’ve seen in web development. The basics are simple and quite easy to use.&lt;br&gt; There are a lot of &lt;a href=&quot;http://en.wikipedia.org/wiki/List_of_Ajax_frameworks&quot;&gt;AJAX frameworks&lt;/a&gt; around like &lt;a href=&quot;http://jquery.com/&quot;&gt;jQuery&lt;/a&gt;, &lt;a href=&quot;http://www.prototypejs.org/&quot;&gt;Prototype&lt;/a&gt; and &lt;a href=&quot;http://bdn.backbase.com/&quot;&gt;backbase&lt;/a&gt;. These frameworks help you create an AJAX application with ease.&lt;br&gt; But is AJAX really that good? No, but if you use it correctly, it is!&lt;/p&gt;
&lt;p&gt;In this article I wish to share my view on AJAX and the possibilities it gives to web developers and designers, and why AJAX is wrong in several situations.&lt;/p&gt;
&lt;div class=&quot;border&quot;&gt;[![What to do with AJAX and what not to](/articles/what-to-do-with-ajax-and-what-not-to/ajaxpost.jpg &quot;What to do with AJAX and what not to&quot;)](/articles/what-to-do-with-ajax-and-what-not-to/)&lt;/div&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;

&lt;h2 id=&quot;case-1-page-loading&quot;&gt;&lt;strong&gt;Case 1: Page loading&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;What’s up with websites and dynamically loading pages through AJAX? Isn’t it a bit strange that when you want to switch to another page, there is no real page switch?&lt;br&gt; Sure, I like it when content is loaded into the website dynamically, saving me bandwidth, time and irritation. But a whole page? Isn’t that kind of missing the point?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First of all: What about the back and forward buttons of your browser? No use for them if you load a whole page in AJAX.&lt;/li&gt;
&lt;li&gt;Second: Funny when a user tries to copy the URL and send it to a friend. Oops, the page is loaded without the content the user expected.&lt;/li&gt;
&lt;li&gt;Third: Search Engines can’t pick it up since it is not really a new page.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A better way to load content through AJAX is to load only small parts of information on the page. If the users wishes to visit another page, let the browser go to another page.&lt;br&gt; Loading content in a small part of the page isn’t a bad thing. If you have a container with tabbed content, it’s easy to load the content of other tabs with AJAX, not a problem.&lt;/p&gt;
&lt;p&gt;Loading a whole page in AJAX is just overusing the functionality and really missing the point of web browsing.&lt;/p&gt;
&lt;h2 id=&quot;case-2-the-content-manager&quot;&gt;&lt;strong&gt;Case 2: The content manager&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Being able to adjust the information of your web profile on a web page with the use of AJAX is cool. Fast feedback, fast loading times and convenient. But is it really secure?&lt;br&gt; I’ve seen sites where the HTTP calls to the server contained the key and value of the part they wanted to configure. Which means the record which will be adjusted is defined. This means you could also change information of other rows in the database. Why? You need to wonder what parts of the profile can be adjusted, and if it applies only to the user who is trying to configure their information, why do you need a key to tell the server which record to adjust?&lt;br&gt; In PHP, for example, it only takes little effort to remember a value in a session. With this, you know which user is using the website and if you open the session in the AJAX server side pages, you can still read that session. Makes it easy to tell which record to update and doesn’t give a user the opportunity to mess around in your system.&lt;/p&gt;
&lt;p&gt;If you do want to send along a key + value, which could be needed in some situations (like inserting a comment), be sure to check the given values in the server side scripts. Can’t say this enough to people, but please be sure the user that is trying to insert / update data has access to that data. This also applies to normal usage of forms, but adjusting an AJAX request is harder for most users. Still it is possible! So be on your guard.&lt;/p&gt;
&lt;h2 id=&quot;case-3-one-click-update&quot;&gt;&lt;strong&gt;Case 3: One click update&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;This one is something I love about AJAX. The vote buttons on sites, the follow button on Twitter, delete entry buttons and many more of those. The convenience of just clicking once without having to refresh the page is awesome. It’s so simple, yet so powerful.&lt;br&gt; If you are using such a thing, keep &lt;em&gt;case 2&lt;/em&gt; in mind.&lt;/p&gt;
&lt;h2 id=&quot;case-4-content-loading&quot;&gt;&lt;strong&gt;Case 4: Content loading&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;One of the most important things of dynamic loading: it has to be quick. Sending a request to a server doesn’t always have to take up most of the time, but loading the response can be a real pain.&lt;br&gt; Keep the response clean and small. I’ve seen examples (I’ve been guilty in the past) of people giving HTML back in the response. With this they’ll adjust the innerHTML of a container. In the worst case they’ll load a whole new page (like in &lt;em&gt;case 1&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;To solve this, please use &lt;a href=&quot;http://www.php.net/json_encode&quot;&gt;JSON&lt;/a&gt; or anything of that kind. JSON helps you convert server side variables to Javascript variables. The response the server will give are Javascript variables for Javascript to read. JSON has been implemented in PHP since version 5.2.0 and is easy to use.&lt;/p&gt;
&lt;p&gt;Don’t give HTML back to your web page, but arrays of information. This helps keeping the presentation of your site and the calculation apart from each other. Do the adjusting of the DOM in Javascript.&lt;/p&gt;
&lt;h2 id=&quot;case-5-external-services&quot;&gt;Case 5: External Services&lt;/h2&gt;
&lt;p&gt;When you use external services and feeds to build a web page in server side scripting, you rely on an external service. This can also result is pages loading slower than needed. The is why AJAX is ideal for loading external services.&lt;/p&gt;
&lt;p&gt;You can see it in action on this very page. The &lt;a href=&quot;http://www.last.fm/user/xgayax&quot;&gt;last.fm&lt;/a&gt; loader actually makes a &lt;a href=&quot;http://www.last.fm/api/show?service=278&quot;&gt;request to last.fm for an XML&lt;/a&gt; and I am reading the XML in PHP and give it back to Javascript. This will prevent slow loading of the rest of the page and let’s the information just easily slip in the page when it’s ready.&lt;/p&gt;
&lt;p&gt;I hope I’ve given my point of view on AJAX and how to use it. If you wish to discuss the things that I’ve said; please do so!&lt;/p&gt;
&lt;p&gt;Share your AJAX stories with me =)&lt;/p&gt;
</description></item><item><title>Customize the default alert() function of Javascript</title><link>https://gaya.pizza/articles/customize-the-default-alert-function-of-javascript/</link><pubDate>Wed, 11 Mar 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/customize-the-default-alert-function-of-javascript/</guid><author></author><description>&lt;p&gt;Web designers, developers and web users know them. We all have run across one of these; the Javascript alert message. Most of the time, I don’t even read them and click them away. But the more important thing is that they just look ugly, no matter which browser you use.&lt;/p&gt;
&lt;p&gt;So why not remake the whole Javascript alert function? This article will give you the basics of my customization of the alert message.&lt;/p&gt;
&lt;div class=&quot;border&quot;&gt;[![Customize the default alert() function of Javascript](/articles/customize-the-default-alert-function-of-javascript/gdalertintro.jpg &quot;Customize the default alert() function of Javascript&quot;)](/articles/customize-the-default-alert-function-of-javascript/)&lt;/div&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;

&lt;p&gt;While working on a new project which will launch in a few months (I hope!) I used a lot of alert messages in Javascript, just because it’s easy and quick to use. The problem still is that it looks ugly. So, I decided to &lt;strong&gt;overwrite the alert function&lt;/strong&gt; and create my own version of it. Sweet, not?&lt;/p&gt;
&lt;p&gt;&lt;em&gt;What did I do?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;First of all, I needed a way to overwrite the alert function because I didn’t want to go and refactor all of my code to call another function, you programmers understand me ;).&lt;br&gt; Next is how the message should displayed on the screen.&lt;/p&gt;
&lt;p&gt;The first problem is surprisingly easy, you can just overwrite a function by declaring it again.&lt;/p&gt;
&lt;p&gt;To display the message, I created a quick container which will be centered. There will also be a container beneath with message box to darken and disable the rest of the page.&lt;/p&gt;
&lt;p&gt;Okay, so now for the things you need to do.&lt;/p&gt;
&lt;p&gt;Go to &lt;a href=&quot;http://script.aculo.us/downloads&quot;&gt;http://script.aculo.us/downloads&lt;/a&gt; and download the latest version of scriptaculous.&lt;br&gt; Also download GdAlert: &lt;a href=&quot;http://gaya.github.io/scripts/gdalert/gdalert.zip&quot;&gt;http://gaya.github.io/scripts/gdalert/gdalert.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Upload the contents to your server.&lt;/p&gt;
&lt;p&gt;Now place the following code in the head section of your page.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/prototype.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/scriptaculous.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/gdAlert.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So now that you’ve got the Javascript files ready, we now need to do one last thing.&lt;/p&gt;
&lt;p&gt;Include the following code right after the **** tag:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'alert_message'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;style&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'display: none'&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;span&lt;/span&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;span&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'button'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;value&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'ok'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'button'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;onclick&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'gdAlert.close()'&lt;/span&gt; /&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;br&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;style&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'clear: both'&lt;/span&gt; /&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That was it. Now all your alert function calls will be nicer and personalized.&lt;/p&gt;
&lt;p&gt;Take a look in the CSS to configure the looks of the message box, I’d really like to see what variations you make of this script.&lt;/p&gt;
&lt;p&gt;Good luck!&lt;/p&gt;
</description></item><item><title>Album art which boosts my inspiration</title><link>https://gaya.pizza/articles/album-art-which-boosts-my-inspiration/</link><pubDate>Mon, 16 Feb 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/album-art-which-boosts-my-inspiration/</guid><author></author><description>&lt;p&gt;Today I was scrolling through albums I got, and I thought that some album covers just look amazing.&lt;/p&gt;
&lt;p&gt;Some of these album covers really want to make me listen to the album. I thought I’d share some with you. If you feel like you can add a nice one, put it in the comments below.&lt;/p&gt;
&lt;div class=&quot;border&quot;&gt;[![Album art which boosts my inspiration](/articles/album-art-which-boosts-my-inspiration/inspirationboosters.jpg &quot;Album art which boosts my inspiration&quot;)](/articles/album-art-which-boosts-my-inspiration/)&lt;/div&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;

&lt;p&gt;Album art has been ordered in alphabetical order.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.myspace.com/animosity/&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Animosity&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;border&quot;&gt;[![animosity_animal](/articles/album-art-which-boosts-my-inspiration/animosity_animal.jpg &quot;animosity_animal&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/animosity_animal/)
 Animal [2007]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;August Burns Red&lt;/span&gt;](http://www.augustburnsred.com/)

&lt;div class=&quot;border&quot;&gt;[![august-burns-red_thrill-seeker](/articles/album-art-which-boosts-my-inspiration/august-burns-red_thrill-seeker.jpg &quot;august-burns-red_thrill-seeker&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/august-burns-red_thrill-seeker/)
 Trill Seeker [2005]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;The Blood Brothers&lt;/span&gt;](http://www.thebloodbrothers.com/)

&lt;div class=&quot;border&quot;&gt;[![bloodbrother_burnpianoislandburn](/articles/album-art-which-boosts-my-inspiration/bloodbrother_burnpianoislandburn.jpg &quot;bloodbrother_burnpianoislandburn&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/bloodbrother_burnpianoislandburn/)&lt;/div&gt;&lt;div class=&quot;border&quot;&gt;&lt;/div&gt;&lt;div class=&quot;border&quot;&gt;Burn Piano Island, Burn [2003][![bloodbrothers_young-machetes](/articles/album-art-which-boosts-my-inspiration/bloodbrothers_young-machetes.jpg &quot;bloodbrothers_young-machetes&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/bloodbrothers_young-machetes/)&lt;/div&gt;&lt;div class=&quot;border&quot;&gt;Young Machetes [2006]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;Circa Survive&lt;/span&gt;](http://www.circasurvive.com/)

&lt;div class=&quot;border&quot;&gt;[![circa-survive_on-letting-go](/articles/album-art-which-boosts-my-inspiration/circa-survive_on-letting-go.jpg &quot;circa-survive_on-letting-go&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/circa-survive_on-letting-go/)
 On Letting Go [2007]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;Destroyer Destroyer&lt;/span&gt;](http://www.myspace.com/destroyerdestroyer/)

&lt;div class=&quot;border&quot;&gt;[![destroyerdestroyer_littered-with-arrows](/articles/album-art-which-boosts-my-inspiration/destroyerdestroyer_littered-with-arrows.jpg &quot;destroyerdestroyer_littered-with-arrows&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/destroyerdestroyer_littered-with-arrows/)
 Littered with Arrows [2007]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;Duck Duck Goose&lt;/span&gt;](http://www.myspace.com/duckduckgoose/)

&lt;div class=&quot;border&quot;&gt;[![duckduckgoose_morenoise](/articles/album-art-which-boosts-my-inspiration/duckduckgoose_morenoise.jpg &quot;duckduckgoose_morenoise&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/duckduckgoose_morenoise/)
 Noise, Noise and More Noise [2007]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;The Devil Wear Prada&lt;/span&gt;](http://www.myspace.com/tdwp/)

&lt;div class=&quot;border&quot;&gt;[![dwp_plagues](/articles/album-art-which-boosts-my-inspiration/dwp_plagues.jpg &quot;dwp_plagues&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/dwp_plagues/)
 Plagues [2007]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;The Fall of Troy&lt;/span&gt;](http://www.thefalloftroy.com/)

&lt;div class=&quot;border&quot;&gt;[![fot_doppelganger](/articles/album-art-which-boosts-my-inspiration/fot_doppelganger.jpg &quot;fot_doppelganger&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/fot_doppelganger/)
 Doppelgänger [2005][![fot_manipulator](/articles/album-art-which-boosts-my-inspiration/fot_manipulator.jpg &quot;fot_manipulator&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/fot_manipulator/)
 Manipulator [2007][![fot_tfot](/articles/album-art-which-boosts-my-inspiration/fot_tfot.jpg &quot;fot_tfot&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/fot_tfot/)
 S/T [2003]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;Fear Before the March of Flames&lt;/span&gt;](http://www.myspace.com/marchofflames/)

&lt;div class=&quot;border&quot;&gt;[![fbtmof_odd-how-people-shake](/articles/album-art-which-boosts-my-inspiration/fbtmof_odd-how-people-shake.jpg &quot;fbtmof_odd-how-people-shake&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/fbtmof_odd-how-people-shake/)
 Odd How People Shake [2004][![fbtmof_the-always-open-mouth](/articles/album-art-which-boosts-my-inspiration/fbtmof_the-always-open-mouth.jpg &quot;fbtmof_the-always-open-mouth&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/fbtmof_the-always-open-mouth/)
 The Always Open Mouth [2006]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;Fugazi&lt;/span&gt;](http://en.wikipedia.org/wiki/Fugazi/)

&lt;div class=&quot;border&quot;&gt;[![fugazi_redmedicine](/articles/album-art-which-boosts-my-inspiration/fugazi_redmedicine.jpg &quot;fugazi_redmedicine&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/fugazi_redmedicine/)
 Red Medicine [1995]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;Genghis Tron&lt;/span&gt;](http://www.genghistron.com/)

&lt;div class=&quot;border&quot;&gt;[![genghis-tron-board_up_the_house](/articles/album-art-which-boosts-my-inspiration/genghis-tron-board_up_the_house.jpg &quot;genghis-tron-board_up_the_house&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/genghis-tron-board_up_the_house/)
 Board Up The House [2008]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;Heavy Heavy Low Low&lt;/span&gt;](http://www.myspace.com/heavyheavylowlow/)

&lt;div class=&quot;border&quot;&gt;[![hhll_fuckit1](/articles/album-art-which-boosts-my-inspiration/hhll_fuckit1.jpg &quot;hhll_fuckit1&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/hhll_fuckit1/)
 ...fuck it?! [2007][![hhll_turtle-nipple-and-toxic-shock1](/articles/album-art-which-boosts-my-inspiration/hhll_turtle-nipple-and-toxic-shock1.jpg &quot;hhll_turtle-nipple-and-toxic-shock1&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/hhll_turtle-nipple-and-toxic-shock1/)
 Turtle Nipple and Toxic Shock [2008]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;HORSE the band&lt;/span&gt;](http://www.horsetheband.com/)

&lt;div class=&quot;border&quot;&gt;[![horsetheband_pizzaep](/articles/album-art-which-boosts-my-inspiration/horsetheband_pizzaep.jpg &quot;horsetheband_pizzaep&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/horsetheband_pizzaep/)
 Pizza EP [2006]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;IAMERROR&lt;/span&gt;](http://www.myspace.com/iamerror/)

&lt;div class=&quot;border&quot;&gt;[![iamerror_trout-yogurt](/articles/album-art-which-boosts-my-inspiration/iamerror_trout-yogurt.jpg &quot;iamerror_trout-yogurt&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/iamerror_trout-yogurt/)
 Trout Yogurt [2007]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;I Set My Friends On Fire&lt;/span&gt;](http://www.isetmyfriendsonfire.com/)

&lt;div class=&quot;border&quot;&gt;[![ismfof_you-cant-spell-slaughter-without-laughter](/articles/album-art-which-boosts-my-inspiration/ismfof_you-cant-spell-slaughter-without-laughter.jpg &quot;ismfof_you-cant-spell-slaughter-without-laughter&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/ismfof_you-cant-spell-slaughter-without-laughter/)
 You Can't Spell Slaughter Without Laughter [2008]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;IWRESTLEDABEARONCE&lt;/span&gt;](http://www.myspace.com/IWRESTLEDABEARONCE/)

&lt;div class=&quot;border&quot;&gt;[![iwrestledabearonce_iwrestledabearonce](/articles/album-art-which-boosts-my-inspiration/iwrestledabearonce_iwrestledabearonce.jpg &quot;iwrestledabearonce_iwrestledabearonce&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/iwrestledabearonce_iwrestledabearonce/)
 EP [2007]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;Maylene and the Sons of Disaster&lt;/span&gt;](http://www.mayleneandthesonsofdisaster.us/)

&lt;div class=&quot;border&quot;&gt;[![maylene_and_the_sons_of_disaster_-_ii](/articles/album-art-which-boosts-my-inspiration/maylene_and_the_sons_of_disaster_-_ii.jpg &quot;maylene_and_the_sons_of_disaster_-_ii&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/maylene_and_the_sons_of_disaster_-_ii/)
 II [2007]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;The Number Twelve Looks Like You&lt;/span&gt;](http://www.itsnumber12time.com/)

&lt;div class=&quot;border&quot;&gt;[![tntlly_mongrel](/articles/album-art-which-boosts-my-inspiration/tntlly_mongrel.jpg &quot;tntlly_mongrel&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/tntlly_mongrel/)
 Mongrel [2007]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;The Promise Ring&lt;/span&gt;](http://en.wikipedia.org/wiki/The_Promise_Ring/)

&lt;div class=&quot;border&quot;&gt;[![promisering_nothing-feels-good](/articles/album-art-which-boosts-my-inspiration/promisering_nothing-feels-good.jpg &quot;promisering_nothing-feels-good&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/promisering_nothing-feels-good/)
 Nothing Feels Good [1997]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;Saetia&lt;/span&gt;](http://www.level-plane.com/saetia/)

&lt;div class=&quot;border&quot;&gt;[![saetia_a-retrospective](/articles/album-art-which-boosts-my-inspiration/saetia_a-retrospective.jpg &quot;saetia_a-retrospective&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/saetia_a-retrospective/)
 A Retrospective [1998]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;Said and Done&lt;/span&gt;](http://www.saidanddone.org/)

&lt;div class=&quot;border&quot;&gt;[![saidanddone_endlessroads](/articles/album-art-which-boosts-my-inspiration/saidanddone_endlessroads.jpg &quot;saidanddone_endlessroads&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/saidanddone_endlessroads/)
 Endless Roads [2008]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;See You Next Tuesday&lt;/span&gt;](http://www.myspace.com/seeyounexttuesday/)

&lt;div class=&quot;border&quot;&gt;[![see-you-next-tuesday_intervals](/articles/album-art-which-boosts-my-inspiration/see-you-next-tuesday_intervals.jpg &quot;see-you-next-tuesday_intervals&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/see-you-next-tuesday_intervals/)
 Intervals [2008][![seeyounexttuesday_parasite](/articles/album-art-which-boosts-my-inspiration/seeyounexttuesday_parasite.jpg &quot;seeyounexttuesday_parasite&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/seeyounexttuesday_parasite/)
 Parasite [2007]&lt;/div&gt;[&lt;span style=&quot;font-size: large;&quot;&gt;Sunny Day Real Estate&lt;/span&gt;](http://en.wikipedia.org/wiki/Sunny_Day_Real_Estate)

&lt;div class=&quot;border&quot;&gt;[![sunny_day_real_estate_diary](/articles/album-art-which-boosts-my-inspiration/sunny_day_real_estate_diary.jpg &quot;sunny_day_real_estate_diary&quot;)](/articles/album-art-which-boosts-my-inspiration/attachment/sunny_day_real_estate_diary/)
 Diary [1994]&lt;/div&gt;</description></item><item><title>Download counter in PHP using .htaccess</title><link>https://gaya.pizza/articles/download-counter-in-php-using-htaccess/</link><pubDate>Thu, 12 Feb 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/download-counter-in-php-using-htaccess/</guid><author></author><description>&lt;p&gt;Ever had this thought: “I want to fire something *&lt;em&gt;extra *&lt;/em&gt;up when somebody downloads a certain file.”? This can be easily fixed by making all you download links link to a php page and output the download file for you. But what if the file is called directly in the browser, say &lt;a href=&quot;http://gaya.github.io/scripts/photonav/photonav.zip&quot;&gt;http://gaya.github.io/scripts/photonav/photonav.zip&lt;/a&gt;? Apache will happily give the file to the user, without me noticing it. Luckily for us, .htaccess is a great place to mess around with Apache.&lt;/p&gt;
&lt;p&gt;This article will explain how to make pre-download conditions in php using .htaccess. I’ll make a download counter in this one.&lt;/p&gt;
&lt;div class=&quot;border&quot;&gt;[![Download counter in PHP using .htaccess](/articles/download-counter-in-php-using-htaccess/downloadcounter.jpg &quot;Download counter in PHP using .htaccess&quot;)](/articles/download-counter-in-php-using-htaccess/)&lt;/div&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;

&lt;p&gt;Think of the possibilities! You could build a download counter, a place to check if the user has rights to download a certain file, create a bandwidth limit, and the list goes on and on.&lt;/p&gt;
&lt;p&gt;Keeping track of downloads is a feature many developers want, even firing *”something”* (read: &lt;strong&gt;doStuff()&lt;/strong&gt;) before a file is requested for download is handy.&lt;/p&gt;
&lt;p&gt;Okay, what do you need?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Apache web server with &lt;a href=&quot;http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html&quot;&gt;rewrite module&lt;/a&gt; enabled (probably the case)&lt;/li&gt;
&lt;li&gt;a decent text editor (like &lt;a href=&quot;http://notepad-plus.sourceforge.net/&quot;&gt;notepad++&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;optional&lt;/em&gt;: in this tutorial I’ll be using PHP&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;First, we need to get an &lt;strong&gt;.htaccess&lt;/strong&gt; rule going. To do this you have to adjust your .htaccess file, or create a new one. To create a new .htaccess file in Notepad++ just open a new file and save as &lt;strong&gt;.htaccess&lt;/strong&gt;. This is a hidden file on a unix system, but don’t worry.&lt;/p&gt;
&lt;p&gt;Put the following lines in the &lt;strong&gt;.htaccess&lt;/strong&gt; file:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;comment&quot;&gt;#Let's do rewriting!&lt;/span&gt;
RewriteEngine on
RewriteRule ^(.*).(rar|zip|pdf)$ /download.php?file=$&lt;span class=&quot;number&quot;&gt;1.&lt;/span&gt;$&lt;span class=&quot;number&quot;&gt;2&lt;/span&gt; [R,L]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This redirects every &lt;em&gt;.rar&lt;/em&gt;, &lt;em&gt;.zip&lt;/em&gt; and &lt;em&gt;.pdf&lt;/em&gt; to the &lt;strong&gt;download.php&lt;/strong&gt; file and include the file path as a parameter. I already hear developers think: “And what if I prompted it to output a .php file though a browser call?”. We’ll fix that in the PHP file.&lt;/p&gt;
&lt;p&gt;To add more extensions, separate them with a &lt;strong&gt;|&lt;/strong&gt; (shift + ).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A few notes on .htaccess:&lt;/strong&gt;&lt;br&gt; The file will work from the root of the folder you’ll put this into at your web server. All folders beneath the root will be affected. If you place the file in say &lt;em&gt;/files/&lt;/em&gt;, the path will not be included in the &lt;strong&gt;file&lt;/strong&gt; parameter. You’ll have to either add this in the &lt;strong&gt;download.php&lt;/strong&gt; file or &lt;strong&gt;.htaccess&lt;/strong&gt; file.&lt;/p&gt;
&lt;p&gt;Upload the file in your webroot.&lt;/p&gt;
&lt;p&gt;Next up, we are going to create a table in MySQL. You can do this in phpMyAdmin, it’s a small table.&lt;/p&gt;
&lt;p&gt;If you already have a table called &lt;strong&gt;download&lt;/strong&gt;, you have to change the SQL code.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;CREATE TABLE `download` (
`filename` varchar(&lt;span class=&quot;number&quot;&gt;255&lt;/span&gt;) NOT &lt;span class=&quot;keyword&quot;&gt;NULL&lt;/span&gt;,
`stats` int(&lt;span class=&quot;number&quot;&gt;11&lt;/span&gt;) NOT &lt;span class=&quot;keyword&quot;&gt;NULL&lt;/span&gt;,
PRIMARY KEY (`filename`)
)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Execute this SQL statement in the SQL window, it’ll create a new table.&lt;/p&gt;
&lt;p&gt;Now it’s time to get the PHP to work.&lt;/p&gt;
&lt;p&gt;The following code allows you to keep track of download requests in the table you created above:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;meta&quot;&gt;&amp;lt;?php&lt;/span&gt;

    &lt;span class=&quot;comment&quot;&gt;//put connection to database here&lt;/span&gt;
    mysql_connect(&lt;span class=&quot;string&quot;&gt;&quot;localhost&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;username&quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&quot;password&quot;&lt;/span&gt;)
    &lt;span class=&quot;keyword&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;die&lt;/span&gt; (&lt;span class=&quot;string&quot;&gt;&quot;Sorry, can't connect to database.&quot;&lt;/span&gt;);
    mysql_select_db(&lt;span class=&quot;string&quot;&gt;&quot;dbname&quot;&lt;/span&gt;);

    $filename = mysql_real_escape_string($_GET[&lt;span class=&quot;string&quot;&gt;'file'&lt;/span&gt;]);
    $path = $_SERVER[&lt;span class=&quot;string&quot;&gt;'DOCUMENT_ROOT'&lt;/span&gt;].&lt;span class=&quot;string&quot;&gt;&quot;/&quot;&lt;/span&gt;; &lt;span class=&quot;comment&quot;&gt;//path of this file&lt;/span&gt;
    $fullPath = $path.$filename; &lt;span class=&quot;comment&quot;&gt;//path to download file&lt;/span&gt;

    $filetypes = &lt;span class=&quot;keyword&quot;&gt;array&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&quot;rar&quot;&lt;/span&gt;,&lt;span class=&quot;string&quot;&gt;&quot;zip&quot;&lt;/span&gt;,&lt;span class=&quot;string&quot;&gt;&quot;pdf&quot;&lt;/span&gt;);

    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (!in_array(substr($filename, &lt;span class=&quot;number&quot;&gt;-3&lt;/span&gt;), $filetypes)) {
        &lt;span class=&quot;keyword&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&quot;Invalid download type.&quot;&lt;/span&gt;;
        &lt;span class=&quot;keyword&quot;&gt;exit&lt;/span&gt;;
    }

    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; ($fd = fopen ($fullPath, &lt;span class=&quot;string&quot;&gt;&quot;r&quot;&lt;/span&gt;)) {
        &lt;span class=&quot;comment&quot;&gt;//add download stat&lt;/span&gt;
        $result = mysql_query(&lt;span class=&quot;string&quot;&gt;&quot;SELECT COUNT(*) AS countfile FROM download
        WHERE filename='&quot;&lt;/span&gt; . $filename . &lt;span class=&quot;string&quot;&gt;&quot;'&quot;&lt;/span&gt;);
        $data = mysql_fetch_array($result);
        $q = &lt;span class=&quot;string&quot;&gt;&quot;&quot;&lt;/span&gt;;

        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; ($data[&lt;span class=&quot;string&quot;&gt;'countfile'&lt;/span&gt;] &amp;gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;) {
            $q = &lt;span class=&quot;string&quot;&gt;&quot;UPDATE download SET stats = stats + 1 WHERE
            filename = '&quot;&lt;/span&gt; . $filename . &lt;span class=&quot;string&quot;&gt;&quot;'&quot;&lt;/span&gt;;
        } &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; {
            $q = &lt;span class=&quot;string&quot;&gt;&quot;INSERT INTO download (filename, stats) VALUES
            ('&quot;&lt;/span&gt; . $filename . &lt;span class=&quot;string&quot;&gt;&quot;', 1)&quot;&lt;/span&gt;;
        }

        $statresult = mysql_query($q);

        &lt;span class=&quot;comment&quot;&gt;//the next part outputs the file&lt;/span&gt;
        $fsize = filesize($fullPath);
        $path_parts = pathinfo($fullPath);

        header(&lt;span class=&quot;string&quot;&gt;&quot;Content-type: application/octet-stream&quot;&lt;/span&gt;);
        header(&lt;span class=&quot;string&quot;&gt;&quot;Content-Disposition: filename=&quot;&lt;/span&gt;.$path_parts[&lt;span class=&quot;string&quot;&gt;&quot;basename&quot;&lt;/span&gt;].&lt;span class=&quot;string&quot;&gt;&quot;&quot;&lt;/span&gt;);
        header(&lt;span class=&quot;string&quot;&gt;&quot;Content-length: $fsize&quot;&lt;/span&gt;);
        header(&lt;span class=&quot;string&quot;&gt;&quot;Cache-control: private&quot;&lt;/span&gt;); &lt;span class=&quot;comment&quot;&gt;//use this to open files directly&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;while&lt;/span&gt;(!feof($fd)) {
            $buffer = fread($fd, &lt;span class=&quot;number&quot;&gt;2048&lt;/span&gt;);
            &lt;span class=&quot;keyword&quot;&gt;echo&lt;/span&gt; $buffer;
        }
    }
    fclose ($fd);
    &lt;span class=&quot;keyword&quot;&gt;exit&lt;/span&gt;;

&lt;span class=&quot;meta&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let me explain what you can change in the code in short; in the first part of the file, you’ll connect to your database. Please change the values to match your settings.&lt;/p&gt;
&lt;p&gt;You can change the &lt;strong&gt;$filetypes&lt;/strong&gt; to your likings, this will contain the accepted file extensions.&lt;/p&gt;
&lt;p&gt;The php script will eventually output the file to your browser, neat eh? &lt;a href=&quot;http://gaya.github.io/scripts/uploads/downloadhtaccess.zip&quot;&gt;Download the zip file&lt;/a&gt; for a quick look in the files.&lt;/p&gt;
&lt;p&gt;I hope this will help you to create pre-conditions on your downloads.&lt;/p&gt;
&lt;p&gt;Good luck!&lt;/p&gt;
</description></item><item><title>Lightbox + PhotoNav = LightNav</title><link>https://gaya.pizza/articles/lightbox-photonav-lightnav/</link><pubDate>Mon, 09 Feb 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/lightbox-photonav-lightnav/</guid><author></author><description>&lt;p&gt;If you’ve been around the web for a while, you might have heard of &lt;a href=&quot;http://www.huddletogether.com/projects/lightbox2/&quot;&gt;Lightbox&lt;/a&gt;. And if you used it, you might also know the limitations.&lt;/p&gt;
&lt;p&gt;One of those limitations is of course the fact that an image wider than your screen goes out of bounds. Very annoying! And it creates ugly scrolbars.&lt;/p&gt;
&lt;p&gt;As you might know, I have created a &lt;a href=&quot;http://gayadesign.nl/post/4/&quot;&gt;Panoramic Photoviewer in Javascript&lt;/a&gt; to fix the problem of images going out of bounds. And I thought to myself: “Why not try and implement PhotoNav on top of Lightbox?”. With this, even super large images would be viewable.&lt;/p&gt;
&lt;p&gt;I created LightNav for this. It runs along Lightbox without changing the script, so you can always update Lightbox if needed.&lt;/p&gt;
&lt;div class=&quot;border&quot;&gt;[![Lightbox + PhotoNav = LightNav](/articles/lightbox-photonav-lightnav/lightnav.jpg &quot;Lightbox + PhotoNav = LightNav&quot;)](/articles/lightbox-photonav-lightnav/)&lt;/div&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;

&lt;p&gt;The &lt;em&gt;example page&lt;/em&gt; is located here:&lt;br&gt;&lt;a href=&quot;http://gaya.github.io/scripts/lightnav/&quot;&gt;http://gaya.github.io/scripts/lightnav/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And the &lt;em&gt;archive is downloadable&lt;/em&gt; here:&lt;br&gt;&lt;a href=&quot;http://gaya.github.io/scripts/lightnav/lightnav.zip&quot;&gt;http://gaya.github.io/scripts/lightnav/lightnav.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Using LightNav is easy! I’ll tell you what you need to do in this step-by-step guide:&lt;/p&gt;
&lt;h2 id=&quot;1-download-lightbox-and-upload-to-your-webpage-&quot;&gt;&lt;strong&gt;1. Download Lightbox and upload to your webpage.&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Go to the Lightbox project page and download the zip: &lt;a href=&quot;http://www.huddletogether.com/projects/lightbox2/#download&quot;&gt;http://www.huddletogether.com/projects/lightbox2/#download&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The files from the zip we are going to need are: &lt;strong&gt;lightbox.js&lt;/strong&gt;, &lt;strong&gt;lightbox.css&lt;/strong&gt; and the images in the &lt;strong&gt;images&lt;/strong&gt; folder.&lt;/p&gt;
&lt;p&gt;For this installation, we &lt;strong&gt;don’t need&lt;/strong&gt; the prototype.js and scriptaculous.js file from this zip.&lt;/p&gt;
&lt;p&gt;Now upload the files to your server. Check the &lt;strong&gt;lightbox.js file&lt;/strong&gt; in the top section for the image paths. These settings are on line 49 and line 50. They have to be set correctly to get a good output on your page.&lt;/p&gt;
&lt;h2 id=&quot;2-download-and-use-scriptaculous-&quot;&gt;&lt;strong&gt;2. Download and use Scriptaculous.&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Go to &lt;a href=&quot;http://script.aculo.us/downloads&quot;&gt;http://script.aculo.us/downloads&lt;/a&gt; and download the latest version of &lt;strong&gt;scriptaculous&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Upload the files to your server.&lt;/p&gt;
&lt;p&gt;Now it’s time to make use of Lightbox and Scriptaculous on your webpage by placing this code in the head section of your webpage:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/prototype.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/scriptaculous.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/lightbox.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;css/lightbox.css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;media&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;screen&quot;&lt;/span&gt; /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Fix the paths&lt;/strong&gt; to the files as they are on your server. Now you have included the technology which will make Lightbox work. Now it’s time to include &lt;a href=&quot;http://gayadesign.nl/post/7/&quot;&gt;LightNav&lt;/a&gt; to upgrade Lightbox!&lt;/p&gt;
&lt;h2 id=&quot;3-download-lightnav-and-use-with-lightbox-&quot;&gt;&lt;strong&gt;3. Download LightNav and use with Lightbox.&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Download&lt;/strong&gt; LightNav here: &lt;a href=&quot;http://gaya.github.io/scripts/lightnav/lightnav.zip&quot;&gt;http://gaya.github.io/scripts/lightnav/lightnav.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;*&lt;em&gt;Upload *&lt;/em&gt;the contents to your server.&lt;/p&gt;
&lt;p&gt;Now place the following code in the head section of your page (&lt;strong&gt;under the previous tags!&lt;/strong&gt;)&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/lightnav.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/photonav.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'css/photonav.css'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'stylesheet'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/css'&lt;/span&gt; /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;LightNav will overwrite some functionality of Lightbox and make use of &lt;a href=&quot;http://gayadesign.nl/post/4/&quot;&gt;PhotoNav&lt;/a&gt; to create a navigation feature.&lt;/p&gt;
&lt;p&gt;You are basically done now! But if you can configure LightNav to your needs in the following part of the lightnav.js file:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//you can adjust this to your needs.&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; LightNavOptions = {
    &lt;span class=&quot;attr&quot;&gt;maxWidth&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;800&lt;/span&gt;,
    &lt;span class=&quot;attr&quot;&gt;maxHeight&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;600&lt;/span&gt;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;strong&gt;maxWidth *&lt;em&gt;and *&lt;/em&gt;maxHeight *&lt;em&gt;give the maximum width and height (in pixels) of the LightBox window, making it impossible to get bigger than that.&lt;br&gt; If you set these variables to *&lt;/em&gt;0&lt;/strong&gt; LightNav will create a width and height according to the browse window of the user, which will also fix the out of bounds problem!&lt;/p&gt;
&lt;p&gt;I hope I helped some people with this. &lt;a href=&quot;http://feeds2.feedburner.com/GayaDesign&quot;&gt;Follow my feed&lt;/a&gt; if you wish to see more Javascript tweaks.&lt;/p&gt;
&lt;p&gt;Happy tweaking your Lightbox!&lt;/p&gt;
</description></item><item><title>Fight the spammers</title><link>https://gaya.pizza/articles/fight-the-spammers/</link><pubDate>Sun, 08 Feb 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/fight-the-spammers/</guid><author></author><description>&lt;p&gt;In the first few weeks of &lt;a href=&quot;http://www.gayadesign.com/&quot;&gt;my website’s&lt;/a&gt; existence, the spam machine left my website alone. But as soon as my site got linked on various webpages around the world. The spam started to slip in. Online casinos, free slot machines and oh-so-hot girls.&lt;br&gt; There had to be something to quickly protect my site against spam. I know captcha works quite well, but the problem with captcha is that users always have to read unreadable images. These impossible captchas annoy the hell out of me, so that was out of the question.&lt;/p&gt;
&lt;p&gt;I know &lt;a href=&quot;http://wordpress.org/&quot;&gt;Wordpress&lt;/a&gt;****has a nice plugin called &lt;a href=&quot;http://akismet.com/&quot;&gt;Akismet&lt;/a&gt; which is filtering spam quite good. I’ve been using it for some time on my &lt;a href=&quot;http://ds.gayadesign.nl/&quot;&gt;DS article site&lt;/a&gt;, and it has been filtering a lot of spam.&lt;/p&gt;
&lt;div class=&quot;border&quot;&gt;[![Fight the spammers](/articles/fight-the-spammers/akismet.jpg &quot;Fight the spammers&quot;)](/articles/fight-the-spammers/)&lt;/div&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;

&lt;p&gt;Here are the things I used to filter spam:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.achingbrain.net/stuff/php/akismet&quot;&gt;http://www.achingbrain.net/stuff/php/akismet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://wordpress.com/api-keys/&quot;&gt;http://wordpress.com/api-keys/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I already had the Wordpress API key because of my DS blog. You can also use one if you already have a Wordpress blog.&lt;/p&gt;
&lt;p&gt;The main thing you need to do in order to filter spam content is to let Akismet check the content of the posted data. This can be for comments, short messages or just any content a user is able to post.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;include&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;'/path/to/akismet/class.php'&lt;/span&gt;);
$WordPressAPIKey = &lt;span class=&quot;string&quot;&gt;'aoeu1aoue'&lt;/span&gt;;
$MyBlogURL = &lt;span class=&quot;string&quot;&gt;'http://www.example.com/blog/'&lt;/span&gt;;

$akismet = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; Akismet($MyBlogURL ,$WordPressAPIKey);
$akismet-&amp;gt;setCommentAuthor($name);
$akismet-&amp;gt;setCommentAuthorEmail($email);
$akismet-&amp;gt;setCommentAuthorURL($url);
$akismet-&amp;gt;setCommentContent($comment);
$akismet-&amp;gt;setPermalink(&lt;span class=&quot;string&quot;&gt;&quot;http://www.example.com/blog/alex/someurl/&quot;&lt;/span&gt;);

&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt;($akismet-&amp;gt;isCommentSpam()) {
    &lt;span class=&quot;comment&quot;&gt;// store the comment but mark it as spam (in case of a mis-diagnosis)&lt;/span&gt;
} &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; {
    &lt;span class=&quot;comment&quot;&gt;// store the comment normally&lt;/span&gt;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It’s just that easy! Include the PHP class, set some parameters and let Akismet do the checking.&lt;/p&gt;
&lt;p&gt;Be sure to store the spam also! Sometimes regular messages can be marked as spam, which is a bad thing. I just used an easy field in my comments table to mark it as spam or a normal message.&lt;/p&gt;
&lt;p&gt;If you want to implement Akismet on another platform you should check out: &lt;a href=&quot;http://akismet.com/development/&quot;&gt;http://akismet.com/development/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Good luck giving the finger to spam without Captcha!&lt;/p&gt;
</description></item><item><title>Groovy, baby!</title><link>https://gaya.pizza/articles/groovy-baby/</link><pubDate>Tue, 03 Feb 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/groovy-baby/</guid><author></author><description>&lt;p&gt;The last six months I’ve been researching a fairly new programming language with some of my classmates. In this period we’ve come to learn a lot about the language and the community surrounding it.&lt;br&gt; Our task was to investigate &lt;a href=&quot;http://groovy.codehaus.org/&quot;&gt;Groovy&lt;/a&gt;, &lt;a href=&quot;http://grails.org/&quot;&gt;Grails&lt;/a&gt;, and their position in a &lt;a href=&quot;http://en.wikipedia.org/wiki/Service-oriented_architecture&quot;&gt;SOA environment&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;After lots and lots of hours of work we managed to finally complete our research study and hold a course day for approx. 20 people at &lt;a href=&quot;http://www.han.nl/start-en/&quot;&gt;HAN University of Applied Sciences&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;border&quot;&gt;[![Groovy, baby!](/articles/groovy-baby/grandeur.jpg &quot;Groovy, baby!&quot;)](/articles/groovy-baby/)&lt;/div&gt;I want to thank Bart van Zeeland, [Youssef El Messaoudi](http://koffieislekker.nl/), [Marco Kuiper](http://www.marcofolio.net/) and Jaap Mengers for being my colleagues during this study. I'd also like to thank Rody Middelkoop and Sander Leer for lecturing us.

&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Download it here:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://gaya.github.io/scripts/uploads/researchpaper.pdf&quot;&gt;http://gaya.github.io/scripts/uploads/researchpaper.pdf&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This paper is aimed at answering the following question:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;‘What are the characteristics of Groovy (and Grails) and what impact do they have for an implementation in an SOA within enterprise applications?’&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Groovy is a dynamic language and utilizes the Java Virtual Machine. Its dynamic nature lies in the ability to alter its classes at runtime, thus allowing for constant change. Due to its foundation in Java, it can cooperate with and enrich the existing Java libraries. One of the more important features that Groovy provides, is the Meta-Object Protocol, which allows Groovy to perform its dynamic capabilities. In essence, each object has an accompanying Meta-Object which contains all properties in the form of a Map, thus allowing it to scale at runtime as needed.&lt;/p&gt;
&lt;p&gt;When using Groovy for constructing webservices, some additional modules can be used. When using SOAP as the desired transport mechanism, the GroovyWS-module provides functionality that abstracts all of the low level transport operations through a simple interface. However, it is still in development and support is therefore minimal.Furthermore, only a very small part of the WS-Security stack is implemented which minimizes the developers choice for securing the webservices.&lt;/p&gt;
&lt;p&gt;For RESTful webservices, Groovy’s webframework Grails can be used. It has full support for all of the HTTP-request methods and provides url mapping. For exposing the SOA to its target audience, the Grails framework offers a quick start for developing a web interface that can interact with the SOA. Scaffolding allows Grails to generate both controllers and views based on the domain classes in the model, enabling rapid development. By default, all domain classes are persisted to a datastore through Grails Object Relational Mapping.&lt;/p&gt;
&lt;p&gt;We believe that Groovy is mature enough to be used in a production environment, however Groovy’s modules do not provide all needed functionality for SOA development, and therefor Java frameworks are still required.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(Source&lt;/em&gt;&lt;a href=&quot;http://wiki.icaprojecten.nl/pages/viewpage.action?pageId=3571717&quot;&gt;* http://wiki.icaprojecten.nl/pages/viewpage.action?pageId=3571717*&lt;/a&gt;&lt;em&gt;)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;All comments on the paper are welcome.&lt;/p&gt;
</description></item><item><title>Panoramic Photoviewer in Javascript</title><link>https://gaya.pizza/articles/panoramic-photoviewer-in-javascript/</link><pubDate>Wed, 14 Jan 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/panoramic-photoviewer-in-javascript/</guid><author></author><description>&lt;p&gt;As a webdesigner you might have had this problem: “I’ve got a nice looking wide image, but I don’t want my visitors to scroll horizontally.”&lt;/p&gt;
&lt;p&gt;A &lt;a href=&quot;http://www.siebdesign.nl/&quot;&gt;colleague&lt;/a&gt; showed me a new project he was working on. A large image appeared and I had the ability to drag and move the image around in a container. Not super efficient if you ask me, I still had to grab the image and move it around holding my mouse button. Can’t there be an easier way?&lt;/p&gt;
&lt;p&gt;This article will show you my solution to the problem and maybe even a different approach on navigation.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/panoramic-photoviewer-in-javascript/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/panoramic-photoviewer-in-javascript/postimage.jpg&quot; alt=&quot;Panoramic Photoviewer in Javascript&quot; title=&quot;Panoramic Photoviewer in Javascript&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;example page&lt;/em&gt; is located here:&lt;br&gt;&lt;a href=&quot;http://gaya.github.io/scripts/photonav/&quot;&gt;http://gaya.github.io/scripts/photonav/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And the &lt;em&gt;archive is downloadable&lt;/em&gt; here:&lt;br&gt;&lt;a href=&quot;http://gaya.github.io/scripts/photonav/photonav.zip&quot;&gt;http://gaya.github.io/scripts/photonav/photonav.zip&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;what-is-it-&quot;&gt;&lt;strong&gt;What is it?&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;This photo container has been adjusted to “move” with the cursor. To achieve this I used Javascript and a library called &lt;a href=&quot;http://www.prototypejs.org/&quot;&gt;Prototype&lt;/a&gt;. Prototype is also needed in order to run script.aculo.us. I also applied script.aculo.us to achieve the smooth moving picture.&lt;/p&gt;
&lt;h2 id=&quot;what-do-we-have-and-what-do-we-need-to-do-&quot;&gt;&lt;strong&gt;What do we have and what do we need to do?&lt;/strong&gt;&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Create a HTML layout for the picture to get in.&lt;/li&gt;
&lt;li&gt;Adjust the CSS.&lt;/li&gt;
&lt;li&gt;Make a call to PhotoNav in Javascript.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;1-create-a-html-layout&quot;&gt;&lt;strong&gt;1. Create a HTML layout&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;This is the easiest step. It might just as well be a copy paste of the code below. But be aware of three things.&lt;br&gt; First give the overall container an id (so Javascript can grab the object).&lt;br&gt; Then make sure the div with classname &lt;em&gt;fixed&lt;/em&gt; gets a second classname to correspond with the CSS (I used &lt;em&gt;opt1&lt;/em&gt; and &lt;em&gt;opt2&lt;/em&gt;).&lt;br&gt; Determine if you want to have links inside of the container, if not; you can leave the container empty.&lt;/p&gt;
&lt;p&gt;Take a look at the code below:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'photo'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;style&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'display: none;'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'navigate'&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'fixed opt1'&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;comment&quot;&gt;&amp;lt;!-- this is optional --&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://gayadesign.com/post/'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'button1'&lt;/span&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://gayadesign.com/portfolio/'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'button2'&lt;/span&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://gayadesign.com/about/'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'button3'&lt;/span&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://gayadesign.com/partners/'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'button4'&lt;/span&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'http://gayadesign.com/contact/'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'button5'&lt;/span&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;a&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The overall container “navigate” will always be hidden prior to the actual Javascript call. I also gave the &lt;em&gt;fixed&lt;/em&gt; div a second class. This classname will point to the options of the container; the height and the background image (the actual image that needs scrolling).&lt;br&gt; You can add &lt;em&gt;a tags&lt;/em&gt; to the &lt;em&gt;fixed&lt;/em&gt; container. I gave them all classnames so they can be positioned in the CSS. This part is optional.&lt;/p&gt;
&lt;p&gt;Remember to include the Prototype library and the PhotoNav Javascript files in the header (and script.aculo.us if you want to enable smooth scrolling). Also include the CSS file &lt;em&gt;photonav.css&lt;/em&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/prototype.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/scriptaculous.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/photonav.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'css/photonav.css'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'stylesheet'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/css'&lt;/span&gt; /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;2-adjust-the-css&quot;&gt;&lt;strong&gt;2. Adjust the CSS&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;The top part of the CSS has to stay the way it is, do not adjust it if you don’t know what you are doing. I put a comment at the spot where you can start to edit the CSS.**&lt;br&gt;** I’ll describe what to do at each part of the CSS.&lt;/p&gt;
&lt;p&gt;*&lt;em&gt;.photonav .photo: *&lt;/em&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.photonav&lt;/span&gt; &lt;span class=&quot;selector-class&quot;&gt;.photo&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;400px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;10px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;border&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1px&lt;/span&gt; solid gray;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Adjust the width of the total container. This has to be a fixed width in order for it to work in IE6. I have no idea why, but if the &lt;em&gt;width&lt;/em&gt; was set to &lt;em&gt;100%&lt;/em&gt;, the height was 0px. You can do &lt;em&gt;100%&lt;/em&gt; in other browser with the &lt;em&gt;!important&lt;/em&gt; trick.&lt;br&gt; The margin and border are optional, just make it as you’d like.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;.photonav .photo .opt1:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.photonav&lt;/span&gt; &lt;span class=&quot;selector-class&quot;&gt;.photo&lt;/span&gt; &lt;span class=&quot;selector-class&quot;&gt;.opt1&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;100px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;background-image&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;url&lt;/span&gt;();
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is the height of the photo container, at least, the &lt;em&gt;fixed&lt;/em&gt; container. But notice the &lt;em&gt;.opt1&lt;/em&gt;, it is the second classname we added to the &lt;em&gt;fixed&lt;/em&gt; container in the HTML part.&lt;br&gt; The background image is the image that has to be viewed inside the container.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The next part is optional and only if you want buttons inside the container.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;a.button*:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;selector-tag&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;selector-class&quot;&gt;.button1&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;margin-left&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;20px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;margin-top&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;30px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;100px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;90px&lt;/span&gt;;
    &lt;span class=&quot;attribute&quot;&gt;background-image&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;url&lt;/span&gt;();
}

&lt;span class=&quot;selector-tag&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;selector-class&quot;&gt;.button1&lt;/span&gt;&lt;span class=&quot;selector-pseudo&quot;&gt;:hover&lt;/span&gt; {
    &lt;span class=&quot;attribute&quot;&gt;background-image&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;url&lt;/span&gt;();
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In order to create a menu navigation like I did on the preview page, you need to add &lt;em&gt;a tags&lt;/em&gt; with different classnames. Define the pixels from the left side and the top of the container in the margin values. State the width and height of the button and the background image (if needed).&lt;br&gt; To create an &lt;em&gt;onhover&lt;/em&gt; effect you can add an other image in the &lt;em&gt;:hover&lt;/em&gt; part.&lt;br&gt; If you want a second &lt;em&gt;a tag&lt;/em&gt; next to the other, subtract the *height *of the previous button from the margin-top.&lt;/p&gt;
&lt;h2 id=&quot;3-make-a-call-to-photonav-in-javascript&quot;&gt;&lt;strong&gt;3. Make a call to PhotoNav in Javascript&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Now that you’ve got all the necessary HTML and CSS set, you can call the PhotoNav functionality. The following code can be put in a js file or in a &lt;em&gt;strict&lt;/em&gt; tag.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;built_in&quot;&gt;document&lt;/span&gt;.getElementById(&lt;span class=&quot;string&quot;&gt;'navigate'&lt;/span&gt;).style.display = &lt;span class=&quot;string&quot;&gt;'block'&lt;/span&gt;;
PhotoNav.init(&lt;span class=&quot;string&quot;&gt;'navigate'&lt;/span&gt;, &lt;span class=&quot;number&quot;&gt;758&lt;/span&gt;, &lt;span class=&quot;number&quot;&gt;1412&lt;/span&gt;, &lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt;, &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The specification is:&lt;br&gt;&lt;strong&gt;function **init(&lt;/strong&gt;String &lt;strong&gt;&lt;em&gt;id_of_container&lt;/em&gt;, **int *&lt;/strong&gt;width_of_container&lt;em&gt;, &lt;strong&gt;int *&lt;/strong&gt;width_of_panorama_picture&lt;/em&gt;, &lt;strong&gt;bool *&lt;/strong&gt;smoothScrolling&lt;em&gt;, &lt;strong&gt;float *&lt;/strong&gt;smoothLevel&lt;/em&gt;, &lt;strong&gt;bool*&lt;/strong&gt;debugMode*);&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;String *&lt;/strong&gt;id_of_container*:&lt;br&gt; The id of the container.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;int *&lt;/strong&gt;width_of_container&lt;em&gt;:&lt;br&gt; Give the width in pixels of the *fixed&lt;/em&gt; container. For calculating reasons.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;int *&lt;/strong&gt;width_of_panorama_picture&lt;em&gt;:&lt;br&gt; Give the width in pixels of the &lt;span style=&quot;font-style: italic;&quot;&gt;panoramic &lt;/span&gt;&lt;/em&gt;picture*. For calculating reasons.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;bool *&lt;/strong&gt;smoothScrolling*:&lt;br&gt; Enable script.aculo.us powered smooth scrolling (default: false)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;float *&lt;/strong&gt;smoothLevel*:&lt;br&gt; Level of smoothing, recommended to keep the default 0.1 (default: 0.1)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;bool*&lt;/strong&gt;debugMode&lt;em&gt;:&lt;br&gt; Enable debug mode. Outputting value to the HTML element with id *’status’&lt;/em&gt;. (default: false)&lt;/p&gt;
&lt;p&gt;If you want to enable debug mode, you have to insert the following code somewhere in your HTML:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'status'&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;symbol&quot;&gt;&amp;amp;nbsp;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that everything is set, you can fire the thing up! Enable the navigation on loading a page or by triggering an event in Javascript. If you have implementations of this script, post your examples in the comment section, I’d like to see them.&lt;/p&gt;
&lt;p&gt;Happy developing! And have fun.&lt;/p&gt;
</description></item><item><title>Customize Eclipse to a webdeveloper’s IDE</title><link>https://gaya.pizza/articles/customize-eclipse-to-a-webdevelopers-ide/</link><pubDate>Fri, 02 Jan 2009 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/customize-eclipse-to-a-webdevelopers-ide/</guid><author></author><description>&lt;p&gt;There are a lot of ways to become a better, or at least faster, webdeveloper. For instance the use of a framework like &lt;a href=&quot;http://cakephp.org/&quot;&gt;CakePHP&lt;/a&gt; to make the developing process rapid.&lt;br&gt; One of the main things I found boosting my productivity is using a nice &lt;a href=&quot;http://en.wikipedia.org/wiki/Integrated_development_environment&quot;&gt;IDE&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This article will describe how to create a PHP developer’s IDE using Eclipse, Aptana and PDT.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/customize-eclipse-to-a-webdevelopers-ide/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/customize-eclipse-to-a-webdevelopers-ide/idepost.jpg&quot; alt=&quot;Customize Eclipse to a webdeveloper&amp;#39;s IDE&quot; title=&quot;Customize Eclipse to a webdeveloper&amp;#39;s IDE&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;What should we do? Download the Aptana standalone or Eclipse? I my case, Eclipse was already installed. So I already  know how to work with it now.&lt;br&gt; I prefer having Aptana plugged into Eclipse because I also use Eclipse for other purposes than webdevelopment. This article will use the Aptana Eclipse plugin.&lt;/p&gt;
&lt;p&gt;Follow the step by step guide to get a nice IDE for PHP developers.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Download Eclipse&lt;/strong&gt;&lt;br&gt; An obvious step would be to download Eclipse. So get it at: &lt;a href=&quot;http://www.eclipse.org/downloads/&quot;&gt;http://www.eclipse.org/downloads/&lt;/a&gt;&lt;br&gt; Pick Eclipse IDE for Java EE Developers and choose your OS to the right.&lt;/p&gt;
&lt;div class=&quot;border&quot;&gt;![1](/articles/customize-eclipse-to-a-webdevelopers-ide/1.png &quot;1&quot;)&lt;/div&gt;**2. Extract Eclipse somewhere**  
 Eclipse will be downloaded as an archive. Pick a location you want to unzip the folder *eclipse*.  
 Startup *eclipse*.

&lt;div class=&quot;border&quot;&gt;![2](/articles/customize-eclipse-to-a-webdevelopers-ide/2.png &quot;2&quot;)&lt;/div&gt;**3. Get Aptana Eclipse Plugin**  
 Go to [http://www.aptana.com/studio/download](http://www.aptana.com/studio/download) and choose *Eclipse Plugin* as the installation type.  
 Click *download*, this will lead to an instructions page.

&lt;div class=&quot;border&quot;&gt;![3](/articles/customize-eclipse-to-a-webdevelopers-ide/3.png &quot;3&quot;)&lt;/div&gt;**4. Follow instructions**  
 Follow the instruction on the page. Or read the quick plugin install guide I wrote.

&lt;ol&gt;
&lt;li&gt;In Eclipse go to: &lt;em&gt;help&lt;/em&gt; &amp;gt; &lt;em&gt;software updates&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Click on the tab &lt;em&gt;available software&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Click on the &lt;em&gt;+ add site&lt;/em&gt; button to the right.&lt;/li&gt;
&lt;li&gt;Enter the url from step 3 of the main guide &lt;em&gt;(&lt;a href=&quot;http://update.aptana.com/update/studio/3.2/&quot;&gt;http://update.aptana.com/update/studio/3.2/&lt;/a&gt;)&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Check the newly appeared box&lt;/li&gt;
&lt;li&gt;Click &lt;em&gt;install&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;next&lt;/em&gt; &amp;gt; &lt;em&gt;I accept&lt;/em&gt; &amp;gt; &lt;em&gt;next&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;wait… a while&lt;/li&gt;
&lt;li&gt;restart eclipse&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;5. Aptana will ask you to install SVN&lt;/strong&gt;&lt;br&gt; You’d probably want this! I tell you. SVN can save your projects.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6. Time to install PHP functionality&lt;/strong&gt;&lt;br&gt; Go to: &lt;em&gt;help&lt;/em&gt; &amp;gt; &lt;em&gt;software updates&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;7. Add DLTK site&lt;/strong&gt;&lt;br&gt; In the tab &lt;em&gt;available software&lt;/em&gt; click on &lt;em&gt;add site&lt;/em&gt;.&lt;br&gt; Enter the following url: &lt;em&gt;&lt;a href=&quot;http://download.eclipse.org/technology/dltk/updates-dev/1.0/&quot;&gt;http://download.eclipse.org/technology/dltk/updates-dev/1.0/&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;8. Add PDT site&lt;/strong&gt;&lt;br&gt; Again, &lt;em&gt;add site&lt;/em&gt; but now with this url: &lt;em&gt;&lt;a href=&quot;http://download.eclipse.org/tools/pdt/updates/2.0/&quot;&gt;http://download.eclipse.org/tools/pdt/updates/2.0/&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;9. Select Dynamic Languages Toolkit checkbox&lt;/strong&gt;&lt;br&gt; In the list to the left, two new sites should have appeared. Expand the Dynamic Languages site and check Dynamic Languages Tooltik (not the uncategorized).&lt;/p&gt;
&lt;div class=&quot;border&quot;&gt;![10](/articles/customize-eclipse-to-a-webdevelopers-ide/10.png &quot;10&quot;)&lt;/div&gt;**10. Select PDT update checkbox  
**Seach for *PDT* in the site list. Again do not check uncategorized.

&lt;div class=&quot;border&quot;&gt;![11](/articles/customize-eclipse-to-a-webdevelopers-ide/11.png &quot;11&quot;)&lt;/div&gt;**11. Install the plugins  
**Click *install*. Follow the instructions. Wait a while and restart Eclipse.

&lt;p&gt;&lt;strong&gt;12. Open the Aptana perspective&lt;/strong&gt;&lt;br&gt; Go to: *window *&amp;gt; *open perspective *&amp;gt; *other *&amp;gt; *aptana&lt;br&gt;*&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;13. Add an FTP site&lt;/strong&gt;&lt;br&gt; In the &lt;em&gt;file browser&lt;/em&gt; (bottom left of the IDE) right click on &lt;em&gt;FTP *&amp;gt; *Add New FTP Site&lt;/em&gt;.&lt;/p&gt;
&lt;div class=&quot;border&quot;&gt;![14](/articles/customize-eclipse-to-a-webdevelopers-ide/14.png &quot;14&quot;)&lt;/div&gt;**14. Fill in information**  
 Fill in your FTP account information. Preferably a test server for now, so you can mess around with the IDE a bit.

&lt;p&gt;&lt;em&gt;&lt;em&gt;15. Start browsing your FTP folders&lt;br&gt;*&lt;/em&gt;You can now use the *file browser&lt;/em&gt; to browse your PHP projects online. When you &lt;em&gt;open *a file it will be downloaded and when you *save&lt;/em&gt; one it will be uploaded to your server. This is simple and quick if you have to adjust something in a PHP project.&lt;/p&gt;
&lt;p&gt;Now you can start experiencing a rich IDE customized to your webdeveloping needs. If you have any tips on how to improve the work flow even more or if you miss something in this guide; Please comment on this article.&lt;/p&gt;
&lt;p&gt;Happy developing!&lt;/p&gt;
</description></item><item><title>Reading XML with PHP</title><link>https://gaya.pizza/articles/reading-xml-with-php/</link><pubDate>Mon, 29 Dec 2008 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/reading-xml-with-php/</guid><author></author><description>&lt;p&gt;Since &lt;strong&gt;webservices&lt;/strong&gt; and &lt;strong&gt;RESTful&lt;/strong&gt; services are becoming more and more popular, &lt;strong&gt;XML&lt;/strong&gt; is getting a common format to exchange information. XML is easy to read and has a nice tree structure, which can be easily interpreted.&lt;/p&gt;
&lt;p&gt;This post will show you how easy it is to &lt;em&gt;read XML in PHP&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/reading-xml-with-php/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/reading-xml-with-php/xml.jpg&quot; alt=&quot;Reading XML with PHP&quot; title=&quot;Reading XML with PHP&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In this tutorial I’ll teach you how to read information which a simple webservice provides. The webservice I choose is &lt;a href=&quot;http://www.last.fm/api&quot;&gt;Last.fm&lt;/a&gt;. It’s quick, fun and has a lot of features. We’ll use the &lt;strong&gt;Recent Tracks&lt;/strong&gt; information of a user profile.&lt;/p&gt;
&lt;p&gt;According to the &lt;a href=&quot;http://www.last.fm/api/&quot;&gt;API of Last.fm&lt;/a&gt; the XML which will be returned will look something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;meta&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;lfm&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;status&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;ok&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;recenttracks&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;user&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;xgayax&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;track&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;nowplaying&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;true&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;artist&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;mbid&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;1bc41dff-5397-4c53-bb50-469d2c277197&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;The Dillinger Escape Plan&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;artist&lt;/span&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;name&lt;/span&gt;&amp;gt;&lt;/span&gt;Party Smasher&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;name&lt;/span&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;streamable&lt;/span&gt;&amp;gt;&lt;/span&gt;1&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;streamable&lt;/span&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;mbid&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;mbid&lt;/span&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;album&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;mbid&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;Ire Works&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;album&lt;/span&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;url&lt;/span&gt;&amp;gt;&lt;/span&gt;http://www.last.fm/music/The+Dillinger+Escape+Plan/_/Party+Smasher&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;url&lt;/span&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;image&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;size&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;small&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;http://userserve-ak.last.fm/serve/34s/19117171.jpg&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;image&lt;/span&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;image&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;size&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;medium&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;http://userserve-ak.last.fm/serve/64s/19117171.jpg&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;image&lt;/span&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;image&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;size&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;large&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;http://userserve-ak.last.fm/serve/126/19117171.jpg&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;image&lt;/span&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;date&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;uts&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;1230497786&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;28 Dec 2008, 20:56&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;date&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;track&lt;/span&gt;&amp;gt;&lt;/span&gt;

        ...

    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;recenttracks&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;lfm&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is a part of the actual XML Last.fm gave me. We can see that is not too complicated, which is a good thing!&lt;/p&gt;
&lt;p&gt;So what do we need to do now? First, we need that XML file in PHP. We can accomplish that by using the &lt;strong&gt;simplexml_load_file&lt;/strong&gt; function in PHP &lt;em&gt;(Introduced with PHP5)&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;It only needs the URI to the XML file and it will convert the string into an XML object. Pretty neat.&lt;/p&gt;
&lt;p&gt;Create a new PHP file and place this code somewhere:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;$completeurl = &lt;span class=&quot;string&quot;&gt;&quot;http://ws.audioscrobbler.com/2.0/?method=&amp;amp;amp;user=xgayax&quot;&lt;/span&gt; .
&lt;span class=&quot;string&quot;&gt;&quot;&amp;amp;api_key=b25b959554ed76058ac220b7b2e0a026&quot;&lt;/span&gt;;
$xml = simplexml_load_file($completeurl);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will load the given file into an object. The url can be adjusted to your needs, preferably the API key since I borrowed it from the Last.fm site.&lt;/p&gt;
&lt;p&gt;All what’s left for us to do is to loop through the given object.&lt;/p&gt;
&lt;p&gt;Take a look at the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;$tracks = $xml-&amp;gt;recenttracks-&amp;gt;track;

&lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; ($i = &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;; $i &amp;lt; &lt;span class=&quot;number&quot;&gt;3&lt;/span&gt;; $i++) {
    $nowplaying = $tracks[$i]-&amp;gt;attributes()-&amp;gt;nowplaying;
    $trackname = $tracks[$i]-&amp;gt;name;
    $artist = $tracks[$i]-&amp;gt;artist;
    $url = $tracks[$i]-&amp;gt;url;
    $date = $tracks[$i]-&amp;gt;date;
    $img = $tracks[$i]-&amp;gt;children();
    $img = $img-&amp;gt;image[&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;];

    &lt;span class=&quot;keyword&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&quot;&amp;lt;a href='&quot;&lt;/span&gt; . $url . &lt;span class=&quot;string&quot;&gt;&quot;' target='TOP'&amp;gt;&quot;&lt;/span&gt;;

    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; ($nowplaying == &lt;span class=&quot;string&quot;&gt;&quot;true&quot;&lt;/span&gt;) {
        &lt;span class=&quot;keyword&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&quot;Now playing: &quot;&lt;/span&gt;;
    }

    &lt;span class=&quot;keyword&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&quot;&amp;lt;img src='&quot;&lt;/span&gt; . $img . &lt;span class=&quot;string&quot;&gt;&quot;' alt='album' /&amp;gt;&quot;&lt;/span&gt; . 
        $artist . &lt;span class=&quot;string&quot;&gt;&quot; - &quot;&lt;/span&gt; . $trackname . &lt;span class=&quot;string&quot;&gt;&quot; @ &quot;&lt;/span&gt; . $date . &lt;span class=&quot;string&quot;&gt;&quot;
    &amp;lt;/a&amp;gt;
    &quot;&lt;/span&gt;;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To understand what is happening, I’ll explain some of the actions I did to get the right information.&lt;/p&gt;
&lt;p&gt;Going through the XML tree is easy.** $xml** will refer to the root element, which is &lt;strong&gt;&lt;lfm&gt;&lt;/strong&gt; in this case. From this element we can navigate through the XML tree.&lt;br&gt; If you want: &lt;strong&gt;&lt;lfm&gt;&lt;recenttracks&gt;&lt;track&gt;&lt;/strong&gt; you’ll get &lt;strong&gt;$xml-&amp;gt;recenttracks-&amp;gt;track&lt;/strong&gt; in PHP. And because &lt;strong&gt;recenttracks *&lt;em&gt;contains multiple *&lt;/em&gt;tracks&lt;/strong&gt; an array will be given.&lt;/p&gt;
&lt;p&gt;The size of the loop is limited to 3, you can however replace this with &lt;strong&gt;sizeof($tracks)&lt;/strong&gt; is you please.&lt;/p&gt;
&lt;p&gt;Just like explained above, getting the information inside a tag is done like this: &lt;strong&gt;$tracks[$i]-&amp;gt;tagname&lt;/strong&gt;. You’ll get the text which is inside (if it contains text, or else you’ll get an object or an empty string.)&lt;/p&gt;
&lt;p&gt;To read attribute information, you need to use the &lt;strong&gt;attributes()&lt;/strong&gt; method. Like I did in this line: &lt;strong&gt;$tracks[$i]-&amp;gt;attributes()-&amp;gt;nowplaying&lt;/strong&gt;. If the attribute doesn’t exist you’ll get an empty string.&lt;/p&gt;
&lt;p&gt;I hope this gets you into reading XML’s using PHP. It is easy and takes little time to learn.&lt;br&gt; I’ve used XML reading for serveral purposes now like synchronizing information with a database and displaying upcoming event information.&lt;/p&gt;
&lt;p&gt;The power of XML is now in your hands.&lt;/p&gt;
</description></item><item><title>Garagedoor effect using Javascript</title><link>https://gaya.pizza/articles/garagedoor-effect-using-javascript/</link><pubDate>Sun, 28 Dec 2008 00:00:00 +0000</pubDate><guid isPermaLink="true">https://gaya.pizza/articles/garagedoor-effect-using-javascript/</guid><author></author><description>&lt;p&gt;You might have noticed the menu at the top right corner of the website. That’s something what I like to call the GarageDoor effect.&lt;/p&gt;
&lt;p&gt;Creating one has now been made easy! This tutorial explains everything you need to know on how to create the same effect yourself.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gaya.pizza/articles/garagedoor-effect-using-javascript/&quot;&gt;&lt;img src=&quot;https://gaya.pizza/articles/garagedoor-effect-using-javascript/garageprev1.jpg&quot; alt=&quot;Garagedoor effect using Javascript&quot; title=&quot;Garagedoor effect using Javascript&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;more&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;An example of the GarageDoor effect in work is found here: &lt;a href=&quot;http://gaya.github.io/scripts/garagedoor/&quot;&gt;http://gaya.github.io/scripts/garagedoor/&lt;/a&gt;
&lt;em&gt;Download&lt;/em&gt; the following archive containing everything you need: &lt;a href=&quot;http://gaya.github.io/scripts/garagedoor/garagedoor.zip&quot;&gt;http://gaya.github.io/scripts/garagedoor/garagedoor.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;*Unzip *the contents of the archive and upload the contents to your server, the set folders can be adjusted to your needs.&lt;/p&gt;
&lt;p&gt;First we need to make the script ans style of the GarageDoor work. To make that happen, you’ll need Scriptaculous. This library enables interface effects, so you don’t have to create it yourself. So &lt;a href=&quot;http://script.aculo.us/downloads&quot;&gt;grab Scriptaculous&lt;/a&gt; and upload it to your server. Make sure you also upload the &lt;strong&gt;prototype.js&lt;/strong&gt; file (in the lib folder).&lt;/p&gt;
&lt;p&gt;Add the following code in the **** tag of your page:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/prototype.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/scriptaculous.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;js/garagedoor.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'css/garagedoor.css'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'stylesheet'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'text/css'&lt;/span&gt; /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will load the scripts and styles needed for the GarageDoor to work. *Adjust the paths where needed.&lt;br&gt;*&lt;/p&gt;
&lt;p&gt;The next thing you want to do is to create the HTML layout for the garagedoors. The following code shows the structure you need to create for your document:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'garagedoor'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'garagedoor'&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;title&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'linktofile'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'item'&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'underlay'&lt;/span&gt;&amp;gt;&lt;/span&gt;
            Caption text
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'uritooverlayimage'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'overlay'&lt;/span&gt; /&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'mouse'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'images/nothing.gif'&lt;/span&gt; /&amp;gt;&lt;/span&gt;&lt;span class=&quot;symbol&quot;&gt;&amp;amp;nbsp;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;title&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'linktofile'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'item'&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'underlay'&lt;/span&gt;&amp;gt;&lt;/span&gt;
            Caption text
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'uritooverlayimage'&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'overlay'&lt;/span&gt; /&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'mouse'&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;'images/nothing.gif'&lt;/span&gt; /&amp;gt;&lt;/span&gt;&lt;span class=&quot;symbol&quot;&gt;&amp;amp;nbsp;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This contains two items that will be the garagedoor. The keywords &lt;strong&gt;linktofile&lt;/strong&gt; and &lt;strong&gt;uritooverlayimage&lt;/strong&gt; have to be adjusted in order to make it work. &lt;strong&gt;Linktofile&lt;/strong&gt; is the URL of the page the button has to link to, might be confusing because it’s not an &lt;em&gt;a tag&lt;/em&gt;, but Javascript fixes it for you.&lt;/p&gt;
&lt;p&gt;The items have a default size of: &lt;strong&gt;100px width *&lt;em&gt;and *&lt;/em&gt;80px height&lt;/strong&gt;. &lt;em&gt;Create overlay images&lt;/em&gt; according to these dimensions. In order to change the size, take a look in the &lt;strong&gt;garagedoor.css&lt;/strong&gt; file and &lt;em&gt;adjust&lt;/em&gt; the &lt;strong&gt;width&lt;/strong&gt; and &lt;strong&gt;height&lt;/strong&gt; of several elements.&lt;/p&gt;
&lt;p&gt;All there is left to do is call the GarageDoor to enable the effect!&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;actionscript&quot;&gt;
    GarageDoor.scrollY = &lt;span class=&quot;number&quot;&gt;-55&lt;/span&gt;;
    GarageDoor.scrollX = &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;;
    GarageDoor.setBindings(&lt;span class=&quot;string&quot;&gt;'garagedoor'&lt;/span&gt;);
&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first line in the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag sets the amount of scrolling the overlay has to do when the cursor is floating over an item. In this example the overlay has to go 55 up, which means move -55px on the Y-axis.&lt;/p&gt;
&lt;p&gt;You can also make it scroll horizontal.&lt;/p&gt;
&lt;p&gt;Give the &lt;strong&gt;id&lt;/strong&gt; of the &lt;strong&gt;garagedoor container&lt;/strong&gt; to the &lt;strong&gt;setBindings&lt;/strong&gt; method and the GarageDoor effect will be initialized! Be sure to make the call &lt;strong&gt;after&lt;/strong&gt; creating the &lt;strong&gt;html&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;You are now set to use the GarageDoor Effect. Good luck!&lt;/p&gt;
</description></item></channel></rss>