Skip to content

TheHippo

if (i=1) throw null;

Archive

Category: Programming

I am currently working on a Flash project. Because it has a lot of GUI stuff and it is always a lot of code to make some nice GUI components in pure ActionScript 3 I decided to give Flex a change. Surprisingly I really like it. It’s nice and a little bit sick (for a framework a lot of magic happens during compilation). Like for ActionScript 3 Adobe again did a really good job on writing a nice documentation.

But not everything works flawless. Here is a thing struggled with:

Embedding an image is quite easy (the image will be compiled into the final swf file):

  1. <mx:Image source="@Embed(source=’image.jpg’)"/>

Using HTML to format text shouldn’t be a problem for anyone.

  1. <mx:Text width="100%">
  2.   <mx:htmlText>
  3.     <![CDATA[<p><img src='url'/>some text</p>]]>
  4.   </mx:htmlText>
  5. </mx:Text>

This will show the image from the given URL and “some text”. The Image is going to be loaded when displayed, it is not embedded into the swf file.

How to use a embedded image in a HTML text element? continue reading…

Today I discovered that a while back on a PHP/HTML/MySQL project I made some serious mistakes on my database design. To explain it in short:

I have one a table, lets call it “table1″, and another table, lets call it “table2″. Table1 references a row from table2, but I didn’t used foreign keys in these days. (I don’t if I didn’t know that they are exist or if InnoDB wasn’t available.) The Website has an admin tool which edits all the tables through some HTML forms. My mistake was that it is possible to delete a row from table2 which leaves all the rows in table1 referencing this row in table2 somehow broken. Today someone discovered this mistake I needed to clean this up. My idea was to create a simple query which cleans table1 and the alter the PHP which deleting rows from table2 to also clean up table1.

I started which the following query:

  1. DELETE FROM table1 WHERE id IN (
  2.   SELECT t1.id
  3.   FROM table1 AS t1
  4.   LEFT JOIN table2 AS t2 ON t1.key = t2.key
  5.   WHERE t2.key IS NULL
  6. )

Which leads to the following error:

#1093 - You can't specify target table 'table1' for update in FROM clause

I was some kind of shocked because I had no idea whats wrong with this query. After searching the web for a while I found out that it is some kind of bug in MySQL but there is a weird looking workaround: continue reading…

I am developing with JavaScript for a while and I am used to a lot of it quirks. But even after years of using this language you still find new curiosities. Today a struggled a while with this one.
Considering this piece of JavaScript code:

  1. var i = 10;
  2. function foo() {
  3.         i++; // i is now 11
  4.         console.log("foo1: "+i);
  5.         i = 0; // i is now 0
  6.         console.log("foo2: "+i);
  7. };
  8. console.log("global1: "+i); // should be 10
  9. foo();
  10. console.log("global2: "+i); // and now 0

Ok. That’s fine. Now we change the code a little bit to this one:

  1. var i = 10;
  2. function foo() {
  3.         i++; // is now 11
  4.         console.log("foo1: "+i);
  5.         var i = 0; //create a new variable with value 0
  6.         console.log("foo2: "+i);
  7. };
  8. console.log("global1: "+i); // expect: 10
  9. foo();
  10. console.log("global2: "+i); // expect: 11

What do you expect? I was quite surprised: continue reading…