Skip to content

Instantly share code, notes, and snippets.

@arsonus
arsonus / mime_content_type.php
Created May 9, 2016 23:47
PHP mime_content_type() adapter.
/**
* mime_content_type
* Check for the PHP function and define if it isn't available.
*
* @param f The file name for which to determine MIME type
* @return A standard MIME type string: genus/species
*/
if( function_exists( 'mime_content_type' ) == false ) {
if( function_exists( 'finfo_file' ) == true ) {
function mime_content_type( $f ) {
@arsonus
arsonus / storagePolyfill.js
Created May 10, 2016 18:38 — forked from jarrodirwin/storagePolyfill.js
LocalStorage/SessionStorage Polyfill with Safari Private Browsing support.
// Refer to https://gist.github.com/remy/350433
try {
// Test webstorage existence.
if (!window.localStorage || !window.sessionStorage) throw "exception";
// Test webstorage accessibility - Needed for Safari private browsing.
localStorage.setItem('storage_test', 1);
localStorage.removeItem('storage_test');
} catch(e) {
(function () {
var Storage = function (type) {
@arsonus
arsonus / Object.watch.js
Created May 15, 2016 02:41 — forked from XoseLluis/Object.watch.js
Polyfill for the Object.watch/Object.unwatch functions available in Mozilla browsers
/*
Polyfill for the Object.watch/Object.unwatch functions available in Mozilla browsers
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/watch
you have a test here:
http://www.telecable.es/personales/covam1/deployToNenyures/SourceCode/Object.watch.test.js
and can read more here:
http://deploytonenyures.blogspot.com.es/2013/02/objectwatch-polyfill.html
*/
@arsonus
arsonus / url_slug.js
Last active May 23, 2016 17:49 — forked from sgmurphy/url_slug.js
URL Slugs in Javascript (with UTF-8 and Transliteration Support)
/**
* Create a web friendly URL slug from a string.
*
* Requires XRegExp (http://xregexp.com) with unicode add-ons for UTF-8 support.
*
* Although supported, transliteration is discouraged because
* 1) most web browsers support UTF-8 characters in URLs
* 2) transliteration causes a loss of information
*
* @author Sean Murphy <[email protected]>
@arsonus
arsonus / twitter.php
Created August 16, 2016 22:55 — forked from Wol/twitter.php
Twitter Analytics PHP Downloader
<?php
$sTarget = "https://analytics.twitter.com/user/$username/tweets/export.json?start_time=$start_time&end_time=$end_time&lang=en";
$sTargetBundle = "https://analytics.twitter.com/user/$username/tweets/bundle?start_time=$start_time&end_time=$end_time&lang=en";
curl_setopt($ch, CURLOPT_URL, $sTarget);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, false);
@arsonus
arsonus / cryptographically_secure_random_strings.php
Created September 17, 2016 01:48 — forked from raveren/cryptographically_secure_random_strings.php
Generate cryptographically secure random strings. Based on Kohana's Text::random() method and this answer:http://stackoverflow.com/a/13733588/179104
function random_text( $type = 'alnum', $length = 8 )
{
switch ( $type ) {
case 'alnum':
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'alpha':
$pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'hexdec':
@arsonus
arsonus / nginx-cors.conf
Created October 3, 2016 19:29 — forked from algal/nginx-cors.conf
nginx configuration for CORS (Cross-Origin Resource Sharing), with an origin whitelist, and HTTP Basic Access authentication allowed
#
# A CORS (Cross-Origin Resouce Sharing) config for nginx
#
# == Purpose
#
# This nginx configuration enables CORS requests in the following way:
# - enables CORS just for origins on a whitelist specified by a regular expression
# - CORS preflight request (OPTIONS) are responded immediately
# - Access-Control-Allow-Credentials=true for GET and POST requests
@arsonus
arsonus / README.md
Created October 17, 2016 20:20 — forked from magnetikonline/README.md
Compile ssh2 bindings extension for PHP7.

Compile ssh2 bindings extension for PHP7

The current PHP ssh2 extension via PECL won't compile under PHP7.

Using a more recent version via PHP's GitHub we can make this work.

$ sudo apt-get install autoconf libssh2-1-dev
$ curl -LO https://github.com/php/pecl-networking-ssh2/archive/master.zip
$ unzip master.zip
$ cd pecl-networking-ssh2-master
@arsonus
arsonus / php_object_to_array.php
Created November 1, 2016 21:06 — forked from victorbstan/php_object_to_array.php
recursively cast a PHP object to array
<?php
/*
This function saved my life.
found on: http://www.sitepoint.com/forums//showthread.php?t=438748
by: crvandyke
It takes an object, and when all else if/else/recursive functions fail to convert the object into an associative array, this one goes for the kill. Who would'a thunk it?!
*/
$array = json_decode(json_encode($object), true);
@arsonus
arsonus / 1.js
Created January 21, 2017 05:23 — forked from chrisbuttery/1.js
Fade in / Fade out
// fade out
function fade(el) {
var op = 1;
var timer = setInterval(function () {
if (op <= 0.1){
clearInterval(timer);
el.style.display = 'none';
}
el.style.opacity = op;