Skip to content

Instantly share code, notes, and snippets.

View garsaud's full-sized avatar
🌐
interneting

Cyril garsaud

🌐
interneting
View GitHub Profile
@garsaud
garsaud / ProcessQueueAndExit.php
Last active October 18, 2021 18:14 — forked from jdforsythe/ProcessQueueAndExit.php
Laravel 5 Artisan Process Entire Queue and Exit Command
<?php
namespace App\Console\Commands;
use Exception;
use Throwable;
use Illuminate\Queue\Worker;
use Illuminate\Console\Command;
use Illuminate\Contracts\Queue\Job;
use Illuminate\Queue\WorkerOptions;
@garsaud
garsaud / lowercase.py
Created June 28, 2017 20:41
Rename files in current directory to lowercase. Also works on windows.
import os
"""
Make every filename within the same directory lowercase, adding a temporary
character in the process to fool windows into believing that the filename has
really changed (windows treats filenames as case insensitive)
Usage: python lowercase.py
"""
@garsaud
garsaud / music.js
Created August 16, 2017 17:48
Electronic music in javascript
// | . | . | . | . |
notes1 = '30934903403050302080473000102000';
notes2 = '90000010900100009000001090010000';
tAudio = 0;
audioCtx = new AudioContext;
scriptProcessor = audioCtx.createScriptProcessor(512, 0, 1);
scriptProcessor.connect(audioCtx.destination);
scriptProcessor.onaudioprocess = e => {
data = e.outputBuffer.getChannelData(0);
for (i = 0; i < data.length; i++)
@garsaud
garsaud / ajax.js
Last active October 9, 2024 15:29
Vanilla JS ajax
// Using with(){} — Deprecated but practical
with (new XMLHttpRequest()) {
open('get', 'search?q='+encodeURIComponent('chaises'), true);
onreadystatechange = function () {
if (readyState !== 4 || status !== 200) return;
console.log(JSON.parse(responseText));
};
send();
}
@garsaud
garsaud / Dockerfile
Created February 20, 2019 17:24
Docker PHP complete extension list
RUN apt update
RUN apt upgrade -y
RUN apt install -y apt-utils
RUN a2enmod rewrite
RUN apt install -y libmcrypt-dev
RUN docker-php-ext-install mcrypt
RUN apt install -y libicu-dev
RUN docker-php-ext-install -j$(nproc) intl
RUN apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng12-dev
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
@garsaud
garsaud / duplicates.sql
Created February 20, 2019 17:27
SQL: Remove duplicates except one
delete t1 from book t1
inner join book t2
where t1.id > t2.id
and t1.title = t2.title
and t1.user_id = t2.user_id
and t1.category_id = t2.category_id;
@garsaud
garsaud / _.php
Last active October 9, 2024 15:27
POST request with file_get_contents()
<?php
file_get_contents(
'https://blah.com/toto.php?something=whatever',
false,
stream_context_create(['http' => [
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query(['hello' => 'goodbye']),
]
@garsaud
garsaud / _.sql
Created November 2, 2020 10:51
Record duplicate counts in a column
update mytable t1
join (select field, count(*) as dup_count from mytable group by field) t2
set t1.count_field = dup_count
where t1.field = t2.field
@garsaud
garsaud / _.py
Created October 9, 2024 08:39
Send and receive text data through bluetooth. Alternative to obsolete rfcomm.
import socket
sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
sock.bind(('XX:XX:XX:XX:XX:XX', 1)) # find local address using `sudo bluetoothctl list`
sock.connect(('YY:YY:YY:YY:YY:YY', 1)) # target device after having paired it
sock.send(b'coucou\n')
sock.recv(100)