2010
04.12

Backups are crucial!
Since that is fact I wrote a little script in Python to easily backup mysql databases on a linux server.

  Python Mysqldump Backup 1.1 (858 bytes, 578 hits)


How do i configure it?
After you downloaded the script to your Linux server you will need a few Linux packages. Execute the following commands as root:

apt-get update
apt-get install python mysqldump bzip2

What does it do?
This script dumps a certain database (or all databases) into a single mysql file, which is zipped (bzip2) afterwards.

Now edit the script with your preferred editor.

vim mysqldump-backup.py

Customize the following lines:

# 2. Config
mysqlUser = “root”
mysqlPwd = “YOUR_PASSWORD”
mysqlDatabase = “–all-databases”
dumpDir = “/tmp/”
dumpFile = “mysqldump-” + strftime(“%Y-%m-%d-%H-%M-%S”, gmtime()) + “.sql”

The last step is to make the script executable:

chmod u +x mysqldump-backup-1.1.py

Thats it!

You can now run the script:

/path/to/the/script/mysqldump-backup-1.1.py

To run it daily (crontab):

crontab -e

Add at the bottom:

0 3 * * * /path/to/the/script/mysqldump-backup.py

Now your databases will be backupped daily at 03:00 am

Download

  Python Mysqldump Backup 1.1 (858 bytes, 578 hits)

Changelog
1.1

  • Removed trailing semicolons
  • Renamed variables

1.0

  • Initial release

Have fun!
Andreas Glaser aka JaZz

2010
03.26

I just came across a problem with “Drupal” related to my server configuration.
I tried to set the user permissions and Drupal would tell me “Validation error, please try again. If this error persists, please contact the site administrator.”.

This error was caused be the php extension “suhosin” which limits the maximal length of post requests.

To fix that open /etc/php5/apache2/conf.d/suhosin.ini and increase the value of suhosin.request.max_value_length to your needs.

2010
03.24

This function retrieves vocabulary names by their id.

getVocabularyNameByVID($vid)

1
2
3
4
5
6
7
8
9
10
11
function getVocabularyNameByVID($vid) {
  /* make sure vid is numeric */
  if(!is_numeric($vid)) return false;
 
  /* fetch name */
  $result = db_query("SELECT name FROM {vocabulary} WHERE vid = %d", $vid);
  $name = db_fetch_object($result)->name;
 
  /* return name or false if not found */
  return $name ? $name : false;
}

Usage

1
print getVocabularyNameByVID(1);
2010
03.22

PHP as well as most (all?) other programming languages provide different ways to comment source code.
Most common comment indicators are # , // and /* */ .

1
2
3
4
5
6
# this is a comment
echo 'print something';
// another comment
phpinfo();
/* and one more */
var_dump($_ENV);

Which one should I use?

# vs //

I definitely tend to # since it’s only one character instead of two slashes.

# and // vs. /* */

If you plan to pack your code I would highly recommend to always use /* */ due to it’s source code packer compatibility.

/* */ also provides multi line commenting.

1
2
3
4
5
/**
* this
* is a
* valid comment
**/

So long,
JaZz

2009
12.14

Well, “perfect” might be a little exaggerated although I consider this a good configuration at the moment.
You can put this globally into your httpd.conf or separately in every vhost configuration file you need it.

1
2
3
4
5
6
7
8
9
10
 
        ExpiresActive On
        ExpiresByType text/css "access plus 1 month"
        ExpiresByType text/javascript "access plus 1 month"
        ExpiresByType application/x-javascript "access plus 1 month"
        ExpiresByType application/javascript "access plus 1 month"
        ExpiresByType image/png "access plus 1 year"
        ExpiresByType image/jpeg "access plus 1 year"
        ExpiresByType image/gif "access plus 1 year"
        ExpiresByType image/x-icon "access plus 1 month"

Make sure you versionize your JavaScript/CSS to be able to force an update, in case you change them.
Example:

1
2
3
4
5
6
 
    My Example
 
Some Content
 
    <script src="javascript.js?version=1" type="text/javascript"><!--mce:0--></script>

You should also give newly updated pictures new names!

Over and out,
JaZz

2009
12.12

