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
/** | |
* Mass (bulk) insert or update on duplicate for Laravel 4/5 | |
* | |
* insertOrUpdate([ | |
* ['id'=>1,'value'=>10], | |
* ['id'=>2,'value'=>60] | |
* ]); | |
* | |
* | |
* @param array $rows |
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
function updatesOrInserts($attributes, $model) | |
{ | |
$available_for_new = []; | |
$colection = collect($attributes); | |
$first_attr = array_first($attributes); | |
$first_keys = array_keys($first_attr); | |
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 function wheresIn($keys, $attributes, $model = null, $result = null){ | |
foreach ($keys as $key) | |
{ | |
$all_values = array_pluck($attributes, $key); | |
if(!$model) | |
$model = $this->whereIn($key, $all_values); | |
else | |
$model->whereIn($key, $all_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
/** | |
* Like php array_key_exists, this instead search if (one or more) keys exists in the array | |
* @param array $needles - keys to look for in the array | |
* @param array $haystack - the <b>Associative</b> array to search | |
* @param bool $all - [Optional] if false then checks if some keys are found | |
* @return bool true if the needles are found else false. <br> | |
* Note: if hastack is multidimentional only the first layer is checked<br>, | |
* the needles should <b>not be<b> an associative array else it returns false<br> | |
* The array to search must be associative array too else false may be returned | |
*/ |
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://culttt.com/2012/10/01/roll-your-own-pdo-php-class/ | |
*/ | |
?> | |
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 | |
/** | |
* Description of VideoStream | |
* | |
* @author Rana | |
* @link http://codesamplez.com/programming/php-html5-video-streaming-tutorial | |
*/ | |
class VideoStream | |
{ | |
private $path = ""; |
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 | |
namespace App\Http; | |
/** | |
* Description of VideoStream | |
* | |
* @author Rana | |
* @link https://gist.github.com/vluzrmos/d5682ad426525196d069 | |
*/ |
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 | |
$string = "z a b c\nd e f k\np q r s"; | |
$string2 = explode("\n",$string); | |
$string3 = array_map(function($item){ | |
return explode(' ',$item); | |
}, $string2); | |
$value = array_map(NULL, ...$string3); | |
$result = array_map(function ($val) { |
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
/** | |
* @param string $string | |
* @param string $pad | |
* @param int $expected_length | |
* @return string | |
*/ | |
function str_pad($string, $pad, $expected_length) | |
{ | |
$left = $expected_length - strlen($string); | |
while ($left > 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
const reducer = ( state = [], action) => { | |
if (action.type === 'split_string') { | |
return action.payload.split(''); | |
} | |
if (action.type === 'add_character') { | |
return [...state, action.payload]; | |
} | |
return state; | |
}; |
OlderNewer