This is a list of tips for the Vim editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
See README.md for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def enum(*sequential, **named): | |
enums = dict(zip(sequential, range(len(sequential))), **named) | |
reverse = dict((value, key) for key, value in enums.iteritems()) | |
enums['reverse_mapping'] = reverse | |
return type('Enum', (), enums) | |
def example(): | |
Numbers = enum(ONE=1, TWO=2, THREE='three') | |
print Numbers.ONE | |
print Numbers.THREE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class JsonSortTest extends PHPUnit_Framework_TestCase { | |
public $fixtureFilename = 'fixture.json'; | |
public $outputFilename = 'output.json'; | |
public $fixtureJson; | |
function ksortObjectsRecursive(&$data, $sortFlags = SORT_REGULAR) { | |
if (!function_exists('ksortObjectsRecursiveCallback')) { | |
function ksortObjectsRecursiveCallback(&$data, $unusedKey, $sortFlags) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function getNewGUID($wrapWithBraces = false) { | |
if (function_exists('com_create_guid')) { | |
return com_create_guid(); | |
} else { | |
mt_srand((double)microtime() * 10000); //optional for php 4.2.0 and up. | |
$charid = strtoupper(md5(uniqid(rand(), true))); | |
$uuid = ($wrapWithBraces ? '{' : '') | |
. substr($charid, 0, 8) . '-' | |
. substr($charid, 8, 4) . '-' | |
. substr($charid, 12, 4) . '-' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* With PHPUnit one can easily mock a class that implements a fluent interface. | |
* | |
* This will make any method call to your mock object return a reference to itself. | |
*/ | |
$mock = $this->getMock('MyClass'); | |
$mock->expects($this->any()) | |
->method(new PHPUnit_Framework_Constraint_IsAnything()) | |
->will($this->returnSelf()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
digraph G { | |
label = "GitHub Workflow\nSource: https://goo.gl/79JCB9" | |
labelloc = "t" | |
subgraph cluster_upstream { | |
label = upstream | |
style = filled | |
color = lightgrey | |
node [style = filled color = white] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class ClassUtil | |
* | |
* Provide useful methods to overcome OOP shortcomings in some versions of PHP. | |
*/ | |
class ClassUtil { | |
/** | |
* The "::class" notation isn't available until PHP 5.5. This method is a workaround for | |
* older versions of PHP. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SplEnumPlus extends \SplEnum { | |
static function hasKey($key) { | |
$foundKey = false; | |
try { | |
$enumClassName = get_called_class(); | |
new $enumClassName($key); | |
$foundKey = true; | |
} finally { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class BetterEnum | |
* | |
* A pure-PHP alternative to SplEnum, although only a 99% compatible replacement for it. | |
* | |
* See: http://php.net/manual/en/class.splenum.php | |
* | |
* To declare an enum class, subclass BetterEnum and define the names and values as constants. |