This is a collection of 40 awesome SPB Mobile Shell Wallpapers (Backgrounds).

  SPB Mobile Shell Wallpapers Vol. 2 (9.5 MiB, 2,893 hits)



  SPB Mobile Shell Wallpapers Vol. 2 (9.5 MiB, 2,893 hits)

All credit goes to the artists of the wallpapers!

Click here to get to Vol. 1

Enjoy,
JaZz

2009
12.04

Every once in a while I’m using one of the freely available JavaScript classes to generate a web2.0ish content rating function. Somehow I felt like creating my own. Of course I don’t wanna hold it back… so… here it is. Enjoy!

Features

  • Fully Customizable
  • Ajax Request
  • Callback
  • Lightweight

Examples

The behavior can be easily changed by customizing following parameters

?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
        var options = {
          scale: 5,
          initialValue: 0,
          locked: false,
 
          lockAfterRating: false,
          setBackAfterRating: false,
 
          ID: 'example-004',
 
          ajax: true,
          ajaxMethod: 'post',
          ajaxAction: 'ajax-request-processor.php',
          ajaxVariable: 'Rating',
          ajaxAdditional: '&amp;OptionalVar=123',
 
          callFunction: true,
          callFunctionName: 'callbackExample',
 
          starFilled: '../images/star-2-filled.png',
          starEmpty: '../images/star-2-empty.png'
        };
 
        new JaZzStars(options);

Download

  JaZz Stars 1.0.1 - JavaScript Content Rating Class (59.4 KiB, 257 hits)

Changelog:
2009-12-04 – 1.0.1

  • Minor fixes

2009-12-04 – 1.0

  • Initial Release
2009
12.03

I just came across a script I have totally forgotten about, which I wrote quite a while ago.
I haven’t managed to write a real documentation so far… anyway… feel free to try it.

All you need to do, is to install php in case you haven’t done it already!

  SRCD/HTTP Synchronizer (1.9 KiB, 282 hits)

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#! /bin/php

<?PHP
/*
SRCDS FastDownload Syncronizer 
Version: 1.0
 
Author:
Andreas Glaser (JaZz)
www.andreas-glaser.com
 
*/
############################*
# Variables (DO NOT TOUCH):
#
$Config = array();
$Files = array();
 
############################*
# Configuration (Required):
#
// :: CONFIG
// :: CONFIG ~ BZIP2
$Config['Bzip2']['Enabled'] = true;
 
// Enable or diable bzip2 compression
$Config['Bzip2']['Path'] = '/bin/bzip2';
 
// Path to Bzip2 (default: /bin/bzip2)
$Config['Htdocs']['Delete'] = false;
 
// Determines whether obsolete files in the webdirectory beeing deleted
$Config['Htdocs']['Override'] = false;
 
// Determines if every time you synchonize your directories the file gonna be overriden
$Config['Chmod']['Enabled'] = true;
 
// Enable or disable to set new RWX rights
$Config['Chmod']['Access'] = '755';
 
// Sets the new
$Config['Chmod']['Path'] = '/bin/chmod';
 
// Path of Chmod
$Config['Chown']['Enabled'] = true;
 
// Determines if you like to set a new user for the synchonizes web files
$Config['Chown']['User'] = 'web001';
 
// Owner of the synchronized files
$Config['Chown']['Group'] = 'web';
 
// Group of the synchronized files
$Config['Chown']['Path'] = '/bin/chown';
 
// Path to Chown
// :: CONFIG ~ PATHS
$Config['Paths']['cstrike'] = '/path/to/your/srcds/';
 
// Path to your CounterStrike Server
$Config['Paths']['htdocs'] = '/path/to/your/htcods/fastdl/';
 
// Path to your web directory
$Config['Paths']['syn_dirs'][] = 'maps';
 
// Directoriyto synchronize
$Config['Paths']['syn_dirs'][] = 'materials';
 
// Directory to synchronize
$Config['Paths']['syn_dirs'][] = 'models';
 
// Directory to synchronize
$Config['Paths']['syn_dirs'][] = 'resource';
 
// Directory to synchronize
$Config['Paths']['syn_dirs'][] = 'sound';
 
