DaWanda - DevBlog

RSS

[sdepold] Sharing Rubymine preferences via Dropbox

Motivation

If you are using Rubymine (like ~50% of the DaWanda devs is), you might have got the idea of sharing your preferences with multiple computers. Because most of us are coding on Apple hardware, this description is for MacOSX, but will work similarly on linux as well.

The naive way

When thinking about sharing stuff on multiple devices, you will stumble across Dropbox. The first and obvious way is moving your preferences folder into it and symlinking it into the origin place:

mv ~/Library/Preferences/RubyMine31 ~/Dropbox/System/Preferences/
ln -s ~/Dropbox/System/Preferences/RubyMine31 ~/Library/Preferences/RubyMine31

When starting RubyMine for the next time, it will complain about a missing preferences folder and bootup some strange environment in which you can work almost normally but have no shortcuts etc. The very next thing I tried was symlink without the “-s” flag. This will fail due to MacOSX’ missing support of hardlinks for directories.

Solution

After googling for a while, I found this discussion on StackOverflow. It explains how to compile a binary for creating directory symlinks. So copy the following snippet and paste it into your favorite place for binaries and shell scripts (because I like sharing custom binaries via Dropbox it is ~/Dropbox/System/Bin/hlink.c for me).

#include <unistd.h>
#include <stdio.h>

int main(int argc, char* argv[]) {
  if (argc != 3) {
    fprintf(stderr,”Use: hlink <src_dir> <target_dir>\n”);
    return 1;
  }
  int ret = link(argv[1],argv[2]);
  if (ret != 0)
    perror(“link”);
  return ret;
}

Afterwards “cd” into that specific folder and do this:

cd ~/Dropbox/System/Bin
gcc hlink.c -o hlink

And finally:

mv ~/Library/Preferences/RubyMine31 ~/Dropbox/System/Preferences/
./hlink ~/Dropbox/System/Preferences/RubyMine31 ~/Library/Preferences/RubyMine31

When running RubyMine for the next time, everything should be just as before!

Have fun,
sdepold

[roman] Update mysql with homebrew

If you want to reuse your old files for databases, just edit my.cnf (defaults in homebrew to /usr/local/var/mysql/my.cnf), the important setting is datadir:

[mysqld]
datadir = /opt/local/var/db/mysql5
innodb_file_per_table
innodb_buffer_pool_size = 250M

default-character-set= utf8
default-collation = utf8_general_ci
default-storage-engine=InnoDB

Here I just reused my macport mysql files. It it advisible to move the folder and change the user/group to your homebrew user (most likely your user-account), otherwise there will be some clashes with macports…

Have fun!

[roman] imagemagick with homebrew (on Mac OSX 10.5)

If you encounter some problems while installing imagemagick with an error-message like this:

libpng12.0.0.0.dylib: No such file or directory

try symlinking following files:

sudo ln -s /usr/X11/lib/libpng12.0.35.0.dylib /usr/X11/lib/libpng12.0.0.0.dylib
sudo ln -s /usr/X11/lib/libpng.3.35.0.dylib /usr/X11/lib/libpng.3.0.0.dylib

That may help!

Happy coding!

[michael] pkill -f kill by pattern/name

 

This post is some kind of reminder for myself.
Sometimes you have to kill a lot of (Rails) Processes at the same time with the same Name/Pattern.
Copy&Paste Id’s is nothing you really want to do if there are 200 Processes running.
pkill is your freind and let’s you kill processes by Process Title pattern

deploy 13470 1 0 11:22 ? 00:01:13 Rails: /srv/… current
deploy 14334 1 0 11:34 ? 00:00:35 Rails: /srv/…current
deploy 16049 1 0 11:55 ? 00:00:42 Rails: /srv/…
deploy 16908 1 0 12:05 ? 00:00:06 Rails: /srv/…
deploy 20172 1 0 12:36 ? 00:00:35 Rails: /srv/…
deploy 20175 1 0 12:36 ? 00:00:55 Rails: /srv/..

pkill -f Rails: will kill all Rails: Processes with one single call ( -9 as param is working as well )

Happy Killing!

[michael] ActiveRecord without default scope

via Pragmatic life

This is a pretty hacky implementation of the feature we needed:
remove the default scope for some queries (e.g. update deleted records)

Code:

class ActiveRecord::Base
def self.without_default_scope(&block)
scope = scoped({})
defaults = scope.current_scoped_methods_when_defined

old = defaults[:find][:conditions]
defaults[:find][:conditions] = {}

begin
yield(scope)
ensure
defaults[:find][:conditions] = old
end
end
end

Usage

MyModel.without_default_scope{|s| s.update_all(:deleted_at => nil)}

There is an less hacky alternative, but it did not work for us (AR 2.3.2)

[mark] Ruby 1.8.7 issues with comments in erb-tags

Ruby 1.8.7 does not complain about <% end #test %> but does not close tags correctly.

Use this cool RegExp to find bad comments:

\#[^{].*\%\>

For comments use

<%#bla %>

Cheers
Mark

Feb 3

[roman] Uppercase first character with MySQL

 

Ever needed to cleanup the user first/lastnames? Here is a start, if you don’ t want to instantiate all the records with ActiveRecord:

DROP FUNCTION IF EXISTS first_upcase;
CREATE FUNCTION first_upcase (s VARCHAR(120)) RETURNS VARCHAR(120) DETERMINISTIC
RETURN
CONCAT(   UCASE( SUBSTR(s, 1, 1) ), SUBSTR(s, -1*(LENGTH(s)-1) ));
UPDATE users SET firstname = first_upcase(firstname);

DETERMINISTIC is needed for replication.

Here at DaWanda we are using munin to monitor our servers.
Recently we switched from nginx + mongrel to nginx + passenger. So it was time to get a munin plugin to monitor the passenger processes. There is already a plugin out by Dan Manges which we used but soon we needed additional monitoring for the nginx global queue. So we simply added the queue support to Dan’s plugin.
You can find the plugin in our public github repository.

Here at DaWanda we are using munin to monitor our servers.

Recently we switched from nginx + mongrel to nginx + passenger. So it was time to get a munin plugin to monitor the passenger processes. There is already a plugin out by Dan Manges which we used but soon we needed additional monitoring for the nginx global queue. So we simply added the queue support to Dan’s plugin.

You can find the plugin in our public github repository.