latest Tweet:
No public Twitter messages.

Der Mob & direkte digitale Demokratie

January 21st, 2011

Kameraüberwachung in Dresden (Bildquelle)Die politische Elite steht unter Druck, am Stammtisch und im digitalen Netzwerk radikalisieren sich die Meinungen. Zeitweise beherrschen Knüppel und Blut vielerorts deutsche Strassen.
Seitdem 1992 Politikverdrossenheit zum Wort des Jahres erklärt wurde, passte das lange zu unserem allgemeinen Selbstverständnis als deutscher Michel. Politik: das wollten wir nicht, das konnten wir nicht, dafür war uns die Zeit zu schade. Facetten einer US-Amerikanern zugeschriebenen Eigenschaft blühten in deutschen Einfamilienhäusern. Im Land der unbegrenzten Möglichkeiten, wie nun hier, liege es zu allererstes in unserer eigenen, direkten Verantwortung wie wir leben und wie es uns geht. Repräsentanten des Volkes wurden offenbar einzig auf die Funktion ihrer internationalen und medialen Repräsentation degradiert.

Umso verhängnisvoller muss das Erlebnis einer zusammenbrechenden Finanzwelt in unsere Köpfe geprescht sein. Read the rest of this entry »

Dynamic model based styles for Paperclip

October 29th, 2010

One might want to set up dynamic attachment dimensions (or other styles) when generating images with thoughtbot’s paperclip. Styles in paperclip are basically represented in the :styles hash of has_attached_file:

class File
  has_attached_file(
    :attachment,
    :styles => { :thumb => "100x100" }
  )
end

Building a related size model in rails might look the following:

class File < ActiveRecord::Base
  has_many :sizes, :class_name => "FileSize", :dependent => :destroy
 
  has_attached_file(
    :attachment,
    :styles => # styles through FileSize model
  )
 
  def styles
   self.sizes.inject({ :thumb => "100x100" }) do |sizes, size|
      sizes[:"#{size.id}"] = "#{size.width}x#{size.height}"; sizes
    end
  end
end
 
class FileSize < ActiveRecord::Base
  belongs_to :file
end

Using a Proc we can fetch sizes from our FileSize model:

  has_attached_file(
    :attachment,
    :styles => Proc.new { |clip| clip.instance.styles }
  )

Clip is the Paperclip instance which holds an instance-method to get back to the calling Class.

As a last issue one might want to reprocess / regenerated images after creating or destroying sizes:

class FileSize < ActiveRecord::Base
  belongs_to :file
 
  after_create  :reprocess
  after_destroy :reprocess
 
  private
 
  def reprocess
    self.file.attachment.reprocess!
  end
end

Iterate over Associative Arrays in Bash

June 24th, 2010

Probably because many people think Bash is outdated it’s that hard to find proper resources digging into this Shell. Now we’ll have a look at an associative array and use each key to rename a file defined in value one got via wget.

Beware: Take a look at the OS X issues at the end of this article if working on a Mac!

#!/bin/bash
unset array; declare -A array # the -A attributes stands for associative
 
array[foo]=bar
array["spaced string"]="foo bar"
 
for i in ${!array[@]}
do
  # do something
done

This is how an iteration could look like. Have a look at bash-hackers.org to get more information. Thanks to Dennis Williamson solving this topic.

To get a file from the given URL perform the following command in the loop:

wget "${array[$i]}" -O "${i}.jpg"

The attribute -O renames the file.

Using variables outside Strings obviate the need for curly brackets so that $i would work as well.
Go on reading if you’re using a Mac:
Read the rest of this entry »

Cross-Domain with Sinatra / Rack and JSONP

March 25th, 2010

There are several situations one might want to do cross-domain (/cross-site) AJAX-requests. Probably you experience the security borders of modern browsers very fast.
JSONP is a hack for JSON that provides a great workaround. It means sending a callback with the URL (eg. ?callback=sampleFunction). Server-sided we setup our application to respond with a JSON body wrapped in a function named like our callback function. In this case

sampleFunction({
  "ourData": [{
    "title": "is an array"
  },
    "title": "..."
  }]   
})

What we have to do (Sample)

Frontend
JS-Frameworks like jQuery are smart enough to send such requests with ease. Lets write a simple function with jQuery:

$.ajax({
  type: 'get',
  url: 'file.json',
  dataType: 'jsonp',
  success: function(data) {
    doSomethingWith(data);
  }
})

Let’s see how to setup the server:
Using Ruby and Rack it becomes very simple to beautifully provide regular JSON for non-JSONP clients and JSONP for jQuery & Co.
Simply use the rack middleware rack-contrib by Ryan Tomayko

gem install rack-rack-contrib --source=http://gems.github.com/

If you’re using pure rack, put this in your config.ru

require 'rack/contrib/jsonp'
use Rack::JSONP

Using Sinatra, I’d put it somewhere with my config files.
Let’s see how a sample Sinatra application could look like:

require 'sinatra'
require 'json'
require 'rack/contrib/jsonp'
 
use Rack::JSONP
 
before do
  content_type :json
end
 
get '/posts' do
  Posts.find.to_a.to_json
end

That simple, this powerful.

InDesign: Sprache für ganzes Dokument ändern