// Directory to synchronize
// :: Config Check (DO NOT TOUCH)
@exec('whoami', $Output);
if ($Output[0] !== 'root') {
  exit('Error: You must be logged in as root'."\n");
}
file_exists($Config['Paths']['cstrike']) && is_dir($Config['Paths']['cstrike']) or exit('Error: The selected cstrike directory does not exist'."\n");
file_exists($Config['Paths']['htdocs']) && is_dir($Config['Paths']['htdocs']) or exit('Error: The selected htdocs directory does not exist'."\n");
if ($Config['Bzip2']['Enabled'] === true) {
  file_exists($Config['Bzip2']['Path']) or exit('Error: Bzip2 was not found on your system'."\n");
}
if ($Config['Chmod']['Enabled'] === true) {
  file_exists($Config['Chmod']['Path']) or exit('Error: Chmod was not found on your system'."\n");
}
if ($Config['Chown']['Enabled'] === true) {
  file_exists($Config['Chown']['Path']) or exit('Error: Chown was not found on your system'."\n");
}
foreach ($Config['Paths']['syn_dirs'] AS $Key => $Val) {
  file_exists($Config['Paths']['cstrike'].$Val.'/') or exit("\n".$Val.' does not exist'."\n");
}
foreach ($Config['Paths']['htdocs'] AS $Key => $Val) {
  file_exists($Config['Paths']['cstrike'].$Val.'/') or exit("\n".$Val.' does not exist'."\n");
}
 
// :: Do it (DO NOT TOUCH)
echo "\n".'<<< START SYNCHRONIZATION >>>'."\n";
foreach ($Config['Paths']['syn_dirs'] AS $Key => $Val) {
  indexCstrike($Config['Paths']['cstrike'], $Val);
}
if ($Config['Htdocs']['Delete'] === true) {
  indexHtdocs($Config['Paths']['htdocs']);
 
  // :: Delete needless files in htdocs
  foreach ($Files['HTDOCS']['FILES'] AS $Key => $Val) {
    $SubDir = substr($Key, strlen($Config['Paths']['htdocs']));
    if ($Config['Bzip2']['Enabled'] === true) {
      if (substr($SubDir, - 4) == '.bz2') {
        $SubDir = substr($SubDir, 0, - 4);
      }
    }
    if (!isset($Files['CSTRIKE']['FILES'][$Config['Paths']['cstrike'].$SubDir])) {
      unlink($Config['Paths']['htdocs'].$SubDir);
    }
  }
 
  // :: Delete needless directories in htdocs
  foreach ($Files['HTDOCS']['DIRS'] AS $Key => $Val) {
    $SubDir = substr($Key, strlen($Config['Paths']['htdocs']));
    if ($Config['Paths']['htdocs'].$SubDir !== $Config['Paths']['htdocs']) {
      if (!isset($Files['CSTRIKE']['DIRS'][$Config['Paths']['cstrike'].$SubDir])) {
        rmdir($Config['Paths']['htdocs'].$SubDir);
      }
    }
  }
}
 
// :: Sync Directories
foreach ($Files['CSTRIKE']['DIRS'] AS $Key => $Val) {
  $SubDir = substr($Val, strlen($Config['Paths']['cstrike']), - 1);
  if (!file_exists($Config['Paths']['htdocs'].$SubDir)) {
    mkdir($Config['Paths']['htdocs'].$SubDir, 0777);
  }
}
 
