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> |
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.'); } }; });
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()); } } }
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
With jQuery you could easily parse a JSON (which is an object in JavaScript Object Notation). The method parseJSON of jQuery translates the JSON even into the corresponding JavaScript data types. As an example I have chosen the following JSON:
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 | {
"firstName": "Joe",
"lastName" : "Black",
"age" : 28,
"address" :
{
"streetAddress": "1st Street",
"city" : "New York",
"state" : "NY",
"postalCode" : "10021"
},
"phoneNumber":
[
{
"type" : "home",
"number": "212555-1234"
},
{
"type" : "fax",
"number": "646555-4567"
}
],
"married" : true,
"developer" : true
} |
This JSON contains nested objects like address, an array like phoneNumber and key-value pairs of different types like firstName (string), age (number) and married (boolean).
Here it is shown how it is parsed: …weiterlesen
Over the years many ways have been created in order to authenticate through Facebook. One of the easiest ways is to use the Facebook Markup Language (FBML). However, from January 2012 is FBML is no longer supported. Who wants to use Facebook Connect to login and logout then, should use the JavaScript SDK provided by Facebook. This supports authentication via OAuth 2.0, which is the recommended way to handle authentication. I programmed an example, that shows how to login and logout with the JavaScript SDK. This example is based on the current JavaScript SDK methods and does not use deprecated methods (because in July 2011 there were some changes). …weiterlesen

0