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 / dehydrateFloat.js
Created February 14, 2014 19:13
JavaScript Fixed Float Dehydratation
// Assuming 5 fixed digits
function dehydrateFloat(f){
return Math.floor(f.toFixed(5)*100000).toString(36);
}
function hydrateFloat(dryf){
return (parseInt(dryf,36)/100000).toFixed(5);
}
@lastguest
lastguest / sanitize_images.sh
Created February 17, 2014 14:51
Remove all images that are not real images (failed http downloads)
find . -type f -name "*.jpg" -o -name "*.png" -o -name "*.gif" | xargs file | grep ASCII | awk -F":" '{print $1}' | xargs rm
@lastguest
lastguest / call_closure.php
Last active August 29, 2015 13:57
Javascript like scope heritage
<?php
function foobarbaz(){
// Extract environment object to local scope (not mandatory, you can access the parent scope via $this. Ex. $this->foo )
extract((array)$this);
var_dump($foo, $bar, $baz);
}
@lastguest
lastguest / get_function_code.php
Last active August 29, 2015 13:57
PHP: Retrieve the body of an user-defined function
/**
* Retrieve the body of an user-defined function
*/
function get_function_code($funcname){
try {
$ref = new ReflectionFunction($funcname);
if ($ref->isInternal()){
return '/*INTERNAL*/';
@lastguest
lastguest / Token.php
Last active August 29, 2015 13:59
Secure Token Generator/Validator
<?php
class Token {
protected static $secret = 'dont_tell_anyone';
public static function secret($the_secret=null){
return $the_secret ? static::$secret = $the_secret : static::$secret;
}
protected static function decompose($token){
/ HTML5 Doctype. Remember to delete these comments (Quirks Mode).
!!!
/ Modernizr HTML tag.
%html.no-js{lang: ""}
/ Let's get started.
%head
/ Document settings and metadata.
<!doctype html>
<html>
<head>
<!-- Run in full-screen mode. -->
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- Make the status bar black with white text. -->
<meta name="apple-mobile-web-app-status-bar-style" content="black">
@lastguest
lastguest / ie-modernizer.html
Created April 30, 2014 07:55
IE Modernizer
<!--[if !IE]>
<script src="//html5shiv-printshiv.googlecode.com/svn/trunk/html5shiv-printshiv.js"></script>
<![endif]-->
<!--[if IE 11]>
<script src="//html5shiv-printshiv.googlecode.com/svn/trunk/html5shiv-printshiv.js"></script>
<![endif]-->
<!--[if IE 10]>
<script src="//html5shiv-printshiv.googlecode.com/svn/trunk/html5shiv-printshiv.js"></script>
<![endif]-->
<!--[if IE 9]>
@lastguest
lastguest / PrototypeExtend.js
Created May 19, 2014 14:19
Prototype Extend
// function for extending a class
function extend (base, constructor) {
var prototype = new Function();
prototype.prototype = base.prototype;
constructor.prototype = new prototype();
constructor.prototype.constructor = constructor;
}
// parent class
<?php
function g($x=0,$r=0){
static $b;
$r || $b='g';
$x || $b.='o';
return $x?$b.$x:function($t=0){return g($t,1);};
}