01 December 2008

Making locales available without .UTF8 appendix on Ubuntu

In Ubuntu locales are added via

apt-get install language-pack-en-base

Where en is the langcode.
By default locales are added with UTF-8 encoding, and are available to the system via nl_NL.UTF-8 or en_US.UTF-8.

In some environments, PHP coms to mind, this UTF-8 appendix isn't really common. We want to be able to access a local via the langcode only.
To make this possible you have to do the following:

Edit /var/lib/locales/supported.d/ (in this example we'll use nl)
Add a line for each langcode without the .UTF-8 appendix, but leav te UTF-8 after the space intact. The file for nl will look like this when we're done:

nl_BE.UTF-8 UTF-8
nl_BE UTF-8
nl_NL.UTF-8 UTF-8
nl_NL UTF-8


Recreate the locales with:
locale-gen --purge

The locales are now available to the system without the UTF-8 extention.

11 November 2008

Reset bandwidth usage of user in DirectAdmin

To reset the monthly bandwidth usage of a user in DirectAdmin enter the following as root in a terminal:


echo 'action=reset&value=USERNAME&type=user' >> /usr/local/directadmin/data/task.queue
echo "" > /var/log/httpd/domains/DOMAIN.EXT.bytes
echo 'action=tally&value=all' >> /usr/local/directadmin/data/task.queue


The first line resets the bandwidth usage.
I'm not sure if the second line is necessarry, but it reset's the http bandwidth usage of said domain.
The last line recalculates the used bandwidth, shown in DirectAdmin.

17 April 2008

(C#) Flatten DataSet to DataTable

Starting with a valid DataSet:

DataSet s = new DataSet();
s.ReadXml(@"C:\orders.xml");

Add table name to all columns that aren't used for binding ...

foreach(DataTable table in s.Tables) {
foreach (DataColumn column in table.Columns)
{
if(!column.ColumnName.Contains("_Id")) column.ColumnName = table.TableName + "." + column.ColumnName;
}
}

Now join all using David M.'s great DataTable Join function (over at http://weblogs.sqlteam.com/davidm/archive/2004/01/20/748.aspx):

DataTable t = s.Tables[s.Relations[0].ChildTable.TableName];
foreach (DataRelation r in s.Relations)
{
t = Join(s.Tables[r.ParentTable.TableName], t, r.ParentColumns[0].ColumnName, r.ChildColumns[0].ColumnName);
}

List removeColumns = new List();
foreach (DataColumn c in t.Columns) if (c.ColumnName.Contains("_Id")) removeColumns.Add(c.ColumnName);
foreach (string cName in removeColumns) t.Columns.Remove(cName);

Pretty easy, huh ;)

01 April 2008

Import MySQL databases with foreign keys

When importing large MySQL databases with lots of tables that have foreign key constrains (such as in our application framework RedOne), these constraints often interfere with each other. So ...

SET FOREIGN_KEY_CHECKS = 0;

... then dump, and afterwards ...

SET FOREIGN_KEY_CHECKS = 1;

... tadaa! :)