compress pictures with the mac terminal

Use the following command to scale all pictures ending with JPG in the current directory down to a height of 600px and save them as small_’original name here’.jpg.
find *JPG -exec sips --out small_{} --resampleHeight 600 {} \;

for-loop in java

Today i discovered a funny way of doing a basic java loop:

1
2
3
4
5
6
7
for(int i = 0; i ++< 10;) {
    System.out.println(i);
}
 
for(int i = 10; i --> 0;) {
    System.out.println(i);
}

It’s nothing special actually since the ‘--‘ or ‘++‘ stands for ‘i = i +/- 1‘, so ‘i‘ gets changed and there is still the condition.

IPTC

I’ve been fighting with IPTC-Fields in JPEG-Files for quite some time now.
I ended up using Apache Sanselan for it. There was no approach of writing IPTC-Fields yet. If so, I’ll of course update this article.
Here goes a simple piece of java code that might be helpful to get started with Sanselan since it’s poorly documentated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package iptc;
 
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
 
import org.apache.sanselan.ImageReadException;
import org.apache.sanselan.Sanselan;
import org.apache.sanselan.common.IImageMetadata;
import org.apache.sanselan.common.ImageMetadata;
import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
 
public class IPTC {
    public static void main(String args[]) {
        try {
            HashMap<String, String> map = getIPTC(new File("C:\\IPTC-Muster.jpg"));
            for(Map.Entry<String, String> e : map.entrySet()) {
                System.out.println(e.getKey() +" -> "+e.getValue());
            }
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
 
    private static HashMap<String, String> getIPTC(File f) throws IOException, ImageReadException {
        HashMap<String, String> result = new HashMap<String, String>();
 
        IImageMetadata metadata = Sanselan.getMetadata(f);
 
        if (metadata instanceof JpegImageMetadata) {
            JpegImageMetadata jpegMeta = (JpegImageMetadata)metadata;
 
            for(int i = 0; i < jpegMeta.getPhotoshop().getItems().size(); i++) {
                ImageMetadata.Item item = (ImageMetadata.Item)jpegMeta.getPhotoshop().getItems().get(i);
                result.put(item.getKeyword(), item.getText());
            }
 
        }
 
        return result;
    }
}

Dreams

Dreams
In Connor’s second thesis it is stated ‘There is no fate but what we make for ourselves.’ Does the routine destroy our creativity or do we lose creativity and fall into the routine? Anyway, who’s up for a road trip!

Gotta love XKCD!

Die Warnung vor dem Sichelfisch

Tag 1:

Sicher durch den Sumpfe gehen
und dabei auch sichergehen,
dass man unbedingt auch sicherlich nicht
tritt auf den Sichelfisch!

Tag 2:

Sichelfisch nicht stichel mich
denn ich mag deinen Stachel nicht
wenn er sich in mein Fleische bohrt
such deinem Stachel einen andern Ort

Tag 3:

Frage an den Sichelfisch:
Sichelfisch
du Stichelfisch
warum nicht gleich oh Stachelfisch?
du hast nicht ‘mal ne Sichel nicht!

Regex

After playing around with regex I decided to develop some patterns (at this time there are two, actually) which i was going to post here so everyone could have a look at them and get some ideas (tho they might not be very complicated, but thats relative, don’t you think).

Matching URLs in a text:
((http(s)?|ftp)://)?(www.)?[A-Za-z0-9]+([.][A-Za-z0-9]+)*[.]([A-Za-z]{2,4})((/([A-Za-z0-9#&_:/=.?]+)?)?)\s

Matching words in a text:
[^\s.:(),?!"0-9]+([0-9][^\s.:(),?!"]+)?

In a small Java Application it could look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
 
public class Main {
	public static void main(String[] args) {
		checkText("This is a text.");
	}
 
	public static void checkText(String text) {
        Pattern p = Pattern.compile("((http(s)?|ftp)://)?(www.)?[A-Za-z0-9]+([.][A-Za-z0-9]+)*[.]([A-Za-z]{2,4})((/([A-Za-z0-9#&_:/=.?]+)?)?)\\s");
        Matcher matcher = p.matcher(text);
        while (matcher.find()) {
        	int start = matcher.start();
        	int end = matcher.end();
        	System.out.println(text.substring(start,end));
        }
	}
}

Science.. just another religion?

I’ve been wondering lately, if science wasn’t just another religion. Sounds stupid, doesn’t it.
Let me get this straight – I think it actually IS another religion.

First of all, there is no real definition for the word religion. Actually there are more than hundred and none of them turned out to be ultimate. So here is my own definition:
Religion is something people rely on, when they don’t understand something. Like when there was a thunder way back, people thought someone was hammering with a gigantic whatever-it-was on something really heavy to create that sound. Now we know better. But do we really?
When we think critically, we will see that we actually can’t KNOW something for sure. We believe in it. And that’s what we do with any other religion too, don’t we.
All we do is trying to find proofs for things that happen around us, based on the senses we got, believing in them. But what if they fail?
My point is, that we need something to believe in for having the drive to develop and go on. Either it is god and the holy halls waiting for us or it is the belief in science and its progress in which we can participate.
Difference to other religions? Science is the only religion not giving us hope, not giving us something supernatural waiting for us to judge. When we die, we die, game over.
But again, it’s just theory. Theories can be right, theories can be wrong – and if they are right, they are right only under certain circumstances. For example that the already proven things are really true and not false, which we can’t really know, but we trust in it.

mp4 to mp3

This post is about how to convert a mp4 file into a mp3 file with the help of some freeware and the unix shell.
Now.. why would i like to do this ???
Youtube saves its videos in the *.flv format. Not such a good quality (sound wise). BUT – the HQ-Videos are saved in mp4 files.
How to get these? Pretty simple. Just add &fmt=6 right behind the link. Like:
http://www.youtube.com/watch?v=qF4dgPv-voI -> http://www.youtube.com/watch?v=qF4dgPv-voI&fmt=6

Now we got a streamed mp4 file. Great. How to get it out of the browser? Either one uses the ff plugin Download Helper or one just gets it out of the cache of the used browser. The first way is easier in my opinion. The ones not liking downloadhelper might also use this: BetterYoutube

So, now we got this mp4 file on our desktop. What to do?

First of all we need the Lame mp3 Encoder and Faad2.
After installing these we are ready to convert.
Just manage your shell into the directory the mp4 is in (via cd) and execute this command:
faad -o - "Input File.mp4" | lame - "Output File.mp3" -b 192
The 192 at the very end of course can be exchanged with any other possible bit rate, like 256.
Well that’s it, basically. Now you just have to wait until the conversion is done and voila – you’ve got a new mp3.

Knaffs and Hunkis

All Knaffs have the same shape and size. All green Hunkis also have the same shape and size.
20 Knaffs fit into a Plauz.
All Hemputis contain green Hunkis.
A green Hunki is 10% larger than a Knaff.
A Hemputi is smaller than a Plauz.
If the contents of all Plauz’ and Hemputis are predominantly red, what’s the maximum number of green Hunkis in a Hemputi?

Our solution:
(Which is of course the best (:. )

Let’s begin with a few definitions:

Knaff := x
greenHunki := z
Plautz := y
Hemputi := t

Initial guess:
t = \alpha z + (\alpha + 1)x

In the Hemputi has to be an amount (\alpha) of green Hunkis and an amount of Knaffs.

..and Hemputis are predominantly red..

- that’s why we set (\alpha + 1)x (We are searching for the maximum amount of green Hunkis, that’s why there has to be exactly ONE more Knaff). Since there are just Hunkis and Knaffs defined, Knaffs HAVE to be red.

Other relations:

A green Hunki is 10% larger than a Knaff.

1,1x = z \Leftrightarrow x = \frac{10}{11}z

All together:
t = \alpha z + (\alpha + 1)\frac{10}{11}z = \alpha z + \frac{10}{11}\alpha z + \frac{10}{11}z
Since we’re calculating in z (z has to be recognized as UNIT) we can set z = 1 for easier equation-solving.
\Rightarrow t = \alpha + \frac{10}{11}\alpha + \frac{10}{11}

t < y

A Hemputi is smaller than a Plauz.

AND x = \frac{10}{11}z

AND 20x = y

20 Knaffs fit into a Plauz.

\Rightarrow y = \frac{200}{11}z
t < y \Rightarrow t < \frac{200}{11}z

Since z = 1

t < \frac{200}{11}

Since \alpha + \frac{10}{11}\alpha + \frac{10}{11} = t

\alpha + \frac{10}{11}\alpha + \frac{10}{11} < \frac{200}{11}

\Leftrightarrow \alpha < \frac{190}{21} \approx 9,0476

The amount of green Hunkis (\alpha) has to be smaller than 9,0476 and \alpha \in \mathbb{N} and it has to be the largest number that fulfills those two conditions. So, in fact, 9 is the solution. Yay.

Felix & Moritz.

Inzidenz-Axiome und das Parallelenaxiom

Inzidenz-Axiome

- Zu je zwei verschiedenen Punkten einer Ebene gibt es genau eine Gerade, auf der die Punkte liegen.
- Jede Gerade enthälte wenigstens 2 Punkte.
- In einer Ebene gibt es mindestens 3 verschiedene Punkte, die nicht alle auf einer Geraden liegen.

Treffen sich zwei verschiedene Geraden in einer Ebene höchstens in einem Punkt?

Sie treffen sich in höchstens einem Punkt, da die beiden Geraden den Schnittpunkt S gemeinsam haben und es zu zwei verschiedenen Punkten einer Ebene immer genau eine Gerade gibt, auf der diese liegen. Somit muss der zweite Punkt P zwischen den Geraden differieren und die Geraden beschreiben, mit Ausnahme von S (sofern überhaupt vorhanden), komplett andere Punkte.

Gibt es in einer Ebene mindestens 3 Geraden?

Es gibt in einer Ebene mindestens 3 Geraden, da eine Ebene durch mindestens 3 Punkte definiert wird, die nicht auf einer Geraden liegen. Somit lassen sich bei den Punkten A, B und C die sich voneinander unterscheidenden Geraden AB, AC und BC konstruieren.

Parallelenaxiom

Befinden sich eine Gerade g und ein Punkt P, der nicht auf g liegt, in einer Ebene, so gibt es genau eine Gerade h in dieser Ebene, die parallel zu g ist und durch den Punkt P geht.

Kann es eine Ebene geben, die nur aus 4 Punkten besteht, aber die Inzidenz-Axiome und das Parallelenaxiom erfüllt?

Die Ebene besteht aus den Punkten A, B, C und D. A und B liegen auf einer Geraden g, C und D liegen auf einer Geraden h, die g nicht entspricht. Es kann keinen Schnittpunkt zwischen g und h geben, da die vorhandenen Punkte nicht identisch sind (Eine Gerade hat immer mindestens 2 Punkte, wie in diesem Fall).
Ferner gibt es die Geraden AC, AD, BC und BD.
Da g und h nicht identisch sind, beschreibt C einen Punkt, der nicht auf g liegt. Die Gerade h verläuft durch diesen Punkt C und hat keinen gemeinsamen Punkt mit g, daher sind g und h parallel und alle Axiome sind erfüllt.

Archives

Categories