Aug 11

Welcome to Better Nested Set for Ruby on Rails

This is a plugin to replace acts_as_nested_set and ehance it.

What is nested set ?

It’s a great and smart way to represent ordered trees into a table. Joe Celko explained this solution in a famous article in 1996.

What is it useful for ?

Categories, or menus, are often organized as ordered trees. Rails provides the good acts_as_tree, but it cannot handle easily ordered trees, and is heavily recursive. Nested set provides a clean way to retrieve tree parts in a single query. It’s longer to insert than with acts_as_tree, but faster to retrieve.

Why extend acts_as_nested_set ?

The nested set proposed in rails is not well suited for many usages; it misses many useful methods. I needed menus and categories systems in some projects, with navigation methods like level, full_set, siblings, children… and move_to methods.

How to install ?

It’s a plugin. You have to copy the code into vendor/plugins of your project. You can retrieve it via svn:

Last stable release:

script/plugin install svn://rubyforge.org/var/svn/betternestedset/tags/stable/betternestedset

or if you want to use the last development version:

script/plugin source svn://rubyforge.org/var/svn/betternestedset/trunk
script/plugin install betternestedset

Another method is to set an external reference to the plugin if you project is versioned with svn:

svn propset svn:externals 'betternestedset svn://rubyforge.org/var/svn/betternestedset/tags/release-0.1' vendor/plugins
Aug 07

Install will_paginate_search

./script/plugin install http://svn.douglasfshearer.com/rails/plugins/will_paginate_search

Setup

Follow through the instructions on setting up acts_as_search in the readme, and give the will_paginate readme a read over too.

Searching With Pagination

First argument is the search query (can be a GET variable or anything else), and after that it takes all the standard will_paginate arguments.

@images = Image.paginate_search 'girl', :page => 1, :per_page => 5

Aug 07

Install

./script/plugin install http://svn.douglasfshearer.com/rails/plugins/acts_as_indexed

Setup

Add acts_as_indexed to the top of any models you want to index, along with a list of the fields you wish to be indexed.


class Post < ActiveRecord::Base
  acts_as_indexed :fields => [:title, :body]

   …
end
Aug 07

First, ensure that you’re running at least RubyGems 1.2 (check gem -v if you’re not sure).

The will_paginate gem is built by GitHub. Add it to your gem sources (once per machine!):

gem sources -a http://gems.github.com

Install the library:

gem install mislav-will_paginate

To enable the library your Rails 2.0.x (or even 1.2.x) project, load it in config/environment.rb:

Rails::Initializer.run do |config|
  ...
end

require 'will_paginate'

Don’t put it before or inside the Rails::Initializer block because the Rails framework is not yet loaded at that point of execution.

That will always load the latest installed version of the gem. If you want to have control of the version loaded, you can use version constraints with the gem method:

# choose one of the following constraints:
gem 'mislav-will_paginate', '2.1.0'
gem 'mislav-will_paginate', '>=2.1.0'
gem 'mislav-will_paginate', '~>2.1' # this will load any 2.x version (greater or equal to 2.1),
                                    # but not 3.x

# finally, load the library
require 'will_paginate'
Jul 13

Fieberhaftes Tüfteln, damit kann man schon so manche Nacht rumbringen.  Nach ewig langem Suchen und Foren lesen, habe ich mich dazu entschlossen, ein Datenbankcluster auf PostgreSQL aufzusetzen, mit hilfe von slony1.  Viele Tutorials erklären, wie es einfach gehen soll, jedoch habe ich noch keine Replikation zu Stande gebracht und ich musste heute morgen leicht durchnächtigt und genervt aufgeben. Neuer Tag neues Glück.

Die Gesamtplanung steht, die erste Funktionalität die ich Launchen werde, wird der Kalenderdienst sein, dessen Homepage unter www.diarise.net/de zu finden sein wird.  So weit die Theorie, denn der Dienst ist noch nicht implementiert, dafür gibt es eine Fülle von wilden Diagrammen und Plänen.  Anschliessend werden die Teile des CMS, die ich fertig habe, noch einmal überarbeitet und angepasst, dass diese als eigenständige Dienste im Netzwerk laufen.  Ich bin gerade dabei, parallel mich in RubyonRails einzuarbeiten.. konzeptionell werden da wohl einige Einflüsse eingehen, das Framework ist sehr faszinierend und doch relativ simpel konzeptioniert..

Ich werde mich da mal einer Datenbank zu wenden… so long

Jul 12

(von  www.ubuntugeek.com)

Configuring postgresql in Ubuntu

Now we need to reset the password for the ‘postgres’ admin account for the server

sudo su postgres -c psql postgres
template1=# ALTER USER postgres WITH ENCRYPTED PASSWORD ‘password’;
template1=# \q

That alters the password for within the database, now we need to do the same for the unix user ‘postgres’:

sudo passwd -d postgres

sudo su postgres -c passwd

Now enter the same password that you used previously.

from here on in we can use both pgAdmin and command-line access (as the postgres user) to run the database server. But before you jump into pgAdmin we should set-up the PostgreSQL admin pack that enables better logging and monitoring within pgAdmin. Run the following at the command-line

we need to open up the server so that we can access and use it remotely - unless you only want to access the database on the local machine. To do this, first, we need to edit the postgresql.conf file:

sudo gedit /etc/postgresql/8.2/main/postgresql.conf

Now, to edit a couple of lines in the ‘Connections and Authentication’ section

Change the line

#listen_addresses = ‘localhost’

to

listen_addresses = ‘*’

and also change the line

#password_encryption = on

to

password_encryption = on

Then save the file and close gedit.

