I'm a Rails newbie and eager to learn. I welcome any suggestions or criticism you have. You can direct them to my inbox or leave me a comment below.
@@ -17,52 +16,36 @@ Styles: typocode.css
It's unlikely that he was surprised at my lengthy response, but I was. I have been known to write him long messages on topics that interest me. However, I've only been learning Rails for two weeks or so. Could I possibly have so much to say about it already? Apparently I do.
Ruby on Rails background
-
I assume a pretty basic knowledge of what Rails is, so if you're not familiar with it now's a good time to read something on the official Rails website and watch the infamous 15-minute screencast, where Rails creator, David Heinemeier Hansson, creates a simple blog application.
-
The screencasts are what sparked my curiosity, but they hardly scratch the surface of Rails. After that I spent hours reading whatever I could find about Rails before deciding to take the time to learn it well. As a result, a lot of what you read here will sound familiar if you've read other blogs and articles about Rails. This post wasn't planned so there's no list of references yet. I hope to add some links though so please contact me if any ideas or paraphrasing here is from your site, or if you know who I should give credit to.
-
Rails through my eyes
-
Rails is like my Black & Decker toolkit. I have a hammer, power screwdriver, tape measure, needle-nose pliers, wire cutters, a level, etc. This is exactly what I need—no more, no less. It helps me get things done quickly and easily that would otherwise be painful and somewhat difficult. I can pick up the tools and use them without much training. Therefore I am instantly productive with them.
-
The kit is suitable for many people who need these things at home, such as myself. Companies build skyscrapers and huge malls and apartments, and they clearly need more powerful tools than I. There are others that just need to drive in a nail to hang a picture, in which case the kit I have is overkill. They're better off just buying and using a single hammer. I happen to fall in the big grey middle chunk, not the other two.
-
I'm a university student. I code because it's satisfying and fun to create software. I do plan on coding for a living when I graduate. I don't work with ancient databases, or create monster sites like Amazon, Google, or Ebay. The last time I started coding a website from scratch I was using PHP, that was around the turn of the millennium. [It was a fan site for a favourite band of mine.]
-
After a year or so I realized I didn't have the time to do it properly (ie. securely and cleanly) if I wanted it to be done relatively soon. A slightly customized MediaWiki promptly took it's place. It did all that I needed quite well, just in a less specific way.
-
The wiki is serving my site extremely well, but there's still that itch to create my own site. I feel if Rails was around back then I may have been able to complete the project in a timely manner. I was also frustrated with PHP. Part of that is likely due to a lack of experience and of formal programming education at that time, but it was still not fun for me. It wasn't until I started learning Rails that I thought "hey, I could create that site pretty quickly using this!"
-
Rails fits my needs like a glove, and this is where it shines. Many professionals are making money creating sites in Rails, so I'm not trying to say it's for amateurs only or something equally silly.
-
Web Frameworks and iPods?
-
Some might say I have merely been swept up in hype and am following the herd. You may be right, and that's okay. I'm going to tell you a story. There was a guy who didn't get one of the oh-so-shiny iPods for a long time, though they looked neat. His discman plays mp3 CDs, and that was good enough for him. The latest iPod, which plays video, was sufficiently cool enough for him to forget that everyone at his school has an iPod and he would be trendy just like them now.
-
Shocker ending: he is I, and I am him. Now I know why everyone has one of those shiny devices. iPods and web frameworks have little in common except that many believe both the iPod and Rails are all hype and flash. I've realized that something creating this kind of buzz may actually just be a good product. I feel that this is the only other thing the iPod and Rails have in common: they are both damn good. Enough about the iPod, everyone hates hearing about it. My goal is to write about the other thing everyone is tired of hearing about.
-
Why is Rails special?
-
Rails is not magic. There are no exclusive JavaScript libraries or HTML tags. We all have to produce pages that render in the same web browsers. My dad was correct, there is nothing special about my website either. It's more or less a stock Typo website.
-
So what makes developing with Rails different? For me there are four big things that set Rails apart from the alternatives:
-
Separating data, function, and design
Readability (which is underrated)
@@ -70,148 +53,120 @@ Styles: typocode.css
Testing is so easy it hurts
-
MVC 101 (or, Separating data, function, and design)
-
Now I'm sure you've heard about separating content from design. Rails takes that one step further from just using CSS to style your website. It uses what's known as the MVC paradigm: Model-View-Controller. This is a tried and tested development method. I'd used MVC before in Cocoa programming on Mac OS X, so I was already sold on this point.
-
The model deals with your data. If you're creating an online store you have a product model, a shopping cart model, a customer model, etc. The model takes care of storing this data in the database (persistence), and presenting it to you as an object you can manipulate at runtime.
-
The view deals only with presentation. That's it, honestly. An interface to your app.
-
The controller binds the model to the view, so that when the user clicks on the Add to cart link the controller is wired to call the add_product method of the cart model and tell it which product to add. Then the controller takes the appropriate action such as redirecting the user to the shopping cart view.
-
Of course this is not exclusive to Rails, but it's an integral part of it's design.
-
Readability
-
Rails, and Ruby, both read amazingly like spoken English. This code is more or less straight out of Typo. You define relationships between objects like this:
dependent => true means if an article is deleted, it's comments go with it. Don't worry if you don't understand it all, this is just for you to see some actual Rails code.
But look how it reads! Read it out loud. I'd bet that my mom would more or less follow this, and she's anything but a programmer. That's not to say programming should be easy for grandma, but code should be easily understood by humans. Let the computer understand things that are natural for me to type, since we're making it understand a common language anyways.
-
Ruby and Ruby on Rails allow and encourage you to write beautiful code. That is so much more important than you may realize, because it leads to many other virtues. Readability is obvious, and hence maintainability. You must read code to understand and modify it. Oh, and happy programmers will be more productive than frustrated programmers.
-
Database Migrations
-
Here's one more life-saver: migrations. Migrations are a way to version your database schema from within Rails. So you have a table, call it albums, and you want to add the date the album was released. You could modify the database directly, but that's not fun. Even if you only have one server, all your configuration will be in one central place, the app. And Rails doesn't care if you have PostgreSQL, MySQL, or SQLite behind it. You can develop and test on SQLite and deploy on MySQL and the migrations will just work in both environments.
Then you run the migration (rake migrate does that) and boom, your up to date. If you're wondering, the self.down method indeed implies that you can take this the other direction as well. Think rake migrate VERSION=X.
-
Along with the other screencasts is one on migrations featuring none other than David Hansson. You should take a look, it's the third video.
-
Testing so easy it hurts
-
To start a rails project you type rails project_name and it creates a directory structure with a fresh project in it. This includes a directory appropriately called test which houses unit tests for the project. When you generate models and controllers it creates test stubs for you in that directory. Basically, it makes it so easy to test that you're a fool not to do it. As someone wrote on their site: It means never having to say "I introduced a new bug while fixing another."
-
Rails builds on the unit testing that comes with Ruby. On a larger scale, that means that Rails is unlikely to flop on you because it is regularly tested using the same method. Ruby is unlikely to flop for the same reason. That makes me look good as a programmer. If you code for a living then it's of even more value to you.
-
I don't know why it hurts. Maybe it hurts developers working with other frameworks or languages to see us have it so nice and easy.
-
Wrapping up
-
Rails means I have fun doing web development instead of being frustrated (CSS hacks aside). David Hansson may be right when he said you have to have been soured by Java or PHP to fully appreciate Rails, but that doesn't mean you won't enjoy it if you do like Java or PHP.
-
Justin Gehtland rewrote a Java app using Rails and the number of lines of code of the Rails version was very close to that of the XML configuration for the Java version. Java has strengths, libraries available now seems to be a big one, but it's too big for my needs. If you're like me then maybe you'll enjoy Rails as much as I do.
-
You're not done, you lied to me!
-
Sort of... there are a few things that it seems standard to include when someone writes about how Rails saved their life and gave them hope again. For completeness sake, I feel compelled to mention some principles common amongst those who develop Rails, and those who develop on Rails. It's entirely likely that there's nothing new for you here unless you're new to Rails or to programming, in which case I encourage you to read on.
-
DRY
-
Rails follows the DRY principle religiously. That is, Don't Repeat Yourself. Like MVC, I was already sold on this. I had previously encountered it in The Pragmatic Programmer. Apart from telling some_model it belongs_to :other_model and other_model that it has_many :some_models nothing has jumped out at me which violates this principle. However, I feel that reading a model's code and seeing it's relationships to other models right there is a Good Thingâ„¢.
-
Convention over configuration (or, Perceived intelligence)
Rails seems to have a level of intelligence which contributes to the wow-factor. After these relationships are defined I can now filter certain negative comments like so:
+```ruby
+article = Article.find :first
+for comment in article.comments do
+ print comment unless comment.downcase == 'you suck!'
+end
+```
Rails knows to look for the field article_id in the comments table of the database. This is just a convention. You can call it something else but then you have to tell Rails what you like to call it.
-
Rails understands pluralization, which is a detail but it makes everything feel more natural. If you have a Person model then it will know to look for the table named people.
-
Code as you learn
-
I love how I've only been coding in Rails for a week or two and I can do so much already. It's natural, concise and takes care of the inane details. I love how I know that I don't even have to explain that migration example. It's plainly clear what it does to the database. It doesn't take long to get the basics down and once you do it goes fast.
-
diff --git a/posts/2006/02/sjs-rails-bundle-0_2-for-textmate.md b/posts/2006/02/sjs-rails-bundle-0_2-for-textmate.md
index 63d8695..8c6dc43 100644
--- a/posts/2006/02/sjs-rails-bundle-0_2-for-textmate.md
+++ b/posts/2006/02/sjs-rails-bundle-0_2-for-textmate.md
@@ -1,10 +1,9 @@
---
-Title: SJ's Rails Bundle 0.2 for TextMate
+Title: "SJ's Rails Bundle 0.2 for TextMate"
Author: Sami Samhuri
-Date: 23rd February, 2006
+Date: "23rd February, 2006"
Timestamp: 2006-02-23T17:18:00-08:00
Tags: textmate, rails, coding, bundle, macros, rails, snippets, textmate
-Styles: typocode.css
---
Everything that you've seen posted on my blog is now available in one bundle. Snippets for Rails database migrations and assertions are all included in this bundle.
@@ -13,15 +12,17 @@ There are 2 macros for class-end and def-end blocks, bound to ⌃C
method(arg1,arg2_)
+```ruby
+method(arg1, arg2_)
+```
Typing ⌃D at this point results in this code:
-
-
def method(arg1,arg2)
- _
-end
+```ruby
+def method(arg1, arg2)
+ _
+end
+```
There is a list of the snippets in Features.rtf, which is included in the disk image. Of course you can also browse them in the Snippets Editor built into TextMate.
diff --git a/posts/2006/02/some-textmate-snippets-for-rails-migrations.md b/posts/2006/02/some-textmate-snippets-for-rails-migrations.md
index 22055e7..0aeebb0 100644
--- a/posts/2006/02/some-textmate-snippets-for-rails-migrations.md
+++ b/posts/2006/02/some-textmate-snippets-for-rails-migrations.md
@@ -1,7 +1,7 @@
---
-Title: Some TextMate snippets for Rails Migrations
+Title: "Some TextMate snippets for Rails Migrations"
Author: Sami Samhuri
-Date: 18th February, 2006
+Date: "18th February, 2006"
Timestamp: 2006-02-18T22:48:00-08:00
Tags: textmate, rails, hacking, rails, snippets, textmate
---
@@ -16,39 +16,53 @@ Scope should be *source.ruby.rails* and the triggers I use are above the snippet
mcdt: **M**igration **C**reate and **D**rop **T**able
- create_table "${1:table}" do |t|
- $0
- end
- ${2:drop_table "$1"}
+```ruby
+create_table "${1:table}" do |t|
+ $0
+end
+${2:drop_table "$1"}
+```
mcc: **M**igration **C**reate **C**olumn
- t.column "${1:title}", :${2:string}
+```ruby
+t.column "${1:title}", :${2:string}
+```
marc: **M**igration **A**dd and **R**emove **C**olumn
- add_column "${1:table}", "${2:column}", :${3:string}
- ${4:remove_column "$1", "$2"}
+```ruby
+add_column "${1:table}", "${2:column}", :${3:string}
+${4:remove_column "$1", "$2"}
+```
I realize this might not be for everyone, so here are my original 4 snippets that do the work of *marc* and *mcdt*.
mct: **M**igration **C**reate **T**able
- create_table "${1:table}" do |t|
- $0
- end
+```ruby
+create_table "${1:table}" do |t|
+ $0
+end
+```
mdt: **M**igration **D**rop **T**able
- drop_table "${1:table}"
+```ruby
+drop_table "${1:table}"
+```
mac: **M**igration **A**dd **C**olumn
- add_column "${1:table}", "${2:column}", :${3:string}
+```ruby
+add_column "${1:table}", "${2:column}", :${3:string}
+```
mrc: **M**igration **R**remove **C**olumn
- remove_column "${1:table}", "${2:column}"
+```ruby
+remove_column "${1:table}", "${2:column}"
+```
I'll be adding more snippets and macros. There should be a central place where the rails bundle can be improved and extended. Maybe there is...
@@ -91,4 +105,3 @@ I'll be adding more snippets and macros. There should be a central place where t
P.S. I tried several ways to get the combo-snippets to put the pieces inside the right functions but failed. We'll see tomorrow if Allan (creator of TextMate) has any ideas.
-
diff --git a/posts/2006/02/textmate-insert-text-into-self-down.md b/posts/2006/02/textmate-insert-text-into-self-down.md
index df9b935..34fb1b6 100644
--- a/posts/2006/02/textmate-insert-text-into-self-down.md
+++ b/posts/2006/02/textmate-insert-text-into-self-down.md
@@ -1,46 +1,44 @@
---
-Title: TextMate: Insert text into self.down
+Title: "TextMate: Insert text into self.down"
Author: Sami Samhuri
-Date: 21st February, 2006
+Date: "21st February, 2006"
Timestamp: 2006-02-21T14:55:00-08:00
Tags: textmate, rails, hacking, commands, macro, rails, snippets, textmate
-Styles: typocode.css
---
UPDATE: I got everything working and it's all packaged up here. There's an installation script this time as well.
Thanks to a helpful thread on the TextMate mailing list I have the beginning of a solution to insert text at 2 (or more) locations in a file.
-
I implemented this for a new snippet I was working on for migrations, rename_column. Since the command is the same in self.up and self.down simply doing a reverse search for rename_column in my hackish macro didn't return the cursor the desired location.
That's enough introduction, here's the program to do the insertion:
#!/usr/bin/env ruby
-def indent(s)
- s=~/^(\s*)/
- ''*$1.length
-end
+up_line = 'rename_column "${1:table}", "${2:column}", "${3:new_name}"$0'
+down_line = "rename_column \"$$1\", \"$$3\", \"$$2\"\n"
-up_line='rename_column "${1:table}", "${2:column}", "${3:new_name}"$0'
-down_line="rename_column \"$$1\", \"$$3\", \"$$2\"\n"
+# find the end of self.down and insert 2nd line
+lines = STDIN.read.to_a.reverse
+ends_seen = 0
+lines.each_with_index do |line, i|
+ ends_seen += 1 if line =~ /^\s*end\b/
+ if ends_seen == 2
+ lines[i..i] = [lines[i], indent(lines[i]) * 2 + down_line]
+ break
+ end
+end
-# find the end of self.down and insert 2nd line
-lines=STDIN.read.to_a.reverse
-ends_seen=0
-lines.each_with_indexdo|line,i|
- ends_seen+=1ifline=~/^\s*end\b/
- ifends_seen==2
- lines[i..i]=[lines[i],indent(lines[i])*2+down_line]
- break
- end
-end
-
-# return the new text, escaping special chars
-printup_line+lines.reverse.to_s.gsub('[$`\\]','\\\\\1').gsub('\\$\\$','$')
+# return the new text, escaping special chars
+print up_line + lines.reverse.to_s.gsub(/([$`\\])/, '\\\\\1').gsub(/\$\$/, '$')
+```
Save this as a command in your Rails, or syncPeople on Rails, bundle. The command options should be as follows:
-
Save: Nothing
Input: Selected Text or Nothing
@@ -49,10 +47,8 @@ Styles: typocode.css
Scope Selector: source.ruby.rails
-
The first modification it needs is to get the lines to insert as command line arguments so we can use it for other snippets. Secondly, regardless of the Re-indent pasted text setting the text returned is indented incorrectly.
-
The macro I'm thinking of to invoke this is tab-triggered and will simply:
Select word (⌃W)
@@ -60,5 +56,3 @@ The macro I'm thinking of to invoke this is tab-triggered and will simply:
UPDATE:This is obsolete, see this post for a better solution.
Duane's comment prompted me to think about how to get the drop_table and remove_column lines inserted in the right place. I don't think TextMate's snippets are built to do this sort of text manipulation. It would be nicer, but a quick hack will suffice for now.
Use MCDT to insert:
-
create_table"table"do|t|
+```ruby
+create_table "table" do |t|
-end
-drop_table"table"
+end
+drop_table "table"
+```
Then press tab once more after typing the table name to select the code drop_table "table". I created a macro that cuts the selected text, finds def self.down and pastes the line there. Then it searches for the previous occurence of create_table and moves the cursor to the next line, ready for you to add some columns.
-
I have this bound to ⌃⌥⌘M because it wasn't in use. If your Control key is to the left the A key it's quite comfortable to hit this combo. Copy the following file into ~/Library/Application Support/TextMate/Bundles/Rails.tmbundle/Macros.
This works for the MARC snippet as well. I didn't tell you the whole truth, the macro actually finds the previous occurence of (create_table|add_column).
-
The caveat here is that if there is a create_table or add_column between self.down and the table you just added, it will jump back to the wrong spot. It's still faster than doing it all manually, but should be improved. If you use these exclusively, the order they occur in self.down will be opposite of that in self.up. That means either leaving things backwards or doing the re-ordering manually. =/
diff --git a/posts/2006/02/textmate-snippets-for-rails-assertions.md b/posts/2006/02/textmate-snippets-for-rails-assertions.md
index 0e7cc1a..6255751 100644
--- a/posts/2006/02/textmate-snippets-for-rails-assertions.md
+++ b/posts/2006/02/textmate-snippets-for-rails-assertions.md
@@ -1,7 +1,7 @@
---
-Title: TextMate Snippets for Rails Assertions
+Title: "TextMate Snippets for Rails Assertions"
Author: Sami Samhuri
-Date: 20th February, 2006
+Date: "20th February, 2006"
Timestamp: 2006-02-20T23:52:00-08:00
Tags: textmate, rails, coding, rails, snippets, testing, textmate
---
diff --git a/posts/2006/02/touch-screen-on-steroids.md b/posts/2006/02/touch-screen-on-steroids.md
index 14cea60..7b7e93b 100644
--- a/posts/2006/02/touch-screen-on-steroids.md
+++ b/posts/2006/02/touch-screen-on-steroids.md
@@ -1,7 +1,7 @@
---
-Title: Touch Screen on Steroids
+Title: "Touch Screen on Steroids"
Author: Sami Samhuri
-Date: 8th February, 2006
+Date: "8th February, 2006"
Timestamp: 2006-02-08T06:06:00-08:00
Tags: technology, touch
---
diff --git a/posts/2006/02/urban-extreme-gymnastics.md b/posts/2006/02/urban-extreme-gymnastics.md
index fd09b10..a3838a6 100644
--- a/posts/2006/02/urban-extreme-gymnastics.md
+++ b/posts/2006/02/urban-extreme-gymnastics.md
@@ -1,7 +1,7 @@
---
-Title: Urban Extreme Gymnastics?
+Title: "Urban Extreme Gymnastics?"
Author: Sami Samhuri
-Date: 15th February, 2006
+Date: "15th February, 2006"
Timestamp: 2006-02-15T10:41:00-08:00
Tags: amusement
---
diff --git a/posts/2006/03/generate-selfdown-in-your-rails-migrations.md b/posts/2006/03/generate-selfdown-in-your-rails-migrations.md
index 0fd9e19..3a11eae 100644
--- a/posts/2006/03/generate-selfdown-in-your-rails-migrations.md
+++ b/posts/2006/03/generate-selfdown-in-your-rails-migrations.md
@@ -1,7 +1,7 @@
---
-Title: Generate self.down in your Rails migrations
+Title: "Generate self.down in your Rails migrations"
Author: Sami Samhuri
-Date: 3rd March, 2006
+Date: "3rd March, 2006"
Timestamp: 2006-03-03T21:38:00-08:00
Tags: rails, textmate, migrations, rails, textmate
---
diff --git a/posts/2006/03/i-dont-mind-fairplay-either.md b/posts/2006/03/i-dont-mind-fairplay-either.md
index 1493050..da1cf2b 100644
--- a/posts/2006/03/i-dont-mind-fairplay-either.md
+++ b/posts/2006/03/i-dont-mind-fairplay-either.md
@@ -1,7 +1,7 @@
---
-Title: I don't mind FairPlay either
+Title: "I don't mind FairPlay either"
Author: Sami Samhuri
-Date: 3rd March, 2006
+Date: "3rd March, 2006"
Timestamp: 2006-03-03T21:56:00-08:00
Tags: apple, mac os x, life, drm, fairplay, ipod, itunes
---
diff --git a/posts/2006/03/spore.md b/posts/2006/03/spore.md
index 770ffbc..a317e43 100644
--- a/posts/2006/03/spore.md
+++ b/posts/2006/03/spore.md
@@ -1,7 +1,7 @@
---
-Title: Spore
+Title: "Spore"
Author: Sami Samhuri
-Date: 3rd March, 2006
+Date: "3rd March, 2006"
Timestamp: 2006-03-03T21:43:00-08:00
Tags: amusement, technology, cool, fun, games
---
diff --git a/posts/2006/04/zsh-terminal-goodness-on-os-x.md b/posts/2006/04/zsh-terminal-goodness-on-os-x.md
index 93cda1d..279123e 100644
--- a/posts/2006/04/zsh-terminal-goodness-on-os-x.md
+++ b/posts/2006/04/zsh-terminal-goodness-on-os-x.md
@@ -1,7 +1,7 @@
---
-Title: zsh terminal goodness on OS X
+Title: "zsh terminal goodness on OS X"
Author: Sami Samhuri
-Date: 4th April, 2006
+Date: "4th April, 2006"
Timestamp: 2006-04-04T14:57:00-07:00
Tags: mac os x, apple, osx, terminal, zsh
---
diff --git a/posts/2006/05/os-x-and-fitts-law.md b/posts/2006/05/os-x-and-fitts-law.md
index ec1b553..48bfbfe 100644
--- a/posts/2006/05/os-x-and-fitts-law.md
+++ b/posts/2006/05/os-x-and-fitts-law.md
@@ -1,7 +1,7 @@
---
-Title: OS X and Fitt's law
+Title: "OS X and Fitt's law"
Author: Sami Samhuri
-Date: 7th May, 2006
+Date: "7th May, 2006"
Timestamp: 2006-05-07T20:43:00-07:00
Tags: mac os x, apple, mac, os, usability, x
---
diff --git a/posts/2006/05/wikipediafs-on-linux-in-python.md b/posts/2006/05/wikipediafs-on-linux-in-python.md
index 97c2ccf..6a81c63 100644
--- a/posts/2006/05/wikipediafs-on-linux-in-python.md
+++ b/posts/2006/05/wikipediafs-on-linux-in-python.md
@@ -1,7 +1,7 @@
---
-Title: WikipediaFS on Linux, in Python
+Title: "WikipediaFS on Linux, in Python"
Author: Sami Samhuri
-Date: 7th May, 2006
+Date: "7th May, 2006"
Timestamp: 2006-05-07T20:49:00-07:00
Tags: hacking, python, linux, fuse, linux, mediawiki, python, wikipediafs
---
diff --git a/posts/2006/06/apple-pays-attention-to-detail.md b/posts/2006/06/apple-pays-attention-to-detail.md
index 59aebbe..cc50544 100644
--- a/posts/2006/06/apple-pays-attention-to-detail.md
+++ b/posts/2006/06/apple-pays-attention-to-detail.md
@@ -1,7 +1,7 @@
---
-Title: Apple pays attention to detail
+Title: "Apple pays attention to detail"
Author: Sami Samhuri
-Date: 11th June, 2006
+Date: "11th June, 2006"
Timestamp: 2006-06-11T01:30:00-07:00
Tags: technology, mac os x, apple
---
diff --git a/posts/2006/06/ich-bin-auslnder-und-spreche-nicht-gut-deutsch.md b/posts/2006/06/ich-bin-auslnder-und-spreche-nicht-gut-deutsch.md
index 3736759..de8ce70 100644
--- a/posts/2006/06/ich-bin-auslnder-und-spreche-nicht-gut-deutsch.md
+++ b/posts/2006/06/ich-bin-auslnder-und-spreche-nicht-gut-deutsch.md
@@ -1,7 +1,7 @@
---
-Title: Ich bin Ausländer und spreche nicht gut Deutsch
+Title: "Ich bin Ausländer und spreche nicht gut Deutsch"
Author: Sami Samhuri
-Date: 5th June, 2006
+Date: "5th June, 2006"
Timestamp: 2006-06-05T10:11:00-07:00
Tags: life, munich, seekport, work
---
diff --git a/posts/2006/06/never-buy-a-german-keyboard.md b/posts/2006/06/never-buy-a-german-keyboard.md
index de487e8..43c012c 100644
--- a/posts/2006/06/never-buy-a-german-keyboard.md
+++ b/posts/2006/06/never-buy-a-german-keyboard.md
@@ -1,7 +1,7 @@
---
-Title: Never buy a German keyboard!
+Title: "Never buy a German keyboard!"
Author: Sami Samhuri
-Date: 9th June, 2006
+Date: "9th June, 2006"
Timestamp: 2006-06-09T01:17:00-07:00
Tags: apple, apple, german, keyboard
---
diff --git a/posts/2006/06/theres-nothing-regular-about-regular-expressions.md b/posts/2006/06/theres-nothing-regular-about-regular-expressions.md
index ca9cd48..385b9b8 100644
--- a/posts/2006/06/theres-nothing-regular-about-regular-expressions.md
+++ b/posts/2006/06/theres-nothing-regular-about-regular-expressions.md
@@ -1,7 +1,7 @@
---
-Title: There's nothing regular about regular expressions
+Title: "There's nothing regular about regular expressions"
Author: Sami Samhuri
-Date: 10th June, 2006
+Date: "10th June, 2006"
Timestamp: 2006-06-10T01:28:00-07:00
Tags: technology, book, regex
---
@@ -16,8 +16,9 @@ It requires more thinking than the last 2 computer books I read, *Programming Ru
QOTD, p. 329, about matching nested pairs of parens:
- \(([^()]|\(([^()]|\(([^()]|\(([^()])*\))*\))*\))*\)
- Wow, that's ugly.
+```conf
+\(([^()]|\(([^()]|\(([^()]|\(([^()])*\))*\))*\))*\)
+Wow, that's ugly.
+```
(Don't worry, there's a much better solution on the next 2 pages after that quote.)
-
diff --git a/posts/2006/07/class-method-instance-method-it-doesnt-matter-to-php.md b/posts/2006/07/class-method-instance-method-it-doesnt-matter-to-php.md
index 3bb1516..7e3e579 100644
--- a/posts/2006/07/class-method-instance-method-it-doesnt-matter-to-php.md
+++ b/posts/2006/07/class-method-instance-method-it-doesnt-matter-to-php.md
@@ -1,7 +1,7 @@
---
-Title: Class method? Instance method? It doesn't matter to PHP
+Title: "Class method? Instance method? It doesn't matter to PHP"
Author: Sami Samhuri
-Date: 21st July, 2006
+Date: "21st July, 2006"
Timestamp: 2006-07-21T07:56:00-07:00
Tags: php, coding
---
@@ -16,7 +16,7 @@ I would fully expect the PHP parser to give me an error like "No class method [f
This code:
-
+```php
class Foo {
public static function static_fun()
{
@@ -29,7 +29,7 @@ class Foo {
}
}
-echo '<pre>';
+echo '
+```php
From Foo:
This is a class method!
This is an instance method!
@@ -52,7 +52,7 @@ This is an instance method!
From $foo = new Foo():
This is a class method!
This is an instance method!
-
+```
What the fuck?! http://www.php.net/manual/en/language.oop5.static.php is lying to everyone.
diff --git a/posts/2006/07/late-static-binding.md b/posts/2006/07/late-static-binding.md
index 6d673b5..965bf34 100644
--- a/posts/2006/07/late-static-binding.md
+++ b/posts/2006/07/late-static-binding.md
@@ -1,7 +1,7 @@
---
-Title: Late static binding
+Title: "Late static binding"
Author: Sami Samhuri
-Date: 19th July, 2006
+Date: "19th July, 2006"
Timestamp: 2006-07-19T10:23:00-07:00
Tags: php, coding, coding, php
---
@@ -10,8 +10,7 @@ Tags: php, coding, coding, php
As colder on ##php (freenode) told me today, class methods in PHP don't have what they call late static binding. What's that? It means that this code:
-
-
+```php
class Foo
{
public static function my_method()
@@ -24,15 +23,13 @@ class Bar extends Foo
{}
Bar::my_method();
-
-
+```
outputs "I'm a Foo!", instead of "I'm a Bar!". That's not fun.
Using __CLASS__ in place of get_class() makes zero difference. You end up with proxy methods in each subclass of Foo that pass in the real name of the calling class, which sucks.
-
-
+```php
class Bar extends Foo
{
public static function my_method()
@@ -40,8 +37,7 @@ class Bar extends Foo
return parent::my_method( get_class() );
}
}
-
-
+```
I was told that they had a discussion about this on the internal PHP list, so at least they're thinking about this stuff. Too bad PHP5 doesn't have it. I guess I should just be glad I won't be maintaining this code.
diff --git a/posts/2006/07/ruby-and-rails-have-spoiled-me-rotten.md b/posts/2006/07/ruby-and-rails-have-spoiled-me-rotten.md
index e27f1dc..768418c 100644
--- a/posts/2006/07/ruby-and-rails-have-spoiled-me-rotten.md
+++ b/posts/2006/07/ruby-and-rails-have-spoiled-me-rotten.md
@@ -1,7 +1,7 @@
---
-Title: Ruby and Rails have spoiled me rotten
+Title: "Ruby and Rails have spoiled me rotten"
Author: Sami Samhuri
-Date: 17th July, 2006
+Date: "17th July, 2006"
Timestamp: 2006-07-17T05:40:00-07:00
Tags: rails, ruby, php, coding, framework, php, rails, ruby, zend
---
diff --git a/posts/2006/07/ubuntu-linux-for-linux-users-please.md b/posts/2006/07/ubuntu-linux-for-linux-users-please.md
index 9c100d4..4bb18ea 100644
--- a/posts/2006/07/ubuntu-linux-for-linux-users-please.md
+++ b/posts/2006/07/ubuntu-linux-for-linux-users-please.md
@@ -1,7 +1,7 @@
---
-Title: Ubuntu: Linux for Linux users please
+Title: "Ubuntu: Linux for Linux users please"
Author: Sami Samhuri
-Date: 13th July, 2006
+Date: "13th July, 2006"
Timestamp: 2006-07-13T08:34:00-07:00
Tags: linux, linux, ubuntu
---
diff --git a/posts/2006/07/working-with-the-zend-framework.md b/posts/2006/07/working-with-the-zend-framework.md
index 188ae38..e22d73b 100644
--- a/posts/2006/07/working-with-the-zend-framework.md
+++ b/posts/2006/07/working-with-the-zend-framework.md
@@ -1,7 +1,7 @@
---
-Title: Working with the Zend Framework
+Title: "Working with the Zend Framework"
Author: Sami Samhuri
-Date: 6th July, 2006
+Date: "6th July, 2006"
Timestamp: 2006-07-06T07:36:00-07:00
Tags: coding, technology, php, framework, php, seekport, zend
---
diff --git a/posts/2006/08/where-are-my-headphones.md b/posts/2006/08/where-are-my-headphones.md
index a7edd27..7895735 100644
--- a/posts/2006/08/where-are-my-headphones.md
+++ b/posts/2006/08/where-are-my-headphones.md
@@ -1,7 +1,7 @@
---
-Title: Where are my headphones?
+Title: "Where are my headphones?"
Author: Sami Samhuri
-Date: 22nd August, 2006
+Date: "22nd August, 2006"
Timestamp: 2006-08-22T07:31:00-07:00
Tags: life, seekport
---
diff --git a/posts/2006/09/buffalo-buffalo-buffalo-buffalo-buffalo-buffalo-buffalo-buffalo.md b/posts/2006/09/buffalo-buffalo-buffalo-buffalo-buffalo-buffalo-buffalo-buffalo.md
index eb178ab..0609077 100644
--- a/posts/2006/09/buffalo-buffalo-buffalo-buffalo-buffalo-buffalo-buffalo-buffalo.md
+++ b/posts/2006/09/buffalo-buffalo-buffalo-buffalo-buffalo-buffalo-buffalo-buffalo.md
@@ -1,7 +1,7 @@
---
-Title: Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo
+Title: "Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo"
Author: Sami Samhuri
-Date: 16th September, 2006
+Date: "16th September, 2006"
Timestamp: 2006-09-16T22:11:00-07:00
Tags: amusement, buffalo
Link: http://en.wikipedia.org/wiki/Buffalo_buffalo_buffalo_buffalo_buffalo_buffalo_buffalo_buffalo
diff --git a/posts/2006/09/some-features-you-might-have-missed-in-itunes-7.md b/posts/2006/09/some-features-you-might-have-missed-in-itunes-7.md
index acf1ae4..9be9bf1 100644
--- a/posts/2006/09/some-features-you-might-have-missed-in-itunes-7.md
+++ b/posts/2006/09/some-features-you-might-have-missed-in-itunes-7.md
@@ -1,7 +1,7 @@
---
-Title: Some features you might have missed in iTunes 7
+Title: "Some features you might have missed in iTunes 7"
Author: Sami Samhuri
-Date: 22nd September, 2006
+Date: "22nd September, 2006"
Timestamp: 2006-09-22T16:59:00-07:00
Tags: apple, apple, itunes
---
diff --git a/posts/2006/12/coping-with-windows-xp-activiation-on-a-mac.md b/posts/2006/12/coping-with-windows-xp-activiation-on-a-mac.md
index 65dd185..622bb6e 100644
--- a/posts/2006/12/coping-with-windows-xp-activiation-on-a-mac.md
+++ b/posts/2006/12/coping-with-windows-xp-activiation-on-a-mac.md
@@ -1,7 +1,7 @@
---
-Title: Coping with Windows XP activiation on a Mac
+Title: "Coping with Windows XP activiation on a Mac"
Author: Sami Samhuri
-Date: 17th December, 2006
+Date: "17th December, 2006"
Timestamp: 2006-12-17T23:30:00-08:00
Tags: parallels, windows, apple, mac os x, bootcamp
---
@@ -28,7 +28,9 @@ If anyone actually knows how to write batch files I'd like to hear any suggestio
You will probably just want to test my method of testing for Parallels and Boot Camp first. The easiest way is to just open a command window and run this command:
- ipconfig /all | find "Parallels"
+```bat
+ipconfig /all | find "Parallels"
+```
If you see a line of output like **"Description . . . . : Parallels Network Adapter"** and you are in Parallels then the test works. If you see no output and you are in Boot Camp then the test works.
@@ -46,8 +48,10 @@ If you're lazy then you can download backup-parallels-wpa.bat
@@ -57,8 +61,10 @@ Download backup-bootcamp-wpa.bat
@@ -72,19 +78,21 @@ If you have XP Pro then you can get it to run using the Group Policy editor. Sav
If you have XP Home then the best you can do is run this script from your Startup folder (Start -> All Programs -> Startup), but that is not really going to work because eventually Windows will not even let you log in until you activate it. What a P.O.S.
- @echo off
+```bat
+@echo off
- ipconfig /all | find "Parallels" > network.tmp
- for /F "tokens=14" %%x in (network.tmp) do set parallels=%x
- del network.tmp
+ipconfig /all | find "Parallels" > network.tmp
+for /F "tokens=14" %%x in (network.tmp) do set parallels=%x
+del network.tmp
- if defined parallels (
- echo Parallels
- copy C:\Windows\System32\Parallels\wpa.* C:\Windows\System32
- ) else (
- echo Boot Camp
- copy C:\Windows\System32\BootCamp\wpa.* C:\Windows\System32
- )
+if defined parallels (
+ echo Parallels
+ copy C:\Windows\System32\Parallels\wpa.* C:\Windows\System32
+) else (
+ echo Boot Camp
+ copy C:\Windows\System32\BootCamp\wpa.* C:\Windows\System32
+)
+```
Download activate.bat
@@ -105,4 +113,3 @@ This method worked for me and hopefully it will work for you as well. I'm intere
I finally bought Windows XP this week and I'm starting to regret it because of all the hoops they make you jump through to use it. I only use it to fix sites in IE because it can't render a web page properly and I didn't want to buy it just for that. I thought that it would be good to finally get a legit copy since I was using a pirated version and was sick of working around validation bullshit for updates. Now I have to work around MS's activation bullshit and it's just as bad! Screw Microsoft for putting their customers through this sort of thing. Things like this and the annoying balloons near the system tray just fuel my contempt for Windows and reinforce my love of Linux and Mac OS X.
I don't make money off any of my sites, which is why I didn't want to have to buy stupid Windows. I hate MS so much for making shitty IE the standard browser.
-
diff --git a/posts/2007/03/digg-v4-reply-to-replies-greasemonkey-script.md b/posts/2007/03/digg-v4-reply-to-replies-greasemonkey-script.md
index 283862a..d5647b6 100644
--- a/posts/2007/03/digg-v4-reply-to-replies-greasemonkey-script.md
+++ b/posts/2007/03/digg-v4-reply-to-replies-greasemonkey-script.md
@@ -1,7 +1,7 @@
---
-Title: Digg v4: Reply to replies (Greasemonkey script)
+Title: "Digg v4: Reply to replies (Greasemonkey script)"
Author: Sami Samhuri
-Date: 8th March, 2007
+Date: "8th March, 2007"
Timestamp: 2007-03-08T23:19:00-08:00
Tags: coding, digg, firefox, userscript
---
diff --git a/posts/2007/03/diggscuss-0_9.md b/posts/2007/03/diggscuss-0_9.md
index 884b769..cffabb7 100644
--- a/posts/2007/03/diggscuss-0_9.md
+++ b/posts/2007/03/diggscuss-0_9.md
@@ -1,7 +1,7 @@
---
-Title: Diggscuss 0.9
+Title: "Diggscuss 0.9"
Author: Sami Samhuri
-Date: 25th March, 2007
+Date: "25th March, 2007"
Timestamp: 2007-03-25T08:03:00-07:00
Tags: coding, digg, firefox, userscript
---
diff --git a/posts/2007/03/full-screen-cover-flow.md b/posts/2007/03/full-screen-cover-flow.md
index 41fa62e..8c9c81d 100644
--- a/posts/2007/03/full-screen-cover-flow.md
+++ b/posts/2007/03/full-screen-cover-flow.md
@@ -1,7 +1,7 @@
---
-Title: Full-screen Cover Flow
+Title: "Full-screen Cover Flow"
Author: Sami Samhuri
-Date: 6th March, 2007
+Date: "6th March, 2007"
Timestamp: 2007-03-06T13:51:00-08:00
Tags: apple, coverflow, itunes
---
diff --git a/posts/2007/04/a-triple-booting-schizophrenic-macbook.md b/posts/2007/04/a-triple-booting-schizophrenic-macbook.md
index c07629a..bfea9c1 100644
--- a/posts/2007/04/a-triple-booting-schizophrenic-macbook.md
+++ b/posts/2007/04/a-triple-booting-schizophrenic-macbook.md
@@ -1,7 +1,7 @@
---
-Title: A triple-booting, schizophrenic MacBook
+Title: "A triple-booting, schizophrenic MacBook"
Author: Sami Samhuri
-Date: 4th April, 2007
+Date: "4th April, 2007"
Timestamp: 2007-04-04T23:30:00-07:00
Tags: linux, mac os x, windows
---
diff --git a/posts/2007/04/activerecord-base_find_or_create-and-find_or_initialize.md b/posts/2007/04/activerecord-base_find_or_create-and-find_or_initialize.md
index 17f86c2..3482add 100644
--- a/posts/2007/04/activerecord-base_find_or_create-and-find_or_initialize.md
+++ b/posts/2007/04/activerecord-base_find_or_create-and-find_or_initialize.md
@@ -1,7 +1,7 @@
---
-Title: ActiveRecord::Base.find_or_create and find_or_initialize
+Title: "ActiveRecord::Base.find_or_create and find_or_initialize"
Author: Sami Samhuri
-Date: 11th April, 2007
+Date: "11th April, 2007"
Timestamp: 2007-04-11T03:24:00-07:00
Tags: activerecord, coding, rails, ruby
---
@@ -12,98 +12,54 @@ They work exactly as you'd expect them to work with possibly one gotcha. If you
Enough chat, here's the self-explanatory code:
-
1
-2
-3
-4
-
-
# extend ActiveRecord::Base with find_or_create and find_or_initialize.
-ActiveRecord::Base.class_eval do
- include ActiveRecordExtensions
-end
+```ruby
+# extend ActiveRecord::Base with find_or_create and find_or_initialize.
+ActiveRecord::Base.class_eval do
+ include ActiveRecordExtensions
+end
+```
+```ruby
+module ActiveRecordExtensions
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
-
moduleActiveRecordExtensions
- defself.included(base)
- base.extend(ClassMethods)
- end
+ module ClassMethods
+ def find_or_initialize(params)
+ find_or_do('initialize', params)
+ end
- moduleClassMethods
- deffind_or_initialize(params)
- find_or_do('initialize', params)
- end
-
- deffind_or_create(params)
- find_or_do('create', params)
- end
+ def find_or_create(params)
+ find_or_do('create', params)
+ end
private
- # Find a record that matches the attributes given in the +params+ hash, or do +action+
- # to retrieve a new object with the given parameters and return that.
- deffind_or_do(action, params)
- # if an id is given just find the record directly
- self.find(params[:id])
+ # Find a record that matches the attributes given in the +params+ hash, or do +action+
+ # to retrieve a new object with the given parameters and return that.
+ def find_or_do(action, params)
+ # if an id is given just find the record directly
+ self.find(params[:id])
- rescueActiveRecord::RecordNotFound => e
- attrs = {} # hash of attributes passed in params
+ rescue ActiveRecord::RecordNotFound => e
+ attrs = {} # hash of attributes passed in params
- # search for valid attributes in params
- self.column_names.map(&:to_sym).each do |attrib|
- # skip unknown columns, and the id field
- nextif params[attrib].nil? || attrib == :id
+ # search for valid attributes in params
+ self.column_names.map(&:to_sym).each do |attrib|
+ # skip unknown columns, and the id field
+ next if params[attrib].nil? || attrib == :id
attrs[attrib] = params[attrib]
- end
+ end
- # no valid params given, return nil
- returnnilif attrs.empty?
+ # no valid params given, return nil
+ return nil if attrs.empty?
- # call the appropriate ActiveRecord finder method
- self.send("find_or_#{action}_by_#{attrs.keys.join('_and_')}", *attrs.values)
- end
- end
-end
+ # call the appropriate ActiveRecord finder method
+ self.send("find_or_#{action}_by_#{attrs.keys.join('_and_')}", *attrs.values)
+ end
+ end
+end
+```
diff --git a/posts/2007/04/funny-how-code-can-be-beautiful.md b/posts/2007/04/funny-how-code-can-be-beautiful.md
index 731846d..685aac4 100644
--- a/posts/2007/04/funny-how-code-can-be-beautiful.md
+++ b/posts/2007/04/funny-how-code-can-be-beautiful.md
@@ -1,14 +1,16 @@
---
-Title: Funny how code can be beautiful
+Title: "Funny how code can be beautiful"
Author: Sami Samhuri
-Date: 30th April, 2007
+Date: "30th April, 2007"
Timestamp: 2007-04-30T07:07:00-07:00
Tags: haskell
---
While reading a Haskell tutorial I came across the following code for defining the Fibonacci numbers:
- fib = 1 : 1 : [ a + b | (a, b) <- zip fib (tail fib) ]
+```haskell
+fib = 1 : 1 : [ a + b | (a, b) <- zip fib (tail fib) ]
+```
After reading it a few times and understanding how it works I couldn’t help but think how beautiful it is. I don’t mean that it’s aesthetically pleasing to me; the beautiful part is the meaning and simplicity. Lazy evaluation is sweet.
@@ -24,4 +26,3 @@ Going deeper down the functional rabbit-hole you’ll find things like What the hell are Monads?
* Monads on WikiBooks
* Monads for the Working Haskell Programmer
-
diff --git a/posts/2007/04/getting-to-know-vista.md b/posts/2007/04/getting-to-know-vista.md
index c41f491..afbd44f 100644
--- a/posts/2007/04/getting-to-know-vista.md
+++ b/posts/2007/04/getting-to-know-vista.md
@@ -1,7 +1,7 @@
---
-Title: Getting to know Vista
+Title: "Getting to know Vista"
Author: Sami Samhuri
-Date: 16th April, 2007
+Date: "16th April, 2007"
Timestamp: 2007-04-16T11:09:00-07:00
Tags: windows
---
diff --git a/posts/2007/04/quickly-inserting-millions-of-rows-with-mysql-innodb.md b/posts/2007/04/quickly-inserting-millions-of-rows-with-mysql-innodb.md
index 2c0f4fe..69eccb1 100644
--- a/posts/2007/04/quickly-inserting-millions-of-rows-with-mysql-innodb.md
+++ b/posts/2007/04/quickly-inserting-millions-of-rows-with-mysql-innodb.md
@@ -1,7 +1,7 @@
---
-Title: Quickly inserting millions of rows with MySQL/InnoDB
+Title: "Quickly inserting millions of rows with MySQL/InnoDB"
Author: Sami Samhuri
-Date: 26th April, 2007
+Date: "26th April, 2007"
Timestamp: 2007-04-26T07:06:00-07:00
Tags: linux, mysql
---
diff --git a/posts/2007/05/a-new-way-to-look-at-networking.md b/posts/2007/05/a-new-way-to-look-at-networking.md
index a927692..7d1bc32 100644
--- a/posts/2007/05/a-new-way-to-look-at-networking.md
+++ b/posts/2007/05/a-new-way-to-look-at-networking.md
@@ -1,7 +1,7 @@
---
-Title: A New Way to Look at Networking
+Title: "A New Way to Look at Networking"
Author: Sami Samhuri
-Date: 5th May, 2007
+Date: "5th May, 2007"
Timestamp: 2007-05-05T16:10:00-07:00
Tags: technology, networking
---
diff --git a/posts/2007/05/a-scheme-parser-in-haskell-part-1.md b/posts/2007/05/a-scheme-parser-in-haskell-part-1.md
index 576eebe..896b2ff 100644
--- a/posts/2007/05/a-scheme-parser-in-haskell-part-1.md
+++ b/posts/2007/05/a-scheme-parser-in-haskell-part-1.md
@@ -1,7 +1,7 @@
---
-Title: A Scheme parser in Haskell: Part 1
+Title: "A Scheme parser in Haskell: Part 1"
Author: Sami Samhuri
-Date: 3rd May, 2007
+Date: "3rd May, 2007"
Timestamp: 2007-05-03T00:47:50-07:00
Tags: coding, haskell
---
@@ -18,9 +18,10 @@ I'm going to explain one of the exercises because converting between the various
Last night I rewrote parseNumber using do and >>= (bind) notations (ex. 3.3.1). Here's parseNumber using the liftM method given in the tutorial:
-
+```
Okay that's pretty simple right? Let's break it down, first looking at the right-hand side of the $ operator, then the left.
* many1 digit reads as many decimal digits as it can.
@@ -41,24 +42,25 @@ The $ acts similar to a pipe in $FAVOURITE_SHELL, and
So how does a Haskell newbie go about re-writing that using other notations which haven't even been explained in the tutorial? Clearly one must search the web and read as much as they can until they understand enough to figure it out (which is one thing I like about the tutorial). If you're lazy like me, here are 3 equivalent pieces of code for you to chew on. parseNumber's type is Parser LispVal (Parser is a monad).
-
Familiar liftM method:
-
+```
If you're thinking "Hey a return, I know that one!" then the devious masterminds behind Haskell are certainly laughing evilly right now. return simply wraps up it's argument in a monad of some sort. In this case it's the Parser monad. The return part may seem strange at first. Since many1 digit yields a monad why do we need to wrap anything? The answer is that using <- causes digits to contain a String, stripped out of the monad which resulted from many1 digit. Hence we no longer use liftM to make (Number . read) monads, and instead need to use return to properly wrap it back up in a monad.
In other words liftM eliminates the need to explicitly re-monadize the contents as is necessary using do.
-
Finally, using >>= (bind) notation:
-
+```
At this point I don't think this warrants much of an explanation. The syntactic sugar provided by do should be pretty obvious. Just in case it's not, >>= passes the contents of its left argument (a monad) to the function on its right. Once again return is needed to wrap up the result and send it on its way.
When I first read about Haskell I was overwhelmed by not knowing anything, and not being able to apply my previous knowledge of programming to anything in Haskell. One piece of syntax at a time I am slowly able to understand more of the Haskell found in the wild.
diff --git a/posts/2007/05/cheating-at-life-in-general.md b/posts/2007/05/cheating-at-life-in-general.md
index 28a3a9e..7eecd58 100644
--- a/posts/2007/05/cheating-at-life-in-general.md
+++ b/posts/2007/05/cheating-at-life-in-general.md
@@ -1,7 +1,7 @@
---
-Title: Cheating at Life in General
+Title: "Cheating at Life in General"
Author: Sami Samhuri
-Date: 16th May, 2007
+Date: "16th May, 2007"
Timestamp: 2007-05-16T02:46:00-07:00
Tags: cheat, vim, emacs, textmate
---
diff --git a/posts/2007/05/dtrace-ruby-goodness-for-sun.md b/posts/2007/05/dtrace-ruby-goodness-for-sun.md
index b6c4204..4c94b61 100644
--- a/posts/2007/05/dtrace-ruby-goodness-for-sun.md
+++ b/posts/2007/05/dtrace-ruby-goodness-for-sun.md
@@ -1,7 +1,7 @@
---
-Title: dtrace + Ruby = Goodness for Sun
+Title: "dtrace + Ruby = Goodness for Sun"
Author: Sami Samhuri
-Date: 9th May, 2007
+Date: "9th May, 2007"
Timestamp: 2007-05-09T08:45:00-07:00
Tags: ruby, dtrace, sun
---
diff --git a/posts/2007/05/dumping-objects-to-the-browser-in-rails.md b/posts/2007/05/dumping-objects-to-the-browser-in-rails.md
index 13f7b4f..09f6fb0 100644
--- a/posts/2007/05/dumping-objects-to-the-browser-in-rails.md
+++ b/posts/2007/05/dumping-objects-to-the-browser-in-rails.md
@@ -1,35 +1,38 @@
---
-Title: Dumping Objects to the Browser in Rails
+Title: "Dumping Objects to the Browser in Rails"
Author: Sami Samhuri
-Date: 15th May, 2007
+Date: "15th May, 2007"
Timestamp: 2007-05-15T13:38:00-07:00
Tags: rails
-Styles: typocode.css
---
Here's an easy way to solve a problem that may have nagged you as it did me. Simply using foo.inspect to dump out some object to the browser dumps one long string which is barely useful except for short strings and the like. The ideal output is already available using the PrettyPrint module so we just need to use it.
-
-Unfortunately typing
<%= PP.pp(@something, '') %>
to quickly debug some possibly large object (or collection) can get old fast so we need a shortcut.
-
+Unfortunately typing <pre><%= PP.pp(@something, '') %></pre> to quickly debug some possibly large object (or collection) can get old fast so we need a shortcut.
Taking the definition of Object#pp_s from the extensions project it's trivial to create a helper method to just dump out an object in a reasonable manner.
+**/app/helpers/application_helper.rb**
-
+```ruby
+def dump(thing)
+ s = StringIO.new
+ PP.pp(thing, s)
+ s.string
+end
+```
Alternatively you could do as the extensions folks do and actually define Object#pp_s so you can use it in your logs or anywhere else you may want to inspect an object. If you do this you probably want to change the dump helper method accordingly in case you decide to change pp_s in the future.
+**lib/local_support/core_ext/object.rb**
-
lib/local_support/core_ext/object.rb
class Object
- def pp_s
- pps=StringIO.new
- PP.pp(self,pps)
- pps.string
- end
-end
+```ruby
+class Object
+ def pp_s
+ pps = StringIO.new
+ PP.pp(self, pps)
+ pps.string
+ end
+end
+```
diff --git a/posts/2007/05/enumerable-pluck-and-string-to_proc-for-ruby.md b/posts/2007/05/enumerable-pluck-and-string-to_proc-for-ruby.md
index 37598bc..f159456 100644
--- a/posts/2007/05/enumerable-pluck-and-string-to_proc-for-ruby.md
+++ b/posts/2007/05/enumerable-pluck-and-string-to_proc-for-ruby.md
@@ -1,10 +1,9 @@
---
-Title: Enumurable#pluck and String#to_proc for Ruby
+Title: "Enumurable#pluck and String#to_proc for Ruby"
Author: Sami Samhuri
-Date: 10th May, 2007
+Date: "10th May, 2007"
Timestamp: 2007-05-10T16:14:00-07:00
Tags: ruby, extensions
-Styles: typocode.css
---
I wanted a method analogous to Prototype's pluck and invoke in Rails for building lists for options_for_select. Yes, I know about options_from_collection_for_select.
@@ -13,114 +12,130 @@ I wanted something more general that I can use anywhere - not just in Rails - so
First you need Symbol#to_proc, which shouldn't need an introduction. If you're using Rails you have this already.
-
Symbol#to_proc
class Symbol
- # Turns a symbol into a proc.
- #
- # Example:
- # # The same as people.map { |p| p.birthdate }
- # people.map(&:birthdate)
- #
- def to_proc
- Proc.new{|thing,*args|thing.send(self,*args)}
- end
-end
-
+**Symbol#to_proc**
+
+```ruby
+class Symbol
+ # Turns a symbol into a proc.
+ #
+ # Example:
+ # # The same as people.map { |p| p.birthdate }
+ # people.map(&:birthdate)
+ #
+ def to_proc
+ Proc.new {|thing, *args| thing.send(self, *args)}
+ end
+end
+```
Next we define String#to_proc, which is nearly identical to the Array#to_proc method I previously wrote about.
-
String#to_proc
class String
- # Turns a string into a proc.
- #
- # Example:
- # # The same as people.map { |p| p.birthdate.year }
- # people.map(&'birthdate.year')
- #
- def to_proc
- Proc.newdo|*args|
- split('.').inject(args.shift)do|thing,msg|
- thing=thing.send(msg.to_sym,*args)
- end
- end
- end
-end
-
+**String#to_proc**
+
+```ruby
+class String
+ # Turns a string into a proc.
+ #
+ # Example:
+ # # The same as people.map { |p| p.birthdate.year }
+ # people.map(&'birthdate.year')
+ #
+ def to_proc
+ Proc.new do |*args|
+ split('.').inject(args.shift) do |thing, msg|
+ thing = thing.send(msg.to_sym, *args)
+ end
+ end
+ end
+end
+```
Finally there's Enumerable#to_proc which returns a proc that passes its parameter through each of its members and collects their results. It's easier to explain by example.
-
Enumerable#to_proc
module Enumerable
- # Effectively treats itself as a list of transformations, and returns a proc
- # which maps values to a list of the results of applying each transformation
- # in that list to the value.
- #
- # Example:
- # # The same as people.map { |p| [p.birthdate, p.email] }
- # people.map(&[:birthdate, :email])
- #
- def to_proc
- @procs||=map(&:to_proc)
- Proc.newdo|thing,*args|
- @procs.mapdo|proc|
- proc.call(thing,*args)
- end
- end
- end
-end
+**Enumerable#to_proc**
+
+```ruby
+module Enumerable
+ # Effectively treats itself as a list of transformations, and returns a proc
+ # which maps values to a list of the results of applying each transformation
+ # in that list to the value.
+ #
+ # Example:
+ # # The same as people.map { |p| [p.birthdate, p.email] }
+ # people.map(&[:birthdate, :email])
+ #
+ def to_proc
+ @procs ||= map(&:to_proc)
+ Proc.new do |thing, *args|
+ @procs.map do |proc|
+ proc.call(thing, *args)
+ end
+ end
+ end
+end
+```
Here's the cool part, Enumerable#pluck for Ruby in all its glory.
-
Enumerable#pluck
module Enumerable
- # Use this to pluck values from objects, especially useful for ActiveRecord models.
- # This is analogous to Prototype's Enumerable.pluck method but more powerful.
- #
- # You can pluck values simply, like so:
- # >> people.pluck(:last_name) #=> ['Samhuri', 'Jones', ...]
- #
- # But with Symbol#to_proc defined this is effectively the same as:
- # >> people.map(&:last_name) #=> ['Samhuri', 'Jones', ...]
- #
- # Where pluck's power becomes evident is when you want to do something like:
- # >> people.pluck(:name, :address, :phone)
- # #=> [['Johnny Canuck', '123 Maple Lane', '416-555-124'], ...]
- #
- # Instead of:
- # >> people.map { |p| [p.name, p.address, p.phone] }
- #
- # # map each person to: [person.country.code, person.id]
- # >> people.pluck('country.code', :id)
- # #=> [['US', 1], ['CA', 2], ...]
- #
- def pluck(*args)
- # Thanks to Symbol#to_proc, Enumerable#to_proc and String#to_proc this Just Works(tm)
- map(&args)
- end
-end
+**Enumerable#pluck**
+
+```ruby
+module Enumerable
+ # Use this to pluck values from objects, especially useful for ActiveRecord models.
+ # This is analogous to Prototype's Enumerable.pluck method but more powerful.
+ #
+ # You can pluck values simply, like so:
+ # >> people.pluck(:last_name) #=> ['Samhuri', 'Jones', ...]
+ #
+ # But with Symbol#to_proc defined this is effectively the same as:
+ # >> people.map(&:last_name) #=> ['Samhuri', 'Jones', ...]
+ #
+ # Where pluck's power becomes evident is when you want to do something like:
+ # >> people.pluck(:name, :address, :phone)
+ # #=> [['Johnny Canuck', '123 Maple Lane', '416-555-124'], ...]
+ #
+ # Instead of:
+ # >> people.map { |p| [p.name, p.address, p.phone] }
+ #
+ # # map each person to: [person.country.code, person.id]
+ # >> people.pluck('country.code', :id)
+ # #=> [['US', 1], ['CA', 2], ...]
+ #
+ def pluck(*args)
+ # Thanks to Symbol#to_proc, Enumerable#to_proc and String#to_proc this Just Works(tm)
+ map(&args)
+ end
+end
+```
I wrote another version without using the various #to_proc methods so as to work with a standard Ruby while only patching 1 module.
-
module Enumerable
- # A version of pluck which doesn't require any to_proc methods.
- def pluck(*args)
- procs=args.mapdo|msgs|
- # always operate on lists of messages
- ifString===msgs
- msgs=msgs.split('.').map{|a|a.to_sym}# allow 'country.code'
- elsif!(Enumerable===msgs)
- msgs=[msgs]
- end
- Proc.newdo|orig|
- msgs.inject(orig){|thing,msg|thing=thing.send(msg)}
- end
- end
+```ruby
+module Enumerable
+ # A version of pluck which doesn't require any to_proc methods.
+ def pluck(*args)
+ procs = args.map do |msgs|
+ # always operate on lists of messages
+ if String === msgs
+ msgs = msgs.split('.').map {|a| a.to_sym} # allow 'country.code'
+ elsif !(Enumerable === msgs)
+ msgs = [msgs]
+ end
+ Proc.new do |orig|
+ msgs.inject(orig) { |thing, msg| thing = thing.send(msg) }
+ end
+ end
- ifprocs.size==1
- map(&procs.first)
- else
- mapdo|thing|
- procs.map{|proc|proc.call(thing)}
- end
- end
- end
-end
+ if procs.size == 1
+ map(&procs.first)
+ else
+ map do |thing|
+ procs.map { |proc| proc.call(thing) }
+ end
+ end
+ end
+end
+```
It's just icing on the cake considering Ruby's convenient block syntax, but there it is. Do with it what you will. You can change or extend any of these to support drilling down into hashes quite easily too.
diff --git a/posts/2007/05/finnish-court-rules-css-ineffective-at-protecting-dvds.md b/posts/2007/05/finnish-court-rules-css-ineffective-at-protecting-dvds.md
index 4147df7..a6e6268 100644
--- a/posts/2007/05/finnish-court-rules-css-ineffective-at-protecting-dvds.md
+++ b/posts/2007/05/finnish-court-rules-css-ineffective-at-protecting-dvds.md
@@ -1,7 +1,7 @@
---
-Title: Finnish court rules CSS ineffective at protecting DVDs
+Title: "Finnish court rules CSS ineffective at protecting DVDs"
Author: Sami Samhuri
-Date: 26th May, 2007
+Date: "26th May, 2007"
Timestamp: 2007-05-26T03:24:00-07:00
Tags: drm
---
diff --git a/posts/2007/05/gotta-love-the-ferry-ride.md b/posts/2007/05/gotta-love-the-ferry-ride.md
index a934ddd..f6ceba7 100644
--- a/posts/2007/05/gotta-love-the-ferry-ride.md
+++ b/posts/2007/05/gotta-love-the-ferry-ride.md
@@ -1,7 +1,7 @@
---
-Title: Gotta Love the Ferry Ride
+Title: "Gotta Love the Ferry Ride"
Author: Sami Samhuri
-Date: 5th May, 2007
+Date: "5th May, 2007"
Timestamp: 2007-05-05T04:25:00-07:00
Tags: life, photo, bc, victoria
---
diff --git a/posts/2007/05/i-cant-wait-to-see-what-matt-stone-trey-parker-do-with-this.md b/posts/2007/05/i-cant-wait-to-see-what-matt-stone-trey-parker-do-with-this.md
index beea637..67335ca 100644
--- a/posts/2007/05/i-cant-wait-to-see-what-matt-stone-trey-parker-do-with-this.md
+++ b/posts/2007/05/i-cant-wait-to-see-what-matt-stone-trey-parker-do-with-this.md
@@ -1,7 +1,7 @@
---
-Title: I Can't Wait to See What Trey Parker & Matt Stone Do With This
+Title: "I Can't Wait to See What Trey Parker & Matt Stone Do With This"
Author: Sami Samhuri
-Date: 9th May, 2007
+Date: "9th May, 2007"
Timestamp: 2007-05-09T14:34:00-07:00
Tags: crazy
---
diff --git a/posts/2007/05/inspirado.md b/posts/2007/05/inspirado.md
index dc78cde..ce6095d 100644
--- a/posts/2007/05/inspirado.md
+++ b/posts/2007/05/inspirado.md
@@ -1,7 +1,7 @@
---
-Title: Inspirado
+Title: "Inspirado"
Author: Sami Samhuri
-Date: 22nd May, 2007
+Date: "22nd May, 2007"
Timestamp: 2007-05-22T13:23:00-07:00
Tags: rails, inspirado
---
diff --git a/posts/2007/05/iphone-humour.md b/posts/2007/05/iphone-humour.md
index 3aa8c4c..831ceed 100644
--- a/posts/2007/05/iphone-humour.md
+++ b/posts/2007/05/iphone-humour.md
@@ -1,7 +1,7 @@
---
-Title: iPhone Humour
+Title: "iPhone Humour"
Author: Sami Samhuri
-Date: 18th May, 2007
+Date: "18th May, 2007"
Timestamp: 2007-05-18T11:34:00-07:00
Tags: apple, funny, iphone
---
diff --git a/posts/2007/05/rails-plugins-link-dump.md b/posts/2007/05/rails-plugins-link-dump.md
index 93d249d..b235b96 100644
--- a/posts/2007/05/rails-plugins-link-dump.md
+++ b/posts/2007/05/rails-plugins-link-dump.md
@@ -1,7 +1,7 @@
---
-Title: Rails Plugins (link dump)
+Title: "Rails Plugins (link dump)"
Author: Sami Samhuri
-Date: 10th May, 2007
+Date: "10th May, 2007"
Timestamp: 2007-05-09T17:22:00-07:00
Tags: rails
---
diff --git a/posts/2007/05/typo-and-i-are-friends-again.md b/posts/2007/05/typo-and-i-are-friends-again.md
index aa18b76..e62c654 100644
--- a/posts/2007/05/typo-and-i-are-friends-again.md
+++ b/posts/2007/05/typo-and-i-are-friends-again.md
@@ -1,7 +1,7 @@
---
-Title: Typo and I are friends again
+Title: "Typo and I are friends again"
Author: Sami Samhuri
-Date: 1st May, 2007
+Date: "1st May, 2007"
Timestamp: 2007-05-01T21:51:37-07:00
Tags: typo
---
diff --git a/posts/2007/06/301-moved-permanently.md b/posts/2007/06/301-moved-permanently.md
index 25516da..e2174a6 100644
--- a/posts/2007/06/301-moved-permanently.md
+++ b/posts/2007/06/301-moved-permanently.md
@@ -1,7 +1,7 @@
---
-Title: 301 moved permanently
+Title: "301 moved permanently"
Author: Sami Samhuri
-Date: 8th June, 2007
+Date: "8th June, 2007"
Timestamp: 2007-06-08T18:00:00-07:00
Tags: life
---
diff --git a/posts/2007/06/back-on-gentoo-trying-new-things.md b/posts/2007/06/back-on-gentoo-trying-new-things.md
index 150e076..632f0ac 100644
--- a/posts/2007/06/back-on-gentoo-trying-new-things.md
+++ b/posts/2007/06/back-on-gentoo-trying-new-things.md
@@ -1,7 +1,7 @@
---
-Title: Back on Gentoo, trying new things
+Title: "Back on Gentoo, trying new things"
Author: Sami Samhuri
-Date: 18th June, 2007
+Date: "18th June, 2007"
Timestamp: 2007-06-18T18:05:00-07:00
Tags: emacs, gentoo, linux, vim
---
diff --git a/posts/2007/06/begging-the-question.md b/posts/2007/06/begging-the-question.md
index 3f48a82..833463a 100644
--- a/posts/2007/06/begging-the-question.md
+++ b/posts/2007/06/begging-the-question.md
@@ -1,7 +1,7 @@
---
-Title: Begging the question
+Title: "Begging the question"
Author: Sami Samhuri
-Date: 15th June, 2007
+Date: "15th June, 2007"
Timestamp: 2007-06-15T11:49:00-07:00
Tags: english, life, pedantry
---
@@ -14,9 +14,11 @@ Anyway I was very pleased to see the only correct usage of the phrase "begs the
This describes a perfectly legitimate mathematical function. We could use it to recognize whether one number is the square root of another, or to derive facts about square roots in general. On the other hand, the definition does not describe a procedure. Indeed, it tells us almost nothing about how to actually find the square root of a given number. It will not help matters to rephrase this definition in pseudo-Lisp:
-
(define (sqrt x)
+```scheme
+(define (sqrt x)
(the y (and (= y 0)
- (= (square y) x))))
+ (= (square y) x))))
+```
This only begs the question.
diff --git a/posts/2007/06/controlling-volume-via-the-keyboard-on-linux.md b/posts/2007/06/controlling-volume-via-the-keyboard-on-linux.md
index f154e5c..7ec9dc2 100644
--- a/posts/2007/06/controlling-volume-via-the-keyboard-on-linux.md
+++ b/posts/2007/06/controlling-volume-via-the-keyboard-on-linux.md
@@ -1,7 +1,7 @@
---
-Title: Controlling volume via the keyboard on Linux
+Title: "Controlling volume via the keyboard on Linux"
Author: Sami Samhuri
-Date: 30th June, 2007
+Date: "30th June, 2007"
Timestamp: 2007-06-30T16:13:00-07:00
Tags: alsa, linux, ruby, volume
---
diff --git a/posts/2007/06/emacs-for-textmate-junkies.md b/posts/2007/06/emacs-for-textmate-junkies.md
index 5f02137..def8f7d 100644
--- a/posts/2007/06/emacs-for-textmate-junkies.md
+++ b/posts/2007/06/emacs-for-textmate-junkies.md
@@ -1,7 +1,7 @@
---
-Title: Emacs for TextMate junkies
+Title: "Emacs for TextMate junkies"
Author: Sami Samhuri
-Date: 23rd June, 2007
+Date: "23rd June, 2007"
Timestamp: 2007-06-22T19:17:00-07:00
Tags: emacs, textmate
---
@@ -14,76 +14,20 @@ Tags: emacs, textmate
Despite my current infatuation with Emacs there are many reasons I started using TextMate, especially little time-savers that are very addictive. I'll talk about one of those features tonight. When you have text selected in TextMate and you hit say the ' (single quote) then TextMate will surround the selected text with single quotes. The same goes for double quotes, parentheses, brackets, and braces. This little trick is one of my favourites so I had to come up with something similar in Emacs. It was easy since a mailing list post has a solution for surrounding the current region with tags, which served as a great starting point.
-
-
;; help out a TextMate junkie
+```lisp
+;; help out a TextMate junkie
(defun wrap-region (left right beg end)
"Wrap the region in arbitrary text, LEFT goes to the left and RIGHT goes to the right."
@@ -103,7 +47,7 @@ With a little modification I now have the following in my ~/.emacs file:
(interactive)
(if (and mark-active transient-mark-mode)
(call-interactively 'wrap-region-with-tag)
- (insert "<")))
+ (insert "<")))
(defun wrap-region-with-tag (tag beg end)
"Wrap the region in the given HTML/XML tag using `wrap-region'. If any
@@ -111,10 +55,10 @@ attributes are specified then they are only included in the opening tag."
(interactive "*sTag (including attributes): \nr")
(let* ((elems (split-string tag " "))
(tag-name (car elems))
- (right (concat "</" tag-name ">")))
+ (right (concat "" tag-name ">")))
(if (= 1 (length elems))
- (wrap-region (concat "<" tag-name ">") right beg end)
- (wrap-region (concat "<" tag ">") right beg end))))
+ (wrap-region (concat "<" tag-name ">") right beg end)
+ (wrap-region (concat "<" tag ">") right beg end))))
(defun wrap-region-or-insert (left right)
"Wrap the region with `wrap-region' if an active region is marked, otherwise insert LEFT at point."
@@ -129,7 +73,8 @@ attributes are specified then they are only included in the opening tag."
(global-set-key "(" (wrap-region-with-function "(" ")"))
(global-set-key "[" (wrap-region-with-function "[" "]"))
(global-set-key "{" (wrap-region-with-function "{" "}"))
-(global-set-key "<" 'wrap-region-with-tag-or-insert) ;; I opted not to have a wrap-with-angle-brackets
+(global-set-key "<" 'wrap-region-with-tag-or-insert) ;; I opted not to have a wrap-with-angle-brackets
+```
↓ Download wrap-region.el
diff --git a/posts/2007/06/emacs-tagify-region-or-insert-tag.md b/posts/2007/06/emacs-tagify-region-or-insert-tag.md
index 4957412..e9e55fb 100644
--- a/posts/2007/06/emacs-tagify-region-or-insert-tag.md
+++ b/posts/2007/06/emacs-tagify-region-or-insert-tag.md
@@ -1,7 +1,7 @@
---
-Title: Emacs: tagify-region-or-insert-tag
+Title: "Emacs: tagify-region-or-insert-tag"
Author: Sami Samhuri
-Date: 25th June, 2007
+Date: "25th June, 2007"
Timestamp: 2007-06-25T15:13:00-07:00
Tags: emacs, tagify
---
diff --git a/posts/2007/06/embrace-the-database.md b/posts/2007/06/embrace-the-database.md
index 892113d..525110f 100644
--- a/posts/2007/06/embrace-the-database.md
+++ b/posts/2007/06/embrace-the-database.md
@@ -1,7 +1,7 @@
---
-Title: Embrace the database
+Title: "Embrace the database"
Author: Sami Samhuri
-Date: 22nd June, 2007
+Date: "22nd June, 2007"
Timestamp: 2007-06-22T03:14:00-07:00
Tags: activerecord, rails, ruby
---
diff --git a/posts/2007/06/floating-point-in-elschemo.md b/posts/2007/06/floating-point-in-elschemo.md
index e599a5b..fe43d91 100644
--- a/posts/2007/06/floating-point-in-elschemo.md
+++ b/posts/2007/06/floating-point-in-elschemo.md
@@ -1,7 +1,7 @@
---
-Title: Floating point in ElSchemo
+Title: "Floating point in ElSchemo"
Author: Sami Samhuri
-Date: 24th June, 2007
+Date: "24th June, 2007"
Timestamp: 2007-06-24T11:53:00-07:00
Tags: elschemo, haskell, scheme
---
@@ -10,24 +10,8 @@ Tags: elschemo, haskell, scheme
The first task is extending the LispVal type to grok floats.
-
-
type LispInt = Integer
+```haskell
+type LispInt = Integer
type LispFloat = Float
-- numeric data types
@@ -41,30 +25,22 @@ data LispVal = Atom String
| Number LispNum
| Char Char
| String String
- | ...
-
+ | ...
+```
The reason for using the new LispNum type and not just throwing a new Float Float constructor in there is so that functions can accept and operate on parameters of any supported numeric type. First the floating point numbers need to be parsed. For now I only parse floating point numbers in decimal because the effort to parse other bases is too great for the benefits gained (none, for me).
ElSchemo now parses negative numbers so I'll start with 2 helper functions that are used when parsing both integers and floats:
-
-
1
-2
-3
-4
-5
-6
-7
-
-
parseSign :: Parser Char
+```haskell
+parseSign :: Parser Char
parseSign = do try (char '-')
- <|> do optional (char '+')
+ <|> do optional (char '+')
return '+'
-applySign :: Char -> LispNum -> LispNum
-applySign sign n = if sign == '-' then negate n else n
-
+applySign :: Char -> LispNum -> LispNum
+applySign sign n = if sign == '-' then negate n else n
+```
parseSign is straightforward as it follows the convention that a literal number is positive unless explicitly marked as negative with a leading minus sign. A leading plus sign is allowed but not required.
@@ -72,94 +48,64 @@ applySign sign n = if sign == '-' then negate n else n
Armed with these 2 functions we can now parse floating point numbers in decimal. Conforming to R5RS an optional #d prefix is allowed.
-
-
-
+ where makeFloat whole fract = Float . fst . head . readFloat $ whole ++ "." ++ fract
+```
The first 6 lines should be clear. Line 7 simply applies the parsed sign to the parsed number and returns it, delegating most of the work to makeFloat. makeFloat in turn delegates the work to the readFloat library function, extracts the result and constructs a LispNum for it.
The last step for parsing is to modify parseExpr to try and parse floats.
-
-
1
-2
-3
-4
-5
-6
-7
-8
-9
-10
-11
-12
-13
-14
-
-
-- Integers, floats, characters and atoms can all start with a # so wrap those with try.
+```haskell
+-- Integers, floats, characters and atoms can all start with a # so wrap those with try.
-- (Left factor the grammar in the future)
parseExpr :: Parser LispVal
parseExpr = (try parseFloat)
- <|> (try parseInteger)
- <|> (try parseChar)
- <|> parseAtom
- <|> parseString
- <|> parseQuoted
- <|> do char '('
- x <- (try parseList) <|> parseDottedList
+ <|> (try parseInteger)
+ <|> (try parseChar)
+ <|> parseAtom
+ <|> parseString
+ <|> parseQuoted
+ <|> do char '('
+ x <- (try parseList) <|> parseDottedList
char ')'
return x
- <|> parseComment
-
+ <|> parseComment
+```
### Displaying the floats ###
-
That's it for parsing, now let's provide a way to display these suckers. LispVal is an instance of show, where show = showVal so showVal is our first stop. Remembering that LispVal now has a single Number constructor we modify it accordingly:
+```haskell
+showVal (Number n) = showNum n
-
1
-2
-3
-4
-5
-6
-7
-
-
showVal (Number n) = showNum n
-
-showNum :: LispNum -> String
+showNum :: LispNum -> String
showNum (Integer contents) = show contents
showNum (Float contents) = show contents
-instance Show LispNum where show = showNum
-
+instance Show LispNum where show = showNum
+```
One last, and certainly not least, step is to modify eval so that numbers evaluate to themselves.
-
- eval env val@(Number _) = return val
+```haskell
+eval env val@(Number _) = return val
+```
There's a little more housekeeping to be done such as fixing integer?, number?, implementing float? but I will leave those as an exercise to the reader, or just wait until I share the full code. As it stands now floating point numbers can be parsed and displayed. If you fire up the interpreter and type 2.5 or -10.88 they will be understood. Now try adding them:
- (+ 2.5 1.1)
- Invalid type: expected integer, found 2.5
+```scheme
+(+ 2.5 1.1)
+Invalid type: expected integer, found 2.5
+```
Oops, we don't know how to operate on floats yet!
@@ -167,79 +113,8 @@ Oops, we don't know how to operate on floats yet!
Parsing was the easy part. Operating on the new floats is not necessarily difficult, but it was more work than I realized it would be. I don't claim that this is the best or the only way to operate on any LispNum, it's just the way I did it and it seems to work. There's a bunch of boilerplate necessary to make LispNum an instance of the required classes, Eq, Num, Real, and Ord. I don't think I have done this properly but for now it works. What is clearly necessary is the code that operates on different types of numbers. I think I've specified sane semantics for coercion. This will be very handy shortly.
-
-
+lispNumLessThanEq :: LispNum -> LispNum -> Bool
+lispNumLessThanEq (Integer x) (Integer y) = x <= y
+lispNumLessThanEq (Integer x) (Float y) = (fromInteger x) <= y
+lispNumLessThanEq (Float x) (Integer y) = x <= (fromInteger y)
+lispNumLessThanEq (Float x) (Float y) = x <= y
+instance Ord LispNum where (<=) = lispNumLessThanEq
+```
Phew, ok with that out of the way now we can actually extend our operators to work with any type of LispNum. Our Scheme operators are defined using the functions numericBinop and numBoolBinop. First we'll slightly modify our definition of primitives:
-
-
-
+ (">=", numBoolBinop (>=)),
+ ("<=", numBoolBinop (<=)),
+ ...]
+```
Note that mod, quotient, and remainder are only defined for integers and as such use integralBinop, while division (/) is only defined for floating point numbers using floatBinop. subtractOp is different to support unary usage, e.g. (- 4) => -4, but it uses numericBinop internally when more than 1 argument is given. On to the implementation! First extend unpackNum to work with any LispNum, and provide separate unpackInt and unpackFloat functions to handle both kinds of LispNum.
-
-
-
+unpackFloat notFloat = throwError $ TypeMismatch "float" notFloat
+```
The initial work of separating integers and floats into the LispNum abstraction, and the code I said would be handy shortly, are going to be really handy here. There's relatively no change in numericBinop except for the type signature. integralBinop and floatBinop are just specific versions of the same function. I'm sure there's a nice Haskelly way of doing this with less repetition, and I welcome such corrections.
-
-
-
+numBoolBinop :: (LispNum -> LispNum -> Bool) -> [LispVal] -> ThrowsError LispVal
+numBoolBinop op params = boolBinop unpackNum op params
+```
That was a bit of work but now ElSchemo supports floating point numbers, and if you're following along then your Scheme might too if I haven't missed any important details!
-
Next time I'll go over some of the special forms I have added, including short-circuiting and and or forms and the full repetoire of let, let*, and letrec. Stay tuned!
-
diff --git a/posts/2007/06/more-scheming-with-haskell.md b/posts/2007/06/more-scheming-with-haskell.md
index aa946d0..a8fdc70 100644
--- a/posts/2007/06/more-scheming-with-haskell.md
+++ b/posts/2007/06/more-scheming-with-haskell.md
@@ -1,7 +1,7 @@
---
-Title: More Scheming with Haskell
+Title: "More Scheming with Haskell"
Author: Sami Samhuri
-Date: 14th June, 2007
+Date: "14th June, 2007"
Timestamp: 2007-06-13T18:09:00-07:00
Tags: coding, haskell, scheme
---
@@ -14,11 +14,14 @@ It's been a little while since I wrote about Haskell and the R5RS compliant numbers, which is exercise 3.3.4 if you're following along the tutorial. Only integers in binary, octal, decimal, and hexadecimal are parsed right now. The syntaxes for those are #b101010, #o52, 42 (or #d42), and #x2a, respectively. To parse these we use the readOct, readDec, readHex, and readInt functions provided by the Numeric module, and import them thusly:
- import Numeric (readOct, readDec, readHex, readInt)
+```haskell
+import Numeric (readOct, readDec, readHex, readInt)
+```
In order to parse binary digits we need to write a few short functions to help us out. For some reason I couldn't find binDigit, isBinDigit and readBin in their respective modules but luckily they're trivial to implement. The first two are self-explanatory, as is the third if you look at the implementation of its relatives for larger bases. In a nutshell readBin says to: "read an integer in base 2, validating digits with isBinDigit."
-
-- parse a binary digit, analagous to decDigit, octDigit, hexDigit
+```haskell
+-- parse a binary digit, analagous to decDigit, octDigit, hexDigit
binDigit :: Parser Char
binDigit = oneOf "01"
@@ -28,24 +31,30 @@ isBinDigit c = (c == '0' || c == '1')
-- analogous to readDec, readOct, readHex
readBin :: (Integral a) = ReadS a
-readBin = readInt 2 isBinDigit digitToInt
+readBin = readInt 2 isBinDigit digitToInt
+```
The next step is to augment parseNumber so that it can handle R5RS numbers in addition to regular decimal numbers. To refresh, the tutorial's parseNumber function looks like this:
- parseNumber :: Parser LispVal
- parseNumber = liftM (Number . read) $ many1 digit
+```haskell
+parseNumber :: Parser LispVal
+parseNumber = liftM (Number . read) $ many1 digit
+```
Three more lines in this function will give us a decent starting point:
- parseNumber = do char '#'
- base <- oneOf "bdox"
- parseDigits base
+```haskell
+parseNumber = do char '#'
+ base <- oneOf "bdox"
+ parseDigits base
+```
Translation: First look for an R5RS style base, and if found call parseDigits with the given base to do the dirty work. If that fails then fall back to parsing a boring old string of decimal digits.
That brings us to actually parsing the numbers. parseDigits is simple, but there might be a more Haskell-y way of doing this.
-
-- Parse a string of digits in the given base.
+```haskell
+-- Parse a string of digits in the given base.
parseDigits :: Char - Parser LispVal
parseDigits base = many1 d >>= return
where d = case base of
@@ -53,7 +62,7 @@ parseDigits base = many1 d >>= return
'd' -> digit
'o' -> octDigit
'x' -> hexDigit
-
+```
The trickiest part of all this was figuring out how to use the various readFoo functions properly. They return a list of pairs so head grabs the first pair and fst grabs the first element of the pair. Once I had that straight it was smooth sailing. Having done this, parsing R5RS characters (#\a, #\Z, #\?, ...) is a breeze so I won't bore you with that.
@@ -61,27 +70,17 @@ The trickiest part of all this was figuring out how to use the various rea
It still takes me some time to knit together meaningful Haskell statements. Tonight I spent said time cobbling together an implementation of cond as a new special form. Have a look at the code. The explanation follows.
-
-
1
-2
-3
-4
-5
-6
-7
-8
-9
-
-
eval env (List (Atom "cond" : List (Atom "else" : exprs) : [])) =
+```haskell
+eval env (List (Atom "cond" : List (Atom "else" : exprs) : [])) =
liftM last $ mapM (eval env) exprs
eval env (List (Atom "cond" : List (pred : conseq) : rest)) =
- do result <- eval env $ pred
+ do result <- eval env $ pred
case result of
- Bool False -> case rest of
- [] -> return $ List []
- _ -> eval env $ List (Atom "cond" : rest)
- _ -> liftM last $ mapM (eval env) conseq
-
+ Bool False -> case rest of
+ [] -> return $ List []
+ _ -> eval env $ List (Atom "cond" : rest)
+ _ -> liftM last $ mapM (eval env) conseq
+```
* __Lines 1-2:__ Handle else clauses by evaluating the given expression(s), returning the last result. It must come first or it's overlapped by the next pattern.
* __Line 3:__ Evaluate a cond by splitting the first condition into predicate and consequence, tuck the remaining conditions into rest for later.
@@ -93,4 +92,3 @@ eval env (List (Atom "cond" : List (pred : conseq) : rest)) =
* __Line 9:__ Anything other than #f is considered true and causes conseq to be evaluated and returned. Like else, conseq can be a sequence of expressions.
So far my Scheme weighs in at 621 lines, 200 more than the tutorial's final code listing. Hopefully I'll keep adding things on my TODO list and it will grow a little bit more. Now that I have cond it will be more fun to expand my stdlib.scm as well.
-
diff --git a/posts/2007/06/propaganda-makes-me-sick.md b/posts/2007/06/propaganda-makes-me-sick.md
index 7ae47d4..01602e9 100644
--- a/posts/2007/06/propaganda-makes-me-sick.md
+++ b/posts/2007/06/propaganda-makes-me-sick.md
@@ -1,7 +1,7 @@
---
-Title: Propaganda makes me sick
+Title: "Propaganda makes me sick"
Author: Sami Samhuri
-Date: 25th June, 2007
+Date: "25th June, 2007"
Timestamp: 2007-06-25T03:55:00-07:00
Tags: propaganda
---
diff --git a/posts/2007/06/recent-ruby-and-rails-regales.md b/posts/2007/06/recent-ruby-and-rails-regales.md
index bb05c40..8b81d8f 100644
--- a/posts/2007/06/recent-ruby-and-rails-regales.md
+++ b/posts/2007/06/recent-ruby-and-rails-regales.md
@@ -1,7 +1,7 @@
---
-Title: Recent Ruby and Rails Regales
+Title: "Recent Ruby and Rails Regales"
Author: Sami Samhuri
-Date: 28th June, 2007
+Date: "28th June, 2007"
Timestamp: 2007-06-28T12:23:00-07:00
Tags: rails, rails on rules, regular expressions, ruby, sake, secure associations, regex
---
diff --git a/posts/2007/06/reinventing-the-wheel.md b/posts/2007/06/reinventing-the-wheel.md
index 3d42df3..737ecbd 100644
--- a/posts/2007/06/reinventing-the-wheel.md
+++ b/posts/2007/06/reinventing-the-wheel.md
@@ -1,7 +1,7 @@
---
-Title: Reinventing the wheel
+Title: "Reinventing the wheel"
Author: Sami Samhuri
-Date: 20th June, 2007
+Date: "20th June, 2007"
Timestamp: 2007-06-20T09:27:00-07:00
Tags: emacs, snippets
---
diff --git a/posts/2007/06/rtfm.md b/posts/2007/06/rtfm.md
index 34846d9..9bb5fc1 100644
--- a/posts/2007/06/rtfm.md
+++ b/posts/2007/06/rtfm.md
@@ -1,7 +1,7 @@
---
-Title: RTFM!
+Title: "RTFM!"
Author: Sami Samhuri
-Date: 26th June, 2007
+Date: "26th June, 2007"
Timestamp: 2007-06-25T14:19:00-07:00
Tags: emacs, rtfm
---
diff --git a/posts/2007/06/so-long-typo-and-thanks-for-all-the-timeouts.md b/posts/2007/06/so-long-typo-and-thanks-for-all-the-timeouts.md
index 31af818..94af7b8 100644
--- a/posts/2007/06/so-long-typo-and-thanks-for-all-the-timeouts.md
+++ b/posts/2007/06/so-long-typo-and-thanks-for-all-the-timeouts.md
@@ -1,7 +1,7 @@
---
-Title: so long typo (and thanks for all the timeouts)
+Title: "so long typo (and thanks for all the timeouts)"
Author: Sami Samhuri
-Date: 8th June, 2007
+Date: "8th June, 2007"
Timestamp: 2007-06-08T18:01:00-07:00
Tags: mephisto, typo
---
@@ -12,22 +12,15 @@ Recently I had looked at converting Typo to Mephisto and it seemed pretty painle
After running that code snippet to fix my tags, I decided to completely ditch categories in favour of tags. I tagged each new Mephisto article with a tag for each Typo category it had previously belonged to. I fired up RAILS_ENV=production script/console and typed something similar to the following:
-
-
+```ruby
+require 'converters/base'
+require 'converters/typo'
+articles = Typo::Article.find(:all).map {|a| [a, Article.find_by_permalink(a.permalink)] }
+articles.each do |ta, ma|
+ next if ma.nil?
+ ma.tags << Tag.find_or_create(ta.categories.map(&:name))
+end
+```
When I say something similar I mean exactly that. I just typed that from memory so it may not work, or even be syntactically correct. If any permalinks changed then you'll have to manually add new tags corresponding to old Typo categories. The only case where this bit me was when I had edited the title of an article, in which case the new Mephisto permalink matched the new title while the Typo permalink matched the initial title, whatever it was.
diff --git a/posts/2007/06/testspec-on-rails-declared-awesome-just-one-catch.md b/posts/2007/06/testspec-on-rails-declared-awesome-just-one-catch.md
index e4bae64..65add7d 100644
--- a/posts/2007/06/testspec-on-rails-declared-awesome-just-one-catch.md
+++ b/posts/2007/06/testspec-on-rails-declared-awesome-just-one-catch.md
@@ -1,7 +1,7 @@
---
-Title: test/spec on rails declared awesome, just one catch
+Title: "test/spec on rails declared awesome, just one catch"
Author: Sami Samhuri
-Date: 14th June, 2007
+Date: "14th June, 2007"
Timestamp: 2007-06-14T07:21:00-07:00
Tags: bdd, rails, test/spec
---
@@ -10,79 +10,47 @@ This last week I've been getting to know
-
-
mkdir /tmp/gtkpod-fix
+```shell
+mkdir /tmp/gtkpod-fix
cd /tmp/gtkpod-fix
wget http://ftp.uni-kl.de/debian-multimedia/pool/main/libm/libmpeg4ip/libmp4v2-0_1.5.0.1-0.3_amd64.deb
wget http://ftp.uni-kl.de/debian-multimedia/pool/main/libm/libmpeg4ip/libmp4v2-dev_1.5.0.1-0.3_amd64.deb
@@ -44,6 +31,7 @@ wget http://ftp.uni-kl.de/debian-multimedia/pool/main/libm/libmpeg4ip/libmpeg4ip
for f in *.deb; do sudo gdebi -n "$f"; done
svn co https://gtkpod.svn.sourceforge.net/svnroot/gtkpod/gtkpod/trunk gtkpod
cd gtkpod
-./autogen.sh --with-mp4v2 && make && sudo make install
+./autogen.sh --with-mp4v2 && make && sudo make install
cd
-rm -rf /tmp/gtkpod-fix
+rm -rf /tmp/gtkpod-fix
+```
diff --git a/posts/2008/01/random-pet-peeve-of-the-day.md b/posts/2008/01/random-pet-peeve-of-the-day.md
index eb43229..6084c2f 100644
--- a/posts/2008/01/random-pet-peeve-of-the-day.md
+++ b/posts/2008/01/random-pet-peeve-of-the-day.md
@@ -1,7 +1,7 @@
---
-Title: Random pet peeve of the day
+Title: "Random pet peeve of the day"
Author: Sami Samhuri
-Date: 7th January, 2008
+Date: "7th January, 2008"
Timestamp: 2008-01-07T09:42:00-08:00
Tags: usability, web
---
diff --git a/posts/2008/02/thoughts-on-arc.md b/posts/2008/02/thoughts-on-arc.md
index e1556e4..8d332ac 100644
--- a/posts/2008/02/thoughts-on-arc.md
+++ b/posts/2008/02/thoughts-on-arc.md
@@ -1,7 +1,7 @@
---
-Title: Thoughts on Arc
+Title: "Thoughts on Arc"
Author: Sami Samhuri
-Date: 19th February, 2008
+Date: "19th February, 2008"
Timestamp: 2008-02-19T03:26:00-08:00
Tags: lisp arc
---
diff --git a/posts/2008/03/project-euler-code-repo-in-arc.md b/posts/2008/03/project-euler-code-repo-in-arc.md
index a7af391..1b2ee00 100644
--- a/posts/2008/03/project-euler-code-repo-in-arc.md
+++ b/posts/2008/03/project-euler-code-repo-in-arc.md
@@ -1,17 +1,17 @@
---
-Title: Project Euler code repo in Arc
+Title: "Project Euler code repo in Arc"
Author: Sami Samhuri
-Date: 3rd March, 2008
+Date: "3rd March, 2008"
Timestamp: 2008-03-03T08:24:00-08:00
Tags: arc, project euler
---
Release early and often. This is a code repo web app for solutions to Project Euler problems. You can only see your own solutions so it's not that exciting yet (but it scratches my itch... once it highlights syntax). You can try it out or download the source. You'll need an up-to-date copy of Anarki to untar the source in. Just run arc.sh then enter this at the REPL:
-
-
arc> (load "euler.arc")
-arc> (esv)
-
+```lisp
+arc> (load "euler.arc")
+arc> (esv)
+```
That will setup the web server on port 3141. If you want a different port then run (esv 25) (just to mess with 'em).
diff --git a/posts/2009/11/using-emacs-to-develop-mojo-apps-for-webos.md b/posts/2009/11/using-emacs-to-develop-mojo-apps-for-webos.md
index e97ea95..13d37dc 100644
--- a/posts/2009/11/using-emacs-to-develop-mojo-apps-for-webos.md
+++ b/posts/2009/11/using-emacs-to-develop-mojo-apps-for-webos.md
@@ -1,7 +1,7 @@
---
-Title: Using Emacs to Develop Mojo Apps for WebOS
+Title: "Using Emacs to Develop Mojo Apps for WebOS"
Author: Sami Samhuri
-Date: 21st November, 2009
+Date: "21st November, 2009"
Timestamp: 2009-11-21T00:00:00-08:00
Tags: emacs, mojo, webos, lisp, javascript
---
diff --git a/posts/2010/01/a-preview-of-mach-o-file-generation.md b/posts/2010/01/a-preview-of-mach-o-file-generation.md
index 0736e70..955f429 100644
--- a/posts/2010/01/a-preview-of-mach-o-file-generation.md
+++ b/posts/2010/01/a-preview-of-mach-o-file-generation.md
@@ -1,7 +1,7 @@
---
-Title: A preview of Mach-O file generation
+Title: "A preview of Mach-O file generation"
Author: Sami Samhuri
-Date: 20th January, 2010
+Date: "20th January, 2010"
Timestamp: 2010-01-20T00:00:00-08:00
Tags: ruby, mach-o, os x, compiler
---
diff --git a/posts/2010/01/basics-of-the-mach-o-file-format.md b/posts/2010/01/basics-of-the-mach-o-file-format.md
index 90c754d..791f109 100644
--- a/posts/2010/01/basics-of-the-mach-o-file-format.md
+++ b/posts/2010/01/basics-of-the-mach-o-file-format.md
@@ -1,7 +1,7 @@
---
-Title: Basics of the Mach-O file format
+Title: "Basics of the Mach-O file format"
Author: Sami Samhuri
-Date: 18th January, 2010
+Date: "18th January, 2010"
Timestamp: 2010-01-18T00:00:00-08:00
Tags: mach-o, os x, compiler
---
@@ -45,17 +45,15 @@ blob of machine code. That blob could be described by a single
section named \_\_text, inside a single nameless segment. Here's a
diagram showing the layout of such a file:
@@ -71,7 +69,6 @@ CStruct we define the Mach header like so:
-
Segments
Segments, or segment commands, specify where in memory the
@@ -92,7 +89,6 @@ be easy enough to follow.
-
Sections
All sections within a segment are described one after the other
@@ -115,7 +111,6 @@ two underscores, e.g. \_\_bss or \_\_text
-
macho.rb
As much of the Mach-O format as we need is defined in
@@ -126,7 +121,6 @@ constants as well.
I'll cover symbol tables and relocation tables in my next post.
-
Looking at real Mach-O files
To see the segments and sections of an object file, run
@@ -145,7 +139,6 @@ also disassemble the \_\_text section with
You'll get to know otool quite well if you work with Mach-O.
-
Take a break
That was probably a lot to digest, and to make real sense of it you
diff --git a/posts/2010/01/working-with-c-style-structs-in-ruby.md b/posts/2010/01/working-with-c-style-structs-in-ruby.md
index f2f40aa..cfd474c 100644
--- a/posts/2010/01/working-with-c-style-structs-in-ruby.md
+++ b/posts/2010/01/working-with-c-style-structs-in-ruby.md
@@ -1,40 +1,18 @@
---
-Title: Working with C-style structs in Ruby
+Title: "Working with C-style structs in Ruby"
Author: Sami Samhuri
-Date: 17th January, 2010
+Date: "17th January, 2010"
Timestamp: 2010-01-17T00:00:00-08:00
Tags: ruby, cstruct, compiler
---
-This is the beginning of a series on generating Mach-O object files in
-Ruby. We start small by introducing some Ruby tools that are useful when
-working with binary data. Subsequent articles will cover a subset of the
-Mach-O file format, then generating Mach object files suitable for linking
-with ld or gcc to produce working executables. A basic knowledge of Ruby and C
-are assumed. You can likely wing it on the Ruby side of things if you know any
-similar languages.
+This is the beginning of a series on generating Mach-O object files in Ruby. We start small by introducing some Ruby tools that are useful when working with binary data. Subsequent articles will cover a subset of the Mach-O file format, then generating Mach object files suitable for linking with ld or gcc to produce working executables. A basic knowledge of Ruby and C are assumed. You can likely wing it on the Ruby side of things if you know any similar languages.
-First we need to read and write structured binary files with Ruby.
-[Array#pack](http://ruby-doc.org/core/classes/Array.html#M002222) and
-[String#unpack](http://ruby-doc.org/core/classes/String.html#M000760)
-get the job done at a low level, but every time I use them I have to look up
-the documentation. It would also be nice to encapsulate serializing and
-deserializing into classes describing the various binary data structures. The
-built-in [Struct class](http://ruby-doc.org/core/classes/Struct.html) sounds
-promising but did not meet my needs, nor was it easily extended to meet them.
+First we need to read and write structured binary files with Ruby. [Array#pack](http://ruby-doc.org/core/classes/Array.html#M002222) and [String#unpack](http://ruby-doc.org/core/classes/String.html#M000760) get the job done at a low level, but every time I use them I have to look up the documentation. It would also be nice to encapsulate serializing and deserializing into classes describing the various binary data structures. The built-in [Struct class](http://ruby-doc.org/core/classes/Struct.html) sounds promising but did not meet my needs, nor was it easily extended to meet them.
-Meet [CStruct](https://github.com/samsonjs/compiler/blob/20c758ae85daa5cfa0ad9276c6633b78e982f8b4/asm/cstruct.rb#files),
-a class that you can use to describe a binary structure, somewhat similar to
-how you would do it in C. Subclassing CStruct results in a class whose
-instances can be serialized, and unserialized, with little effort. You can
-subclass descendants of CStruct to extend them with additional members.
-CStruct does not implement much more than is necessary for the compiler. For
-example there is no support for floating point. If you want to use this for
-more general purpose tasks be warned that it may require some work. Anything
-supported by Array#pack is fairly easy to add though.
+Meet [CStruct](https://github.com/samsonjs/compiler/blob/20c758ae85daa5cfa0ad9276c6633b78e982f8b4/asm/cstruct.rb#files), a class that you can use to describe a binary structure, somewhat similar to how you would do it in C. Subclassing CStruct results in a class whose instances can be serialized, and unserialized, with little effort. You can subclass descendants of CStruct to extend them with additional members. CStruct does not implement much more than is necessary for the compiler. For example there is no support for floating point. If you want to use this for more general purpose tasks be warned that it may require some work. Anything supported by Array#pack is fairly easy to add though.
-First a quick example and then we'll get into the CStruct class itself. In
-C you may write the following to have one struct "inherit" from another:
+First a quick example and then we'll get into the CStruct class itself. In C you may write the following to have one struct "inherit" from another:
@@ -42,30 +20,16 @@ With CStruct in Ruby that translates to:
-CStructs act like Ruby's built-in Struct to a certain extent. They are
-instantiated the same way, by passing values to #new in the same order they
-are defined in the class. You can find out the size (in bytes) of a CStruct
-instance using the #bytesize method, or of any member using #sizeof(name).
+CStructs act like Ruby's built-in Struct to a certain extent. They are instantiated the same way, by passing values to #new in the same order they are defined in the class. You can find out the size (in bytes) of a CStruct instance using the #bytesize method, or of any member using #sizeof(name).
-The most important method (for us) is #serialize, which returns a binary
-string representing the contents of the CStruct.
+The most important method (for us) is #serialize, which returns a binary string representing the contents of the CStruct.
-(I know that CStruct.new_from_bin should be called CStruct.unserialize, you
-can see where my focus was when I wrote it.)
+(I know that CStruct.new_from_bin should be called CStruct.unserialize, you can see where my focus was when I wrote it.)
-CStruct#serialize automatically creates a "pack pattern", which is an array
-of strings used to pack each member in turn. The pack pattern is mapped to the
-result of calling Array#pack on each corresponding member, and then the
-resulting strings are joined together. Serializing strings complicates matters
-so we cannot build up a pack pattern string and then serialize it in one go,
-but conceptually it's quite similar.
+CStruct#serialize automatically creates a "pack pattern", which is an array of strings used to pack each member in turn. The pack pattern is mapped to the result of calling Array#pack on each corresponding member, and then the resulting strings are joined together. Serializing strings complicates matters so we cannot build up a pack pattern string and then serialize it in one go, but conceptually it's quite similar.
-Unserializing is the same process in reverse, and was mainly added for
-completeness and testing purposes.
+Unserializing is the same process in reverse, and was mainly added for completeness and testing purposes.
-That's about all you need to know to use CStruct. The code needs some work
-but I decided to just go with what I have already so I can get on with the
-more interesting and fun tasks.
+That's about all you need to know to use CStruct. The code needs some work but I decided to just go with what I have already so I can get on with the more interesting and fun tasks.
*Next in this series: [Basics of the Mach-O file format](/posts/2010/01/basics-of-the-mach-o-file-format)*
-
diff --git a/posts/2010/11/37signals-chalk-dissected.md b/posts/2010/11/37signals-chalk-dissected.md
index c03ed40..a495b3c 100644
--- a/posts/2010/11/37signals-chalk-dissected.md
+++ b/posts/2010/11/37signals-chalk-dissected.md
@@ -1,7 +1,7 @@
---
-Title: 37signals' Chalk Dissected
+Title: "37signals' Chalk Dissected"
Author: Sami Samhuri
-Date: 4th November, 2010
+Date: "4th November, 2010"
Timestamp: 2010-11-04T00:00:00-07:00
Tags: 37signals, chalk, ipad, javascript, web, html, css, zepto.js
---
@@ -14,7 +14,8 @@ Tags: 37signals, chalk, ipad, javascript, web, html, css, zepto.js
The manifest is a nice summary of the contents, and allows browsers to cache the app for offline use. Combine this with mobile Safari's "Add to Home Screen" button and you have yourself a free chalkboard app that works offline.
Not much there, just 10 requests to fetch the whole thing. 11 including the manifest. In we go.
@@ -170,7 +171,6 @@ chalk-sprites.png
-
When the light switch is touched (or clicked) the shade class on the body element is toggled. Nothing to it.
diff --git a/posts/2011/11/lights.md b/posts/2011/11/lights.md
index 864c578..cfeb60b 100644
--- a/posts/2011/11/lights.md
+++ b/posts/2011/11/lights.md
@@ -1,9 +1,8 @@
---
-Title: Lights
+Title: "Lights"
Author: Sami Samhuri
-Date: 27th November, 2011
+Date: "27th November, 2011"
Timestamp: 2011-11-27T18:11:00-08:00
-Tags:
Link: http://lights.elliegoulding.com/
---
diff --git a/posts/2011/11/recovering-old-posts.md b/posts/2011/11/recovering-old-posts.md
index ab2bf59..3bb2d31 100644
--- a/posts/2011/11/recovering-old-posts.md
+++ b/posts/2011/11/recovering-old-posts.md
@@ -1,7 +1,7 @@
---
-Title: Recovering Old Blog Posts
+Title: "Recovering Old Blog Posts"
Author: Sami Samhuri
-Date: 27th November, 2011
+Date: "27th November, 2011"
Timestamp: 2011-11-27T01:15:00-08:00
Tags: recover, old, blog, posts
---
diff --git a/posts/2011/12/i-see-http.md b/posts/2011/12/i-see-http.md
index 4b3cf4c..f1b3ec5 100644
--- a/posts/2011/12/i-see-http.md
+++ b/posts/2011/12/i-see-http.md
@@ -1,9 +1,8 @@
---
-Title: I see HTTP
+Title: "I see HTTP"
Author: Sami Samhuri
-Date: 15th December, 2011
+Date: "15th December, 2011"
Timestamp: 2011-12-15T07:47:15-08:00
-Tags:
Link: http://calendar.perfplanet.com/2011/i-see-http/
---
diff --git a/posts/2011/12/my-kind-of-feature-checklist.md b/posts/2011/12/my-kind-of-feature-checklist.md
index 28c0634..8a6eca7 100644
--- a/posts/2011/12/my-kind-of-feature-checklist.md
+++ b/posts/2011/12/my-kind-of-feature-checklist.md
@@ -1,9 +1,8 @@
---
-Title: My kind of feature checklist
+Title: "My kind of feature checklist"
Author: Sami Samhuri
-Date: 19th December, 2011
+Date: "19th December, 2011"
Timestamp: 2011-12-19T20:20:05-08:00
-Tags:
Link: http://www.marco.org/2011/12/19/amazon-kindle-vs-ipad
---
diff --git a/posts/2011/12/new-release-of-firefox-for-android-optimized-for-tablets.md b/posts/2011/12/new-release-of-firefox-for-android-optimized-for-tablets.md
index e298fcb..b048634 100644
--- a/posts/2011/12/new-release-of-firefox-for-android-optimized-for-tablets.md
+++ b/posts/2011/12/new-release-of-firefox-for-android-optimized-for-tablets.md
@@ -1,9 +1,8 @@
---
-Title: New Release of Firefox for Android, Optimized for Tablets
+Title: "New Release of Firefox for Android, Optimized for Tablets"
Author: Sami Samhuri
-Date: 22nd December, 2011
+Date: "22nd December, 2011"
Timestamp: 2011-12-25T18:54:11-08:00
-Tags:
Link: http://daringfireball.net/linked/2011/12/22/firefox-android
---
diff --git a/posts/2011/12/pure-css3-images-hmm-maybe-later.md b/posts/2011/12/pure-css3-images-hmm-maybe-later.md
index 2e6dade..df81f9e 100644
--- a/posts/2011/12/pure-css3-images-hmm-maybe-later.md
+++ b/posts/2011/12/pure-css3-images-hmm-maybe-later.md
@@ -1,9 +1,8 @@
---
-Title: Pure CSS3 images? Hmm, maybe later
+Title: "Pure CSS3 images? Hmm, maybe later"
Author: Sami Samhuri
-Date: 11th December, 2011
+Date: "11th December, 2011"
Timestamp: 2011-12-11T12:25:03-08:00
-Tags:
Link: http://calendar.perfplanet.com/2011/pure-css3-images-hmm-maybe-later/
---
diff --git a/posts/2011/12/static-url-shortener-using-htaccess.md b/posts/2011/12/static-url-shortener-using-htaccess.md
index 2337fc0..d0fd049 100644
--- a/posts/2011/12/static-url-shortener-using-htaccess.md
+++ b/posts/2011/12/static-url-shortener-using-htaccess.md
@@ -1,7 +1,7 @@
---
-Title: A Static URL Shortener Using .htaccess
+Title: "A Static URL Shortener Using .htaccess"
Author: Sami Samhuri
-Date: 10th December, 2011
+Date: "10th December, 2011"
Timestamp: 2011-12-10T22:29:09-08:00
Tags: s42.ca, url, shortener, samhuri.net, url shortener
---
diff --git a/posts/2011/12/the-broken-pixel-theory.md b/posts/2011/12/the-broken-pixel-theory.md
index 969cf1a..f575d16 100644
--- a/posts/2011/12/the-broken-pixel-theory.md
+++ b/posts/2011/12/the-broken-pixel-theory.md
@@ -1,9 +1,8 @@
---
-Title: The Broken Pixel Theory
+Title: "The Broken Pixel Theory"
Author: Sami Samhuri
-Date: 25th December, 2011
+Date: "25th December, 2011"
Timestamp: 2011-12-25T18:54:20-08:00
-Tags:
Link: http://jtaby.com/2011/12/25/the-broken-pixel-theory.html
---
diff --git a/posts/2012/01/fujitsu-has-lost-their-mind.md b/posts/2012/01/fujitsu-has-lost-their-mind.md
index 9815063..2597d86 100644
--- a/posts/2012/01/fujitsu-has-lost-their-mind.md
+++ b/posts/2012/01/fujitsu-has-lost-their-mind.md
@@ -1,9 +1,8 @@
---
-Title: Fujitsu has lost their mind
+Title: "Fujitsu has lost their mind"
Author: Sami Samhuri
-Date: 19th January, 2012
+Date: "19th January, 2012"
Timestamp: 2012-01-19T20:05:33-08:00
-Tags:
Link: http://tablet-news.com/2012/01/17/fujitsu-lifebook-2013-concept-incorporates-a-tablet-for-a-keyboard-phone-and-digital-camera/
---
diff --git a/posts/2012/01/recovering-from-a-computer-science-education.md b/posts/2012/01/recovering-from-a-computer-science-education.md
index f61dadb..8d3a70f 100644
--- a/posts/2012/01/recovering-from-a-computer-science-education.md
+++ b/posts/2012/01/recovering-from-a-computer-science-education.md
@@ -1,9 +1,8 @@
---
-Title: Recovering From a Computer Science Education
+Title: "Recovering From a Computer Science Education"
Author: Sami Samhuri
-Date: 17th January, 2012
+Date: "17th January, 2012"
Timestamp: 2012-01-17T00:00:00-08:00
-Tags:
Link: http://prog21.dadgum.com/123.html
---
diff --git a/posts/2012/01/sopa-lives-and-mpaa-calls-protests-an-abuse-of-power.md b/posts/2012/01/sopa-lives-and-mpaa-calls-protests-an-abuse-of-power.md
index 5f4bada..c2a48e4 100644
--- a/posts/2012/01/sopa-lives-and-mpaa-calls-protests-an-abuse-of-power.md
+++ b/posts/2012/01/sopa-lives-and-mpaa-calls-protests-an-abuse-of-power.md
@@ -1,9 +1,8 @@
---
-Title: SOPA lives - and MPAA calls protests an "abuse of power"
+Title: "SOPA lives - and MPAA calls protests an \"abuse of power\""
Author: Sami Samhuri
-Date: 17th January, 2012
+Date: "17th January, 2012"
Timestamp: 2012-01-17T02:46:40-08:00
-Tags:
Link: http://arstechnica.com/tech-policy/news/2012/01/sopa-livesand-mpaa-calls-protests-an-abuse-of-power.ars
---
diff --git a/posts/2012/01/the-40-standup-desk.md b/posts/2012/01/the-40-standup-desk.md
index b1a9f32..12ab2ed 100644
--- a/posts/2012/01/the-40-standup-desk.md
+++ b/posts/2012/01/the-40-standup-desk.md
@@ -1,9 +1,8 @@
---
-Title: The $40 Standup Desk
+Title: "The $40 Standup Desk"
Author: Sami Samhuri
-Date: 9th January, 2012
+Date: "9th January, 2012"
Timestamp: 2012-01-09T00:16:40-08:00
-Tags:
Link: http://opensoul.org/blog/archives/2012/01/09/the-40-standup-desk/
---
diff --git a/posts/2012/01/yak-shaving.md b/posts/2012/01/yak-shaving.md
index f1cd90d..60f6ec5 100644
--- a/posts/2012/01/yak-shaving.md
+++ b/posts/2012/01/yak-shaving.md
@@ -1,9 +1,8 @@
---
-Title: Yak shaving
+Title: "Yak shaving"
Author: Sami Samhuri
-Date: 4th January, 2012
+Date: "4th January, 2012"
Timestamp: 2012-01-04T13:24:00-08:00
-Tags:
Link: http://blog.hasmanythrough.com/2012/1/4/yak-shaving
---
diff --git a/posts/2013/03/zelda-tones-for-ios.md b/posts/2013/03/zelda-tones-for-ios.md
index 9d185ec..b568ebf 100644
--- a/posts/2013/03/zelda-tones-for-ios.md
+++ b/posts/2013/03/zelda-tones-for-ios.md
@@ -1,7 +1,7 @@
---
-Title: Zelda Tones for iOS
+Title: "Zelda Tones for iOS"
Author: Sami Samhuri
-Date: 6th March, 2013
+Date: "6th March, 2013"
Timestamp: 2013-03-06T18:51:13-08:00
Tags: zelda, nintendo, pacman, ringtones, tones, ios
---
diff --git a/posts/2013/09/linky.md b/posts/2013/09/linky.md
index 848e36e..9b6a99a 100644
--- a/posts/2013/09/linky.md
+++ b/posts/2013/09/linky.md
@@ -1,7 +1,7 @@
---
-Title: Linky
+Title: "Linky"
Author: Sami Samhuri
-Date: 27th September, 2013
+Date: "27th September, 2013"
Timestamp: 2013-09-27T21:49:02-07:00
Tags: linky, north watcher, ruby, gmail, links, notifications
---
@@ -35,17 +35,23 @@ Yup, that is a lot of moving parts. It is rather elegant in a [Unixy way](http:/
For example, the following lines would be created in a file at `~/Dropbox/Linky/Ruxton/.txt` for my machine named [Ruxton](http://en.wikipedia.org/wiki/Ruxton_Island).
- Callbacks as our Generations' Go To Statement
- http://tirania.org/blog/archive/2013/Aug-15.html
+```markdown
+Callbacks as our Generations' Go To Statement
+http://tirania.org/blog/archive/2013/Aug-15.html
+```
The filename field is defined as:
- {FromAddress}-{ReceivedAt}
+```conf
+{FromAddress}-{ReceivedAt}
+```
And the content is:
- {Subject}
- {BodyPlain}
+```conf
+{Subject}
+{BodyPlain}
+```
That means that when you email links, the subject should contain the title and the body should contain the link on the first line. It's ok if there's stuff after the body (like your signature), they will be ignored later.
@@ -63,7 +69,9 @@ This is a quick and dirty thing I whipped up a couple of years ago, and now it's
It has a text configuration file kind of like [cron](http://en.wikipedia.org/wiki/Cron). Here's mine from Ruxton:
- + Dropbox/Linky/Ruxton ruby /Users/sjs/bin/linky-notify
+```shell
++ Dropbox/Linky/Ruxton ruby /Users/sjs/bin/linky-notify
+```
That tells NorthWatcher to run `ruby /Users/sjs/bin/linky-notify` when files are added to the directory `~/Dropbox/Linky/Ruxton`.
@@ -80,4 +88,3 @@ You can get `terminal-notifier` with [homebrew](http://brew.sh) in a few seconds
## Cool story, bro
It may not be exciting, but as someone who typically suffers from [NIH syndrome](http://en.wikipedia.org/wiki/Not_invented_here) and writes too much from scratch, I found it pretty rewarding to cobble something seemingly complicated together with a bunch of existing components. It didn't take very long and only involved about 10 lines of code. It's not exactly what I wanted but it's surprisingly close. Success!
-
diff --git a/posts/2014/02/ember-structure.md b/posts/2014/02/ember-structure.md
index 7f771a2..cb6a56f 100644
--- a/posts/2014/02/ember-structure.md
+++ b/posts/2014/02/ember-structure.md
@@ -1,7 +1,7 @@
---
-Title: Structure of an Ember app
+Title: "Structure of an Ember app"
Author: Sami Samhuri
-Date: 3rd February, 2014
+Date: "3rd February, 2014"
Timestamp: 2014-02-03T18:05:49-08:00
Tags: ember.js
---
diff --git a/posts/2015/05/a-bitcoin-miner-in-every-device-and-in-every-hand.md b/posts/2015/05/a-bitcoin-miner-in-every-device-and-in-every-hand.md
index 6cf4d89..192cc3c 100644
--- a/posts/2015/05/a-bitcoin-miner-in-every-device-and-in-every-hand.md
+++ b/posts/2015/05/a-bitcoin-miner-in-every-device-and-in-every-hand.md
@@ -1,9 +1,8 @@
---
-Title: A bitcoin miner in every device and in every hand
+Title: "A bitcoin miner in every device and in every hand"
Author: Sami Samhuri
-Date: 19th May, 2015
+Date: "19th May, 2015"
Timestamp: 2015-05-18T19:53:54-07:00
-Tags:
Link: https://medium.com/@21dotco/a-bitcoin-miner-in-every-device-and-in-every-hand-e315b40f2821
---
diff --git a/posts/2015/05/apple-watch-human-interface-guidelines.md b/posts/2015/05/apple-watch-human-interface-guidelines.md
index 6c168b1..3de1b91 100644
--- a/posts/2015/05/apple-watch-human-interface-guidelines.md
+++ b/posts/2015/05/apple-watch-human-interface-guidelines.md
@@ -1,9 +1,8 @@
---
-Title: Apple Watch Human Interface Guidelines
+Title: "Apple Watch Human Interface Guidelines"
Author: Sami Samhuri
-Date: 10th May, 2015
+Date: "10th May, 2015"
Timestamp: 2015-05-09T18:57:19-07:00
-Tags:
Link: https://developer.apple.com/watch/human-interface-guidelines/
---
diff --git a/posts/2015/05/constraints-and-transforms-in-ios-8.md b/posts/2015/05/constraints-and-transforms-in-ios-8.md
index c92aaf2..43ac907 100644
--- a/posts/2015/05/constraints-and-transforms-in-ios-8.md
+++ b/posts/2015/05/constraints-and-transforms-in-ios-8.md
@@ -1,9 +1,8 @@
---
-Title: Constraints and Transforms in iOS 8
+Title: "Constraints and Transforms in iOS 8"
Author: Sami Samhuri
-Date: 15th May, 2015
+Date: "15th May, 2015"
Timestamp: 2015-05-15T07:26:35-07:00
-Tags:
Link: http://revealapp.com/blog/constraints-and-transforms.html
---
diff --git a/posts/2015/05/github-flow-like-a-pro.md b/posts/2015/05/github-flow-like-a-pro.md
index e275370..9a77f1d 100644
--- a/posts/2015/05/github-flow-like-a-pro.md
+++ b/posts/2015/05/github-flow-like-a-pro.md
@@ -1,9 +1,8 @@
---
-Title: GitHub Flow Like a Pro
+Title: "GitHub Flow Like a Pro"
Author: Sami Samhuri
-Date: 28th May, 2015
+Date: "28th May, 2015"
Timestamp: 2015-05-28T07:42:27-07:00
-Tags:
Link: http://haacked.com/archive/2014/07/28/github-flow-aliases/
---
diff --git a/posts/2015/05/importing-modules-in-lldb.md b/posts/2015/05/importing-modules-in-lldb.md
index beb74dd..52921cc 100644
--- a/posts/2015/05/importing-modules-in-lldb.md
+++ b/posts/2015/05/importing-modules-in-lldb.md
@@ -1,9 +1,8 @@
---
-Title: Importing Modules in LLDB
+Title: "Importing Modules in LLDB"
Author: Sami Samhuri
-Date: 12th May, 2015
+Date: "12th May, 2015"
Timestamp: 2015-05-11T19:03:35-07:00
-Tags:
Link: http://furbo.org/2015/05/11/an-import-ant-change-in-xcode/
---
diff --git a/posts/2015/05/lenovo-thinkpad-x1-carbon.md b/posts/2015/05/lenovo-thinkpad-x1-carbon.md
index 95e4b29..f1c5a51 100644
--- a/posts/2015/05/lenovo-thinkpad-x1-carbon.md
+++ b/posts/2015/05/lenovo-thinkpad-x1-carbon.md
@@ -1,9 +1,8 @@
---
-Title: Lenovo ThinkPad X1 Carbon
+Title: "Lenovo ThinkPad X1 Carbon"
Author: Sami Samhuri
-Date: 22nd May, 2015
+Date: "22nd May, 2015"
Timestamp: 2015-05-21T17:36:29-07:00
-Tags:
Link: http://www.anandtech.com/show/9264/the-lenovo-thinkpad-x1-carbon-review-2015
---
diff --git a/posts/2015/05/magical-wristband.md b/posts/2015/05/magical-wristband.md
index 40342c9..c16a82b 100644
--- a/posts/2015/05/magical-wristband.md
+++ b/posts/2015/05/magical-wristband.md
@@ -1,9 +1,8 @@
---
-Title: Magical Wristband
+Title: "Magical Wristband"
Author: Sami Samhuri
-Date: 27th May, 2015
+Date: "27th May, 2015"
Timestamp: 2015-05-26T22:17:29-07:00
-Tags:
Link: http://www.wired.com/2015/03/disney-magicband/
---
diff --git a/posts/2015/05/undocumented-corestorage-commands.md b/posts/2015/05/undocumented-corestorage-commands.md
index 2f1a325..97dcc80 100644
--- a/posts/2015/05/undocumented-corestorage-commands.md
+++ b/posts/2015/05/undocumented-corestorage-commands.md
@@ -1,9 +1,8 @@
---
-Title: Undocumented CoreStorage Commands
+Title: "Undocumented CoreStorage Commands"
Author: Sami Samhuri
-Date: 24th May, 2015
+Date: "24th May, 2015"
Timestamp: 2015-05-23T19:58:36-07:00
-Tags:
Link: http://blog.fosketts.net/2011/08/05/undocumented-corestorage-commands/
---
diff --git a/posts/2015/06/debugging-layouts-with-recursive-view-descriptions-in-xcode.md b/posts/2015/06/debugging-layouts-with-recursive-view-descriptions-in-xcode.md
index c4a79d2..f5f1fc8 100644
--- a/posts/2015/06/debugging-layouts-with-recursive-view-descriptions-in-xcode.md
+++ b/posts/2015/06/debugging-layouts-with-recursive-view-descriptions-in-xcode.md
@@ -1,9 +1,8 @@
---
-Title: Debugging Layouts with Recursive View Descriptions in Xcode
+Title: "Debugging Layouts with Recursive View Descriptions in Xcode"
Author: Sami Samhuri
-Date: 2nd June, 2015
+Date: "2nd June, 2015"
Timestamp: 2015-06-02T16:35:35-07:00
-Tags:
Link: http://jeffreysambells.com/2013/01/24/debugging-layouts-with-recursive-view-descriptions-in-xcode
---
diff --git a/posts/2015/06/the-unofficial-guide-to-xcconfig-files.md b/posts/2015/06/the-unofficial-guide-to-xcconfig-files.md
index e4da317..093614c 100644
--- a/posts/2015/06/the-unofficial-guide-to-xcconfig-files.md
+++ b/posts/2015/06/the-unofficial-guide-to-xcconfig-files.md
@@ -1,9 +1,8 @@
---
-Title: The Unofficial Guide to xcconfig files
+Title: "The Unofficial Guide to xcconfig files"
Author: Sami Samhuri
-Date: 1st June, 2015
+Date: "1st June, 2015"
Timestamp: 2015-06-01T08:16:51-07:00
-Tags:
Link: http://pewpewthespells.com/blog/xcconfig_guide.html?utm_campaign=iOS%2BDev%2BWeekly&utm_source=iOS_Dev_Weekly_Issue_200
---
diff --git a/posts/2015/07/scripts-to-rule-them-all.md b/posts/2015/07/scripts-to-rule-them-all.md
index 6b0119c..c2150a1 100644
--- a/posts/2015/07/scripts-to-rule-them-all.md
+++ b/posts/2015/07/scripts-to-rule-them-all.md
@@ -1,9 +1,8 @@
---
-Title: Scripts to Rule Them All
+Title: "Scripts to Rule Them All"
Author: Sami Samhuri
-Date: 1st July, 2015
+Date: "1st July, 2015"
Timestamp: 2015-07-01T07:37:04-07:00
-Tags:
Link: http://githubengineering.com/scripts-to-rule-them-all/
---
diff --git a/posts/2015/07/swift-new-stuff-in-xcode-7-beta-3.md b/posts/2015/07/swift-new-stuff-in-xcode-7-beta-3.md
index 92e0715..371dbbd 100644
--- a/posts/2015/07/swift-new-stuff-in-xcode-7-beta-3.md
+++ b/posts/2015/07/swift-new-stuff-in-xcode-7-beta-3.md
@@ -1,9 +1,8 @@
---
-Title: Swift: New stuff in Xcode 7 Beta 3
+Title: "Swift: New stuff in Xcode 7 Beta 3"
Author: Sami Samhuri
-Date: 9th July, 2015
+Date: "9th July, 2015"
Timestamp: 2015-07-09T09:17:13-07:00
-Tags:
Link: http://ericasadun.com/2015/07/08/swift-new-stuff-in-xcode-7-beta-3/
---
diff --git a/posts/2015/08/acorn-5s-live-help-search.md b/posts/2015/08/acorn-5s-live-help-search.md
index 5159e57..84687fc 100644
--- a/posts/2015/08/acorn-5s-live-help-search.md
+++ b/posts/2015/08/acorn-5s-live-help-search.md
@@ -1,9 +1,8 @@
---
-Title: Acorn 5's Live Help Search
+Title: "Acorn 5's Live Help Search"
Author: Sami Samhuri
-Date: 25th August, 2015
+Date: "25th August, 2015"
Timestamp: 2015-08-24T22:00:27-07:00
-Tags:
Link: http://shapeof.com/archives/2015/8/acorn_5_search_index.html
---
diff --git a/posts/2015/08/cloaks-updated-privacy-policy.md b/posts/2015/08/cloaks-updated-privacy-policy.md
index b9a3077..099e7f8 100644
--- a/posts/2015/08/cloaks-updated-privacy-policy.md
+++ b/posts/2015/08/cloaks-updated-privacy-policy.md
@@ -1,9 +1,8 @@
---
-Title: Cloak's Updated Privacy Policy
+Title: "Cloak's Updated Privacy Policy"
Author: Sami Samhuri
-Date: 27th August, 2015
+Date: "27th August, 2015"
Timestamp: 2015-08-26T19:56:54-07:00
-Tags:
Link: https://blog.getcloak.com/2015/08/25/updated-privacy-policy/
---
diff --git a/posts/2016/03/moving-beyond-the-oop-obsession.md b/posts/2016/03/moving-beyond-the-oop-obsession.md
index fd3cb3a..89148bb 100644
--- a/posts/2016/03/moving-beyond-the-oop-obsession.md
+++ b/posts/2016/03/moving-beyond-the-oop-obsession.md
@@ -1,9 +1,8 @@
---
-Title: Moving Beyond the OOP Obsession
+Title: "Moving Beyond the OOP Obsession"
Author: Sami Samhuri
-Date: 28th March, 2016
+Date: "28th March, 2016"
Timestamp: 2016-03-28T09:08:47-07:00
-Tags:
Link: http://prog21.dadgum.com/218.html
---
diff --git a/posts/2016/03/reduce-the-cognitive-load-of-your-code.md b/posts/2016/03/reduce-the-cognitive-load-of-your-code.md
index 5311ff4..397cc94 100644
--- a/posts/2016/03/reduce-the-cognitive-load-of-your-code.md
+++ b/posts/2016/03/reduce-the-cognitive-load-of-your-code.md
@@ -1,9 +1,8 @@
---
-Title: Reduce the cognitive load of your code
+Title: "Reduce the cognitive load of your code"
Author: Sami Samhuri
-Date: 30th March, 2016
+Date: "30th March, 2016"
Timestamp: 2016-03-30T07:10:29-07:00
-Tags:
Link: http://chrismm.com/blog/how-to-reduce-the-cognitive-load-of-your-code/
---
diff --git a/posts/2016/04/tales-of-prk-laser-eye-surgery.md b/posts/2016/04/tales-of-prk-laser-eye-surgery.md
index c7c5f5c..6acbade 100644
--- a/posts/2016/04/tales-of-prk-laser-eye-surgery.md
+++ b/posts/2016/04/tales-of-prk-laser-eye-surgery.md
@@ -1,9 +1,8 @@
---
-Title: Tales of PRK Laser Eye Surgery
+Title: "Tales of PRK Laser Eye Surgery"
Author: Sami Samhuri
-Date: 12th April, 2016
+Date: "12th April, 2016"
Timestamp: 2016-04-11T20:52:53-07:00
-Tags:
---
Today I scheduled PRK laser eye surgery on April 19th. Exciting but also kind of terrifying because the procedure sounds a bit horrific. Most accounts from people don't sound very bad though so the operation itself should be a breeze! I scoured the web for PRK recovery stories to get an idea of what I was in for and found some good quotes.
diff --git a/posts/2016/08/easy-optimization-wins.md b/posts/2016/08/easy-optimization-wins.md
index edfcfd6..22289fa 100644
--- a/posts/2016/08/easy-optimization-wins.md
+++ b/posts/2016/08/easy-optimization-wins.md
@@ -1,7 +1,7 @@
---
-Title: Easy Optimization Wins
+Title: "Easy Optimization Wins"
Author: Sami Samhuri
-Date: 10th August, 2016
+Date: "10th August, 2016"
Timestamp: 2016-08-10T10:30:49-07:00
Tags: ios, git
---
@@ -10,7 +10,7 @@ It's not hard to hide a whole lot of complexity behind a function call, so you h
Here's some example code illustrating a big performance problem I found in a codebase I've inherited. We have a dictionary keyed by a string representing a date, e.g. "2016-08-10", and where the values are arrays of videos for that given date. Due to some unimportant product details videos can actually appear in more than one of the array values. The goal is to get an array of all videos, sorted by date, and with no duplicates. So we need to discard duplicates when building the sorted array.
-```Swift
+```swift
func allVideosSortedByDate(allVideos: [String:[Video]]) -> [Video] {
var sortedVideos: [Video] = []
// sort keys newest first
@@ -32,7 +32,7 @@ Because this is being called from within a loop that's already looping over all
In this particular case my first instinct is to reach for a set. We want a collection of all the videos and want to ensure that they're unique, and that's what sets are for. So what about sorting? Well we can build up the set of all videos, then sort that set, converting it to an array in the process. Sounds like a lot of work right? Is it really faster? Let's see what it looks like.
-```Swift
+```swift
func allVideosSortedByDate(allVideos: [String:[Video]]) -> [Video] {
var uniqueVideos: Set