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 | |
/** | |
* Depend from csv_to_array and get_in functions | |
* @link https://gist.github.com/nicklasos/11251754 | |
* @link https://gist.github.com/nicklasos/9206376 | |
*/ | |
function t($phrase) | |
{ | |
static $dictionary; |
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 | |
if (!function_exists('array_column')) { | |
function array_column(array $input, $columnKey, $indexKey = null) { | |
$result = array(); | |
if (null === $indexKey) { | |
if (null === $columnKey) { | |
// trigger_error('What are you doing? Use array_values() instead!', E_USER_NOTICE); | |
$result = array_values($input); |
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
public struct MainPage | |
{ | |
public string Threads { get; set; } | |
public List<Pager> Pages { get; set; } | |
} | |
public struct Pager | |
{ | |
private string filename; | |
public string Filename |
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 | |
include __DIR__ . '/vendor/autoload.php'; | |
$faker = Faker\Factory::create(); | |
$randData = [ | |
'gmt_diff' => 'randomDigitNotNull', | |
'ios_id' => 'uuid', | |
'email' => 'email', |
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 variable_name(&$var) | |
{ | |
$old = $var; | |
$var = $new = 'UNIQUE' . mt_rand() . 'VARIABLE'; | |
$vname = false; | |
foreach($GLOBALS as $key => $val) { | |
if($val === $new) { | |
$vname = $key; |
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 mongo_id_from_time($yourTimestamp) | |
{ | |
static $inc = 0; | |
$ts = pack('N', $yourTimestamp); | |
$m = substr(md5(gethostname()), 0, 3); | |
$pid = pack('n', posix_getpid()); | |
$trail = substr(pack('N', $inc++), 1, 3); |
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 multiple_download(array $urls, $save_path = '/tmp') | |
{ | |
$multi_handle = curl_multi_init(); | |
$file_pointers = []; | |
$curl_handles = []; | |
// Add curl multi handles, one per file we don't already have | |
foreach ($urls as $key => $url) { |
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 | |
/** | |
* Interactively prompts for input without echoing to the terminal. | |
* Requires a bash shell or Windows and won't work with | |
* safe_mode settings (Uses `shell_exec`) | |
* | |
* @see http://us.php.net/manual/en/function.ncurses-noecho.php | |
* @see http://us.php.net/manual/en/function.ncurses-getch.php | |
* | |
* Works only on normal OS, not in windows. |
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
-module(plists). | |
-export([pmap/2,pforeach/2,npforeach/2, parmap/2]). | |
%%% Map | |
pmap(F, L) -> | |
S = self(), | |
Pids = lists:map(fun(I) -> spawn(fun() -> pmap_f(S, F, I) end) end, L), | |
pmap_gather(Pids). |
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 retry($retries, callable $fn) | |
{ | |
beginning: | |
try { | |
return $fn(); | |
} catch (\Exception $e) { | |
if (!$retries) { | |
throw new \Exception(); |