Skip to content

Instantly share code, notes, and snippets.

@rrd108
rrd108 / index.html
Created April 11, 2024 15:05
QR generator
<!DOCTYPE html>
<html>
<head>
<style>
input {
font-size: 2rem;
}
</style>
</head>
<body>
@rrd108
rrd108 / authMiddleware.php
Created March 31, 2024 15:56
PHP middleware example
<?php
class RequestPolicy implements RequestPolicyInterface
{
public function canAccess($identity, ServerRequest $request)
{
if (!$identity) {
Configure::load('permissions', 'default', false);
$permissions = Configure::read('Permissions.noAuth');
return $this->checkPermission($permissions, $request);
}
@rrd108
rrd108 / migrations.md
Last active April 19, 2022 07:54
CakePHP Migations cheatsheet

Field definition

fieldName:fieldType?[length]:indexType:indexName email:string[120]:unique:EMAIL_INDEX

Add new table

bin/cake bake migration CreateProducts name:string description:text created modified

types: string | text | integer | biginteger | float | decimal | datetime | timestamp | time | date | binary | boolean | uuid

SELECT
abstract.departmentId AS departmentId,
abstract.departmentCode AS departmentCode,
(SUM(debitAmount)) AS debitAmount,
(SUM(creditamount)) AS creditAmount,
departmentId AS department_id,
2 AS reportlineId,
debitAmount - creditAmount AS amount
FROM
(
@rrd108
rrd108 / gist:2137e44c91869682fd8b09a8f481a473
Created October 13, 2021 08:14
cake password generation
bin/cake console
>>> $p = new \Cake\Auth\DefaultPasswordHasher();
=> Cake\Auth\DefaultPasswordHasher {#202}
>>> $p->hash('123');
=> "$2y$10$bWI0LOzmQaw8t1swBWCplO0oHL6W5GzXiRImA5np1gr02pkc0jh6y"
$ cat mylist.txt
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
$ ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4
@rrd108
rrd108 / xdebug.ini
Last active October 27, 2021 11:23
xdebug 3 setup
;read this for more info: https://xdebug.org/docs/upgrade_guide
zend_extension=xdebug.so
;mode is a new setting. debug let us use debugger in an IDE, develop enhances var_dump output
xdebug.mode=debug,develop
;default port changed to 9003, so we should change this in our IDE also
xdebug.client_port=9003
;trigger it via get variable or cookie
xdebug.start_with_request=trigger
xdebug.remote_log="/tmp/xdebug.log"
xdebug.cli_color=2
@rrd108
rrd108 / 0-install
Last active July 8, 2021 13:37
Create CakePHP API
composer create-project --prefer-dist cakephp/app:~4.0 myProject
cd myProject
composer require ozee31/cakephp-cors
composer require cakedc/users
# composer require muffin/throttle
@rrd108
rrd108 / CakePHPTable.php
Last active September 29, 2019 19:27
SELECT MAX of related table
<?php
// in UsersTable.php
public function findLastPosts(Query $query)
{
$latestPosts = $this->getAssociation('Posts')->find();
$latestPosts = $latestPosts->select(['maxId' => $latestPosts->func()->max('Posts.id')])->group('Posts.user_id');
return $query->where(['Posts.id IN' => $latestPosts]);
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;