Skip to content

Instantly share code, notes, and snippets.

View mikehins's full-sized avatar

Mike Hins mikehins

  • Trinary
  • Mont-Tremblant
  • 15:55 (UTC -04:00)
View GitHub Profile
// Laravel class methods
$response->assertCookie();
$response->assertCookieExpired();
$response->assertCookieMissing();
$response->assertCookieNotExpired();
$response->assertCreated();
$response->assertDontSee();
$response->assertDontSeeText();
$response->assertExactJson();
# wilcard ssl
sudo certbot certonly --server https://acme-v02.api.letsencrypt.org/directory --manual --preferred-challenges dns -d *.hins.dev
# OR
sudo certbot certonly --manual -d '*.hins.dev'
# Update permission on archive
sudo chown -R mikehins /etc/letsencrypt/archive/
First Row of Many Similar Ones
SQL is a straightforward and expressive language, but it sometimes lacks constructs for writing queries in a simple way. It's more complicated than it should be to write a query to get, e.g., only the most expensive order for every customer of the current fiscal year. You can either use PostgreSQL's vendor-specific DISTINCT ON feature or window functions for every other database.
MySQL
SELECT *
FROM (
SELECT *, RANK() OVER(
PARTITION BY customer_id
# https://soft-builder.com/how-to-list-all-foreign-keys-in-mysql-database/
SELECT RefCons.constraint_schema, RefCons.table_name, RefCons.referenced_table_name, RefCons.constraint_name, KeyCol.column_name
FROM information_schema.referential_constraints RefCons
JOIN information_schema.key_column_usage KeyCol ON RefCons.constraint_schema = KeyCol.table_schema
AND RefCons.table_name = KeyCol.table_name
AND RefCons.constraint_name = KeyCol.constraint_name
WHERE RefCons.constraint_schema = 'DATABASE_NAME';
@mikehins
mikehins / reset-local-repo
Last active December 28, 2023 02:39
git: sync local repo with remote one
http://stackoverflow.com/questions/6373277/git-sync-local-repo-with-remote-one
This makes your local repo exactly like your remote repo.
Remember to replace origin and master with the remote and branch that you want to synchronize with.
git fetch origin
git reset --hard origin/master
git clean -f -d
#GIT UNDO
@mikehins
mikehins / rev.php
Created December 15, 2023 16:04
Add application version to Laravel app
// AppServiceProvider
public function boot(): void
{
//...
Blade::directive('rev', function () {
$v = config('app.version');
$b = exec('git rev-parse --short HEAD');
return ($v ? 'Version ' . $v : '') . ($b ? '<br>Build ' . $b : '');
certbot -d '*.hins.dev' --manual --preferred-challenges dns certonly
sudo chmod 0755 /etc/letsencrypt/
sudo chmod 0711 /etc/letsencrypt/live/
sudo chmod 0750 /etc/letsencrypt/live/hins.dev/
sudo chmod 0711 /etc/letsencrypt/archive/
sudo chmod 0750 /etc/letsencrypt/archive/hins.dev/
sudo chmod 0640 /etc/letsencrypt/archive/hins.dev/{cert,chain,fullchain}*.pem
sudo chmod 0640 /etc/letsencrypt/archive/hins.dev/privkey*.pem
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Bookings';
protected static ?string $modelLabel = 'Booking';
protected static ?string $navigationLabel = 'Bookings';
protected static ?int $navigationSort = 1;
@mikehins
mikehins / git.sh
Last active October 19, 2023 12:08
# undo lat commit
git reset --soft HEAD^
http://stackoverflow.com/questions/6373277/git-sync-local-repo-with-remote-one
This makes your local repo exactly like your remote repo.
Remember to replace origin and master with the remote and branch that you want to synchronize with.
git fetch origin
git reset --hard origin/develop
@mikehins
mikehins / port
Last active September 26, 2023 13:03
kill -9 $(lsof -ti:4321)
lsof -i tcp:8080
kil PID
# wmysql PID
ps -ef | grep mysql