Skip to content

Instantly share code, notes, and snippets.

View catwhocode's full-sized avatar

Cat who code catwhocode

View GitHub Profile
@catwhocode
catwhocode / date_diff.php
Created January 8, 2023 00:28
Using PHP DateTime::diff()
<?php
$datetime1 = new DateTime("2010-06-20");
$datetime2 = new DateTime("2011-06-22");
$difference = $datetime1->diff($datetime2);
echo 'Difference: '.$difference->y.' years, '
.$difference->m.' months, '
.$difference->d.' days';
@catwhocode
catwhocode / nginx.conf
Created August 25, 2022 06:03 — forked from mreschke/nginx.conf
Nginx config for multiple laravel sites based on /api/v1 url paths
# This config will host your main [Laravel] GUI application at /, and any additional [Lumen] webservices at /api/v1 and /api/v2...
# This also works perfectly for all static file content in all projects
# This is full of debug comments so you can see how to print debug output to browser! Took me hours to nail this perfect config.
# Example:
# http://example.com - Main Laravel site as usual
# http://example.com/about - Main Laravel site about page as usual
# http://example.com/robots.txt - Main Laravel site static content as usual
# http://example.com/api/v1 - Lumen v1 api default / route
# http://example.com/api/v1/ - Lumen v1 api default / route
@catwhocode
catwhocode / require_all_files.php
Created July 31, 2022 02:39
REQUIREd all php files in certain folders
<?php
$dir = __DIR__ . '/routes/';
$files = glob($dir . "*.php");
foreach($files as $file)
{
require $file;
}
@catwhocode
catwhocode / README.md
Created July 31, 2022 02:30
PHP: Batch convert webp to png
@catwhocode
catwhocode / index.php
Created June 16, 2022 06:44
Encryt and Decrypt with Defuse
<?php
require 'defuse-crypto.phar';
use Defuse\Crypto\Key;
use Defuse\Crypto\Crypto;
function loadEncryptionKeyFromConfig()
{
$keyAscii = 'def00000288b40f6e9f784932da638b3a01079fd620f75f8ac77e3999dbf0dc76b96fef7a52bb1b931196f1693a45a0921373d2b0542e70f0c1abc399a849ce4e174e2e9';
return Key::loadFromAsciiSafeString($keyAscii);
@catwhocode
catwhocode / index.php
Last active June 16, 2022 05:58
PHP: Create MySQL Database
<?php
session_start();
$mysqli = new mysqli('localhost', 'root', '', '');
if ($mysqli->connect_errno) {
throw new RuntimeException('mysqli connection error: ' . $mysqli->connect_error);
}
/* Set the desired charset after establishing a connection */
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use DiDom\Document;
$client = new Client();
$url = 'https://www.bca.co.id/id/informasi/kurs';
$userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36';
@catwhocode
catwhocode / decode-jwt.js
Created April 20, 2022 04:59
JS: Decode JWT without library
/* taken from: */
/* https://stackoverflow.com/questions/38552003/how-to-decode-jwt-token-in-javascript-without-using-a-library?noredirect=1&lq=1 */
const token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImp0aSI6ImU3YjQ0Mjc4LTZlZDYtNDJlZC05MTZmLWFjZDQzNzhkM2U0YSIsImlhdCI6MTU5NTg3NzUxOCwiZXhwIjoxNTk1ODgxMTE4fQ.WXyDlDMMSJAjOFF9oAU9JrRHg2wio-WolWAkAaY3kg4';
const tokenDecodablePart = token.split('.')[1];
const decoded = Buffer.from(tokenDecodablePart, 'base64').toString();
console.log(decoded)
@catwhocode
catwhocode / createcertificate.php
Created April 10, 2022 09:02 — forked from jlainezs/createcertificate.php
Creates a certificate using OpenSSL with PHP. sing.php could be used to sign a text with the pkey generated with createCertificate. verify.java shows how to load the certificate from a resource and a verification sample of the text signed with sign.php
/**
* Creates an OpenSSL certificate
* @param $dn Array Associative array "key"=>"value"
* @param $duration int Number of days which the certificate is valid
* @throws Exception If there are any errors
* @return Array Associative array with the security elements: "cer"=>self signed certificate, "pem"=>private key, "file"=>path to the files
*
* @see http://www.php.net/manual/en/function.openssl-csr-new.php
* @author Pep Lainez
*/
@catwhocode
catwhocode / google-apps-script.md
Created April 5, 2022 08:01 — forked from labnol/google-apps-script.md
How to Learn Google Apps Script

Learning Google Apps Script

Find the best resources for learning Google Apps Script, the glue that connects all GSuite services including Gmail, Google Drive, Calendar, Google Sheets, Forms, Maps, Analytics and more.

A good place to learn more about Google Apps Script is the official documentation available at developers.google.com. Here are other Apps Script resources that will help you get up to speed.

  1. Google Apps Script Code Samples by Amit Agarwal
  2. Google Apps Script Development - Create Google Apps Script projects locally inside VS Code - video tutorial
  3. Awesome Google Scripts by Amit Agarwal
  4. Google Developer Experts - Follow Apps Scr