inicio mail me! sindicaci;ón

Archive for Note to self

Zero-config Rails und PHP mit puma-dev

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:

LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php7_module libexec/apache2/libphp7.so
Include /private/etc/apache2/extra/httpd-vhosts.conf

Virtual Hosts Konfiguration /etc/apache2/extra/httpd-vhosts.conf

<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.

Happy hacking!

Push local branch to specific heroku app

You use two heroku apps as staging and production for your project. You added both as git remotes, e.g. “production” and “staging”.

Now you want to push your local branch “poster” to remote “staging”, use
git push staging poster:master

Note, that you can only push to “master” on herokus side. This is just git syntax, but I keep forgetting it, so here it is for future reference.

Ruby: map Array to Hash

Sometimes you may wish to map an Array to a Hash in Ruby, like say, you got the output of I18n.available_locales

locales = [:en, :de, :fr]

and want to transform that into a Hash to fill a select element, like so:

{:en => 'EN', :de => 'DE', :fr => 'FR'}

How do you do that in the most concise way?
First, there is always inject:

locales.inject({}) {|hsh, sym| hsh[sym] = sym.to_s.upcase; hsh}

But I like the following approach way better, mainly because it emphasizes my intention more clearly (and, btw. is faster too):

Hash[locales.map{|sym| [sym, sym.to_s.upcase]}]

Remember: Hash[[[:a,:b],[:c,:d]]] (as well as Hash[:a,:b,:c,:d])
produces {:a => :b, :c => :d}.

Vor kurzem dazugelernt:

Suche nach Wort unter dem Cursor in vim: #.

jssh ist eine JavaScript Shell, die den Firefox per Port 9997 fernsteuerbar macht.
Download z.B. hier.

y erzeugt einen YAML dump auf der Rails console, mehr dazu hier.

=3D ist ein escaptes “=” in quoted_printable.

sudo /usr/libexec/locate.updatedb aktualisiert unter MacOSX sofort die locate Datenbank.

rake db:migrate:redo führt unter rails die letzte Migration rückwärts und sofort wieder vorwärts aus, so dass sich die Vorwärts-Action korrigieren läßt

ack -Q bringt ack dazu, literal, also ohne RegExp zu suchen.

MacOSX Boot-Tastenkombinationen: single user, verbose, safe

In den single user mode (root shell) starten, beim Neustart:
[CMS] s

In den verbose mode (boot log) starten:
[CMD] v

In den safe mode (nur core kexts) starten:
[SHIFT]

Accidentally unpacked a jar into home dir?

find . -newerBt '10 minutes ago' -depth 1 -print 2>/dev/null