Mit puma-dev lassen sich beliebig viele Rack/Rails-Anwendungen durch Erstellen von Symlinks verfügbar machen.
Allerdings ist damit Port 80 blockiert und steht nicht mehr für Apache zur Verfügung.
Zum Glück erlaubt puma-dev nicht nur das Erstellen von Symlinks auf Rack-Apps sondern auch das Erstellen von Files innerhalb von ~/.puma-dev/, die als Inhalt einen alternativen Port enthalten.
Damit kann man alle Applikationen, die statt von puma-dev von Apache behandelt werden sollen, z.B. PHP-Apps und statische Seiten, als Files anlegen, die nur 81 enthalten.
Außerdem muss man Apache auf Port 81 lauschen lassen.
Die erforderlichen Schritte sind:
Apache-Konfiguration /etc/apache2/httpd.conf
Apache soll zukünftig auf Port 80 lauschen:
Listen 81
Die Module für virtuelle Hosts, Rewrite und PHP sollen verwendet werden:
<VirtualHost 127.0.0.1:81>
ServerName any.dev
ServerAlias *.dev
UseCanonicalName Off
VirtualDocumentRoot "/Users/{username}/Sites/%1"
<Directory "/Users/{username}/Sites/*">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Angenommen die gewünschte PHP-Applikation liegt im Verzeichnis /Users/{username}/Sites/meine-app/.
Erstellt man eine Datei ~/.puma-dev/meine-app mit dem Inhalt 81, dann wird diese unter http://meine-app.test durch Apache verfügbar gemacht.
Working with Heroku I recently wanted to pull the Heroku production DB to my local DB. Using pg:pull I got the following error message: pg_dump: aborting because of server version mismatch
because Heroku uses PostgreSQL 9.4 and my local version was 9.3.
So I had to update my local DB; this is what I did:
1) shut down db and remove launch agent plists: launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.postgresql*
2) remove links to old binaries, install new version (links automatically): brew unlink postgresql93
brew install postgres
Note that I do not yet uninstall the old binaries, we need them to run pg_update later!
3) Link the new launch agent plist ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
4) create a new empty cluster with the same locale as the old one: initdb /usr/local/var/postgres9.4 --locale=en_US.UTF-8
5) run the upgrade script (using the binary of the new version) pg_upgrade -v \
-d /usr/local/var/postgres \
-D /usr/local/var/postgres9.4 \
-b /usr/local/Cellar/postgresql93/9.3.5/bin \
-B /usr/local/Cellar/postgresql/9.4.5_2/bin
6) start new server and uninstall the old version: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
brew uninstall postgresql93
7) optional: re-install the pg rem for my ruby app gem uninstall pg
bundle
When you use an expression as a ruby default argument like in
def delay(time=2.minutes.from_now)
... # stuff that needs to be done later
end
you might wonder, when exactly the expression gets evaluated, at parse time or at execution time. The difference, especially for time based expressions, can be huge!
Let’s find out:
puts 'A'
def delay(time=puts('B'))
end
puts 'C'
delay()
The output is
A
C
B
So it’s at execution time, which is much more useful anyway.
September 29, 2014 at 11:45 am · Filed under Allgemein
HTML5 provides us with ways to specify different types of input, complete with client side validation. Inputs can be marked as required and it is even possible to specify regexp patterns for valid input.
Let’s put this into action by creating an input for german zip codes, consisting of 5 numbers:
As you can see, this works, but the actual validation message you get when entering a wrong code is a bit generic (In german: “Ihre Eingabe muss mit dem geforderten Format übereinstimmen.”). Instead, you would want the message to state what a correct zip code has to look like.
Fortunately there is a way to specify the message to be displayed via the javascript setCustomValidity method (unfortunately there is no way to do this via another attribute, say pattern-invalidmessage).
Now, when using the setCustomValidity method there is a conceptual problem. Setting this on an input field, automatically renders this field invalid, no matter whether it is otherwise perfectly fine!
So for our case, we want to set this message only after the browser has decided, that the field does not match the pattern, kind of as a second error on the field. The message should be specified in another attribute called data-invalidmessage.
The following CoffeeScript does just that:
Februar 18, 2014 at 2:29 pm · Filed under Allgemein
Using just a data-attribute and a simple stylesheet rule it is possible to change the content of a link when hovering over it.
Use an HTML / SASS combination like the following:
März 29, 2012 at 12:17 pm · Filed under Rails, Ruby
Let’s say we want a simple controller action that checks, if a given code is valid.
It should return true and false and, if the code is invalid, give the reason (whether that is because it is unknown or because it has been used already). The action could look like this:
Now this deep nesting effectively hides the underlying algorithm, a simple one in this case.
Expressing this using throw and catch straightens the code a bit:
We are down to one respond_with line but the has merging and the throws at the beginning of the line are not particularly pretty.
Let’s introduce a little Ruby mixin for the Hash class that provides it with a compact method that its friend Array has had all along:
Now using this to clean up the response hash and moving the throw statements to the end so the steps of the algorithm are visible we have our final version of the action: