Skip to content

Instantly share code, notes, and snippets.

View omitobi's full-sized avatar
👑
The faithful shall receive the crown of life from Jesus

Oluwatobi Samuel Omisakin omitobi

👑
The faithful shall receive the crown of life from Jesus
View GitHub Profile
@omitobi
omitobi / massInsertOrUpdate.php
Created April 25, 2017 18:29 — forked from RuGa/massInsertOrUpdate.php
Mass (bulk) insert or update on duplicate for Laravel 4/5
/**
* Mass (bulk) insert or update on duplicate for Laravel 4/5
*
* insertOrUpdate([
* ['id'=>1,'value'=>10],
* ['id'=>2,'value'=>60]
* ]);
*
*
* @param array $rows
@omitobi
omitobi / massUpdateOrInsert.php
Last active April 25, 2017 20:37
massupdateOrInsert
function updatesOrInserts($attributes, $model)
{
$available_for_new = [];
$colection = collect($attributes);
$first_attr = array_first($attributes);
$first_keys = array_keys($first_attr);
@omitobi
omitobi / wheresIn.php
Created April 25, 2017 21:44
For Laravel Model wheresIn, in order to retrieve the model where many attributes values exists in many the columns given
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);
@omitobi
omitobi / arrays_keys_exists.php
Created April 25, 2017 21:47
arrays_keys_exists
/**
* 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
*/
@omitobi
omitobi / PDO PHP Class
Created May 7, 2017 20:24 — forked from geoffreyhale/PDO PHP Class
Roll Your Own PDO PHP Class
<?php
/**
* http://culttt.com/2012/10/01/roll-your-own-pdo-php-class/
*/
?>
@omitobi
omitobi / VideoStream.php
Created July 3, 2017 14:33 — forked from ranacseruet/VideoStream.php
PHP VideoStream class for HTML5 video streaming
<?php
/**
* Description of VideoStream
*
* @author Rana
* @link http://codesamplez.com/programming/php-html5-video-streaming-tutorial
*/
class VideoStream
{
private $path = "";
<?php
namespace App\Http;
/**
* Description of VideoStream
*
* @author Rana
* @link https://gist.github.com/vluzrmos/d5682ad426525196d069
*/
@omitobi
omitobi / matrix_transpose.php
Last active September 25, 2017 04:37
Transpose matrix without regex
<?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) {
@omitobi
omitobi / str_pad.php
Created November 7, 2017 12:56
String pad
/**
* @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) {
@omitobi
omitobi / reduxinbit.js
Created January 26, 2018 11:04
redux in bit
const reducer = ( state = [], action) => {
if (action.type === 'split_string') {
return action.payload.split('');
}
if (action.type === 'add_character') {
return [...state, action.payload];
}
return state;
};