Skip to content

Instantly share code, notes, and snippets.

View manish-manghwani's full-sized avatar
💬

Manish Manghwani manish-manghwani

💬
View GitHub Profile
@manish-manghwani
manish-manghwani / failure_response_after_service_provider.txt
Created November 12, 2019 18:52
Failure Response after creating ReponseServiceProvider.php
public function getUserData(Request $request) {
$rules = [
"userId" => "required"
];
$validatedResponse = $this->validate($request,$rules);
try {
$data = DB::table("users")
@manish-manghwani
manish-manghwani / success_response_with_service_provider.txt
Created November 12, 2019 18:49
Success response after creating ResponseServiceProvider.php
public function getUserData(Request $request) {
$rules = [
"userId" => "required"
];
$validatedResponse = $this->validate($request,$rules);
$data = DB::table("users")
->where("id",$validatedResponse["userId"])
@manish-manghwani
manish-manghwani / ResponseServiceProvider.php
Created November 12, 2019 18:43
Service provider that handles success and error scenarios and acts as single source of truth
<?php
namespace App\Providers;
use Illuminate\Routing\ResponseFactory;
use Illuminate\Support\ServiceProvider;
class ResponseServiceProvider extends ServiceProvider
{
/**
@manish-manghwani
manish-manghwani / failure_response.txt
Created November 12, 2019 18:35
Failure response (php/laravel)
public function getUserData(Request $request) {
$rules = [
"userId" => "required"
];
$validatedResponse = $this->validate($request,$rules);
try {
$data = DB::table("users")
@manish-manghwani
manish-manghwani / success_response.txt
Created November 12, 2019 18:24
success response snippet (php/laravel)
public function getUserData(Request $request) {
$rules = [
"userId" => "required"
];
$validatedResponse = $this->validate($request,$rules);
$data = DB::table("users")
->where("id",$validatedResponse["userId"])
@manish-manghwani
manish-manghwani / mysql_user_creation.sql
Last active October 17, 2019 06:21
Mysql User creation with different roles
#Create user with prefix (privileges)
# c_ for create only
# r_ for read only
# u_ for update only
# de_ for delete only
# dr_ for drop only
# grants can be mereged
# Eg : User with CREATE, READ, UPDATE access
# c_r_u_<user_name>@host
let ip = [1,2,34,5,6,7,34];
let maxValue = 0;
let indexMaxValue = 0;
var lastElement = false;
const lastIndex = ip.length-1;
ip.forEach((value,key) => {
if(value >= maxValue){
<?php
function quick_sort($unsortedArray)
{
$left = $right = array();
if(count($unsortedArray) < 2)
{
return $unsortedArray;
}
$pivot_key = key($unsortedArray);
$pivot = array_shift($unsortedArray);
@manish-manghwani
manish-manghwani / quickSort_failing.php
Created July 7, 2019 20:55
Trying to find why allocate memory exceeds 500MB even when there are 2 entries
<?php
function quickSort($unsortedArray){
$leftArray = [];
$rightArray = [];
$arrayCount = count($unsortedArray);
//considering middle of array
$pivot = $unsortedArray[(int)floor($arrayCount / 2)];
for($i = 0; $i < $arrayCount ; $i++){
<?php
//merge sort example
function merge_sort($unsortedArray){
$arrayCount = count($unsortedArray);
//check if one element (passed by merge function or main function)
if($arrayCount === 1){
//already sorted