Skip to content

Instantly share code, notes, and snippets.

View andrienko's full-sized avatar
🇺🇦
~

Ilia Andrienko andrienko

🇺🇦
~
View GitHub Profile
@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{
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 August 29, 2015 13:57
Get the function name
Function.prototype.name = function(){
return this.toString().match(/function ([^\(]+)/)[1];
}
@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 / 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 / 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 / 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 / bandcamp
Last active August 29, 2015 14:12
Get links to all tracks on bandcamp page in pretty form
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");
<?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 August 29, 2015 14:21
iOS safe cookie session start
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;
}