Recently in Code snippets Category

If you've created a new domain using xen-tools you might run into the situation that the console works, but if you SSH in you get:

"PTY allocation request failed on channel 0" and "stdin is not a tty"

You need to install udev. Connect via console (xm console <domain id>) (you can get <domain id> with xm list) and simply run:

apt-get install udev

And restart / stop+start. Problem solved!

PS: Don't forget to apt-get install build-essentials
For a client of mine we've been using mobile sync. To send the settings we use OTA OMA. Basically we make a XML file with settings, convert to WBXML. A good start guide can be found on http://mobiforge.com/developing/story/email-configuration-sms

I've found that sony ericsson phones (unlike Nokia) is more touchy on how to send username+password for sync (w5 type) application. This is a OK XML for SE+Nokia:

"<?xml version=\"1.0\"?>"
"<!DOCTYPE wap-provisioningdoc PUBLIC \"-//WAPFORUM//DTD PROV 1.0//EN\" \"http://www.wapforum.org/DTD/prov.dtd\">"
"<wap-provisioningdoc version=\"1.0\">"
"<characteristic type=\"APPLICATION\"> "
"    <parm name=\"APPID\" value=\"w5\"/> "
"    <parm name=\"NAME\" value=\"Radarspot LAB\"/> "
"    <characteristic type=\"APPADDR\"> "
"     <parm name=\"ADDR\" value=\"www.radarspotlab.com:8080/funambol/ds\"/> "
"    </characteristic> "
"    <characteristic type=\"APPAUTH\"> "
"     <parm name=\"AAUTHNAME\" value=\"%s\"/> "
"     <parm name=\"AAUTHSECRET\" value=\"%s\"/> "
"    </characteristic> "
"    <characteristic type=\"RESOURCE\"> "
      "<parm name=\"URI\" value=\"card\"/>"
      "<parm name=\"NAME\" value=\"Contacts DB\"/>"
"     <parm name=\"AACCEPT\" value=\"text/x-vcard;2.1,text/vcard;3.0\"/> "
"    </characteristic> "
"  </characteristic> "
"</wap-provisioningdoc>";

(Forgive me for the quotes, it's copy/past)

This is a mental note to myself. Somethings using pre-installed VPS the PHP executed by Apache is lacking the necessary permissions to run binary files (shellscript and built-in commands works fine though). It doesn't generate errors, it simply doesn't work.

Those VPS often has the PHP-CGI version installed and thus you can:

  1. Make your PHP script execute a shell script
  2. Init the shell script with PHP-CGI
  3. Execute
This is how the shell script in step 2 looks like:
#!/usr/bin/php
<?
exec('/home/user/www/mybinaryfiletoexecute');
?>

Note that the binary file must be in your www-dir.


Every now and then you have the (miss fortunate) to need sIFR. I usually go for the jquery plugin. However, jquery sIFR measures the width of the html text (not the block itself) and then creates a matching flash. Since flash text is often wider, a line break appears.

Thus - jquery sIFR needs support for css width.

In jquery.sifr.js, efter line 297 (sendOptions[height]), add:

if( $each.css(width) !== "auto" ) {
    sendOptions[width] = $each.css(width).replace('px','');
}else{
   sendOptions[width] = sendOptions[width] || $alt[0][offsetWidth] || $alt[0][parentNode][offsetWidth] || $each.css(width);
          }   

Works for me.. 
From time to time you have the need to duplicate an mysql database, here's how you do it:

mysqldump -u DB_user --password=DB_pass DB_name | mysql -u DB_user --password=DB_pass -h DB_host DB_name

Source

Sometimes you feel the need to have custom fonts in HTML and you feel like SIFR is the way to go. However, your happy feelins are battered because of your SIFR plugin line breaks at the wrong place. Often it's the last word that doesn't fit.

This problem occurs because SIFR measures the HTML width of the text. Depending on your custom font it's most likely less then your flash needs to be. You can solve this by adding:

letter-spacing: 100%;

or depending on your font:

letter-spacing: 30px;

To your CSS. It doesn't effect your none-sifr layout (if js is turned off) but it solves the sifr issue.

Source

For a multimedia project one of our clients at Happyplace wanted to burn a CD with:

  1. Audiotrack for stereos/car players
  2. PC Data with a flash projector which autostarts
  3. Mac data with a finder window that auto opens
This post is a reminder to myself how I did it. I am using Toast.

  1. Collect all PC data, add the autostart.inf and all that.
  2. Collect all Mac data and store it in a .dmg (more on this later)
  3. Burn the audio CD, make sure you use "write session" and not "write disc"
  4. In Toast -> Preferences -> Show legacy formats and settings
  5. Burn a custom Hybrid with the PC data and the mac .dmg
Collecting Mac data:
  1. Using the disc utility, create a new disc with a size that fit your needs (I used 100MB)
  2. Add all the data you need
  3. Set the finder background and size as you want, originize the icon you wish to show (I only show the .app file)
  4. Close and re-open the finder window to save you settings
  5. (You need to have Xtools installed for this) run the terminal command "/Developer/Tools/SetFile -a V /Volumes/Mounted Disc/file" to hide the file "file" on "Mounted Disc". This will make the file invisible
  6. To make the finder window autoopen, use: udo bless -folder /Volumes/Mounted \Disc/ -openfolder /Volumes/Mounted \Disc/
  7. That's it. Cool!
That should do the trick. You now have a CD that plays audio files in steroes and autostarts on PC and Mac with the appropriate files.

For various reasons, you might end up needing to put your mod_rewrite syntax in your httpd.conf, usually if you want to use basic rewriting, but with .htaccess support turned of.

In that case, you need to be aware that you need to add a / for it to work, like this:

From http://drupal.org/node/9418:
herefore :
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
becomes
RewriteRule ^/(.*)$ /index.php?q=$1 [L,QSA]
in my case


Some of us does not have a approved SMTP server on our development server, or are working outside the office. So how do you then send email when using Django as your python framework?

The answer is simple: Gmail

You will need:
  • A gmail account
  • Django (of course...)
Open up your settings.py and enter the following information:

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '<user>@gmail.com'
EMAIL_HOST_PASSWORD = '<password>
EMAIL_PORT = 587
EMAIL_USE_TLS = True

That's it. Given, you can't use it in your production environment. But it works like a charm during development. And if you need help sending html mail with alternative content (html+txt), check out Ross Poultons article Easy Multi-Part E-Mails with Django
By default, both Firefox and IE limits the number of connections per server too 2. Upping the value to 6-8 is a good way if you want to:

  • Browser faster (the connection limit is a usual bottleneck for fast connections)
  • Download more then 2 files at the same time

Firefox:
Go to the location bar and type:

about:config

This will give you all configuration alternatives for firefox, find (or search):

network.http.max-persistent-connections-per-server

and make it above 2, below 10.

IE
Following these instructions..

About this Archive

This page is a archive of recent entries in the Code snippets category.

Articles and seminars is the previous category.

Flash & FMS is the next category.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.21-en