From 0af82ec66ab8d8e7bc81f79f7e098cbf19fc145d Mon Sep 17 00:00:00 2001 From: Ariejan de Vroom Date: Tue, 30 Jan 2024 09:26:51 +0100 Subject: [PATCH] Replace
 tags with code fences

---
 ...nstall-ruby-mysql-on-mac-os-x-104-tiger.md | 12 ++-
 ...-current-svn-revision-in-your-rails-app.md | 24 ++++--
 ...2-20-svn-merge-a-branch-with-your-trunk.md | 12 ++-
 ...materails-easy-partials-for-better-code.md | 16 ++--
 ...1-19-print-this-page-with-ruby-on-rails.md | 10 ++-
 ...ew-in-rails-resource-scaffold-generator.md | 12 ++-
 ...07-01-23-rails-nested-resource-scaffold.md | 76 +++++++++++++------
 ...07-03-07-wordpress-plugin-autoflickr-10.md |  4 +-
 ...ging-informational-messages-to-your-log.md | 10 ++-
 ...ip-snippet-create-a-comma-seperate-list.md |  4 +-
 ...5-21-merge-request-failed-on-pathtofile.md |  6 +-
 ...lling-rmagick-ruby-gem-on-mac-os-x-1049.md | 16 ++--
 ...007-05-29-slow-connections-with-proftpd.md |  4 +-
 ...ebadmin-plugin-and-global-configuration.md | 26 +++++--
 ...-10-find-and-replace-with-a-mysql-query.md |  4 +-
 ...6-10-send-mail-with-a-bash-shell-script.md | 16 ++--
 ...-12-bash-your-svn-and-trac-installation.md |  6 +-
 ...07-07-07-clear-dns-cache-on-your-router.md |  8 +-
 ...2007-08-27-blueprintcss-rails-generator.md |  8 +-
 ...nd-making-sure-something-gets-displayed.md | 14 +++-
 ...9-26-flash-not-clearing-after-a-request.md |  4 +-
 ...-it-number-of-messages-in-postfix-queue.md |  4 +-
 ...set-the-auto-increment-value-of-a-table.md |  8 +-
 ...7-12-06-rails-calculated-column-caching.md | 20 +++--
 ...rite-a-dvd-video-from-the-linux-console.md | 18 +++--
 ...04-09-enabling-trac-email-notifications.md |  6 +-
 ...008-04-10-debian-etch-rmagick-loaderror.md | 12 ++-
 ...15-permanently-redirect-wordpress-pages.md | 12 ++-
 ...ompile-packages-on-debianubuntu-by-hand.md | 20 +++--
 ...cannot-be-undone-irreversible-migration.md | 18 +++--
 ...-14-useless-ruby-gems-for-your-pleasure.md | 12 ++-
 ...08-11-27-export-csv-directly-from-mysql.md |  6 +-
 ...-to-start-a-rails-edge-app-the-easy-way.md | 22 ++++--
 ...2009-02-07-warcraft-armory-010-released.md | 10 ++-
 ...how-to-create-a-dsa-openssl-certificate.md |  6 +-
 ...2009-04-23-compacting-a-sqlite3-db-file.md |  6 +-
 .../2009-06-05-install-hpricot-on-ubuntu.md   | 12 ++-
 ...find-all-that-have-no-associated-object.md | 18 +++--
 ...le-utility-query-imdb-from-your-console.md | 22 ++++--
 ...best-practice-the-git-development-cycle.md | 28 ++++---
 ...by-gem-0-4-0-now-available-at-rubyforge.md |  8 +-
 ...09-09-01-jinput-mac-os-x-64-bit-natives.md | 12 ++-
 42 files changed, 398 insertions(+), 174 deletions(-)

diff --git a/content/posts/2006-12-06-install-ruby-mysql-on-mac-os-x-104-tiger.md b/content/posts/2006-12-06-install-ruby-mysql-on-mac-os-x-104-tiger.md
index add0de1..6cab275 100644
--- a/content/posts/2006-12-06-install-ruby-mysql-on-mac-os-x-104-tiger.md
+++ b/content/posts/2006-12-06-install-ruby-mysql-on-mac-os-x-104-tiger.md
@@ -12,19 +12,23 @@ Most notably, you want to install this gem if you get dropped MySQL connections
 
 So we do:
 
-
$ sudo gem install mysql
+```bash
+$ sudo gem install mysql
 ...
-ERROR: Failed to build gem native extension.
+ERROR: Failed to build gem native extension. +``` Normall this would install fine, but not on Mac OS X. This is because Mac OS X keeps its code, headers and libraries in odd places (compared to Linux). But don't panic. There's an easy solution to all this! Just compile the gem yourself, and add some special ingredients. Well, not even that. Just compile it again like this: -
$ cd /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7
+```bash
+$ cd /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7
 $ sudo ruby extconf.rb --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include
 $ sudo make
-$ sudo make install
+$ sudo make install +``` Now, you have the ruby-mysql gem installed and ready to go! No more dropped MySQL connections for Rails! diff --git a/content/posts/2006-12-13-show-the-current-svn-revision-in-your-rails-app.md b/content/posts/2006-12-13-show-the-current-svn-revision-in-your-rails-app.md index e1dc61b..7c00ba4 100644 --- a/content/posts/2006-12-13-show-the-current-svn-revision-in-your-rails-app.md +++ b/content/posts/2006-12-13-show-the-current-svn-revision-in-your-rails-app.md @@ -18,32 +18,40 @@ Luckily for me, I use capistrano. Here's how I fixed the problem. First of all, I created a partial that contains the revision number and render this in my layout. app/views/layouts/_revision.rhtml: -
+```bash
+
 CURRENT
-
+ +``` This shows CURRENT always when I work with my working copy. app/views/layouts/mylayout.rhtml -
+```ruby
+
   < %= render :partial => 'layout/revision' %>
-
+ +``` Now, I assume you have already setup capistrano for your project and that you have a config/deploy.rb file. I've added the following helper to my config/deploy.rb file: -
desc "Write current revision to app/layouts/_revision.rhtml"
+```ruby
+desc "Write current revision to app/layouts/_revision.rhtml"
 task :publish_revision do
   run "svn info #{release_path} | grep ^Revision > #{release_path}/app/views/layouts/_revision.rhtml"
-end
+end +``` Next, I added the following hook 'after_update_code'. This will automatically be run after update_code which is called in 'deploy'. -
desc "Run this after update_code"
+```ruby
+desc "Run this after update_code"
 task :after_update_code do
   publish_revision
-end
+end +``` That's it. When I deploy the application, the current code is checked out and and the layouts/_revision.rhtml file is overwritten with the current revision information. diff --git a/content/posts/2006-12-20-svn-merge-a-branch-with-your-trunk.md b/content/posts/2006-12-20-svn-merge-a-branch-with-your-trunk.md index 64583bc..c6e5cea 100644 --- a/content/posts/2006-12-20-svn-merge-a-branch-with-your-trunk.md +++ b/content/posts/2006-12-20-svn-merge-a-branch-with-your-trunk.md @@ -14,17 +14,23 @@ Here's a handy-dandy guide on how to merge your branch code with your trunk. Firstly, make sure you have a working copy of your trunk. I choose to switch my working copy back: (oh, make sure you have all your changes checked in in your branch before you switch!) -
$ svn switch http://example.com/svn/myproject/trunk
+```bash +$ svn switch http://example.com/svn/myproject/trunk +``` This removes, adds and updates all files you have worked on in your branch and creates a working copy of the code in the trunk. Now, with my trunk in place, I can call 'merge' and apply the changes. -
$ svn merge http://example.com/svn/myproject/trunk http://example.com/svn/myproject/branches/TRY-AJAX
+```bash +$ svn merge http://example.com/svn/myproject/trunk http://example.com/svn/myproject/branches/TRY-AJAX +``` Since the files from the trunk and the beginning of the TRY-branch are still exact copies, I won't get in any trouble. If you do (and you did change your code in your trunk), make sure to resolve merging problems before checking in. When ready, check in your new code! -
$ svn ci -m "Merge TRY-AJAX branch with trunk"
+```bash +$ svn ci -m "Merge TRY-AJAX branch with trunk" +``` That's it. You have now merged the branch with your trunk. Enjoy! diff --git a/content/posts/2006-12-22-textmaterails-easy-partials-for-better-code.md b/content/posts/2006-12-22-textmaterails-easy-partials-for-better-code.md index 757fc0c..2757f06 100644 --- a/content/posts/2006-12-22-textmaterails-easy-partials-for-better-code.md +++ b/content/posts/2006-12-22-textmaterails-easy-partials-for-better-code.md @@ -19,7 +19,9 @@ First something about partials for those who don't know about it. Partials are stored in files that start with an _ (underscore) and end in .rthml (or .rjs or .rxml) and you may include them in your ERb like this: -
< %= render :partial => 'userinfo' %>
+```ruby +< %= render :partial => 'userinfo' %> +``` This will include the partial _userinfo.rhtml for you. This way you can avoid duplication by including the same ERb template (partial) over and over again. @@ -27,7 +29,8 @@ Partials are also useful to keep your views (templates) clean and easy to unders Let's say you have a profile page where you want to show a users's profile and some options for when the user is viewing his own profile. Also, you want to show a simple message when the users has not yet created a profile, which is a possibility in my application. The show.rhtml template for the profile may look like this -

