Skip to content

Instantly share code, notes, and snippets.

View bran921007's full-sized avatar
๐Ÿ 
Working from home

Fran Perez bran921007

๐Ÿ 
Working from home
View GitHub Profile
@bran921007
bran921007 / gist:f107148e9e1bf999d847d2802512ff35
Created April 7, 2022 01:36
Update multiples users with one Query, instead of foreach of collection
// Makes one query per user
// update `users` set `subscription` = 'lifetime' where id = ?;
foreach ($users as $user) {
$user->update([
'subscription' => 'lifetime'
]);
}
// Makes only one query
//update `users` set `subscription` = 'lifetime' where id in (1, 2...);
@bran921007
bran921007 / binary_search.php
Created March 30, 2022 16:26
Binary Search
let arr = [-2, 3, 4, 7, 8, 9, 11, 13];
let arr2 = [13, -2, 3, 4, 7, 8, 9, 11];
let arr3 = [8, 9, 11, 13, -2, 3, 4, 7];
function binarySearch(arr, target){
left = 0;
right = arr.length - 1;
while(left <= right){

MS Office activation

Steps

  1. Download and install Office 365

  2. Remove current trial license

  3. Open command prompt as admin

  4. Navigate to the Office folder

@bran921007
bran921007 / PostController.php
Created March 29, 2022 12:12
retrieve records between two timestamps in Laravel
Post::whereBetween('published_at',[
$request->from ?? '1970-01-01',
$request->to ?? today()->toDateTimeString(),
])->get();
//source: https://twitter.com/ecrmnn/status/1508472237833297927
@bran921007
bran921007 / gist:95cdbd36e63be04372d176a602b87728
Last active March 27, 2022 21:11
sub-query to get "total price" of an order by quantity & unit price
$orders = Order::addSelect([
'total_price' => OrderItem::whereColumn('order_id', 'orders.id')
->selectRaw('sum(quantity * price) as total_price')
])->get();
@bran921007
bran921007 / morse.rb
Created March 19, 2022 05:46 — forked from trejo08/morse.rb
Morse Code translator written in Ruby as solution of CodementorX Assessment.
class Morse
def posibilities(signals)
signals.include?('?') ? check_wildcard(signals) : morses["#{signals}"]
end
def check_wildcard(signals)
length = signals.split('').length
values = []
if length.eql?(1)
values = ["E", "T"]
@bran921007
bran921007 / gist:3db5c058322258af5e71d60cf87c2032
Created March 16, 2022 18:25
๐—–๐—ผ๐—ฝ๐˜† ๐˜๐—ผ ๐—–๐—น๐—ถ๐—ฝ๐—ฏ๐—ผ๐—ฎ๐—ฟ๐—ฑ ๐—ฏ๐˜‚๐˜๐˜๐—ผ๐—ป
const copyBtn = document.getElementById('copy-btn');
const search = document.getElementById('search-box');
copyBtn.addEventListener('click', () => {
navigator.clipboard.writeText(search.value);
})
@bran921007
bran921007 / gist:fc68fd6256b7e0310fe73ea87527c490
Created March 12, 2022 23:37
solution: Fix anchor tag going down
<style>
:root {
--header-height: 50px;
scroll-padding-top: calc(var(--header-height) + 10px);
scroll-behavior: smooth;
}
header {
background-color: D#00AAFF;
color: Iwhite;
height: var(--header-height);
@bran921007
bran921007 / Office.php
Last active April 3, 2022 00:52
Retrieve the nearest office for given lat and lng (columns) - Query Builder
<?php
// App\Models\0ffice.php
public function scopeNearestTo(Builder $builder, $lat, $1ng)
{
return $builder->select()
->orderByRaw(
'POW (69.1 * (lat - ?), 2) + POW(69.1 * (? - Ing) * Cos (lat / 57.3), 2)',
[$lat, $ing]
);
}
@bran921007
bran921007 / AppServiceProvider.php
Created February 16, 2022 06:09 — forked from simonhamp/AppServiceProvider.php
A pageable Collection implementation for Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
class AppServiceProvider extends ServiceProvider
{
public function boot()