Skip to content

Instantly share code, notes, and snippets.

@allaniftrue
allaniftrue / laravel-query-too-many-placeholder.php
Created March 6, 2023 01:48 — forked from sentiasa/laravel-query-too-many-placeholder.php
Laravel - Query +100k placeholders in Laravel using `whereIn()`
<?php
$transactionIds = Transaction::pluck('id'); // +100k transaction ids
$maxAtOneTime = 5000;
$total = count($transactionIds);
$pages = ceil($total / $maxAtOneTime);
$transactions = collect();
root@sydney:/mnt/vol2# rclone sync spaces-sgp1:mybucket1 /mnt/vol2 --checkers 256 --transfers 256 --progress --fast-list --size-only
2023-02-27 07:18:50 ERROR : 52231/: Failed to copy: failed to open source object: NoSuchKey:
status code: 404, request id: tx00000000000001d4ec082-0063fc595a-285cf3d6-sgp1b, host id:
2023-02-27 07:18:54 ERROR : Local file system at /mnt/vol2: not deleting files as there were IO errors
2023-02-27 07:18:54 ERROR : Local file system at /mnt/vol2: not deleting directories as there were IO errors
2023-02-27 07:18:54 ERROR : Attempt 1/3 failed with 3 errors and: failed to open source object: NoSuchKey:
status code: 404, request id: tx00000000000001d4ec082-0063fc595a-285cf3d6-sgp1b, host id:
Transferred: 2.276M / 2.276 MBytes, 100%, 3.198 MBytes/s, ETA 0s
2023-02-27 07:20:04 ERROR : 52231/: Failed to copy: failed to open source object: NoSuchKey:
status code: 404, request id: tx00000000000001d4e5352-0063fc59a4-28667c7c-sgp1b, host id:
@allaniftrue
allaniftrue / s3_set_object_public.sh
Last active February 16, 2023 01:24 — forked from alexclifford/s3_set_object_public.sh
Make S3 object public and private via s3cmd command line
s3cmd setacl s3://bucket/path/to/file --acl-public
s3cmd info s3://bucket/path/to/file
s3cmd setacl s3://bucket/path/to/file --acl-private
# S3CMD SET ALL FILES IN FOLDER TO PRIVATE
s3cmd setacl s3://bucket/path/to/file --acl-private --recursive
@allaniftrue
allaniftrue / keypress.js
Created June 3, 2021 06:46
Reactjs prevent characters on keypress
use { useState } from 'react';
const Test = () => {
const [tipAmount, setTipAmount] = useState('');
const handleKeypress = (e) => {
if(!((e.keyCode > 95 && e.keyCode < 106)
|| (e.keyCode > 47 && e.keyCode < 58)
|| e.keyCode == 8)) {
e.preventDefault(); // Let's stop this event.
@allaniftrue
allaniftrue / 422Error.php
Created May 14, 2021 19:19
Laravel Throw custom 422 error message
<?php
use Illuminate\Validation\ValidationException;
throw ValidationException::withMessages(['field_name' => 'This value is incorrect']);
@allaniftrue
allaniftrue / countries.json
Created April 16, 2021 02:00
Alpha-2 ISO3166 countries
[
{
"label": "Afghanistan",
"value": "AF"
},
{
"label": "Åland Islands",
"value": "AX"
},
{
@allaniftrue
allaniftrue / SomeController.php
Created April 11, 2021 14:17
Dompdf API response
<?php
public function pdf($id)
{
//...
$pdf = PDF::loadView('pdf.payroll');
return response()->json([
'pdf' => base64_encode($pdf->output())
]);
@allaniftrue
allaniftrue / formatBytes.js
Created March 23, 2021 02:28 — forked from zentala/formatBytes.js
Convert size in bytes to human readable format (JavaScript)
function formatBytes(bytes,decimals) {
if(bytes == 0) return '0 Bytes';
var k = 1024,
dm = decimals || 2,
sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
// Usage:
@allaniftrue
allaniftrue / utils.php
Created February 3, 2021 21:04
Laravel Helpers
<?php
if (! function_exists('getSql')) {
/**
* @param $model
* @return string
*/
function getSql($model): string
{
$replace = function ($sql, $bindings)
<?php
...
$stack = HandlerStack::create();
$logger = new Logger('Logger');
$handler = new RotatingFileHandler(storage_path('logs/guzzle.log'), 5, Logger::DEBUG, true, 0664);
// $logger->pushHandler(new StreamHandler(storage_path('logs/guzzle.log')), Logger::DEBUG);
$logger->pushHandler($handler);