Skip to content

Instantly share code, notes, and snippets.

View jewei's full-sized avatar

Jewei Mak jewei

View GitHub Profile
@jewei
jewei / laravel.php
Created March 17, 2024 02:49
Insert large data from CSV to database
<?php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
function chuckFile(string $filePath, callable $callable, int $chuckSize)
{
$file = fopen($filePath, 'r');
$data = [];
cd ${FORGE_SITE_PATH}
# Maintenance mode
$FORGE_PHP artisan down || true
# Clean up
$FORGE_PHP artisan horizon:pause
$FORGE_PHP artisan auth:clear-resets
$FORGE_PHP artisan optimize:clear
git checkout .
cd ${FORGE_SITE_PATH}
# Maintenance mode
$FORGE_PHP artisan down || true
# Clean up
$FORGE_PHP artisan optimize:clear
git checkout .
# Fetch latest
@jewei
jewei / HasBinaryUuidPrimaryKey.php
Created September 4, 2022 10:03
Implementation of Ordered Binary UUID as Database Primary Key for Laravel 9
<?php
namespace App\Models\Traits;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Ramsey\Uuid\Uuid;
// Clear or truncate log files
truncate -s 0 /var/log/*.log
truncate -s 0 /var/log/**/*.log
find /var/log -type f -name '*.log' -exec truncate -s 0 {} +
find /var/log -type f -iname '*.log' -print0 | xargs -0 truncate -s0
<?php
class Example
{
public function handle()
{
$this->sendHeader('test.csv');
$this->sendData(['foo', 'bar', 'foobar'], [
['a', 'b', 'c'],
['d', 'e', 'f'],
@jewei
jewei / Laravel56.psalm.xml
Created May 21, 2018 10:39
psalm.xml for Laravel
<?xml version="1.0"?>
<psalm
totallyTyped="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="app" />
</projectFiles>
@jewei
jewei / NodeJS.md
Last active February 26, 2018 07:10
Ubuntu 17.10 Server Setup

Install NodeJS

curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
@jewei
jewei / keybase.md
Created February 9, 2018 04:43
keybase.md

Keybase proof

I hereby claim:

  • I am jewei on github.
  • I am jewei (https://keybase.io/jewei) on keybase.
  • I have a public key ASC2ykLyNwPS-jO8LiLFD2bbKN-k6XcdFZaGtLkJ0GgZFwo

To claim this, I am signing this object:

@jewei
jewei / gist:dd8c8e15fb2bed54eaa1d50d7321d728
Created October 25, 2017 11:32
New Ubuntu Server Init
// Set timezone.
sudo dpkg-reconfigure tzdata
// Update.
sudo apt update
// Language fix.
sudo apt install -y language-pack-en-base
export LC_ALL=en_US.UTF-8