Skip to content

Instantly share code, notes, and snippets.

View antonmedv's full-sized avatar

Anton Medvedev antonmedv

View GitHub Profile
@antonmedv
antonmedv / DotNotation.php
Last active August 11, 2022 13:47
Dot notation for access multidimensional arrays.
<?php
/**
* Dot notation for access multidimensional arrays.
*
* $dn = new DotNotation(['bar'=>['baz'=>['foo'=>true]]]);
*
* $value = $dn->get('bar.baz.foo'); // $value == true
*
* $dn->set('bar.baz.foo', false); // ['foo'=>false]
*
@antonmedv
antonmedv / expect.coffee
Last active December 17, 2015 04:28
Check json structure: expect json, {mustBe: yes, sub: {weNeedThis: yes, butNotThis: no}}
exports.expect = expect = (json, pattern, throws = false, current = []) ->
condition = false
for own key, value of pattern
at = current.concat [key]
if typeof value is 'boolean'
condition = if value is true then json[key]? else not json[key]?
if not condition and throws
throw (if value is true then 'expected' else 'unexpected') + ' ' + at.join(' ')
else
if json[key]?
<?php
/* (c) Anton Medvedev <anton@elfet.ru>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Entity;
use Doctrine\ORM\Mapping as ORM;
<?php
$c='
<?php
$c=\'%s\';
printf($c, addslashes($c));';
printf($c, addslashes($c));
@antonmedv
antonmedv / Example.php
Created October 21, 2013 10:11
Example of getters and setters in PHP.
<?php
$foo = new Foo();
$foo->id = 1;
$foo->text = 'Hello';
echo $foo->id; // 1
echo $foo->text; // Hello World!
$(function () {
$("pre").each(function() {
var pre = $(this);
// Not for this
if (
pre.parents().hasClass('highlight') ||
pre.parents().hasClass('gist')
) {
return;
@antonmedv
antonmedv / Flyspeck.js
Last active November 26, 2019 07:01
Simple and Small Dependency Injection Container inspired by Pimple.
/*
* Flyspeck is Dependency Injection Container.
*
* Copyright (c) 2014 Anton Medvedev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
@antonmedv
antonmedv / asciitree.js
Last active July 25, 2018 06:37
JavaScript function to print ASCII Tree
/**
* (c) 2014 Anton Medvedev
*
* SELECT_________________
* / \ \
* .___ FROM JOIN
* / \ | / \
* a city_name people address ON
* |
* =___________
@antonmedv
antonmedv / inception.php
Created February 25, 2015 07:12
We need to go deeper.
<?php
$dream = 'Unicorn';
${'3 level'} = 'dream';
${'2 level'} = '3 level';
${'1 level'} = '2 level';
$DiCaprio = '1 level';
echo $$$$$DiCaprio;
// http://3v4l.org/RiB8b
@antonmedv
antonmedv / async_dom_loaded.js
Created June 10, 2015 12:06
Async DOM Content Loaded
/**
* Async DOM Content Loaded
*/
function onAsyncDOMContentLoaded(callback) {
if (document.readyState == 'loading') {
document.addEventListener('DOMContentLoaded', callback);
} else {
callback();
}