Skip to content

Instantly share code, notes, and snippets.

View robertbasic's full-sized avatar

Robert Basic robertbasic

View GitHub Profile
import xml.etree.ElementTree
xml = xml.etree.ElementTree.parse("file.xml")
root = xml.getroot()
elem = xml.etree.ElementTree.Element("foo")
>>> d
{'foo': 'bar'}
>>> keys
['foo', 'spam']
>>> for key in keys:
... if not d.has_key(key):
... d[key] = None
...
>>> d
{'foo': 'bar', 'spam': None}
10024 execve("/sbin/service", ["service", "httpd", "start"], [/* 27 vars */]) = 0
10024 brk(0) = 0x23fd000
10024 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcc39ac8000
10024 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
10024 open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
10024 fstat(3, {st_mode=S_IFREG|0644, st_size=96707, ...}) = 0
10024 mmap(NULL, 96707, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fcc39ab0000
10024 close(3) = 0
10024 open("/lib64/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = 3
10024 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220\315\0-<\0\0\0"..., 832) = 832
(gdb)
#0 0x000000d7000000d4 in ?? ()
#1 0x00007fffed261d07 in execute () from /etc/httpd/modules/libphp5.so
#2 0x00007fffed1f4520 in zend_call_function () from /etc/httpd/modules/libphp5.so
#3 0x00007fffed13fdc4 in ?? () from /etc/httpd/modules/libphp5.so
#4 0x00007fffed2a7f62 in ?? () from /etc/httpd/modules/libphp5.so
#5 0x00007fffed261d07 in execute () from /etc/httpd/modules/libphp5.so
#6 0x00007fffed202bde in zend_execute_scripts () from /etc/httpd/modules/libphp5.so
#7 0x00007fffed1a290d in php_execute_script () from /etc/httpd/modules/libphp5.so
#8 0x00007fffed2aa26a in ?? () from /etc/httpd/modules/libphp5.so
<?php
class Foo {
public function this($param) {
// $this->bar is object Bar
return $this->bar->this($param);
}
public function that($param) {
function! NumberToggle()
if(&relativenumber == 1)
set number
else
set relativenumber
endif
endfunc
nnoremap <C-A-n> :call NumberToggle()<cr>
@robertbasic
robertbasic / Test.php
Created September 13, 2012 20:42
Zend\Db\Adapter\Adapter mocking with mockery
<?php
protected function getAdapterMock()
{
$adapter = m::mock('Zend\Db\Adapter\Adapter');
$platform = m::mock('Zend\Db\Adapter\Platform\Mysql[getName]');
$stmt = m::mock('Zend\Db\Adapter\Driver\Pdo\Statement');
$paramContainer = m::mock('Zend\Db\Adapter\ParameterContainer');
$platform->shouldReceive('getName')
@robertbasic
robertbasic / Test.php
Created September 13, 2012 21:19
Chained returns of mocked objects
<?php
/**
* Ad-hoc unit tests for various scenarios reported by users
*/
class Mockery_AdhocTest extends PHPUnit_Framework_TestCase
{
public function setup ()
<?php
namespace Blog\View\Helper;
use Hex\View\Helper\ServiceLocatorAwareHelper;
use Zend\Tag\Cloud as ZendTagCloud;
use Zend\Tag\Cloud\Decorator\HtmlCloud as TagCloudDecorator;
use Zend\Tag\Cloud\Decorator\HtmlTag as TagCloudTag;
If you are a developer with knowledge of the routing system in Zend Framework 1.x, you should know that some of
the old terminology does not apply in Zend Framework 2.x. In the new routing system we don't have a router as
such, as every route can match and assemble URIs by themselves, which makes them routers, too.
That said, in most cases the developer does not need to worry about this, because Zend Framework 2.x will take
care of this "under the hood". Chances are that the work of the router will done by ``Zend\Mvc\Router\SimpleRouteStack``
or ``Zend\Mvc\Router\Http\TreeRouteStack``.