This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function FizzBuzz($from=1, $to=100) | |
{ | |
$result = []; | |
for($i = $from; $i <= $to; $i++) { | |
if ($i % 15 == 0) { | |
$result[] = 'FizzBuzz'; | |
} elseif ($i % 3 == 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
wget -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz | |
gzip -d -f GeoIP.dat.gz | |
wget -N http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz | |
gzip -d -f GeoIPv6.dat.gz | |
wget -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz | |
gzip -d -f GeoLiteCity.dat.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function array_group_by(array $array, callable $key_selector) | |
{ | |
$result = []; | |
foreach ($array as $values) { | |
$key = call_user_func($key_selector, $values); | |
$result[$key][] = $values; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://25labs.com/alternative-for-file_get_contents-using-curl/ | |
function file_get_contents_curl($url, $retries=5) | |
{ | |
$ua = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.82 Safari/537.36'; | |
if (extension_loaded('curl') === true) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://nitschinger.at/Handling-JSON-like-a-boss-in-PHP | |
class JsonHandler | |
{ | |
protected static $_messages = array( | |
JSON_ERROR_NONE => 'No error has occurred', | |
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded', | |
JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function vd($var, $return=false) | |
{ | |
$s = var_export($var, true); | |
$s = preg_replace( '/[^[:print:]]/', '',$s); | |
$s = preg_replace('#[ ]+#', '', $s); | |
$s = str_replace(array('array(', ')', '=>', ',]'), array('[', ']', ':', ']'), $s); | |
if ($return) return $s; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
var keys = []; | |
var konami = '38,38,40,40,37,39,37,39,66,65'; | |
$(document) | |
.keydown( | |
function(e) { | |
keys.push( e.keyCode ); | |
if ( keys.toString().indexOf( konami ) >= 0 ){ | |
console.log("konami code") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://hactheplanet.com/blog/11 | |
function cachedHTMLForURL($url) | |
{ | |
// Request the cache from Google. | |
$googleRequestURL = "http://webcache.googleusercontent.com/search?q=" . urlencode("cache:" . $url); | |
$googleResponse = file_get_contents($googleRequestURL); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
## | |
# This is script with usefull tips taken from: | |
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx | |
# | |
# install it: | |
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://www.geekality.net/2010/11/17/php-output-a-number-of-bytes-in-a-human-readable-way/ | |
function make_pretty($bytes) | |
{ | |
$symbols = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'); | |
$exp = floor(log($bytes) / log(1024)); | |
return sprintf('%.2f '.$symbols[$exp], $bytes/pow(1024, floor($exp))); |