Archive for the ‘programming’ Category
Intial Divine Guardian Tests
I been wanting to look in the effectiveness of the 20% raid wall granted by Divine Guardian (4th tier talent in a Paladin’s protection tree). To do this I wrote a very simple Python program to read the combat log, detect with DG goes up and then record all the damage that was taken [...]
javascript; sending me insane
>>> []
[]
>>> [] == true
false
>>> [] == false
true
>>> [] == []
false
>>> false == false
true
total mysql rows
Turns out our Mysql server at work is a little bigger than I thought:
Databases 75
Tables 1,549
Rows 1,018,085,348
However over the last couple of months, we’ve only averaged 130 queries/second
Hacked up PHP to gather stats:
class MysqlCounter
{
public function __construct($host, $username, $password)
{
$this->conn = mysql_connect($host, $username, $password, true);
[...]
WoW Combat Log Splitter
Something quick I whipped up last night, after noticing that after my log file was > 4GB the WorldOfLogs parser will no longer do real time logging.
Edit: Turns out that the WoW client itself stopped logging, even though the log file was a little over expected limit (4,334,806,196 bytes)
Note: The code is just a one [...]
array_unique javascript snippet
function array_unique(a)
{
return a.reduce(function(u, e)
{
if(!(e in u))
u.push(e);
return u;
}, []);
}
Javascript map-sort
I’m sure sorting method has a real name, but I’ve had no luck searching for it.
function mapSort(array, mapFunction, sortFunction)
{
// Store both original value, and transformed value
var mapData = array.map(function(e)
{
return [e, mapFunction(e)];
});
// Sort the data using the second element of [...]
i hate working with dates
This little snippet gets all the days in a month, and groups them by week.
<?php
error_reporting(E_ALL);
// Return an array of all the days in a month grouped by week number
// (Sunday is considered to be the first day of the week)
function weeksInMonth($month, $year)
{
[...]
Extracing links from HTML using PHP
Many months ago there was a PHP competition to make the smallest script to extract all the links from a document. I’ve lost a link to the actual site, but the rules and conditions were set up expecting everyone to solve the problem with regular expressions. In my opinion relying on regular expressions [...]
Simple type checking in PHP
<?php
error_reporting(E_ALL | E_STRICT);
/*
Manual optional type checking for PHP functions
Basic example:
function log_error($line_number, $filename, $desc)
{
CheckFunctionArgs(‘integer’, ’string’, ’string’);
[snip]
}
Object example:
class LogObject {}
function register_object($obj)
{
// Check for [...]
sizeof(int) = 68
Pankaj Kumar has a slightly disturbing look at memory usage in PHP.
Each element requires a value structure (zval) which takes 16 bytes.
Also requires a hash bucket – which takes 36 bytes. That gives 52 bytes
per value. Memory allocation headers take another 8 bytes*2 – which
gives 68 bytes. Pretty close to what you have.