Skip to content

Instantly share code, notes, and snippets.

View lastguest's full-sized avatar
❄️
I may be slow to respond.

Stefano Azzolini lastguest

❄️
I may be slow to respond.
View GitHub Profile
@lastguest
lastguest / JSON_to_URLEncoded.js
Created July 10, 2014 17:47
Convert JavaScript object to x-www-form-urlencoded format
function JSON_to_URLEncoded(element,key,list){
var list = list || [];
if(typeof(element)=='object'){
for (var idx in element)
JSON_to_URLEncoded(element[idx],key?key+'['+idx+']':idx,list);
} else {
list.push(key+'='+encodeURIComponent(element));
}
return list.join('&');
}
@lastguest
lastguest / jenkins_one_at_a_time_hash.php
Last active March 20, 2024 14:11
Bob Jenkins' One-At-A-Time hashing algorithm.
<?php
// Bob Jenkins' One-At-A-Time hashing algorithm.
function jenkins_hash($key) {
$key = (string)$key;
$len = strlen($key);
for($hash = $i = 0; $i < $len; ++$i) {
$hash += ord($key[$i]);
$hash += ($hash << 10);
$hash ^= ($hash >> 6);
@lastguest
lastguest / append_on_copy.js
Created May 20, 2015 13:25
[JavaScript] Append text on clipboard copy from a page.
document.addEventListener('copy', function() {
//Get the selected text and append the extra info
var selection = window.getSelection(),
pagelink = '<br /><br /> Read more at: ' + document.location.href,
copytext = selection + pagelink,
newdiv = document.createElement('div');
//hide the newly created container
newdiv.style.position = 'absolute';
newdiv.style.left = '-99999px';
@lastguest
lastguest / excel_to_array.php
Created April 3, 2014 16:43
Read an Excel sheet as PHP array. (Needs PHPExcel)
<?php
// Needs PHPExcel
// https://phpexcel.codeplex.com/
function excel_to_array($inputFileName,$row_callback=null){
if (!class_exists('PHPExcel')) return false;
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
@lastguest
lastguest / access_property.php
Last active January 24, 2024 09:18
PHP - Read/Write public/protected/private object property
<?php
// Access a property with no restrictions
function stole($object,$property){
$dict = (array)$object;
$class = get_class($object);
return isset($dict[$property])?
$dict[$property]:(isset($dict["\0*\0$property"])?
$dict["\0*\0$property"]:(isset($dict["\0$class\0$property"])?
$dict["\0$class\0$property"]:null));
@lastguest
lastguest / dabblet.css
Created August 21, 2012 09:31 — forked from daneden/dabblet.css
Photo Stack Gallery
/**
* Photo Stack Gallery
*/
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
@lastguest
lastguest / event.function.php
Last active September 6, 2023 23:24
PHP global event handling in a single function.
<?php
/*
* Use
* event('eventname',function(){ ... })
* to add an event handler for 'eventname' event.
*
* Trigger an event with
* event('eventname')
*
@lastguest
lastguest / Chainable.class.php
Last active March 17, 2023 09:46
PHP Class Chainable.Wrapper for convenient chaining methods.
<?php
/**
* Class Chainable
* Wrapper for convenient chaining methods
*
* @author Stefano Azzolini <lastguest@gmail.com>
*/
class Chainable {
private $instance = null;
@lastguest
lastguest / getSocialFollowersFor.php
Last active October 6, 2022 17:27
[Get followers for various social platforms] #PHP #outdated
<?php
function getSocialFollowersFor($usernames){
$preg_extract = function($p,$t,$g=0){preg_match($p,$t,$m);return @$m[$g];};
$results = [];
if(!is_array($usernames)){
$tmp = [
'pinterest' => $usernames,
'facebook' => $usernames,
@lastguest
lastguest / C.php
Created September 6, 2015 22:26
[PHP] Tweet sized micro container
<?php
class C{static function __callStatic($n,$p){static$_;return($f=&$_[$n])?$f():$f=$p[0];}}
C::now(function(){
return new DateTime();
});
var_dump(C::now());
/*