Skip to content

Instantly share code, notes, and snippets.

View andrienko's full-sized avatar
🇺🇦
~

Ilia Andrienko andrienko

🇺🇦
~
View GitHub Profile
@andrienko
andrienko / parameter trash
Created July 21, 2014 17:17
Passing parameters by their names, like some languages allow.
<?php
function _f($callback,$arguments) {
if(!is_callable($callback))throw new Exception('Function '.$callback.' does not exist.');
$params = new ReflectionFunction($callback);
$params = $params->getParameters();
$argNames = array(); foreach ($params as $param){
$argNames[] = $param->name;
@andrienko
andrienko / clone an object
Created March 19, 2014 16:46
cloning object
if(typeof Object.prototype.clone !== 'function'){
Object.prototype.clone = function(){
var F= function(){};
F.prototype = this;
return new F();
};
}
@andrienko
andrienko / String sanitize
Created March 18, 2014 12:13
sanitize string to look more like identifier. Numberless.
String.prototype.sanitize = function(){
return this.replace(/[^a-zA-Z]/g,'_').replace(/_{2,}/g,'_').toLowerCase().replace(/^_+|_+$/g,'');
}
@andrienko
andrienko / JS assign
Created March 18, 2014 10:43
Assigning (extending) function.
assign = function(par,child,func){
var theOldOne = par[child];
par[child] = function(){
theOldOne.call(this,arguments);
func.call(this,arguments);
}
}
assign(window.console,'log',function(args){alert(args);});
@andrienko
andrienko / JS function name
Last active August 29, 2015 13:57
Get the function name
Function.prototype.name = function(){
return this.toString().match(/function ([^\(]+)/)[1];
}
document.registerCallback = function(callbackEvent, callbackFunction){
if(typeof document.callbacks == 'undefined')document.callbacks = {};
if(typeof document.callbacks[callbackEvent]=='undefined')document.callbacks[callbackEvent]=[];
document.callbacks[callbackEvent].push(callbackFunction);
return callbackFunction;
};
document.runCallbacks = function(callbackEvent,arguments){
for(var name in document.callbacks[callbackEvent]){
document.callbacks[callbackEvent][name].apply(null,arguments);
@andrienko
andrienko / wheel reinvented
Created December 7, 2013 12:19
I did it because I can.
<?
class a{
public $something;
function output(){
echo("A happens!<br>");
}
}
class b{