Skip to content

Instantly share code, notes, and snippets.

View acip's full-sized avatar

Ciprian Amariei acip

View GitHub Profile
@acip
acip / reverb.md
Last active October 27, 2025 08:51
Laravel Reverb WebSocket Setup with Nginx Proxy, JWT Authentication, and /ws Path Prefix

Laravel Reverb WebSocket Setup with Nginx Proxy, JWT Authentication, and /ws/ Path Prefix

This guide explains how to configure Laravel Reverb to work behind Nginx with a /ws/ WebSocket path prefix. Using a custom path helps prevent conflicts with other routes and ensures WebSocket traffic is correctly proxied. This allows to run the WebSocket traffic on the same domain as the Web Server. Oprtional: It also demonstrates how to authenticate connections using JWT tokens.

Nginx Configuration for WebSocket Proxying via /ws/

The following Nginx block forwards all /ws/ requests to the Reverb WebSocket server running locally on port 8080:

@acip
acip / extract_copy_parameters.js
Created March 9, 2023 15:54
Copy data as JSON from OpenAI ChatGPT 3.5 Turbo playground bookmarklet
javascript: (function () { const messagesArray = []; messagesArray.push({ role: "system", message: document.querySelector(".chat-pg-instructions textarea").value }); const chatExchange = document.querySelector('.chat-pg-exchange'); const chatMessages = chatExchange.querySelectorAll('.chat-pg-message'); chatMessages.forEach(message => { const el = message.querySelector('.chat-message-role-text'); if (!el) { return; } const role = el.textContent; const messageTextarea = message.querySelector('.text-input'); if (!messageTextarea) { return; } const messageValue = messageTextarea.value; const messageObject = { role: role, message: messageValue }; messagesArray.push(messageObject); }); const messagesJSON = JSON.stringify(messagesArray); console.log(messagesJSON); const params = {}; const parameterPanelGrid = document.querySelector('.parameter-panel-grid'); const textContents = ['Temperature', 'Top P', 'Frequency penalty', 'Presence penalty']; const elements = parameterPanelGrid.querySelectorAll('*'); for (let i = 0
@acip
acip / importmap.blade.php
Last active March 2, 2023 16:46
JavaScript Import Maps - use Laravel mix for modules versioning
<script type="importmap">
{
"scopes": {
"/path/to/modules": {
"m1": "{{ mix("/js/m1.js") }}",
"m2": "{{ mix("/js/m2.js") }}"
}
}
}
</script>
@acip
acip / queries.blade.php
Created August 31, 2022 08:30
Display executed queries in Laravel blade (counting duplicates)
@php
// requires \DB::enableQueryLog(); to be executed for the query log is available
$queries = array_count_values(array_column(\DB::getQueryLog(), 'query'));
arsort($queries);
echo "\n";
foreach($queries as $query => $count) {
echo sprintf("%s: %s\n", $count > 1 ? "<span style='color:red'>{$count}</span>" : $count, $query);
}
@endphp
@acip
acip / monitor-space.sh
Last active August 22, 2022 01:42
Get disk space on Linux and send notification to Slack channel via webhook if above threshold.
#!/bin/bash
# get disk space available and report to Slack if below threshold
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/TXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
DISK_THRESHOLD=60
DISK_USAGE=$(df -h / | awk '{ print $5 }' | tail -n 1 | sed 's/%//g')
if [ $DISK_USAGE -ge $DISK_THRESHOLD ]; then
echo "Disk usage is $DISK_USAGE% - sending notification to slack"
@acip
acip / install-percona5.7.sh
Last active August 13, 2022 21:17
Install Percona 5.7 (drop in MysqSql 5.7 replacement) on Ubuntu 22.04 Jammy
wget https://downloads.percona.com/downloads/Percona-Server-5.7/Percona-Server-5.7.38-41/binary/debian/focal/x86_64/libperconaserverclient20_5.7.38-41-1.focal_amd64.deb
wget https://downloads.percona.com/downloads/Percona-Server-5.7/Percona-Server-5.7.38-41/binary/debian/focal/x86_64/percona-server-client-5.7_5.7.38-41-1.focal_amd64.deb
wget https://downloads.percona.com/downloads/Percona-Server-5.7/Percona-Server-5.7.38-41/binary/debian/focal/x86_64/percona-server-common-5.7_5.7.38-41-1.focal_amd64.deb
wget https://downloads.percona.com/downloads/Percona-Server-5.7/Percona-Server-5.7.38-41/binary/debian/focal/x86_64/percona-server-server-5.7_5.7.38-41-1.focal_amd64.deb
apt purge mysql-server* -y
apt autoremove -y
apt install mysql-common debsums libmecab2
wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1l-1ubuntu1.6_amd64.deb
dpkg -i libssl1.1_1.1.1l-1ubuntu1.6_amd64.deb
@acip
acip / woocommerce_customers.sql
Last active March 16, 2022 19:09
Retrieve customers details from Woocommerce, including total spent amount (only completed orders)
SELECT
B.meta_value AS first_name,
C.meta_value AS last_name,
K.user_email AS email,
D.meta_value AS phone,
ROUND(SUM(L.meta_value)) AS total_orders,
H.meta_value AS city,
G.meta_value AS state,
F.meta_value AS country,
I.meta_value AS postcode
@acip
acip / copy-folder.sh
Created January 3, 2022 18:23
Copy Composer vendor folder methods speed comparison
# 189M vendor
# 3.7s
time tar cf - ./vendor --warning=no-file-changed | (cd /tmp/; tar xf -)
# 4.7s
rsync -aW --no-compress vendor/ /tmp/
# 5s
cp -a ./vendor /tmp/
# different drives - on the same drive cp is slightly faster
@acip
acip / local-time.html
Created August 18, 2021 15:59
Display UTC time in local time with JavaScript without dependencies.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Local time</title>
</head>
<body>
Local time for 2011-10-10T14:48:00Z is: <time datetime="2011-10-10T14:48:00Z" data-format="hh:mm:ss A"></time>
@acip
acip / accessibility-check.js
Last active November 26, 2020 13:50
Run an accessibility test and generate report with Puppeteer and Accessibility Developer Tools - https://github.com/GoogleChrome/accessibility-developer-tools.
const puppeteer = require('puppeteer');
const fs = require('fs');
(async () => {
const browser = await puppeteer.launch({
userDataDir: './myUserDataDir',
dumpio: true,
});
const page = await browser.newPage();
await page.goto('https://google.com');