Skip to content
accelerando

Tag Archives: Tipps

Linux: Persistent wake-on-lan

03-Mar-10

Just a quick reminder for myself: You need to enable wake-on-lan on the nic in most linux distributions via ethtool.

If your nic supports WOL, it probably needs to be enabled in your computers BIOS first.

Most WOL tools use the “MagicPacket(tm)” method, so the right command to enable it on the nic “eth0″ would be

ethtool -s eth0 wol g

This is not a persistent setting and it is gone after a reboot. Most tips around recommend creating a runlevel script for executing this command after boot or before shutdown.

I’ve added the command as a hook in my network scripts:

auto eth0
iface eth0 inet dhcp
        pre-down ethtool -s eth0 wol g

You can also use post-up. I like this method because i tend to forget about my runlevel scripts and so i keep the network stuff in one place ;)

If you are a debian user, you maybe need to stop your system from turning off the nic on HALT. To do so, add

NETDOWN=no

to “/etc/default/halt”.

How to change the image assets path in Rails

01-Nov-09

I found no other way to change the path of “images” in a Rails application than monkey patching the AssetTagHelper like so:

module ActionView
  module Helpers #:nodoc:
    module AssetTagHelper
      def image_path(source)
        compute_public_path(source, 'static_images')
      end
      alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
    end
  end
end

SVN: Revert to previous version

09-Sep-09

Just a quick reminder:

To revert a complete working copy or a single file use:

svn merge -rHEAD:PREV .
# or
svn merge -rHEAD:PREV path/to/file
svn commit -m "reverted"

Phusion Passenger and memcache-client revisited

23-Mar-09

The last Passenger update brought some good explanation off the problems regarding Passenger and memcache-client (see here).

Smart spawning of Passenger processes creates shared file descriptors. As the connections to memcached are sockets they are shared as well so data on them gets corrupted which is explained very nicely in the Passenger documentation: Example 1: Memcached connection sharing (harmful).

The solution presented there works like a charm. The reestablish_connection_to_memcached line is actually not more than CACHE.reset where CACHE is the reference to the memcache connection.

After that change, spawning methods smart-lv2 and smart will work in connection with environment.rb configured memcache connections.

Edit: As requested in the comments, a little example:

memcache_options = {
  :c_threshold => 10000,
  :compression => true,
  :debug => false,
  :namespace => 'some_ns',
  :readonly => false,
  :urlencode => false
}
 
CACHE = MemCache.new memcache_options
CACHE.servers = '127.0.0.1:11211'
begin
   PhusionPassenger.on_event(:starting_worker_process) do |forked|
     if forked
       # We're in smart spawning mode, so...
       # Close duplicated memcached connections - they will open themselves
       CACHE.reset
     end
   end
# In case you're not running under Passenger (i.e. devmode with mongrel)
rescue NameError => error
end

In this case, CACHE is the global constant that i use to access my memcache-client.

I guess you’ll need to do the same with the global Rails.cache object, but i’m not sure. Anyway, the above solution works for me.

Phusion Passenger and memcached / memcache-client

23-Feb-09

I recently switch from a mod_proxy / thin setup to Phusion Passenger and my application started to do the funniest things and the production.log was full with errors related to memcached.

It seems, that passengers spawn method “smart” isn’t compatible with memcached. Within seconds on a lightly loaded server the cache gets corrupted big time.

I got better results with a newer memcache client (the ruby gem actually), but for that i need to remove the client from the rails vendor lib. Furthermore, under higher load there still where errors.

Only solution is to set the spawn method to conservative like so

RailsSpawnMethod conservative

Problem seems to be known in the Phusion and Rails teams.

Ruby: Formatting time values as RFC3339

01-Nov-08

Times in RSS Feeds and the like are formatted as RFC3339 most of the time. You can save yourself from strftime by using

Time.now.xmlschema

Turn off RoRs automatic timezone conversion for columns

01-Nov-08

I couldn’t find this in the documents, but Geoff Buesing showed me the hooks to turn off Ruby On Rails’ automatic timezone conversions for some columns of a model or a complete model:

# Turn it off for just some columns
class Picture < ActiveRecord::Base
 def self.skip_time_zone_conversion_for_attributes
   [:created_at, :published_at]
 end
end
 
# Turin it off for the whole model
class Picture < ActiveRecord::Base
 def self.time_zone_aware_attributes
   false
 end
end

Thanks a lot!

Sony Ericsson C702: Show received and send traffic

28-Jul-08

Once again, a quick reminder for myself: Howto display the internet traffic on your Sony Ericsson C702:

Menü, #, 4th Tab, 5

(On a german phone: “Einstellungen / Anrufe / Zeit und Kosten”)

I guess that works with other SEs like K800i and K850i.

I remember an old SE that i had which always displayed the traffic after ending an internet session, i wonder why they changed it.

Make XQuartz more usable

28-Jul-08

This post is an update to Make Gimp.app usable on a mac:

The “Click through” property on both Apples X11 and the X11 provided by XQuartz is not set. This leads to the fact, that you have to click on each X11 window twice: First activating it, 2nd pushing a button or whatever else. I hate this, i really do.

With Apples X11, open a terminal and enter:

defaults write com.apple.X11 wm_click_through -bool true

With XQuartz X11 enter:

defaults write org.x.X11 wm_click_through -bool true

This will help you with all X11 apps, like Gimp, Inkscape, Open Office and the likes.

Put your mac to rest via ssh

17-Jul-08

Sometimes my Macbook decides to wake up from his sleep (a.k.a hibernation). Most of the times i notice this at work when my emails disappear from my imap inbox as Mail.app applies his rules.

As i do not have Apple Remote Desktop or any other VNC server enabled on my Macbook, i do have a problem.

I can vpn into my home and i can ssh into the Macbook, so i came up with the following solution:

Put the following three lines into a plain textfile, i.e. “sleep.txt” and save it somewhere:

tell application "Finder"
  sleep
end tell

Then, open Terminal.app, change to the directory you saved the file in and execute:

osascript sleep.txt

Your ssh connection will then timeout and the Mac sleeps.

Stupid me forgot that ssh can execute remote commands: From your workmachine execute

ssh my_home_computer 'osascript sleep.txt'

and you’re done. Thanks “tante” for reminding me :)

Alternatively, you can achieve similar with Mail.app itself, have a look at the solution here, but i like mine better.

Close
E-mail It