Skip to content

Instantly share code, notes, and snippets.

<?php
$list = [];
$keys = ['a', 'x'];
foreach ($keys as $key) {
$list[] = ['key' => $key, 'quality' => 1];
}
array_walk($list, function (&$v, $k) {
// Decorate
@jk
jk / ReflectParameterClassHint.php
Last active August 29, 2015 14:13
Get parameter class type hint at runtime
<?php
class Language
{
public function getDefaultLanguage()
{
return "en-US";
}
}
class TestClass
{
<?php
class MockPhpStream
{
protected $index = 0;
protected $length = null;
protected $data = '';
public $context;
@jk
jk / generate_cache_key.php
Created December 25, 2014 12:41
Generate cache key from method invocation
<?php
class MyClass {
public function myFunction($myParam) {
$callee = debug_backtrace(null, 2)[1];
$method_string = $callee['class'].$callee['type'].$callee['function'].'('.implode(', ', $callee['args']).')';
return $method_string;
}
}
@jk
jk / .vimrc
Created December 9, 2014 10:22
set number
set backspace=indent,eol,start
set shiftwidth=4
set tabstop=4
set autoindent
set selectmode=mouse
set cmdheight=2
set nobackup
set nowritebackup
set ruler
@jk
jk / anonymous_array_map.php
Created December 3, 2014 10:31
Map array with closure
<?php
$array = range(0,4);
$add = 10;
// Beware: importing variables (i.e. $add) copies the variable, you can out-out by value (i.e. &$add)
$array = array_map(function($value) use ($add) {
return $value + $add;
}, $array);
var_dump($array);
@jk
jk / composer.json
Created October 6, 2014 06:25
Restler 3.0 RC6 composer.json
{
"require": {
"luracast/restler": "3.0.0-RC6",
"bshaffer/oauth2-server-php": "1.5",
"symfony/yaml": "2.5.5",
"rodneyrehm/plist": "2.0",
"luracast/restler": "3.0.0-RC6"
}
}
<?php
public class GermanPostalCodeToStateMap {
const STATE_BADEN_WUERTTEMBERG = 'Baden-Württemberg';
const STATE_BAYERN = 'Bayern';
const STATE_BERLIN = 'Berlin';
const STATE_BRANDENBURG = 'Brandenburg';
const STATE_BREMEN = 'Bremen';
const STATE_HAMBURG = 'Hamburg';
const STATE_HESSEN = 'Hessen';
@jk
jk / output.txt
Last active August 29, 2015 14:04
Parameter #0 [ <required> BaseClass $baseClass ]
array(4) {
'type hinted class' =>
string(9) "BaseClass"
'position' =>
int(0)
'default value available?' =>
bool(false)
'variable / param name' =>
string(9) "baseClass"
@jk
jk / gitlab.yml
Last active August 29, 2015 14:03
Draft for the gitlab docker container pull request
## Default project features settings
default_projects_features:
issues: {{PROJECT_DEFAULTS_ISSUES}} # can be true | false
merge_requests: {{PROJECT_DEFAULTS_MERGE_REQUESTS}} # can be true | false
wiki: {{PROJECT_DEFAULTS_WIKI}} # can be true | false
wall: {{PROJECT_DEFAULTS_WALL}} # can be true | false
snippets: {{PROJECT_DEFAULTS_SNIPPETS}} # can be true | false
visibility_level: "{{GITLAB_PROJECTS_VISIBILITY}}" # can be "private" | "internal" | "public"
## External issues trackers