Benny's Blog
27. Januar 2012

Ein Code sagt mehr als tausend Worte:

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
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Centering a Div horizontally and vertically</title>
    <style type="text/css">
      html
      {
        background-color: black;
      }
 
      body
      {
        width: 100%;
        height: 100%;
        position: static; /* don't make it relative! */
      }
 
      #centered
      {
        position: absolute;
        height: 396px;
        width: 400px;
        margin: -198px 0px 0px -200px; /* 50% height, 0px, 0px, 50% width */
        top: 50%;
        left: 50%;
        background-color: violet;
        border: 1px solid white;
      }
    </style>
  </head>
  <body>  
    <div id="centered"></div>
  </body>
</html>
25. Januar 2012

One line of code is worth ten thousand words.

./index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Asynchronous Module Definition Example with RequireJS</title>
  </head>
  <body>  
    <!-- Let's use RequireJS as module loader (there are also others!) -->
    <script src="./js/require-1.0.4.js"></script>
    <script>
      require(['js/my_amd_module'], // Requires ./js/my_amd_module.js
      function(myModule)
      {
        myModule.sayHello();
        myModule.doSomething();        
      });
    </script>
</html>

./js/my_amd_module.js

define('js/my_amd_module', // module name, has to match filename (without .js)
  ['js/jquery-1.7.min'], // requirements of this module (./js/jquery-1.7.min.js)
  function($) // $ for jQuery
  {
    return {
      sayHello: function()
      {
        alert('Hello World!');
      },
      doSomething: function()
      {
        alert('I did.');
      }
    };
  });
13. Januar 2012

Mit dem folgendem Code kann ein beliebiger Inhalt in eine Textdatei geschrieben werden. Sollte die Datei bereits existieren, wird der Text am Ende der Datei angefügt:

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
 
public class SimpleFileWriter
{
 
  static final Logger logger = Logger.getLogger(SimpleFileWriter.class.getName());
 
  public static void writeFile(String pathName, String content) throws IOException
  {
    File file = new File(pathName);
    try (FileWriter writer = new FileWriter(file, true))
    {
      writer.write(content);
      writer.flush();
    }
  }
 
  public static void main(String[] args)
  {
    try
    {
      writeFile("C:/Temp/test.txt", "Hello World!" + System.getProperty("line.separator", "\r\n"));
      System.out.println("Data was successfully written.");
    }
    catch (IOException ex)
    {
      logger.log(Level.WARNING, ex.getLocalizedMessage());
    }
  }
}
13. Januar 2012

Here is a tutorial on how to install the latest Java 7 JDK and JRE on a Debian Linux system:

1
2
3
4
5
6
7
8
9
10
11
12
13
apt-get update && apt-get upgrade -y
sudo apt-get install sun-java6-jdk -y
mkdir /tmp/downloads && cd /tmp/downloads 
wget http://download.oracle.com/otn-pub/java/jdk/7u2-b13/jdk-7u2-linux-i586.tar.gz
tar -xvf jdk-7u2-linux-i586.tar.gz
mv /tmp/downloads/jdk1.7.0_02 /usr/lib/jvm
mv /usr/lib/jvm/jdk1.7.0_02 /usr/lib/jvm/java-7-oracle
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-7-oracle/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-7-oracle/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/java-7-oracle/bin/javaws" 1
sudo update-alternatives --config java
java -version
rm -r /tmp/downloads
13. Januar 2012

For some Java applications it might be important to access the console to print some information from a console command. That’s why I wrote a little program which reads the output from the Windows command-line interface (cmd) and shows it on the screen. Note: This script also works on a Linux shell!

…weiterlesen

10. Januar 2012

VirtualRouter eignet sich hervorragend, wenn man eine Internetverbindung über WLAN für andere Geräte freigeben möchte. Manchmal kommt es aber zur Fehlermeldung: “Virtual Router Could Not Be Started”. Bei mir hat in diesem Fall ein manueller Neustart des VirtualRouterService geholfen. Dazu muss man nur unter Dienste (Systemsteuerung\System und Sicherheit\Verwaltung\Dienste) den VirtualRouterService über einen Rechtsklick beenden und wieder starten. Danach sollte das Programm VirtualRouter wieder wie gewohnt funktionieren.