// :: Sync Files
$tmp_Counter = 0;
foreach ($Files['CSTRIKE']['FILES'] AS $Key => $Val) {
  if ($tmp_Counter !== 0 && ($tmp_Counter % 4) === 0) {
    echo '.';
  }
  $tmp_Counter++;
  $SubDir = substr($Key, strlen($Config['Paths']['cstrike']));
  if (!file_exists($Config['Paths']['htdocs'].$SubDir.'.bz2')) {
    if (!file_exists($Config['Paths']['htdocs'].$SubDir)) {
      copy($Key, $Config['Paths']['htdocs'].$SubDir);
      if ($Config['Bzip2']['Enabled'] === true) {
        $LastLine = system($Config['Bzip2']['Path'].' -9 '.str_replace(' ', '\ ', $Config['Paths']['htdocs'].$SubDir), $RetVal);
      }
    }
    else {
      if ($Config['Htdocs']['Override'] === true || $Val['Size'] !== filesize($Config['Paths']['htdocs'].$SubDir)) {
        unlink($Config['Paths']['htdocs'].$SubDir);
        copy($Key, $Config['Paths']['htdocs'].$SubDir);
        if ($Config['Bzip2']['Enabled'] === true) {
          $LastLine = system($Config['Bzip2']['Path'].' -9 '.str_replace(' ', '\ ', $Config['Paths']['htdocs'].$SubDir), $RetVal);
        }
      }
      else {
        if ($Config['Bzip2']['Enabled'] === true) {
          $LastLine = system($Config['Bzip2']['Path'].' -9 '.str_replace(' ', '\ ', $Config['Paths']['htdocs'].$SubDir), $RetVal);
        }
      }
    }
  }
  else {
    if ($Config['Htdocs']['Override'] === true && $Config['Bzip2']['Enabled'] === true) {
      unlink($Config['Paths']['htdocs'].$SubDir.'.bz2');
      copy($Key, $Config['Paths']['htdocs'].$SubDir);
      $LastLine = system($Config['Bzip2']['Path'].' -9 '.str_replace(' ', '\ ', $Config['Paths']['htdocs'].$SubDir), $RetVal);
    }
  }
}
unset($tmp_Counter);
if ($Config['Chmod']['Enabled'] === true) {
  system('chmod -R '.$Config['Chmod']['Access'].' '.$Config['Paths']['htdocs'], $RetVal);
}
if ($Config['Chown']['Enabled'] === true) {
  system('chown -R '.$Config['Chown']['User'].':'.$Config['Chown']['Group'].' '.$Config['Paths']['htdocs'], $RetVal);
}
echo "\n".'<<< DONE >>>'."\n";
echo "\n".'| INFORMATION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|';
echo "\n".'| Script:         SRCDS FastDownload Syncronizer                  |';
echo "\n".'| Version:        1.0                                             |';
echo "\n".'| Author:         Andreas Glaser                                  |';
echo "\n".'| Website:        www.andreas-glaser.com                          |';
echo "\n".'| Creation Date:  2009-01-14                                      |';
echo "\n".'| Last Update:    2009-01-14                                      |';
echo "\n".'|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|'."\n";
 
function indexCstrike($Dir = NULL, $SubDir = 'subdir')
{
  global $Files;
  $Dir = $Dir.$SubDir.'/';
  $Files['CSTRIKE']['DIRS'][$Dir] = $Dir;
  if (file_exists($Dir)) {
    $handler = opendir($Dir);
    while ($file = readdir($handler)) {
      if ($file != '.' && $file != '..') {
        if (!is_dir($Dir.$file)) {
          $Files['CSTRIKE']['FILES'][$Dir.$file]['Size'] = filesize($Dir.$file);
        }
        else {
          indexCstrike($Dir, $file);
        }
      }
    }
    closedir($handler);
  }
}
 
function indexHtdocs($Dir = NULL, $SubDir = 'subdir')
{
  global $Files;
  if ($SubDir !== 'subdir') {
    $Dir = $Dir.$SubDir.'/';
  }
  $Files['HTDOCS']['DIRS'][$Dir] = $Dir;
  if (file_exists($Dir)) {
    $handler = opendir($Dir);
    while ($file = readdir($handler)) {
      if ($file != '.' && $file != '..') {
        if (!is_dir($Dir.$file)) {
          $Files['HTDOCS']['FILES'][$Dir.$file]['Size'] = filesize($Dir.$file);
        }
        else {
          indexHtdocs($Dir, $file);
        }
      }
    }
    closedir($handler);
  }
}
?>

  SRCD/HTTP Synchronizer (1.9 KiB, 282 hits)

JaZz

2009
11.26

For the best video quality with the default video player, choose following setting in you video converter.
I would recommend to use “Super” which converts almost any format!

Max Resolution: 800x480px
Container: MP4
Codec: H.264/AVC
Bitrate: 768kbs (maybe a bit more)
Framerate: 25

Audio Codec: AAC LC
Bitrate: 112kbs
Frequency: 44100

External Links

2009
11.11

Unfortunately Subversion provides no inbuilt function to add all new files at once.
This however is a solution:

1
svn status | grep "^?" | awk '{print $2}' | xargs svn add

Enjoy,
JaZz