Page 159 of 173

Netbeans 6.8 on Ubuntu + problems with hanging SVN

After months of using RapidSVN, I've decided to go back and use Netbeans integrated SVN client. However it started to hang my Netbeans IDE when I've been committing stuff into repo. After 5-6 attempts Netbeans finally committed stuff but come on - 6 IDE restarts to make one commit? Hell no!

Go into:

Tools --> Options --> Miscellaneous -->Versioning --> Subversion

Find: Path to the SVN executable File: and change it into:

/usr/bin

Restart your IDE and use it with SVN client without any hangs. You should also disable any plugins you are not using.

Acts As Random – plugin do generowania losowych ID zamiast autoincrement

O tym dlaczego ważne jest generowanie losowych ID, pisałem już w innym poście. Tutaj opiszę jak działa najważniejsza część mojego pluginu. Do pobrania jest tutaj.

Jak go dodać do klasy:

class CoolClass < ActiveRecord::Base
    acts_as_random
end

I od tego momentu generuje nam losowe wartości naszych id. W każdej klasie dziedziczącej po ActiveRecord, dodając acts_as_random, otrzymamy pseudolosowe id.

A działa to tak:

      def before_create
        range = 2147483647
        id = rand(range)
        while self.class.exists?(id) do
          id = rand(range)
        end
        self.id = id
      end

Malutko prawda? :)
Najpierw mamy deklarację zakresu INT(11) w (nawiasem mówiąc, taka sama jest w Postgresie. Wynika to z rozmiaru INTa a nie specyfikacji danego systemu bazodanowego). Następnie losujemy id z naszego zakresu, czyli od 0 do range. Sprawdzamy czy taki wpis istnieje i jeśli tak, to dopóki wpisy o ID takim jak losujemy istnieją, to musimy losować inne ID. Kiedy już mamy ID to po prostu je przydzielamy do naszego obiektu.

Proste, w miarę czytelne, niewielkie, ale swoje robi. Plusem tego pluginu jest to, że można go podpinać pod już istniejące projekty mające autoincrement. Stare elementy będą inkrementowane, ale nowe już nie.

Copyright © 2025 Closer to Code

Theme by Anders NorenUp ↑