Profile for < %=h @profile.user.login %>

+```ruby +

Profile for < %=h @profile.user.login %>

< % if @profile.exists? -%> @@ -57,7 +60,8 @@ Let's say you have a profile page where you want to show a users's profile and s
  • < %= link_to "Change password", :controller => 'account', :action => "change_password" %>
  • < %= link_to "Edit your profile", profile_edit_url(:login => current_user.login) %>
  • -< % end -%>
    +< % end -%> +``` As you may see, this is chaos. It's not easy to read and you can't easily change something when you need to. Wouldn't it be great to store all three seperate blocks (profile, no profile message and options) in partials? @@ -75,7 +79,8 @@ After you click OK, the partial will be created containing the code you selected After all this the same ERb template looks like this: -

    Profile for < %=h @profile.user.login %>

    +```ruby +

    Profile for < %=h @profile.user.login %>

    < % if @profile.exists? -%> < %= render :partial => 'profile' %> @@ -85,7 +90,8 @@ After all this the same ERb template looks like this: < % if @profile.user.id == current_user.id -%> < %= render :partial => 'options' %> -< % end -%>
    +< % end -%> +``` Now, isn't that more readable? Even, if you want to change a profile, you can just edit _profile.rhtml and you're done. diff --git a/content/posts/2007-01-19-print-this-page-with-ruby-on-rails.md b/content/posts/2007-01-19-print-this-page-with-ruby-on-rails.md index 1b8b654..707433b 100644 --- a/content/posts/2007-01-19-print-this-page-with-ruby-on-rails.md +++ b/content/posts/2007-01-19-print-this-page-with-ruby-on-rails.md @@ -11,8 +11,10 @@ You have put a lot of effort into creating a sexy overview of whatever data your How to go about that? Just printing the page with data is generally not a good idea because it has been optimized for display on a screen. The first step we need to take is adapting our page for printing. Stylesheets are very handy tools for this. Check the following part of the header of my layout: -
    stylesheet_link_tag('default', :media => :screen)
    -stylesheet_link_tag('print', :media => :print)
    +```ruby +stylesheet_link_tag('default', :media => :screen) +stylesheet_link_tag('print', :media => :print) +``` This will generate HTML code that includes two stylesheets. However, only the 'default' stylesheet is used on screen. When the users prints a particular page, the print stylesheet is used instead. So, what do you want to change in the print stylesheet? @@ -35,7 +37,9 @@ Now, with all this in place, load your page with data. Print your page or watch The final touch is adding a "Print this page" link to your navigation on screen. Here you can use link_to_function: -
    link_to_function("Print this Page", "javascript:print()")
    +```ruby +link_to_function("Print this Page", "javascript:print()") +``` That's it. Just hit the Print this Page button and your browsers print dialog will pop up and use your fancy new print stylesheet. diff --git a/content/posts/2007-01-23-new-in-rails-resource-scaffold-generator.md b/content/posts/2007-01-23-new-in-rails-resource-scaffold-generator.md index 0cb7456..189c499 100644 --- a/content/posts/2007-01-23-new-in-rails-resource-scaffold-generator.md +++ b/content/posts/2007-01-23-new-in-rails-resource-scaffold-generator.md @@ -15,15 +15,21 @@ Well, Rails wouldn't be Rails if there weren't a generator for it! This example is really easy. I want to create products in my database and expose them as HTML and XML to my users. Just do the following: -
    $ ./script/generate scaffold_resource Product title:string description:text
    +```bash +$ ./script/generate scaffold_resource Product title:string description:text +``` A migration is generated automatically so update that if you want to before running -
    $ rake db:migrate
    +```bash +$ rake db:migrate +``` As you can see in config/routes.rb, Rails has automatically generated routes for this resource! -
    map.resource :products
    +```ruby +map.resource :products +``` Now you can start up your Rails app and access http://localhost:8000/products. Add some products if you like. Now if you got to http://localhost:8000/products/1 you a nice HTML scaffold. If you add .xml: http://localhost:8000/products/1.xml you'll get nice XML! diff --git a/content/posts/2007-01-23-rails-nested-resource-scaffold.md b/content/posts/2007-01-23-rails-nested-resource-scaffold.md index 93c2579..65e0df1 100644 --- a/content/posts/2007-01-23-rails-nested-resource-scaffold.md +++ b/content/posts/2007-01-23-rails-nested-resource-scaffold.md @@ -15,84 +15,114 @@ I assume you have Rails 1.2.1 installed for this tutorial to work properly. First, I create an new rails project named 'cookbook'. I use an SQLite3 database because it's easy to do so. You may use any Rails compatible database for this example. -
    $ mkdir cookbook
    +```bash
    +$ mkdir cookbook
     rails --database sqlite3 cookbook
    -cd cookbook
    +cd cookbook +``` First I create resource scaffolds for both the Recipe and Ingredient models: -
    $ ./script/generate scaffold_resource Recipe title:string instructions:text
    -./script/generate scaffold_resource Ingredient name:string quantity:string
    +```bash +$ ./script/generate scaffold_resource Recipe title:string instructions:text +./script/generate scaffold_resource Ingredient name:string quantity:string +``` As you can see I did not add a recipe_id to the ingredient model because of the has_many relationship. Add this column to the migration file. You should now be able to migrate your database: -
    $ rake db:migrate
    +```bash +$ rake db:migrate +``` If you add the recipe_id to the generate script the view for your ingredients will include a field for the recipe_id and that's not what you want. Next, make the has_many relationship in your models. app/models/recipe.rb: -
    class Recipe < ActiveRecord::Base
    +```ruby
    +class Recipe < ActiveRecord::Base
       has_many :ingredients
    -end
    +end +``` app/models/ingredient.rb -
    class Ingredient < ActiveRecord::Base
    +
    ```ruby +class Ingredient < ActiveRecord::Base belongs_to :recipe -end +end +``` So far, nothing new. Next we check out config/routes.rb: -
    map.resources :ingredients
    -map.resources :recipes
    +```ruby +map.resources :ingredients +map.resources :recipes +``` What we want is to map ingredients as a resource to recipes. Replace these two lines with: -
    map.resources :recipes do |recipes|
    +```ruby
    +map.resources :recipes do |recipes|
     	recipes.resources :ingredients
    -end
    +end +``` This will give you urls like /recipes/123/ingredients/321 Now we need to make some changes to the ingredients controller. Every ingredient belongs to a recipe. First add the filter: -
    before_filter(:get_recipe)
    +```ruby
    +before_filter(:get_recipe)
     
     private
     def get_recipe
     	@recipe = Recipe.find(params[:recipe_id])
    -end
    +end +``` This will make sure that every ingredient knows what recipe it belongs to. In the index method of the ingredient controller, make sure you have this: -
    @ingredients = @recipe.ingredients.find(:all)
    +```ruby +@ingredients = @recipe.ingredients.find(:all) +``` This makes sure you only show ingredients for this recipe, and not all ingredients in the database. Because we changed the route for ingredients, we need to update all ingredient_url() and ingredient_path() calls in our controller and views. Change all occurrences of -
    ingredient_url(@ingredient)
    +```ruby +ingredient_url(@ingredient) +``` and -
    ingredient_path(@ingredient)
    +```ruby +ingredient_path(@ingredient) +``` to -
    ingredient_url(@recipe, @ingredient)
    +```ruby +ingredient_url(@recipe, @ingredient) +``` and -
    ingredient_path(@recipe, @ingredient)
    +```ruby +ingredient_path(@recipe, @ingredient) +``` Note: Make sure that you don't replace 'ingredient' with '@ingredient' in your views! Add a link to the ingredients to your recipe's index.rhtml view. -
    link_to 'Ingredients', ingredients_path(recipe)
    +```ruby +link_to 'Ingredients', ingredients_path(recipe) +``` And, at last, make sure the create method of your ingredients controller attaches the ingredient to the right recipe. Make sure the first two lines look like this: -
    def create
    -  @ingredient = @recipe.ingredients.new(params[:ingredient])
    +```ruby +def create + @ingredient = @recipe.ingredients.new(params[:ingredient]) +``` You may now start your webserver and check out http://localhost:8000/recipes . Create some recipes and click 'ingredients'. You can now add ingredients for this recipe! diff --git a/content/posts/2007-03-07-wordpress-plugin-autoflickr-10.md b/content/posts/2007-03-07-wordpress-plugin-autoflickr-10.md index 128379a..5d70006 100644 --- a/content/posts/2007-03-07-wordpress-plugin-autoflickr-10.md +++ b/content/posts/2007-03-07-wordpress-plugin-autoflickr-10.md @@ -38,7 +38,9 @@ That's it. Optionally you may want to adapt autoflickr.css to change the way the If you want to include images in another place than the default, you may disable AutoFlickr for all pages and include the following PHP code in your template. Note that this code must be used within "The Loop". -
    +```php + +```

    Demo

    diff --git a/content/posts/2007-03-22-rails-tip-snippet-logging-informational-messages-to-your-log.md b/content/posts/2007-03-22-rails-tip-snippet-logging-informational-messages-to-your-log.md index af8c236..592b649 100644 --- a/content/posts/2007-03-22-rails-tip-snippet-logging-informational-messages-to-your-log.md +++ b/content/posts/2007-03-22-rails-tip-snippet-logging-informational-messages-to-your-log.md @@ -10,15 +10,19 @@ This "Rails Tip Snippet" is one in a series of small blocks of code that will ma This first snippet shows you how you can log informational message to your log file so you can track any important actions that happened. As an example you may want to log all user accounts that get deleted: -
    def destroy
    +```ruby
    +def destroy
        @user = User.find(params[:id])
        @user.destroy!
        logger.info("User account '#{@user.login}' deleted by user #{current_user.login})
        ...
    -end
    +end +``` Line 4 will put a string like "User account 'johnlocke" delete by user ariejan" in your log file. Use that information any way you want. You may also use the logger to inspect variables: -
    logger.info("article inspection: #{@article.inspect}")
    +```ruby +logger.info("article inspection: #{@article.inspect}") +``` Until next time! Any tips are welcome at tips@ariejan.net. diff --git a/content/posts/2007-03-27-rails-tip-snippet-create-a-comma-seperate-list.md b/content/posts/2007-03-27-rails-tip-snippet-create-a-comma-seperate-list.md index 6f45816..5df162d 100644 --- a/content/posts/2007-03-27-rails-tip-snippet-create-a-comma-seperate-list.md +++ b/content/posts/2007-03-27-rails-tip-snippet-create-a-comma-seperate-list.md @@ -12,7 +12,9 @@ Users: John, Dick, Harry With Ruby on Rails this is really easy. You probably have a collection of user objects. All you want is a list of names: -
    @users.collect{|u| u.name}.join(', ')
    +```ruby +@users.collect{|u| u.name}.join(', ') +``` Read more Tip Snippets? diff --git a/content/posts/2007-05-21-merge-request-failed-on-pathtofile.md b/content/posts/2007-05-21-merge-request-failed-on-pathtofile.md index 909a4fd..aefb07e 100644 --- a/content/posts/2007-05-21-merge-request-failed-on-pathtofile.md +++ b/content/posts/2007-05-21-merge-request-failed-on-pathtofile.md @@ -8,8 +8,10 @@ description = "How to fix this annoying Subversion problem." After upgrading my Subversion server to Ubuntu Feisty, I noticed that when committing I got the following error: -
    svn: MERGE request failed on '/svn/repository/trunk'
    -svn: MERGE of '/svn/repository/trunk': 200 OK (http://svn.myserver.com)
    +```text +svn: MERGE request failed on '/svn/repository/trunk' +svn: MERGE of '/svn/repository/trunk': 200 OK (http://svn.myserver.com) +``` Although the messages says that the commit failed, it has not. A simple 'svn update' will merge the changes you made to the repository to your working copy again and you're good to go. diff --git a/content/posts/2007-05-29-installing-rmagick-ruby-gem-on-mac-os-x-1049.md b/content/posts/2007-05-29-installing-rmagick-ruby-gem-on-mac-os-x-1049.md index e11ba9a..f28a73c 100644 --- a/content/posts/2007-05-29-installing-rmagick-ruby-gem-on-mac-os-x-1049.md +++ b/content/posts/2007-05-29-installing-rmagick-ruby-gem-on-mac-os-x-1049.md @@ -15,7 +15,8 @@ Before you jump in, make sure you have curl -O http://download.savannah.gnu.org/releases/freetype/freetype-2.1.10.tar.gz +```bash +curl -O http://download.savannah.gnu.org/releases/freetype/freetype-2.1.10.tar.gz tar xzvf freetype-2.1.10.tar.gz cd freetype-2.1.10 ./configure --prefix=/usr/local @@ -47,17 +48,22 @@ cd tiff-3.8.2 ./configure --prefix=/usr/local make sudo make install -cd .. +cd .. +``` Next we install ImageMagick: -
    curl -O http://easynews.dl.sourceforge.net/sourceforge/imagemagick/ImageMagick-6.3.0-0.tar.gz
    +```bash
    +curl -O http://easynews.dl.sourceforge.net/sourceforge/imagemagick/ImageMagick-6.3.0-0.tar.gz
     tar xzvf ImageMagick-6.3.0-0.tar.gz
     cd ImageMagick-6.3.0
     ./configure --prefix=/usr/local
     make
     sudo make install
    -cd ..
    +cd .. +``` And now, ladies and gentlemen, what you've all been waiting for: RMagick: -
    sudo gem install --no-rdoc --no-ri RMagick
    +```bash +sudo gem install --no-rdoc --no-ri RMagick +``` In my case the generation of the documentation fails, so I tell rubygems not to compile the docs. You now have RMagick installed on you Mac OS X 10.4.9 machine! Congratulations! diff --git a/content/posts/2007-05-29-slow-connections-with-proftpd.md b/content/posts/2007-05-29-slow-connections-with-proftpd.md index 6ed7f90..59625aa 100644 --- a/content/posts/2007-05-29-slow-connections-with-proftpd.md +++ b/content/posts/2007-05-29-slow-connections-with-proftpd.md @@ -12,6 +12,8 @@ So, I investigated and found that by default ProFTPD tries to revolve the hostna It's easy to stop ProFTPD from behaving like this by adding the following line to your proftpd.conf in /etc/proftpd: -
    IdentLookups off
    +```text +IdentLookups off +``` Restart ProFTPD and you'll have a fast FTP connection to enjoy! \ No newline at end of file diff --git a/content/posts/2007-05-30-trac-webadmin-plugin-and-global-configuration.md b/content/posts/2007-05-30-trac-webadmin-plugin-and-global-configuration.md index 8189877..67ca26b 100644 --- a/content/posts/2007-05-30-trac-webadmin-plugin-and-global-configuration.md +++ b/content/posts/2007-05-30-trac-webadmin-plugin-and-global-configuration.md @@ -12,15 +12,19 @@ I was happy, since trac 0.10.3 has many improvements over 0.9.x, but there was o What happened? After upgrading the trac package, the plugins directory was emptied. Well, just re-install the WebAdmin plugin for 0.10.x. -
    cd /usr/share/trac/plugins
    +```bash
    +cd /usr/share/trac/plugins
     sudo svn co http://svn.edgewall.org/repos/trac/sandbox/webadmin/
     cd webadmin
     sudo python setup.py bdist_egg
     cd dist
    -sudo easy_install-2.4 TracWebAdmin-0.1.2dev_r4429-py2.4.egg
    +sudo easy_install-2.4 TracWebAdmin-0.1.2dev_r4429-py2.4.egg +``` That was easy, next I wanted to enable the plugin for all my trac installations by adding the proper configuration to /usr/share/trac/conf/trac.ini, the global trac configuration file that is used by all trac installs. -
    [components]
    -webadmin.* = enabled
    +```text +[components] +webadmin.* = enabled +``` After restarting Apache (this is needed for some reason to get trac to read the new configuration file), no admin button showed up in any of the projects. What went wrong is that Ubuntu (or Debian?) maintainers have changed the location of the global configuration file for trac. There are three solutions to this, all of them work fine, although I recommend you use the first one. @@ -28,13 +32,17 @@ What went wrong is that Ubuntu (or Debian?) maintainers have changed the locatio 1. Move your global configuration The best way to tackle this problem is to move your global configuration file to the new location: /etc/trac/trac.ini -
    sudo mv /usr/share/trac/conf/trac.ini /etc/trac/trac.ini
    +```bash +sudo mv /usr/share/trac/conf/trac.ini /etc/trac/trac.ini +``` This way you're configuration is safe from new upgrades and confirms to the defaults the package maintainer has set. 2. Symlink the configuration If for some reason you don't want to actually move your /usr/share/trac/conf/trac.ini file, you can create a symlink to the new location: -
    sudo ln -sf /usr/share/trac/conf/trac.ini /etc/trac/trac.ini
    +```bash +sudo ln -sf /usr/share/trac/conf/trac.ini /etc/trac/trac.ini +```
     
     This leaves your original configuration file in tact, but it may be removed by new upgrades.
    @@ -42,10 +50,12 @@ This leaves your original configuration file in tact, but it may be removed by n
     3. Change Trac
     
     You may also change the location where trac looks for the configuration file. Open up /var/lib/python-support/python2.5/trac/siteconfig.py and change the following:
    -
    < __default_conf_dir__ = '/etc/trac'
    +```python
    +< __default_conf_dir__ = '/etc/trac'
     > __default_conf_dir__ = '/usr/share/trac/conf'[/pre]
     
     (Note: the > and < symbols mark what is removed and what is added to the file.)
     
    -In any case, reboot your web server and you should be good to go again.
    +In any case, reboot your web server and you should be good to go again. +``` diff --git a/content/posts/2007-06-10-find-and-replace-with-a-mysql-query.md b/content/posts/2007-06-10-find-and-replace-with-a-mysql-query.md index 622d90b..ba5d2a2 100644 --- a/content/posts/2007-06-10-find-and-replace-with-a-mysql-query.md +++ b/content/posts/2007-06-10-find-and-replace-with-a-mysql-query.md @@ -11,6 +11,8 @@ There are times when you have a lot of data in a database (let's say wp_posts fo But, as I always say: "You're a programmer! You should script the hell out of everything!" So, I found this: MySQL has built-in support to find and replace! Just a simple query will do: -
    UPDATE wp_posts set post_body = replace(post_body, 'needle', 'chocolate');
    +```sql +UPDATE wp_posts set post_body = replace(post_body, 'needle', 'chocolate'); +``` That's it. The entire table 'wp_posts' is searched and all occurrences of "needle" are replaced with "chocolate". The query only took about a split second. diff --git a/content/posts/2007-06-10-send-mail-with-a-bash-shell-script.md b/content/posts/2007-06-10-send-mail-with-a-bash-shell-script.md index 429e7ac..5dda4b4 100644 --- a/content/posts/2007-06-10-send-mail-with-a-bash-shell-script.md +++ b/content/posts/2007-06-10-send-mail-with-a-bash-shell-script.md @@ -12,20 +12,25 @@ This time I want to show you how you can easily send an e-mail from a BASH scrip We're going to use the GNU Mail utility here. The basic syntax to send an email is like this: -
    /usr/bin/mail -s "Subject" someone@example.org < message.txt
    +```bash +/usr/bin/mail -s "Subject" someone@example.org < message.txt +``` The trick when using this in a shell script is creating and using the message.txt file correctly. Let's setup the basis first: -
    #!/bin/bash
    +```bash
    +#!/bin/bash
     SUBJECT="Automated Security Alert"
     TO="alarms@ariejan.net"
     MESSAGE="/tmp/message.txt"
     
    -/usr/bin/mail -s "$SUBJECT" "$TO" < $MESSAGE
    +/usr/bin/mail -s "$SUBJECT" "$TO" < $MESSAGE +``` All we need to do now is create the message. In this example we're going to notify the receiver that something happened at a certain time. We can use the append (>>) operator to add text to the message file. Afterwards, we must remove the temporary message file, of course. The complete script now becomes: -
    #!/bin/bash
    +```bash
    +#!/bin/bash
     SUBJECT="Automated Security Alert"
     TO="alarms@ariejan.net"
     MESSAGE="/tmp/message.txt"
    @@ -35,7 +40,8 @@ echo "Time: `date`" >> $MESSAGE
     
     /usr/bin/mail -s "$SUBJECT" "$TO" < $MESSAGE
     
    -rm $MESSAGE
    +rm $MESSAGE +``` The email will contain the a timestamp from when the mail was sent. diff --git a/content/posts/2007-06-12-bash-your-svn-and-trac-installation.md b/content/posts/2007-06-12-bash-your-svn-and-trac-installation.md index 2a622ca..d338c51 100644 --- a/content/posts/2007-06-12-bash-your-svn-and-trac-installation.md +++ b/content/posts/2007-06-12-bash-your-svn-and-trac-installation.md @@ -13,7 +13,8 @@ Creating a new SVN repository and Trac installation every time is quite boring a The result is the following BASH script. It takes one argument, the name of the project you want to create. E.g if you wanted to create a SVN repository and trac installation for "My Project" you would run the following command:
    $ ./create_dev_env my_project
    The script it self looks like this: -
    #!/bin/sh
    +```bash
    +#!/bin/sh
     echo == Creating Subversion and Trac installation for $1
     echo  = Creating SVN Repository...
     
    @@ -58,7 +59,8 @@ trac-admin /var/lib/trac/$1 permission add ariejan TRAC_ADMIN
     chown -R www-data:www-data /var/lib/trac/$1
     
     echo
    -echo == Done.
    +echo == Done. +``` First it creates the SVN directory in /var/lib/svn/my_project and creates repository and adds the trac post-commit hook for trac integration. Next, it creates the trac installation in /var/lib/trac/my_project and removes all the persmission the anonymous users has. (You may want to remove these lines for open source or public projects.) diff --git a/content/posts/2007-07-07-clear-dns-cache-on-your-router.md b/content/posts/2007-07-07-clear-dns-cache-on-your-router.md index 5da6434..5ed8359 100644 --- a/content/posts/2007-07-07-clear-dns-cache-on-your-router.md +++ b/content/posts/2007-07-07-clear-dns-cache-on-your-router.md @@ -17,11 +17,15 @@ The problem was, that my router was caching parts from the old and parts from th What you need to do is login to the admin panel of your router and enable SSH access (for your own network, not for the outside world!). You SSH to your route, probably as the 'root' or 'admin' user. In this case the IP is your routers IP address. -
    $ ssh -l admin 10.0.0.1
    +```bash +$ ssh -l admin 10.0.0.1 +``` Once you're in, you can issue the killall command to issue the 'HUP' signal to DNSMasq. This does not kill your DNSMasq, but tells it to flush the cache an reread its configuration, thus starting over with a clean slate. The 'HUP' signal has the number '1' so you can run the following command once logged in: -
    $ killall -1 dnsmasq
    +```bash +$ killall -1 dnsmasq +``` Now you can logout, and notice that your cache was indeed cleared. This method should work on every Linux based router that uses DNSMasq and support SSH logins. diff --git a/content/posts/2007-08-27-blueprintcss-rails-generator.md b/content/posts/2007-08-27-blueprintcss-rails-generator.md index 22abbb7..d0f8a03 100644 --- a/content/posts/2007-08-27-blueprintcss-rails-generator.md +++ b/content/posts/2007-08-27-blueprintcss-rails-generator.md @@ -13,9 +13,13 @@ I think that, if you're a web developer, you've seen the
    ./script/plugin install http://svn.ariejan.net/plugins/blueprint +```bash +./script/plugin install http://svn.ariejan.net/plugins/blueprint +``` And then generate as many BlueprintCSS layouts as you'd like. To create a layout for your posts controller, simply run the following command: -
    ./script/generate blueprint posts
    +```bash +./script/generate blueprint posts +``` This will create a posts.rhtml template in app/views/layouts, and add the proper CSS and images to your application. That's all! Note 1: You may remove a few lines of inline CSS from your layout to remove the supporting background images. diff --git a/content/posts/2007-09-01-content_for-yield-and-making-sure-something-gets-displayed.md b/content/posts/2007-09-01-content_for-yield-and-making-sure-something-gets-displayed.md index 46859de..0318c58 100644 --- a/content/posts/2007-09-01-content_for-yield-and-making-sure-something-gets-displayed.md +++ b/content/posts/2007-09-01-content_for-yield-and-making-sure-something-gets-displayed.md @@ -8,13 +8,17 @@ description = "Some nifty Rails trick using content_for and yield." You may have heard of a very nice Rails technique that used content_for and yield to stuff custom blocks of content into a layout. For example, in a view you could add a block like this: -
    <% content_for :sidebar do %>
    +```html
    +<% content_for :sidebar do %>
       This goes into the sidebar when viewing this action!
    -<% end %>
    +<% end %> +``` It doesn't matter where you put it in the view, because, as you may notice, the content within the content_for block is not shown in the view. The layout can pull the content for :sidebar and show it in a custom place, mostly the sidebar: -
    <%= yield :sidebar %>
    +```html +<%= yield :sidebar %> +``` Nice, you now don't have to hard-code the sidebar (and it's layout elements) in your views everytime. You can even move the sidebar to another place, without breaking any of your views. How great is that? @@ -22,7 +26,9 @@ What does break your views, however, is not assigning anything to :sidebar. If y So, how can you solve this? Quite easily, actually. What you want, probably, is display a default sidebar when no custom sidebar has been assigned. you can do this with the following line of über sexy Ruby code: -
    <%= (sidebar = yield :sidebar) ? sidebar : render(:partial => 'shared/sidebar') %>
    +```html +<%= (sidebar = yield :sidebar) ? sidebar : render(:partial => 'shared/sidebar') %> +``` First, you grab the :sidebar content and stuff it into a variable named, you guessed it, 'sidebar'. If this sidebar containts anything, show it. If it doesn't, you render a partial in the app/views/shared directory named _sidebar.rhtml. diff --git a/content/posts/2007-09-26-flash-not-clearing-after-a-request.md b/content/posts/2007-09-26-flash-not-clearing-after-a-request.md index 278b1fc..6449b70 100644 --- a/content/posts/2007-09-26-flash-not-clearing-after-a-request.md +++ b/content/posts/2007-09-26-flash-not-clearing-after-a-request.md @@ -13,6 +13,8 @@ Well, that's all nice, but what if you notice that your flash is not cleared, an The reason your flash is not cleared is that it will only be cleared if you render the current action, or if you redirect to another action. If you render another action or template, the flash will not be cleared out. Solving this is quite easy, actually. You only need to know how to do it. Use the following code in combination with render to show it only for the current action: -
    flash.now[:notice] = "Render, render! This will only show up once."
    +```ruby +flash.now[:notice] = "Render, render! This will only show up once." +``` That's all there is to it really. diff --git a/content/posts/2007-11-15-bash-it-number-of-messages-in-postfix-queue.md b/content/posts/2007-11-15-bash-it-number-of-messages-in-postfix-queue.md index 4c52f57..c0f316a 100644 --- a/content/posts/2007-11-15-bash-it-number-of-messages-in-postfix-queue.md +++ b/content/posts/2007-11-15-bash-it-number-of-messages-in-postfix-queue.md @@ -8,7 +8,9 @@ description = "How to get the number of messages in your Postfix queue." Got bash? Here's a nice snippet that will return the number of messages currently in the postfix queue. -
    postqueue -p | tail -n 1 | cut -d' ' -f5
    +```bash +postqueue -p | tail -n 1 | cut -d' ' -f5 +``` Feel free to post any updates or improvements. diff --git a/content/posts/2007-11-30-mysql-reset-the-auto-increment-value-of-a-table.md b/content/posts/2007-11-30-mysql-reset-the-auto-increment-value-of-a-table.md index a4e7bcb..9c82f4c 100644 --- a/content/posts/2007-11-30-mysql-reset-the-auto-increment-value-of-a-table.md +++ b/content/posts/2007-11-30-mysql-reset-the-auto-increment-value-of-a-table.md @@ -10,11 +10,15 @@ Sometimes it's necessary to set the starting point of a MySQL auto-increment val Normally, MySQL starts auto-incrementing at 1. But let's say you want to start at 10.000, because you want at least a five figure number. You can use the following query to set the MySQL auto-index: -
    ALTER TABLE some_table AUTO_INCREMENT=10000
    +```sql +ALTER TABLE some_table AUTO_INCREMENT=10000 +``` If you want to delete all records from your table and restart auto-index at 1, you might be tempted to run a DELETE query, followed by the above example, setting the auto increment value to 1. There is a shortcut, however: -
    TRUNCATE TABLE some_table
    +```sql +TRUNCATE TABLE some_table +``` This will basically reset the table, deleting all data and resetting the auto increment index. Do not that the truncate command is a hard-reset option. For instance, any triggers "ON DELETE" will not be fired when using truncate. diff --git a/content/posts/2007-12-06-rails-calculated-column-caching.md b/content/posts/2007-12-06-rails-calculated-column-caching.md index df9f003..814bd57 100644 --- a/content/posts/2007-12-06-rails-calculated-column-caching.md +++ b/content/posts/2007-12-06-rails-calculated-column-caching.md @@ -10,30 +10,38 @@ Sometimes you're working on a Rails project and you think: "hey! This should be I'm using the
    acts_as_rateable plugin which creates an extra database table containing all ratings. I also have a table with my objects. Using the plugin I'm now able to do the following: -
    obj = Object.find(:first)
    +```ruby
    +obj = Object.find(:first)
     obj.add_rating Rating.new(:rating => 4)
     obj.add_rating Rating.new(:rating => 5)
     obj.rating
    -=> 4.5
    +=> 4.5 +``` This works all perfectly, until you want to sort objects by rating. You could construct a huge SQL query to join the two tables, but that's not really efficient, especially when your database gets bigger. The solution is very easy and even more elegant. Use a cache! For this, you'll first have to add a new field to the objects table. Do this in a migration: -
    add_column :objects, :rating_cache, :float
    +```ruby +add_column :objects, :rating_cache, :float +``` Now, in the Object model, add the following method: -
    def rate_with(rating)
    +```ruby
    +def rate_with(rating)
       add_rating(rating)
       update_attribute('rating_cache', self.rating)
    -end
    +end +``` You'll need to change your controller from using #add_rating to #rate_with. The syntax is exactly the same. Now, when you add a rating, we also store the average rating in the rating_cache column. To get back to the sorting problem, you can now use the rating_cache column to sort Objects. -
    Object.find(:all, :order => 'rating_cache DESC')
    +```ruby +Object.find(:all, :order => 'rating_cache DESC') +``` Of course, you can use this trick on all sorts of relations. Have fun with it. diff --git a/content/posts/2007-12-31-write-a-dvd-video-from-the-linux-console.md b/content/posts/2007-12-31-write-a-dvd-video-from-the-linux-console.md index 33dbef3..87c48bf 100644 --- a/content/posts/2007-12-31-write-a-dvd-video-from-the-linux-console.md +++ b/content/posts/2007-12-31-write-a-dvd-video-from-the-linux-console.md @@ -12,25 +12,33 @@ I know, there are tons of fancy apps (with a decent GUI) that allow you to creat All you really need to burn a DVD-Video is one packages: dvd+rw-tools. If you're on Debian or Ubuntu, just run this: -
    apt-get install dvd+rw-tools
    +```bash +apt-get install dvd+rw-tools +``` So, I have this VIDEO_TS folder and a blank DVD in my DVD driver (which is known to my system as /dev/sr0). To make a correct DVD, you'll also need an AUDIO_TS folder. It doesn't matter if it's empty, it should be there. I'm assuming you're all doing this as root. If not, just add 'sudo' in front of every command you perform -
    mkdir AUDIO_TS
    +```bash +mkdir AUDIO_TS +``` Next, we need to set the correct permissions on the VIDEO_TS, AUDIO_TS and the files contained in these directories. -
    chown -R root:root VIDEO_TS AUDIO_TS
    +```bash
    +chown -R root:root VIDEO_TS AUDIO_TS
     chmod 500 VIDEO_TS AUDIO_TS
    -chmod 400 VIDEO_TS/*
    +chmod 400 VIDEO_TS/* +``` Well, you already have all your files prepped, and you're good to go. The following command will burn you a nice video DVD. Make sure a blank DVD is inserted into your drive. As I said before, my drive is located at /dev/sr0. You system is probably different. Check your boot log (dmesg) for messages of a dvd driver. -
    growisofs -dvd-compat -Z /dev/sr0 -dvd-video .
    +```bash +growisofs -dvd-compat -Z /dev/sr0 -dvd-video . +``` It's very important not to forget the tailing dot, it tells growisofs that you want to use the current directory as the source for your DVD. Depending on the speed of your burner, you'll have a new DVD to watch in a few minutes. Enjoy! And a happy 2008! diff --git a/content/posts/2008-04-09-enabling-trac-email-notifications.md b/content/posts/2008-04-09-enabling-trac-email-notifications.md index 7604f0b..a3c112c 100644 --- a/content/posts/2008-04-09-enabling-trac-email-notifications.md +++ b/content/posts/2008-04-09-enabling-trac-email-notifications.md @@ -11,7 +11,8 @@ Now, email notification are nothing exotic. You don't need any plugins, just an In your trac directory open up conf/trac.ini and look for the [notification] header. Make sure you have at least the following settings. Of course, make sure you enter valid values for your situation. -
    always_notify_owner = true
    +```text
    +always_notify_owner = true
     always_notify_reporter = true
     always_notify_updater = true
     smtp_always_cc = trac-updates@mailinglist # Optional if you want to archive outgoing emails
    @@ -22,7 +23,8 @@ smtp_replyto = noreply@ariejan.net
     smtp_user =
     smtp_password =
     smtp_server = localhost
    -smtp_port = 25
    +smtp_port = 25 +``` There are a few more options like 'ignore_domains' if you don't want to send emails to certain domains. diff --git a/content/posts/2008-04-10-debian-etch-rmagick-loaderror.md b/content/posts/2008-04-10-debian-etch-rmagick-loaderror.md index 76c57d9..78c44d5 100644 --- a/content/posts/2008-04-10-debian-etch-rmagick-loaderror.md +++ b/content/posts/2008-04-10-debian-etch-rmagick-loaderror.md @@ -7,7 +7,9 @@ slug = "debian-etch-rmagick-loaderror" If you're on Debian Etch, you may encounter the following error -
    libMagickWand.so.1: cannot open shared object file: No such file or directory - /usr/lib/ruby/gems/1.8/gems/rmagick-2.3.0/lib/RMagick2.so
    +```text +libMagickWand.so.1: cannot open shared object file: No such file or directory - /usr/lib/ruby/gems/1.8/gems/rmagick-2.3.0/lib/RMagick2.so +``` This basically means that the libMagickWand.so.1 file cannot be found. However, it is available on your system. All you need to do to fix it, is tell your box to look in the right place for the file. @@ -15,11 +17,15 @@ To fix this issue once and for all, open up /etc/ld.so.conf.d/whatever_file_is_h In this file, add the following line at the bottom -
    /usr/local/lib
    +```text +/usr/local/lib +``` Save the file and next run the 'ldconfig' command. This will reread the configuration file you just edited. Now, restart your Rails app and you'll notice the error is gone and all is good again. -
    ldconfig
    +```sh +ldconfig +``` This change will be kept after you reboot, so you won't encounter this error any time soon again. diff --git a/content/posts/2008-04-15-permanently-redirect-wordpress-pages.md b/content/posts/2008-04-15-permanently-redirect-wordpress-pages.md index 936dc46..f493079 100644 --- a/content/posts/2008-04-15-permanently-redirect-wordpress-pages.md +++ b/content/posts/2008-04-15-permanently-redirect-wordpress-pages.md @@ -11,7 +11,8 @@ I'm running WordPress with Apache2, so it shouldn't be too hard redirect those o Here is the default .htaccess file generated by WordPress: -
    # BEGIN WordPress
    +```text
    +# BEGIN WordPress
     
     RewriteEngine On
     RewriteBase /
    @@ -20,13 +21,15 @@ RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule . /index.php [L]
     
     
    -# END WordPress
    +# END WordPress +``` As I said, it's generated by WordPress. It would be very unwise to edit this, because our changes might get lost in the future. The solution is simple. Add another block above the generated one that does permanent redirects. In this example I rewrite pages/svnsheet to http://ariejan.net/svncheatsheet. -
    
    +```text
    +
     RewriteEngine On
     RewriteBase /
     RewriteCond %{REQUEST_FILENAME} !-f
    @@ -43,7 +46,8 @@ RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule . /index.php [L]
     
     
    -# END WordPress
    +# END WordPress +``` FYI, the R=301 means the browser (or search bot) receives a "Moved Permanently" message. L means this is the last rewrite rule to read. diff --git a/content/posts/2008-05-04-how-to-compile-packages-on-debianubuntu-by-hand.md b/content/posts/2008-05-04-how-to-compile-packages-on-debianubuntu-by-hand.md index ac8d2af..913e29d 100644 --- a/content/posts/2008-05-04-how-to-compile-packages-on-debianubuntu-by-hand.md +++ b/content/posts/2008-05-04-how-to-compile-packages-on-debianubuntu-by-hand.md @@ -11,13 +11,17 @@ Let's say we want to recompile mod_python for apache 2 to hook in to python 2.5, First, get every thing installed you may need to build the libapache2-mod-python package. -
    $ apt-get build-dep libapache2-mod-python
    +```sh +$ apt-get build-dep libapache2-mod-python +``` Okay, next let's grab the source for the package. The source will be unpacked to your current working directory, so it may be a good idea to create a seperate directory for this. -
    $ mkdir src
    +```sh
    +$ mkdir src
     $ cd src
    -$ apt-get source libapache2-mod-python
    +$ apt-get source libapache2-mod-python +``` In the case of this example, you don't need to do anything special to get python 2.5 linked. Just install the python2.5 and python2.5-dev packages. @@ -25,14 +29,18 @@ In the case of this example, you don't need to do anything special to get python Okay, now go to the source directory and build the package. This is the tricky command here: -
    $ cd libapache2-mod-python
    -$ dpkg-buildpackage -rfakeroot -b
    +```sh +$ cd libapache2-mod-python +$ dpkg-buildpackage -rfakeroot -b +``` This will build the package. You will get some warnings and errors about missing GPG keys. This is okay. You are not the package maintainer, so your packages should not be marked as 'original'. You're now ready to install your compiled package. -
    dpkg -i ../libapache2-mod-python-3.3.1-3-i386.deb
    +```sh +dpkg -i ../libapache2-mod-python-3.3.1-3-i386.deb +``` That's all! You compiled and installed a package from source! diff --git a/content/posts/2008-05-06-the-migration-that-cannot-be-undone-irreversible-migration.md b/content/posts/2008-05-06-the-migration-that-cannot-be-undone-irreversible-migration.md index 87a4fc2..0ccdd0b 100644 --- a/content/posts/2008-05-06-the-migration-that-cannot-be-undone-irreversible-migration.md +++ b/content/posts/2008-05-06-the-migration-that-cannot-be-undone-irreversible-migration.md @@ -9,26 +9,32 @@ Migrations have up and down methods, as we all know. But in some cases, your up For example: -
    def self.up
    +```ruby
    +def self.up
       # Change the zipcode from the current :integer to a :string type.
       change_column :address, :zipcode, :string
    -end
    +end +``` Now, converting integers to strings will always work. But, you feel it coming, converting a string into an integer will not always be possible. In other words, we can't reverse this migration. That's why we should raise ActiveRecord::IrreversibleMigration in the down method. -
    def self.down
    +```ruby
    +def self.down
       raise ActiveRecord::IrreversibleMigration
    -end
    +end +``` Now, if you run your migration (upwards), you'll see it being applied like it shoud. However, if you try to go back, you'll see rake aborting with ActiveRecord::IrreversibleMigration. -
    $ rake db:migrate VERSION=4
    +```sh
    +$ rake db:migrate VERSION=4
     -- Database is migrated
     $ rake db:migrate VERSION=3
     -- Rake aborted!
    --- ActiveRecord::IrreversibleMigration
    +-- ActiveRecord::IrreversibleMigration +``` So, if you have things you can't undo, raise ActiveRecord::IrreversibleMigration in your migration's down method. diff --git a/content/posts/2008-08-14-useless-ruby-gems-for-your-pleasure.md b/content/posts/2008-08-14-useless-ruby-gems-for-your-pleasure.md index 2b4c7d1..982c1e9 100644 --- a/content/posts/2008-08-14-useless-ruby-gems-for-your-pleasure.md +++ b/content/posts/2008-08-14-useless-ruby-gems-for-your-pleasure.md @@ -15,7 +15,8 @@ The ActsAsGold Gem allows you to extend your ActiveRecord model with this money Let me give you a small tour. -
    class Player < ActiveRecord::Base
    +```ruby
    +class Player < ActiveRecord::Base
       acts_as_gold :column => :money
     end
     
    @@ -26,7 +27,8 @@ end
     
     # You can also easily earn or spend money
     @player.earn(10.gold + 75.silver)
    -@player.spend(1.gold + 10.silver + 95.copper)
    +@player.spend(1.gold + 10.silver + 95.copper) +``` Read more about the Gem, or install the gem right now: @@ -46,12 +48,14 @@ WA (WarcraftArmory) allows you to easily retrieve character information from the It works for both EU and US warcraft servers. -
    require 'warcraft_armory'
    +```ruby
    +require 'warcraft_armory'
     
     character = WarcraftArmory.find(:eu, 'Aszune', 'Nosius')
     
     character.race => "Human"
    -character.level => 15
    +character.level => 15 +``` Again, simply install the plugin and use it like any other gem or read the README first. diff --git a/content/posts/2008-11-27-export-csv-directly-from-mysql.md b/content/posts/2008-11-27-export-csv-directly-from-mysql.md index 20dbc00..8713009 100644 --- a/content/posts/2008-11-27-export-csv-directly-from-mysql.md +++ b/content/posts/2008-11-27-export-csv-directly-from-mysql.md @@ -9,11 +9,13 @@ How ofter were you asked by a client for a CSV (or excel) file with data from th Let's say you want to export the id, name and email fields from your users table to a CSV file. Here is your code: -
    SELECT id, name, email INTO OUTFILE '/tmp/result.csv'
    +```sql
    +SELECT id, name, email INTO OUTFILE '/tmp/result.csv'
     FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
     ESCAPED BY ‘\\’
     LINES TERMINATED BY '\n'
    -FROM users WHERE 1
    +FROM users WHERE 1 +``` Well, if you know MySQL, you'll know how to customize this query to spit out the the right data. Your csv file can be found in /tmp/result.csv diff --git a/content/posts/2009-01-04-how-to-start-a-rails-edge-app-the-easy-way.md b/content/posts/2009-01-04-how-to-start-a-rails-edge-app-the-easy-way.md index 6137ddd..9e7ae59 100644 --- a/content/posts/2009-01-04-how-to-start-a-rails-edge-app-the-easy-way.md +++ b/content/posts/2009-01-04-how-to-start-a-rails-edge-app-the-easy-way.md @@ -11,14 +11,16 @@ Most likely you can't wait to get started with these new features, especially wh Let's go... -
    +```sh
    +
     mkdir -p myapp/vendor
     cd myapp
     git init
     git submodule add git://github.com/rails/rails.git vendor/rails
     git commit -m "Frozen Rails Edge as submodule"
     ruby vendor/rails/railties/bin/rails .
    -# Add generated files to git, and code on...
    +# Add generated files to git, and code on... +``` First, you create a new directory for your app, including the vendor directory. Easy, right? @@ -38,23 +40,29 @@ That's all, you now have a new Rails Edge application. Try ruby script/ser At some point you'll push your myapp project to a remote git server. When you clone a fresh copy, you'll have to initialize the git submodules. This is quite easy: -
    +```sh
    +
     git submodule init
    -git submodule update
    +git submodule update +``` Updating Rails Edge As I said earlier, Git will not keep your submodules up-to-date for you, but will stick with the revision you added. To keep track of Rails Edge's progress, you'll need to update the submodule. This is done like this: -
    cd myapp/vendor/rails
    +```sh
    +cd myapp/vendor/rails
     git remote update
    -git merge origin/master
    +git merge origin/master +``` This will update your Rails Edge code. Make a commit, stating you updated the code! After updating Rails Edge, you may want to update your rails application (like javascript files, config files etc). -
    rake rails:update
    +```sh +rake rails:update +``` Good luck! And happy coding! diff --git a/content/posts/2009-02-07-warcraft-armory-010-released.md b/content/posts/2009-02-07-warcraft-armory-010-released.md index 062849e..7a947b9 100644 --- a/content/posts/2009-02-07-warcraft-armory-010-released.md +++ b/content/posts/2009-02-07-warcraft-armory-010-released.md @@ -13,12 +13,16 @@ This is an early version that allows the retrieval of character information from Feel free to check-out the code, read the docs or just install the gem: -
    sudo gem install warcraft-armory
    +```sh +sudo gem install warcraft-armory +``` -
    require 'warcraft-armory'
    +```ruby
    +require 'warcraft-armory'
     adries = WarcraftArmory::Character.find(:eu, :aszune, :adries)
     adries.description
    -# => "Level 48 Human Warrior"
    +# => "Level 48 Human Warrior" +``` It's my first gem, so useful comments are appreciated! Keep an eye out for updates! diff --git a/content/posts/2009-04-19-how-to-create-a-dsa-openssl-certificate.md b/content/posts/2009-04-19-how-to-create-a-dsa-openssl-certificate.md index 6b169dd..d40455a 100644 --- a/content/posts/2009-04-19-how-to-create-a-dsa-openssl-certificate.md +++ b/content/posts/2009-04-19-how-to-create-a-dsa-openssl-certificate.md @@ -7,11 +7,13 @@ slug = "how-to-create-a-dsa-openssl-certificate" I just needed an OpenSSL DSA public key. This is not really difficult, you just need to know the right commands. On my Mac I ran the following commands to obtain both private dsa_priv.pem and public dsa_pub.pem keys. -
    +```sh
    +
     openssl dsaparam 1024 < /dev/random > dsaparam.pem
     openssl gendsa dsaparam.pem -out dsa_priv.pem
     openssl dsa -in dsa_priv.pem -pubout -out dsa_pub.pem
    -
    + +``` Needless to say, keep your private key in secure location and make sure you have a backup of it! diff --git a/content/posts/2009-04-23-compacting-a-sqlite3-db-file.md b/content/posts/2009-04-23-compacting-a-sqlite3-db-file.md index 0daadbc..7abd53b 100644 --- a/content/posts/2009-04-23-compacting-a-sqlite3-db-file.md +++ b/content/posts/2009-04-23-compacting-a-sqlite3-db-file.md @@ -11,10 +11,12 @@ This can be annoying, so you'll need to clean up old indices and other cruft tha The solution is über-easy: -
    $ sqlite3 mystuff.db
    +```sh
    +$ sqlite3 mystuff.db
     SQLite version 3.6.6.2
     sqlite> VACUUM;
    -sqlite> .quit
    +sqlite> .quit +``` Note that you need to use capitals here. This will clean your db file and reduce its file size dramatically (depending on the amount of cruft you have, of course). diff --git a/content/posts/2009-06-05-install-hpricot-on-ubuntu.md b/content/posts/2009-06-05-install-hpricot-on-ubuntu.md index 687c841..d4db651 100644 --- a/content/posts/2009-06-05-install-hpricot-on-ubuntu.md +++ b/content/posts/2009-06-05-install-hpricot-on-ubuntu.md @@ -9,17 +9,21 @@ It's quite easy. Make sure you have RubyGems and Ruby installed first, of course The problem: -
    $ sudo gem install hpricot
    +```sh
    +$ sudo gem install hpricot
     Building native extensions.  This could take a while...
     ERROR:  Error installing hpricot:
     	ERROR: Failed to build gem native extension.
     
     /usr/bin/ruby1.8 extconf.rb
     extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
    -	from extconf.rb:1
    + from extconf.rb:1 +``` The solution: -
    sudo apt-get install ruby1.8-dev build-essential
    -sudo gem install hpricot
    +```sh +sudo apt-get install ruby1.8-dev build-essential +sudo gem install hpricot +``` diff --git a/content/posts/2009-06-07-has_one-find-all-that-have-no-associated-object.md b/content/posts/2009-06-07-has_one-find-all-that-have-no-associated-object.md index 2e87899..ed08d21 100644 --- a/content/posts/2009-06-07-has_one-find-all-that-have-no-associated-object.md +++ b/content/posts/2009-06-07-has_one-find-all-that-have-no-associated-object.md @@ -7,29 +7,35 @@ slug = "has_one-find-all-that-have-no-associated-object" Let me pose a typical Rails situation: -
    class Person < ActiveRecord::Base
    +```ruby
    +class Person < ActiveRecord::Base
       has_one :fancy_hat
     end
     
     class FancyHat < ActiveRecord::Base
       belongs_to :person
    -end
    +end +``` Now, how can you get all the people that don't have a fancy hat? -
    class Person < ActiveRecord::Base
    +```ruby
    +class Person < ActiveRecord::Base
       has_one :fancy_hat
     
       named_scope :hatless, :joins => 'LEFT JOIN fancy_hats ON fancy_hats.person_id = people.id', :conditions => 'fancy_hats.person_id IS NULL'
    -end
    +end +``` Now you can find all the hatless people you want. FYI: Finding fancy hats that have no one to wear them is a lot easier, because the foreign key is stored in the fancy_hats table. -
    class FancyHat < ActiveRecord::Base
    +```ruby
    +class FancyHat < ActiveRecord::Base
       belongs_to :person
     
       named_scope :wearerless, :conditions => { :person_id => nil }
    -end
    +end +``` diff --git a/content/posts/2009-06-07-imdb-0-3-0-now-including-console-utility-query-imdb-from-your-console.md b/content/posts/2009-06-07-imdb-0-3-0-now-including-console-utility-query-imdb-from-your-console.md index 10aa122..8975fba 100644 --- a/content/posts/2009-06-07-imdb-0-3-0-now-including-console-utility-query-imdb-from-your-console.md +++ b/content/posts/2009-06-07-imdb-0-3-0-now-including-console-utility-query-imdb-from-your-console.md @@ -13,7 +13,8 @@ Let me show you: Search IMDB -
    $ imdb Star Trek
    +```sh
    +$ imdb Star Trek
     >> Searching for "Star Trek"
      > 0060028 | Star Trek (1966) (TV series)
      > 0796366 | Star Trek (2009)
    @@ -24,7 +25,8 @@ Let me show you:
      > 0084726 | Star Trek: The Wrath of Khan (1982)
      > 0092007 | Star Trek IV: The Voyage Home (1986)
      > 0079945 | Star Trek: The Motion Picture (1979)
    - > 0244365 | Enterprise (2001) (TV series)
    + > 0244365 | Enterprise (2001) (TV series) +``` For clarity, only the ten first search results are shown. I'm thinking of including an option to set the number of returned titles. Let me know what you think about that. @@ -32,7 +34,8 @@ For clarity, only the ten first search results are shown. I'm thinking of includ So, let's pick a movie we want to get details about. -
    $ imdb 0796366
    +```sh
    +$ imdb 0796366
     >> Fetching movie 0796366
     
     Star Trek (2009)
    @@ -43,14 +46,17 @@ Directed by: J.J. Abrams
     Cast: Chris Pine, Zachary Quinto, Leonard Nimoy, Eric Bana, Bruce Greenwood
     Genre: Action, Adventure, Sci-Fi
     A chronicle of the early days of James T. Kirk and his fellow USS Enterprise crew members. |
    -========================================================================
    +======================================================================== +``` Combine with GNU commands Or, as mentioned earlier, you can combine it with other console commands. So to get the rating of a movie, do this: -
    $ imdb 0796366 | grep "^Rating" | cut -d" " -f 2
    -8.4
    +```sh +$ imdb 0796366 | grep "^Rating" | cut -d" " -f 2 +8.4 +``` Installation, source and issues @@ -58,7 +64,9 @@ I'm still working on perfecting the console output, so if you have any tips, ple You can get this as a Ruby Gem with -
    sudo gem install imdb
    +```sh +sudo gem install imdb +``` The source is also available at http://github.com/ariejan/imdb. diff --git a/content/posts/2009-06-08-best-practice-the-git-development-cycle.md b/content/posts/2009-06-08-best-practice-the-git-development-cycle.md index 3af36ba..827e224 100644 --- a/content/posts/2009-06-08-best-practice-the-git-development-cycle.md +++ b/content/posts/2009-06-08-best-practice-the-git-development-cycle.md @@ -13,31 +13,41 @@ But, how do you use Git effectively for development on a daily basis? Let me exp With git you normally have a 'master' branch. This is also the branch you use to sync your code with other repositories. That is also the reason why you should never code in the 'master' branch. Always create a new branch and develop your code there. -
    $ git checkout -b new_feature
    -# add, commit, repeat
    +```sh +$ git checkout -b new_feature +# add, commit, repeat +``` Rebase Now, while you are working hard on your new feature, other developers complete theirs and push their changes to the remote master branch. When you're done with your project, you need to first get the most recent version of the project's code. -
    $ git checkout master
    -$ git pull
    +```sh +$ git checkout master +$ git pull +``` Now, to make merging your new feature easy, you should rebase your new_feature_branch. What this does is add all the commits you just pulled in to your new_feature branch. Any conflicts that arise will happen in your new_feature branch as well, leaving your master branch clean and in order. -
    $ git checkout new_feature
    -$ git rebase master
    +```sh +$ git checkout new_feature +$ git rebase master +``` Merge Now, you have resolved all (if any) conflicts with the current code and your new_feature, you can now merge your new_feature into the project's master branch without any problems. -
    $ git checkout master
    -$ git merge new_feature
    +```sh +$ git checkout master +$ git merge new_feature +``` This will create a new commit, containing your new_feature. Now is also the time to push your changes to the remote repository. -
    $ git push origin master
    +```sh +$ git push origin master +``` What's next? diff --git a/content/posts/2009-06-14-imdb-ruby-gem-0-4-0-now-available-at-rubyforge.md b/content/posts/2009-06-14-imdb-ruby-gem-0-4-0-now-available-at-rubyforge.md index 2caddad..1951502 100644 --- a/content/posts/2009-06-14-imdb-ruby-gem-0-4-0-now-available-at-rubyforge.md +++ b/content/posts/2009-06-14-imdb-ruby-gem-0-4-0-now-available-at-rubyforge.md @@ -18,8 +18,12 @@ I just released version 0.4.0 of the IMDB Ruby Gem into the wild. There are only Installation or upgrade -
    $ sudo gem install imdb
    -
    $ sudo gem update imdb
    +```sh +$ sudo gem install imdb +``` +```sh +$ sudo gem update imdb +``` Issues, source or contributions diff --git a/content/posts/2009-09-01-jinput-mac-os-x-64-bit-natives.md b/content/posts/2009-09-01-jinput-mac-os-x-64-bit-natives.md index 5e6945c..df5f3f9 100644 --- a/content/posts/2009-09-01-jinput-mac-os-x-64-bit-natives.md +++ b/content/posts/2009-09-01-jinput-mac-os-x-64-bit-natives.md @@ -9,24 +9,28 @@ Yesterday I ran into a little problem running +```none + $ file libjinput-osx.jnilib libjinput-osx.jnilib: Mach-O universal binary with 2 architectures libjinput-osx.jnilib (for architecture ppc): Mach-O dynamically linked shared library ppc libjinput-osx.jnilib (for architecture i386): Mach-O dynamically linked shared library i386 - + +``` Thus, the default JInput natives provided by LWJGL, and subsequently by projects like Slick 2D and jME are of no use on a system running Java 6 64 bit. Also games and other apps based on those libraries won't run on Java 6 64 bit! To solve this, I recompiled the JInput natives from CVS with 64 bit support: -
    +```none
    +
     $ file libjinput-osx.jnilib
     libjinput-osx.jnilib: Mach-O universal binary with 3 architectures
     libjinput-osx.jnilib (for architecture ppc):	Mach-O dynamically linked shared library ppc
     libjinput-osx.jnilib (for architecture i386):	Mach-O dynamically linked shared library i386
     libjinput-osx.jnilib (for architecture x86_64):	Mach-O 64-bit dynamically linked shared library x86_64
    -
    + +``` I packaged the Mac OS X native (libjinput-osx.jnilib) and the resulting jinput.jar and jinput-test.jar up and you can download them here: