xarg.org | Most Recent Hacking Article

Camara support in HTML5 and JavaScript

At the moment, there are very good efforts to be able to access devices directly with HTML5, which would integrate native webcam support directly into the browser. However, there is still the fundamental problem on the Internet that most systems do not support HTML5. Even the current browsers do not provide the update functionality, which would cover the needs of today’s speed of development. This topic, however was already discussed in a previous article.
Read the rest of the article »

More Recent Hacking Articles
Resolve many-to-many relations a bit different with MySQL

In database modeling, a m:n relationship is usually resolved by an additional table. But what if this relation is used only for archiving and the number of links in the resulting table is not too high? In that context, I got the idea to store all referring ID’s as CSV string directly into a TEXT column of one of the referring tables. I came to this idea, because otherwise I would have to build complicated foreign keys and this way I also save one additional table. Certainly, this only makes sense if the data is not frequently accessed as foreign key. Nevertheless, I would like to tackle the problem, even if the implementation is very MySQL-oriented.
Read the rest of the article »

SQL-modes right to exist

At the beginning of a new project, one is faced with the question if MySQL’s strict mode should be used or if the default behavior is sufficient for most scenarios. This mode certainly makes only sense if you evaluate the error codes and acting accordingly in the application – thus, it would be a bad idea to apply SQL modes to a running system. Unfortunately, SQL modes are not really common and have thereby a few bugs. Also the fact, that the user can bypass the mode in the session raises the question whether it makes sense to use these settings at all. I decided to only set a selected list of options; just what really makes sense and improve the behavior of MySQL. Strangely that these modes are not set by default, what one might expect, as they are close to a natural approach of databases usage.
Read the rest of the article »


Camara support in HTML5 and JavaScript

At the moment, there are very good efforts to be able to access devices directly with HTML5, which would integrate native webcam support directly into the browser. However, there is still the fundamental problem on the Internet that most systems do not support HTML5. Even the current browsers do not provide the update functionality, which would cover the needs of today’s speed of development. This topic, however was already discussed in a previous article.
Read the rest of the article »


More Recent Hacking Articles

Resolve many-to-many relations a bit different with MySQL

In database modeling, a m:n relationship is usually resolved by an additional table. But what if this relation is used only for archiving and the number of links in the resulting table is not too high? In that context, I got the idea to store all referring ID’s as CSV string directly into a TEXT column of one of the referring tables. I came to this idea, because otherwise I would have to build complicated foreign keys and this way I also save one additional table. Certainly, this only makes sense if the data is not frequently accessed as foreign key. Nevertheless, I would like to tackle the problem, even if the implementation is very MySQL-oriented.
Read the rest of the article »


SQL-modes right to exist

At the beginning of a new project, one is faced with the question if MySQL’s strict mode should be used or if the default behavior is sufficient for most scenarios. This mode certainly makes only sense if you evaluate the error codes and acting accordingly in the application – thus, it would be a bad idea to apply SQL modes to a running system. Unfortunately, SQL modes are not really common and have thereby a few bugs. Also the fact, that the user can bypass the mode in the session raises the question whether it makes sense to use these settings at all. I decided to only set a selected list of options; just what really makes sense and improve the behavior of MySQL. Strangely that these modes are not set by default, what one might expect, as they are close to a natural approach of databases usage.
Read the rest of the article »

Use MySQL binlog to collect accesslogs

The easiest way to get user statistics from your own site is probably binding third-party tools like, e.g. Google Analytics into your code or parsing the logfiles with AWstats or webalizer. Evaluating your own logged data is the best way to look over the (imaginary) shoulder of users and bots. Moving static content on different servers remain the accesslog also manageable and free from unnecessary data.
Read the rest of the article »

My jQuery Playground

Probably the biggest problem of a high degree of specialization may be that learning outcomes can be long in coming if you do not even open up new areas of studies for yourself. So I was looking for a system that I’ve never used before. The second criterion was that I wanted to quickly achieve results to have something demonstratable at the end of the day. Thus, I have to announce two new jQuery plugins, which are really useful – at least, I hope you also see the benefits 🙂
Read the rest of the article »

Combine CSS and JavaScript with lighttpd

In early 2007, a nice trick made the circuit to reduce parallel connections by bundling CSS and JavaScript files to one larger file. I immediately started the research to optimize this approach. But why should you combine static files at all?
Read the rest of the article »

Optimized way of getting subqueries at once using JSON

Imagine we have a user table in MySQL and similarly, a products table. Each user can now busily buy items. But this is not what this article is all about. This article is more about, that users can also favor articles they like. From a database point of view, this represents a m:n relation, which is resolved by an additional table. We now want to display a list of all products and all users who favor a specific article. In real world scenarios, this can be a really big amount of data, but let’s bring an approximation later into play and focus on the main idea for the moment. In addition we want to know, if the person who is actually logged in into the system, already favors a certain product.
Read the rest of the article »

Design a developer friendly web

A few years ago, I’ve started creating a list of features, that web-browsers should be able to do, to build rich Internet applications without complicated tweaks and hacks. The time passed away and nowadays, many creative heads concern on web-development, thus some of my ideas landed in HTML5 or other web-standards, without my help. So, I want to show an extensive collection about techniques of browsers, which are already implemented, and which are still needed for developers to design the Internet of the future.
Read the rest of the article »

Is an angle between two other angles?

With my last HTML5 experiment “Space Shooter”, I had to solve a problem of checking, if an angle is between two other angles. Sounds easy for the first moment, but let’s see, if there is not the one or the other portion of trouble in it.
Read the rest of the article »

Disable ON UPDATE CURRENT_TIMESTAMP in MySQL

In a few scenarios, I prefer using the data-type TIMESTAMP of MySQL, with the flag ON UPDATE CURRENT_TIMESTAMP. This is much easier and even faster than using a trigger which sets a specified column to NOW() or CURRENT_DATE(). I love this feature, when it comes to set last modified flags of tables. Now, I encountered a problem with a tagging table by using the flag. Every tag in the table has besides the tag-name, also the aggregated number of relations and a timestamp of last update (or the insert). Everything is okay, until you want to update the aggregated column, when the numbers are wrong for any reason.
Read the rest of the article »

Originally posted on June 7th, 2010.

Analyze online behavior with MySQL and PHP

A useful feature of statistical systems in social networking backend’s is the analysis of when members are mostly, or better said, in average online. Imagine, that we have a database table to store DATETIME-timestamps of when users logged in, which could look like this:
Read the rest of the article »

Originally posted on June 4th, 2010. 1 comment

Cracking a Caesar cipher

The Caesar cipher is one of the simplest encryption algorithms in which every latin letter of a given string is simply shifted cycliacally by a certain offset.
Read the rest of the article »

Optimizing integer multiplication

I’ve already mentioned the topic integer-multiplication optimization in the article about my mathematical failures. I was quite obsessed with the idea and while I looked over some results of this optimization method, I noticed a beautiful pattern in the binary representation. I wrote a small algorithm to get all possible numbers which can be optimized a bit as constant factor of a multiplication. The algorithm is implemented in JavaScript, so if you’re interested in the source code, feel free to read it.
Read the rest of the article »

Dynamic thumbnail generation on the static server

It’s quite natural to use features of the main programming language used in a project to generate user thumbnails or thumbnails of other images. Let’s assume, that we generate 3 sizes of every picture. With a rigid system, you would generate every size and store them temporarily on the webserver until it wasn’t uploaded to the static server. That means we have a lot of write operations on the webserver to generate the small pictures and finally writes to upload each of these pics to the static server – the CPU cycles intentionally left out.
Read the rest of the article »

Calculate date ratios

When I celebrated my birthday, I got the idea that there must theoretically be a date on which two peoples ages are in a certain ratio. The basic idea were born when I thought that there must be a date on which my mother is exactly twice as old as me. Actually, this is the point of time when I’m as old as my mother was, when I were born. That means
Read the rest of the article »

jQuery webcam plugin

The jQuery webcam plugin is a transparent layer to communicate with a camera directly in JavaScript.
Overview

This plugin provides three different modes to access a webcam through a small API directly with JavaScript – or more precisely jQuery. Thus, it is possible to bring the image on a Canvas (callback mode), to store the image on the server (save mode) and to stream the live image of the Flash element on a Canvas (stream mode). If you just want to download the plugin, click here:


http://www.xarg.org/project/jquery-webcam-plugin/
© 2008-2010 Robert Eisele | http://www.xarg.org/

The jQuery webcam plugin is a transparent layer to communicate with a camera directly in JavaScript.

Overview

This plugin provides three different modes to access a webcam through a small API directly with JavaScript – or more precisely jQuery. Thus, it is possible to bring the image on a Canvas (callback mode), to store the image on the server (save mode) and to stream the live image of the Flash element on a Canvas (stream mode). If you just want to download the plugin, click here:

Download the jQuery webcam plugin

jQuery webcam example

Take a picture after 3 seconds | Take a picture instantly

Available Cameras

  • Laptop Integrated Webcam
  • Google Camera Adapter 0
  • Google Camera Adapter 1

If you activate the filter with the button on the right side of the picture, methods of my already published jQuery plugin xcolor will be used to distort the colors of the Canvas.

General information about the interface

The following snippet describes the interface of the webcam API:

$("#camera").webcam({
        width: 320,
        height: 240,
        mode: "callback",
        swffile: "/download/jscam_canvas_only.swf",
        onTick: function() {},
        onSave: function() {},
        onCapture: function() {},
        debug: function() {},
        onLoad: function() {}
});

Config Parameter

width
The width of the flash movie.

height
The height of the flash movie. Both parameters have to be changed in the Flash file as well. Follow the instructions below to recompile the swf after the size change.

mode
The storage mode can be one of the following: callback, save, stream. Details about the usage of each parameter can be found under the according heading below.

swffile
Points to the swf file of the Flash movie, which provides the webcam API. There are two swf files provided via the download archive: jscam.swf, which provides the full API and jscam_canvas_only.swf which have no embedded JPEG library (I embedded an adjusted JPGEncoder of the AS 3 corelib). Thereby, the file is only one third as large as the original.

onTick, onSave, onCapture
These callbacks are described in detail below, since they change with each mode.

onLoad
The onLoad callback is called as soon as the registration of the interface is done. In the example above, I use the callback to get a list of all cameras available:

onLoad: function() {

    var cams = webcam.getCameraList();
    for(var i in cams) {
        jQuery("#cams").append("<li>" + cams[i] + "</li>");
    }
}

Once the onLoad callback is called, a global object window.webcam is available, which provides the following methods:

  • capture([delay])
    Captures an image internally.
  • save([file])
    Saves the captured image accordingly to the storage mode.
  • getCameraList()
    Get’s an array of available cameras. If no camera is installed, an error is thrown and an empty array is returned.
  • setCamera([index])
    Switches to a different camera. The parameter is the index of the element in the resulting array of getCameraList()

debug
The debug callback is called whenever there is a note or an error you should be notified. In the example above, I just replace the html content of the output container:

debug: function (type, string) {
        $("#status").html(type + ": " + string);
}

Callback Interface Leer más “jQuery webcam plugin”