Skip to content

Instantly share code, notes, and snippets.

View lsolesen's full-sized avatar

Lars Olesen lsolesen

View GitHub Profile
@lsolesen
lsolesen / gist:327883
Created March 10, 2010 14:00
Make mysql query use an index
/* I want to run this query: */
SELECT SUM( price ) AS total_price, date_month
FROM daily
WHERE processed =0
AND date_month = '200910'
AND customerid =1
GROUP BY date_month, customerid
/* On this table */
<?php
require_once 'Translation2/Admin.php';
$file = dirname(__FILE__) . "/i18n.xml";
@unlink($file);
touch($file);
$driver = "XML";
$options = array(
"filename" => $file
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html xmlns="http://www.w3.org/1999/xhtml" lang="da">
<head>
<title>Intraface.dk</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
@import "/core/css/stylesheet.php?theme=2&amp;fontsize=small";
</style>
<link rel="stylesheet" href="/core/css/print.css" type="text/css" media="print" title="Printvenlig" />
<script type="text/javascript" src="/core/javascript/yui/yahoo/yahoo-min.js"></script>
<?php
if(!isset($picture_size) || $picture_size == '') {
$picture_size = 'thumbnail';
}
$only_show_products_with_pictures = 1;
?>
<?php if (is_array($products) AND count($products) > 0): ?>
<?php if(isset($headline) && $headline != ''): ?>
@lsolesen
lsolesen / Howto replace deprecated ereg() function?
Created May 19, 2010 21:20
Howto replace deprecated ereg() function?
<?php
/**
* Validator
*
* @author Lars Olesen <[email protected]>
* @author Sune Jensen <[email protected]>
*/
require_once 'Validate.php';
@lsolesen
lsolesen / intl
Created May 24, 2010 08:37
Using intl pecl extension
// using the intl pecl extension
$datefmt = new IntlDateFormatter("da-DK", IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, date_default_timezone_get());
$danish = '2010-10-10 10:10:10';
$formatted = $datefmt->format(strtotime($danish)); // 10/10/10 10.10
echo $parsed = $datefmt->parse($formatted); // 1286698200
$fmt = new NumberFormatter( 'da_DK', NumberFormatter::DECIMAL );
$num = "1234.567,891";
$parsed_number = $fmt->parse($num); // 1234567.891
@lsolesen
lsolesen / gist:584072
Created September 17, 2010 11:18
Using mock in python
#!/usr/bin/env python
from mock import Mock
mock_xmlservice = Mock()
mock_xmlservice.foo = Mock()
mock_xmlservice.foo.return_value = "result"
mock_xmlservice.foo()
# Will output "result" - so now it works
@lsolesen
lsolesen / git build-failed file for cijoe
Created December 8, 2010 23:52
build-failed git hook for cijoe
#!/usr/bin/env bash
# Note the use of env. This is because executables may not be placed in the same place on all systems. Notoriously, bsd (and thus mac osx) differs from linux. However, /usr/bin/env always exists in the same place, and it can tell you where other executables are. Thus, the above is good style for portability.
COMMIT_VERSION=$(git rev-parse --verify HEAD)
COMMIT_LOG=$(git log -n 1)
# You could also use backticks, but the $() syntax is generally more readable
# Convention is to put variables in uppercase in shell script
LOG="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "${COMMIT_LOG}")"
curl -k -u user:password \
@lsolesen
lsolesen / ci-project.sh
Created December 10, 2010 18:37
checking for svn update. if updated run unit test
#!/usr/bin/env bash
# Note the use of env. This is because executables may not be placed in the same place on all systems. Notoriously, bsd (and thus mac osx) differs from linux. However, /usr/bin/env always exists in the same place, and it can tell you where other executables are. Thus, the above is good style for portability.
# Convention is to put variables in uppercase in shell script. The $() syntax is generally more readable
# You can embed a variable in a string, using the ${VAR_NAME} syntax
LOCAL_VERSION=$(svn info /var/www/project |grep Revision: |cut -c11-)
HEAD_VERSION=$(svn info /var/www/project -r 'HEAD' |grep Revision: |cut -c11-)
if [ ${LOCAL_VERSION} != ${{HEAD_VERSION} ]; then
@lsolesen
lsolesen / TestListener.php
Created December 10, 2010 18:40
Testlistener for phpunit notifying on error
<?php
class TestListener implements PHPUnit_Framework_TestListener
{
protected $errors;
protected $error_count;
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
{
$this->error_count++;
}