March 8th, 2010

InDesign Es gibt zwei Möglichkeiten die Sprache für das Text- und Absatzformat in InDesign zu ändern. Wenn wir allerdings nicht für jedes Textfeld die Sprache ändern wollen, müssen wir uns eines Workarounds bedienen. Schließlich gibt es kein “Sprache für Dokument ändern”. Dann wollen wir mal:
Read the rest of this entry »

Erfolg im Leben

February 9th, 2010

Es kann so einfach sein.. Werbung von Morgen.

Erfolg im Leben

Aufgenommen: Bf Hamburg Altona (neben Mc Donalds) – “Werbekasten”


Update via @MrRaffnix – so macht man’s richtig:

Read the rest of this entry »

Brief an einen Freund

February 8th, 2010

Um herauszufinden, was du willst, musst du bewusster leben – nicht danach suchen. Denn erst Erlebtes lässt sich reflektieren. Leben ist permanent in Bewegung zu bleiben.
Studien haben ergeben, dass sportliche Menschen, denen man mehrere Wochen lang Faulenzen verordnet hat, schon nach kürzester Zeit schwere physische Mängelerscheinungen aufwiesen. Ich bin mir trotz fehlenden Studien sicher, dass genau dies auch mit deiner Psyche passiert wenn du deinen Geist zu Bette trägst. Am ehesten passiert dies, wenn du dich auf Erreichtem ausruhst. Was dein Körper dir mit schwammigen Polstern verbucht, endet für dein Wesen in einer erträglichen, unbewussten Einfalt. Die Seligkeit scheint omnipräsent – ist aber zerbrechlich wie Porzellan. Es ist einfacher.

Reflektierst du diese Hypothese auf deine Beziehungen, wirst du ganz ähnliche Zusammenhänge erkennen. Insbesondere partnerschaftliche Beziehungen können unter der enormen Last der Unbedarftheit bersten. Die Schlichtheit einer Beziehung ist bester Nährboden für Glückseligkeit. Wenn sich Lebensbedingungen und Beziehungen ändern kann es aber sein, dass dieser Boden nicht mehr trägt. Was man also bis hierher aufgebaut hat, kann sich geradewegs entrüsten. Du bist entmutigt und enttäuscht von dir selbst. An dieser Stelle bist du gerade. Du musst nun beantworten ob du dir zutraust mit den gleichen Steinen, mit der Annahme die Architektur besser zu verstehen, das Fundament neu zu verlegen. Wenn, denke daran, dass du entweder die Ruinen des alten Baus – so weit möglich – wegräumst, oder ein, in seiner Stabilität gefährdetes, Neues darauf setzt. Oder du sogar neue Gründe erforscht und auf neuem Raum mit neuem Material baust.
In jedem Fall ist es maßgebend, dass du die ständige Anpassung und Auseinandersetzung wahrst. Lass dies dein oberster Grundsatz sein.

Viel Erfolg und Glück!

Cheatsheet: moving data from one server to another

January 20th, 2010

This article is about moving a running web-environment along with it’s MySQL database from one server to another via SSH.

Compress files

Let’s compress the directory we’re going to move using gzip:

tar cfvz backup.tar.gz /path/

Dump MySQL database content

mysqldump -uUser -p -hlocalhost database_name > dump.sql

You can also dump several databases with mysqldump by addind the --databases or --all-databases parameter.

Moving files

Now we use SCP to move files to our new machine. The following example copies from the old machine:

scp user@host:/path/backup.tar.gz .

The other way round, copying the file to the new machine from the old one would look like this:

scp backup.tar.gz user@host:/path/backup.tar.gz

Do the same with your database dump.

Uncompress files

Simply type:

tar xfvz backup.tar.gz

Now we should have the same directory structure we had on our old machine.

Import MySQL database

mysql -uUser --default-character-set=utf8 -hlocalhost -p database_name < dump.sql

If you have international content and an utf-8 environment running don’t forget to pass the charset-parameter!

Hamburger Hafen im Winter

January 12th, 2010

Passend zum Schneechaos in Norddeutschland ein paar Eindrücke aus dem Hamburger Hafen im Winter. Ich habe noch nichts nachbearbeitet – also seht ihr Rohmaterial aus der Kamera.

Eisbrecher Hamburg

Read the rest of this entry »

select any HTML text in element with jQuery

November 19th, 2009

The following script jQuery extension selects any text from a given jQuery selector. Tested with Firefox and Safari – should work in IE6+ as well.

jQuery.fn.extend({
  selectText: function() {
    var text = $(this)[0];
    if ($.browser.msie) {
      var range = document.body.createTextRange();
      range.moveToElementText(text);
      range.select();
    } else if ($.browser.mozilla || $.browser.opera) {
      var selection = window.getSelection();
      var range = document.createRange();
      range.selectNodeContents(text);
      selection.removeAllRanges();
      selection.addRange(range);
    } else if ($.browser.safari) {
      var selection = window.getSelection();
      selection.setBaseAndExtent(text, 0, text, 1);
    }
    return $(this);
  }
})

To use it simly do:

var shortSelector = $('#name').selectText();
var longSelector = $('ul#names li:contains("Hampel")').selectText();

written on top of Source and Source