Skip to content

Instantly share code, notes, and snippets.

Avatar
⚔️
~

Ilia Andrienko andrienko

⚔️
~
View GitHub Profile
@andrienko
andrienko / wheel reinvented
Created Dec 7, 2013
I did it because I can.
View wheel reinvented
<?
class a{
public $something;
function output(){
echo("A happens!<br>");
}
}
class b{
View Callbacks
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 / JS function name
Last active Aug 29, 2015
Get the function name
View JS function name
Function.prototype.name = function(){
return this.toString().match(/function ([^\(]+)/)[1];
}
@andrienko
andrienko / JS assign
Created Mar 18, 2014
Assigning (extending) function.
View JS assign
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 / String sanitize
Created Mar 18, 2014
sanitize string to look more like identifier. Numberless.
View String sanitize
String.prototype.sanitize = function(){
return this.replace(/[^a-zA-Z]/g,'_').replace(/_{2,}/g,'_').toLowerCase().replace(/^_+|_+$/g,'');
}
View clone an object
if(typeof Object.prototype.clone !== 'function'){
Object.prototype.clone = function(){
var F= function(){};
F.prototype = this;
return new F();
};
}
@andrienko
andrienko / parameter trash
Created Jul 21, 2014
Passing parameters by their names, like some languages allow.
View parameter trash
<?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 / bandcamp
Last active Aug 29, 2015
Get links to all tracks on bandcamp page in pretty form
View bandcamp
document.body.innerHTML = ((function(d,o){
o.y=new Date(d.album_release_date).getFullYear();
o.r=['<h1>'+ o.a([d.artist,o.y,d.current.title].join(' - '),d.url)+'</h1>'];
(o.u = d.artFullsizeUrl) && o.r.push('<img src="'+ o.u+'"/>');
d.trackinfo.forEach(function(t){
for(o.i in t.file){}
o.r.push(o.a((""+t.track_num).replace(/^(\d{1})$/g,'0$1') + ' - '+ t.title+'.mp3',t.file[o.i]));
});
return o.r.join("<br/>\n");
View Dotted Plish
<?php
// Loading plish from hard drive and getting plish dimentions
$plish = imagecreatefrompng('plish.png');
list($x,$y) = array(imagesx($plish),imagesy($plish));
// --- Creating black image with dots
// Creating new image (black by default) with dimentions of a plish
$dots = imagecreatetruecolor($x,$y);
@andrienko
andrienko / gist:14331b88b0e877087a2f
Last active Aug 29, 2015
iOS safe cookie session start
View gist:14331b88b0e877087a2f
function cookiesafe_session_start(){
$sn = session_name();
if (isset($_COOKIE[$sn])) {
$sessid = $_COOKIE[$sn];
} else if (isset($_GET[$sn])) {
$sessid = $_GET[$sn];
} else {
session_start();
return false;
}