Now for the final step, we must define who can access the server. This is all done using the pg_hba.conf file.

sudo gedit /etc/postgresql/8.2/main/pg_hba.conf

Comment out, or delete the current contents of the file, then add this text to the bottom of the file

DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database
# super user can access the database using some other method.
# Noninteractive
# access to all databases is required during automatic maintenance
# (autovacuum, daily cronjob, replication, and similar tasks).
#
# Database administrative login by UNIX sockets
local all postgres ident sameuser
# TYPE DATABASE USER CIDR-ADDRESS METHOD

# “local” is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5

# Connections for all PCs on the subnet
#
# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
host all all [ip address] [subnet mask] md5

and in the last line, add in your subnet mask (i.e. 255.255.255.0) and the IP address of the machine that you would like to access your server (i.e. 138.250.192.115). However, if you would like to enable access to a range of IP addresses, just substitute the last number for a zero and all machines within that range will be allowed access (i.e. 138.250.192.0 would allow all machines with an IP address 138.250.192.x to use the database server).

adminpack:

sudo aptitude install postgresql-contrib-8.3 slony1-bin

sudo su postgres -c psql < /usr/share/postgresql/8.2/contrib/adminpack.sql

That’s it, now all you have to do is restart the server

sudo /etc/init.d/postgresql-8.2 restart

get the sql-scripts an put them into a folder for pgadmin, for creating clustermasters

ausführen: createlang -d dbname plpgsql

That’s it you can start using postgresql in Ubuntu

Jul 05

sudo aptitude install pmount usbmount

die config liegt in /etc/usbmount/usbmount.conf

Unbedingt die Config lesen!

Ranstecken, unter /media/ sind die aktiven usb-Geräte farblich hervorgehoben, fertig.

Jul 05

Diese Installationsanleitung deckt VMWare Server und VMWare mui ab, vorrausgesetzt wird, das die VMWarepackete und eine gültige Lizens vorhanden sind.

Benötigte Packete installieren:

sudo aptitude install build-essential linux-headers-$(uname -r) xinetd libxi6 xfsprogs psmisc libxext6 libxtst6 libxrender1 libsm6 libice6 libxt6

ungetestet ist der Hinweis für 64bit Benutzer noch das Packet ia32-libs zu installieren.

Die VMWare Packete am besten nach /tmp/ kopieren und erst mal mittels tar xzf VMware-server… entpacken.  Dann in das neu erstellte Verzeichnis wechseln und mit root-Recht ./vmware-install.pl ausführen. Nach der Installation scheiden sich die Geister: Die einen schreiben, mittels root-Recht die /lib/libgcc_s.so.1 nach /usr/lib/vmware/lib/libgcc_s.so.1 und die /usr/lib/libpng12.so.0 nach /usr/lib/vmware/lib/libpng12.so.0 zu kopieren, andere schreiben nur einen symbolischen Link zu setzen.  Bei mir hat das Kopieren funktioniert.

Ungetestet ist der Tip für 64bitter:

mit rootrecht: ln -s /usr/lib32 /usr/l32

sed -i -e ’s:usr/lib/:usr/l32/:g’ /usr/lib32/gtk-2.0/2.10.0/loader-files.d/libgtk2.0-0.loaders

sed -i -e ’s:usr/lib/:usr/l32/:g’ /usr/lib32/libgdk_pixbuf-2.0.so.0.1200.9

Damit sollte der VMware Server laufen.

Um mui zu installieren muss das Archiv wieder wie beim Server entpackt werden, und im Verzeichnis die vmware-install.pl ausgeführt werden.  Anzumerken ist, das die install.pl Scripte nicht korrekt laufen, wenn man sie nicht direkt aus ihrem Verzeichnis aufruft.

Jul 05

Leider wird einem immer die defaultroute auf den VPN-Tunnel gelenkt, wenn man diese aufbaut.  Um das Problem zu umschiffen, gibt es folgende Möglichkeit, bei der bei OS X 10.5 Leopard die Standartroute deaktiviert sein muss, bei Tiger im Ordner /etc/ppp/ den Unterordner peers anlegen, anschliessend in dem Ordner peers eine leere Datei anlegen, die den gleichen Namen wie die VPN-Verbindung bekommt. In dieser Datei wird

“nodefaultroute”

eingetragen und gespeichert.

Um jetzt die eigendliche Route zu setzen, erstellt man in dem ordner /etc/ppp/ die Datei ip-up und schreibt dort folgendes rein:

#!/bin/sh

/sbin/route -n add -net <die ersten drei Tripel des Remotenetzes> $IPREMOTE >/tmp/ppp.log 2>&1

Diese Datei muss nun ausführbar gemacht werden mittels dem chmod u+x /etc/ppp/ip-up -Befehl, anschliessend werden nur noch Packete für das Remotenetz durch den VPN-Tunnel geschickt, und man kann über sein lokales Netz weiterhin das Internet besuchen.  Um das ganze abzurunden und nach dem Abbauen der VPN-Verbindung die gesetzte Route wieder zu entfernen, erstellt man die Datei ip-down im gleichen Verzeichnis.  Folgende Zeilen müssen dort rein:

#!/bin/sh

/sbin/route -n del -net <ersten drei Tripel des Remotenetzes> $IPREMOTE > /tmp/ppp.log 2>&1

Diese Datei wird nun wieder ausführbar gemacht. Um die Routingtabelle anzuschauen, gibt man den Befehl netstat -rn in das Terminal ein.

Jul 05

Um versteckte Dateien anzeigen zu lassen, muss folgendes in das Terminal eingegeben werden:

defaults write com.apple.finder AppleShowAllFiles ON