Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View yavgel85's full-sized avatar

Eugene Yavgel yavgel85

View GitHub Profile
@yavgel85
yavgel85 / Laravel Controller to upload, zip, password protect the zip, save the password encrypted.php
Created March 26, 2021 08:24
Laravel Controller to upload, zip, password protect the zip, save the password encrypted #laravel
<?php
// The issue this solves is to allow the user to upload a document and for us to save the document such that: the document is zip'd, the zip file is given a unique name, the zip file is password protected with a unique password, the password is encrypted for storage in the db table.
// The following will allow for creating one codeset to be called for the creation of all Documents.
// For the moment, we will need to set up IF statements for the statement that creates an instance of $Document
// which will allow for us to create a new entry in the appropriate database table.
public function storeInitDocument($request, $id, $theUserID, $ignore, $tableName){
// This function will determine if the User has uploading any documents. If so, the document's properties will be stored,
// followed by the storage of the physical document with a unique name. The document will be
@yavgel85
yavgel85 / Query Builder Macros.php
Last active June 14, 2022 14:09
whereLike macro #laravel #queryBuilder #macro
// Create custom method for Query Builder
<?php
// You can put it the boot method of App\Providers\AppServiceProvider or a service provider of your own.
//Usage Model::whereLike('name', ['mike', 'joe'])->get()
//Usage Model::whereLike('message.type', ['text', 'sms'])->get();
Builder::macro('whereLike', function ($attributes, $terms) {
@yavgel85
yavgel85 / Docker and docker-compose commands.md
Last active November 25, 2021 16:15
Docker and docker-compose commands #docker #command

Docker Compose

start the containers (in detached mode)
docker-compose up -d 
start and build containers
docker-compose up -d --build 
@yavgel85
yavgel85 / Specified key was too long.php
Last active October 29, 2021 08:14
Specified key was too long #laravel #sql
<?php
// SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
@yavgel85
yavgel85 / Shorter and more readable syntax.md
Last active June 1, 2021 07:24
Shorter and more readable syntax #laravel #bestpractices
Common syntax Shorter and more readable syntax
Session::get('cart') session('cart')
$request->session()->get('cart') session('cart')
Session::put('cart', $data) session(['cart' => $data])
$request->input('name'), Request::get('name') $request->name, request('name')
return Redirect::back() return back()
is_null($obj->relation) ? null : $obj->relation->id optional($obj->relation)->id
return view('index')->with('title', $title)->with('client', $client) return view('index', compact('title', 'client'))
request->has('value') ? request->value : 'default' request->get('value', 'default')
@yavgel85
yavgel85 / quickSort.js
Last active March 26, 2021 12:01
quickSort #js #algorithm
// Sorts an array of numbers, using the quicksort algorithm.
// Use recursion.
// Use the spread operator (...) to clone the original array, arr.
// If the length of the array is less than 2, return the cloned array.
// Use Math.floor() to calculate the index of the pivot element.
// Use Array.prototype.reduce() and Array.prototype.push() to split the array into two subarrays (elements smaller or equal to the pivot and elements greater than it), destructuring the result into two arrays.
// Recursively call quickSort() on the created subarrays.
const quickSort = arr => {
@yavgel85
yavgel85 / selectionSort.js
Created March 26, 2021 11:53
selectionSort #js #algorithm
// Sorts an array of numbers, using the selection sort algorithm.
// Use the spread operator (...) to clone the original array, arr.
// Use a for loop to iterate over elements in the array.
// Use Array.prototype.slice() and Array.prototype.reduce() to find the index of the minimum element in the subarray to the right of the current index and perform a swap, if necessary.
const selectionSort = arr => {
const a = [...arr];
for (let i = 0; i < a.length; i++) {
const min = a
@yavgel85
yavgel85 / heapsort.js
Created March 26, 2021 11:52
heapsort #js #algorithm
// Sorts an array of numbers, using the heapsort algorithm.
// Use recursion.
// Use the spread operator (...) to clone the original array, arr.
// Use closures to declare a variable, l, and a function heapify.
// Use a for loop and Math.floor() in combination with heapify to create a max heap from the array.
// Use a for loop to repeatedly narrow down the considered range, using heapify and swapping values as necessary in order to sort the cloned array.
const heapsort = arr => {
const a = [...arr];
@yavgel85
yavgel85 / bucketSort.js
Created March 26, 2021 11:48
bucketSort #js #algorithm
// Sorts an array of numbers, using the bucket sort algorithm.
// Use Math.min(), Math.max() and the spread operator (...) to find the minimum and maximum values of the given array.
// Use Array.from() and Math.floor() to create the appropriate number of buckets (empty arrays).
// Use Array.prototype.forEach() to populate each bucket with the appropriate elements from the array.
// Use Array.prototype.reduce(), the spread operator (...) and Array.prototype.sort() to sort each bucket and append it to the result.
const bucketSort = (arr, size = 5) => {
const min = Math.min(...arr);
const max = Math.max(...arr);
@yavgel85
yavgel85 / luhnCheck.js
Created March 26, 2021 11:47
luhnCheck #js #algorithm
// Implementation of the Luhn Algorithm used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers etc.
// Use String.prototype.split(''), Array.prototype.reverse() and Array.prototype.map() in combination with parseInt() to obtain an array of digits.
// Use Array.prototype.splice(0, 1) to obtain the last digit.
// Use Array.prototype.reduce() to implement the Luhn Algorithm.
// Return true if sum is divisible by 10, false otherwise.
const luhnCheck = num => {
let arr = (num + '')
.split('')