Page 25 of 30

Rails caching notes

General Notes

Very nice tutorial for rails 2.1 caching.

API references: Fragments, Sweepers, the Store

Post how to move the page cache in a folder with some server examples

Observing Controllers with Sweepers

Here is described how you can use the Sweepers to observe controller actions. I totaly agree that the documenation is very bad on the sweepers and it is like a rule book of MTG than usefull rdoc.

Here is what I have found on the naming of the callbacks.

Checking the source code in sweeping.rb shows that the callbacks that are used for the controller are constructed in this way:

controller_callback_method_name = "#{timing}_#{controller.controller_name.underscore}"
action_callback_method_name = "#{controller_callback_method_name}_#{controller.action_name}"

This means that the method which will be called in the sweeper will be named

  • after/before_user – for the controller UserController
  • after/before_user_login – for the action login in the controller UserController

Here is an example.

class Dagens::UserController < Dagens::BaseController
  cache_sweeper DagensAgentSweeper, :only => [:do_login, :do_delete_account, :do_logout]
  def do_login
  end
  ....
end

class DagensAgentSweeper < ActionController::Caching::Sweeper
  observe DagensAgent

  def after_user_do_login
    puts "after do login \n \n \n \n \n \n \n "
    expire_cache_for(@logged_user)
  end
end

Skipping callbacks from an observer

I know that it is not good idea, but some times there is no time/way to do skip it. I have found a plugin and this post here. I have choose to use the second one in my project. Here is the example

class DagensAgentSweeper < ActionController::Caching::Sweeper
  observe DagensAgent

  def self.skip_callback(callback, &block)
    method = instance_method(callback)
    remove_method(callback) if respond_to?(callback)
    define_method(callback) { true }
    result = yield
    remove_method(callback)
    define_method(callback, method)
    result
  end
........
end

And later in the controller….model…

      DagensAgentSweeper.skip_callback(:after_update) do
        @agent.shown_times += 1
        @agent.save
      end

timed_fragment_cache

Some patches on the timed_fragment_cache plugin.

Note how Jolyon Says suggest to expire the cache when you have time zone : when_fragment_expired ‘tags_home_page’, Time.now + 10.minutes do

I have notice that timed_fragment_cache (or the patch) have a problem with expiring the cache from the controller. In the documenation it is stated that it is ok to expire the cache only in the controller with

when_fragment_expired  "_last_update",  Time.now + 1.minutes  do

and there is no need to expire it in the view, but you MUST expire it in the view.

cache "_last_update" do

must be

cache "_last_update", Time.now + 1.minutes  do



		
	

Bash tips and tricks

Nice quick bash book

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html (loops)

How to check if files containt “this” and “that”

grep -i 'for nut in self._foundNuts:' `grep -ril "loop(1):" *`

Display timestamp

date -d @1231351762

Microsoft has locked Windows Vista Home to only one language

Great!

One of my friends has bouth a new laptop from USA and I want to change the base language of his operating system to Bulgarian. The Bulgarian language is fully support by Microsoft. My surprise was big when I got the “Only language please…” from the Regional Settings language switcher pane.

I want to use one language but I don’t want English I want Bulgarian. Why I cant switch it?

The solution come from Vistalizator. This software has fixed all my troubles. Now I have two languages on my Windows Vista Home (who said that Vista Home dosn’t support two languages :) ?

Someone has made already forum/topic where you can express what you feel working with Microsoft products.

Magic the Gathering how to build or print deck

Here are my resources.

Magic The Gathering Rule Book

This is THE program for building decks. It is java based so you can use it on your favourite OS (I hope).

You should follow this forum topic or this blog post here. It is not so hard

  • Download and extract a couple of zip files
  • Download the art via ready packages also with the java application from this link
  • Download some decks
  • Change the path to the art directory in the config.txt file
  • Start some of the .bat files from the directory you have extracted all the files
  • Drag & Drop (you can drop entire directory with decks if you want to generate more decks at once)

My first game was with decks from here and here

Post & Get requests

Post using curl

curl  -A ‘Mozilla/4.0’  -F “vote=5&btnSubmit.x=34&btnSubmit.y=14&btnSubmit=%D0%A0%D0%B5%D0%B3%D0%B8%D1%81%D1%82%D1%80%D0%B8%D1%80%D0%B0%D0%B9” http://www.germanos-konkurs.com/

Nginx with Rails

downloaded from here
documentation here
If you want to try different solution check it haproxy Continue reading

Not happy with WordPress

Dear WordPress (and authors),

I am not happy that you are releasing versions every month. Continue reading

Semantic web

http://www.powerset.com/

http://www.trueknowledge.com/

http://www.spock.com/

good blog (bg)

lecutre in bg

Forum based search engine http://www.omgili.com/

SEO tools

Check the links for a page

http://validator.w3.org/checklink?uri=http%3A%2F%2Fwww.cenite.com&hide_type=all&depth=&check=Check

lowercase the filenames

#!/bin/sh
# lowerit
# convert all file names in the current directory to lower case
# only operates on plain files--does not change the name of directories
# will ask for verification before overwriting an existing file
# http://www.linuxjournal.com/content/convert-filenames-lowercase  Continue reading

© 2025 Gudasoft

Theme by Anders NorénUp ↑