be the change you want to see in the world
dan.hawk
This user hasn't shared any biographical information
Homepage: http://www.insightmed.eu
Posts by dan.hawk
Windows reloaded or failure reloaded?
Jun 3rd
Today i had some time to look inside of some newsletter i got in the last few days. One of them seemed pretty interesting because it was talking about a totally new Windows, with cool new stuff(yeah heard that before) and a complete new design(same here). While i wasn’t quite convinced about the last, i took a look at one of the videos presenting the new redesigned UI. In my oppion the changes look good, though they don’t bring something really spectacular compared to competition (in fact it shouldn’t, as it has to be still friendly for people coming from prior versions), but it’s a good change that strengthens my belief that Windows is one of the best choices for most of the people when it comes to daily computer usage. One interesting thing is that Microsoft started to impose restrictions for the Windows 8 tablet chipmakers according to windows8center.com, which in my oppinion is one of the best things they’ve did in the past decade … it should bring more quality, lower prices and most of all … a better experience(did they finally learn the apple philosophy?). – original post here
Anyway here are the videos.
And second one from the Windows 8 presentation in taiwan.
More information can be found on windows8center.com
Using the right tools at the right time
May 27th
Reading my daily dose of feeds on GReader, i came across on an older post from Bruno Lowagie’s blog (if iText rings any bells) explaining why software needs to be kept simple and oriented to its designed role and not doing a ton of things that don’t have anything to do with the initial target. I don’t know why but the story amuzes me everytime i read it. here it is:
Will Microsoft screw up on this too?
May 12th
Rumours are getting bigger and bigger everyday about Microsoft taking over Skype for 8.5 billion. At first look seems like a good move for Microsoft as Skype is in someway the missing link to the top of mobile/internet business. Everything seems great, but as far as users are concerned Microsoft does not have a good history when it comes to marketing/making stuff for mobiles or web. Only time can tell though if this is a good move both for Microsoft and for the users.
Original article here:
[rb] Fonts and their open source alternatives
May 11th
Swiss 921 – Antone by Vernon Adams [http://www.google.com/webfonts/preview#font-family=Anton]
* to be updated *
[rb]Custom doctrine count query
May 7th
Sometimes you may need to use count with the index column rather than *, because of some dark corners of sql driven databases. Though this is somehow rare, this is how you could do it with Doctrine … this example is part of a symfony 1.4 project(place the file in any of the /lib dirs … app ones or global one):
<?php
class Custom_Doctrine_Query extends Doctrine_Query {
public static function create($conn = null, $class = null)
{
if ( ! $class) {
$class = 'Custom_Doctrine_Query';
}
return new $class($conn);
}
public function getCustomCountSqlQuery()
{
// triggers dql parsing/processing
$this->getSqlQuery(array(), false); // this is ugly
// initialize temporary variables
$where  = $this->_sqlParts['where'];
$having = $this->_sqlParts['having'];
$groupby = $this->_sqlParts['groupby'];
$rootAlias = $this->getRootAlias();
$tableAlias = $this->getSqlTableAlias($rootAlias);
$primaryKey = $tableAlias . '.' . $this->_queryComponents[$rootAlias]['table']->getColumnName( $this->_queryComponents[$rootAlias]['table']->getIdentifier());
// Build the query base
$q = 'SELECT COUNT(' . $primaryKey . ') AS ' . $this->_conn->quoteIdentifier('num_results') . ' FROM ';
// Build the from clause
$from = $this->_buildSqlFromPart(true);
// Build the where clause
$where = ( ! empty($where)) ? ' WHERE ' . implode(' ', $where) : '';
// Build the group by clause
$groupby = ( ! empty($groupby)) ? ' GROUP BY ' . implode(', ', $groupby) : '';
// Build the having clause
$having = ( ! empty($having)) ? ' HAVING ' . implode(' AND ', $having) : '';
// Building the from clause and finishing query
if (count($this->_queryComponents) == 1 && empty($having)) {
$q .= $from . $where . $groupby . $having;
} else {
// Subselect fields will contain only the pk of root entity
$ta = $this->_conn->quoteIdentifier($tableAlias);
$map = $this->getRootDeclaration();
$idColumnNames = $map['table']->getIdentifierColumnNames();
$pkFields = $ta . '.' . implode(', ' . $ta . '.', $this->_conn->quoteMultipleIdentifier($idColumnNames));
// We need to do some magic in select fields if the query contain anything in having clause
$selectFields = $pkFields;
if ( ! empty($having)) {
// For each field defined in select clause
foreach ($this->_sqlParts['select'] as $field) {
// We only include aggregate expressions to count query
// This is needed because HAVING clause will use field aliases
if (strpos($field, '(') !== false) {
$selectFields .= ', ' . $field;
}
}
// Add having fields that got stripped out of select
preg_match_all('/`[a-z0-9_]+`\.`[a-z0-9_]+`/i', $having, $matches, PREG_PATTERN_ORDER);
if (count($matches[0]) > 0) {
$selectFields .= ', ' . implode(', ', array_unique($matches[0]));
}
}
// If we do not have a custom group by, apply the default one
if (empty($groupby)) {
$groupby = ' GROUP BY ' . $pkFields;
}
$q .= '(SELECT ' . $selectFields . ' FROM ' . $from . $where . $groupby . $having . ') '
. $this->_conn->quoteIdentifier('dctrn_count_query');
}
return $q;
}
public function count($params = array())
{
$q = $this->getCustomCountSqlQuery();
$params = $this->getCountQueryParams($params);
$params = $this->_conn->convertBooleans($params);
if ($this->_resultCache) {
$conn = $this->getConnection();
$cacheDriver = $this->getResultCacheDriver();
$hash = $this->getResultCacheHash($params).'_count';
$cached = ($this->_expireResultCache) ? false : $cacheDriver->fetch($hash);
if ($cached === false) {
// cache miss
$results = $this->getConnection()->fetchAll($q, $params);
$cacheDriver->save($hash, serialize($results), $this->getResultCacheLifeSpan());
} else {
$results = unserialize($cached);
}
} else {
$results = $this->getConnection()->fetchAll($q, $params);
}
if (count($results) > 1) {
$count = count($results);
} else {
if (isset($results[0])) {
$results[0] = array_change_key_case($results[0], CASE_LOWER);
$count = $results[0]['num_results'];
} else {
$count = 0;
}
}
return (int) $count;
}
}
The usage of the above class should be something like this:
$query = Custom_Doctrine_Query::create()->from('TargetTable t');
$count = $query->count();
or the bulky way omitting the static create method:
$query = Doctrine_Query::create(null, 'Custom_Doctrine_Query')->from('TargetTable t');
$count = $query->count();
The result of the above queries should be something like “SELECT COUNT(index_field) from target_table”.
Intel reinvents the micro-chip design
May 7th
Intel presented 2 days ago at San Francisco, one of the biggest breakthroughs of the last decade regarding the design of microchips, on which the new 22nm processor generations will be based. More information about it can be found here:
Transistors go 3D as Intel re-invents the microchip
and here
WTH swiftmailer
Apr 9th
Now it’s kindda obvious that swift mailer is the best php mail library, but as any other great php library it sometimes lets you right in the middle of nowhere, when you’re thinking everything should be fine. This was the case with a freshly downloaded version … everything went fine until Swift_KeyCache_KeyCacheInputStream interface not found in … to shorten the story … swift looks for that interface which is expected to be in the file KeyCache.php … the declaration seems to be missing from the downloaded package … the fix is pretty simple(though there is probably a good reason why it isn’t there anymore, but for a quick fix will do) … open /classes/Swift/KeyCache.php and add these lines:
interface Swift_KeyCache_KeyCacheInputStream extends Swift_InputByteStream
{
public function setKeyCache(Swift_KeyCache $keyCache);
public function setNsKey($nsKey);
public function setItemKey($itemKey);
public function setWriteThroughStream(Swift_InputByteStream $is);
public function __clone();
}
save it … and you’re good to go.
[snip] Doctrine update enum field
Feb 5th
$query = Doctrine_Query::create()->update('table')->set('field',Doctrine_Manager::connection()->quote('some_value', 'text'))->where('id = ?', $id);
[rb]symfony’s 1.4 sfForm isValid()
Someone asked me a few days ago how can he use the sfform validation feature to validate an object created “by hand”. While i’m not quite sure yet of the usage of such a thing, here’s my approach(we’ll assume we have a table called Selections with 4 fields like id(incremental/key/bigint), target_id(bigint), type(varchar), name(varchar)):
public function executeAdd(sfWebRequest $request) {
if($request->isXmlHttpRequest()) {
$this->setLayout(false);
$this->forward404Unless($id = $request->getParameter('id'));
$this->forward404Unless($type = $request->getParameter('type'));
$selection = new Selections();
$selection->setTargetId($id);
$selection->setType(ucfirst($type));
$selection->setName('DEFAULT');
$form = new SelectionsForm(null, array(), false);
$values = $selection->toArray();
$form->bind($values);
if($form->isValid()) { $form->save(); echo 'OK'; }
else {
echo 'ERROR';
}
return sfView::NONE;
} else $this->forward404();
}
