Skip to content

Instantly share code, notes, and snippets.

View rtio's full-sized avatar
🐘

Rafael Meneses rtio

🐘
View GitHub Profile
@rtio
rtio / img_to_byte_str.php
Created July 25, 2023 20:53
Convert an image to a byte string
<?php
$webpFilePath = 'new.jpeg';
$byteArray = array_values(unpack('C*', file_get_contents($webpFilePath)));
$byteString = implode(array_map('chr', $byteArray));
echo base64_encode($byteString);
@rtio
rtio / isWebPAnimated.js
Created July 20, 2023 19:36
Check whether a webp image is animated or not with javascript on the browser
/**
* Check if a WebP image is animated
* @param {*} url
* @returns boolean
*/
async function isWebPAnimated(url) {
try {
const response = await fetch(url);
const buffer = await response.arrayBuffer();
const dataView = new DataView(buffer);
@rtio
rtio / TestClass.php
Created April 14, 2023 19:55
Validade TierDown runs on every test iteration
<?php
namespace MyCode;
class TestClass extends TestCase {
/**
* MySQL table
* @var array
*/
private array $users = [];

Endpoints

Structure

Every response is contained by an envelope. That is, each response has a predictable set of keys with which you can expect to interact:

#!

{
<input type='text' id="textBox">
{
"name": "Rafael Meneses",
"email": "rafael@petcoach.co",
"country": "Brazil",
"zip_code": "55544",
"pets": [
{
"name": "Ryley",
"policy_number": "WAG6053240",
"pet_type": "Dog",
<?php
const SECRET_KEY = '2ff58dd1339f33ea688b89753d50e8cfefe82f6fdfb429f4f1dad4e45c04d499'; // Example key
const ENCRYPT_METHOD = 'AES-256-CBC'; // Encrypt method
const IV = '2ff58dd1339f33ea'; // Random hash with 16 bits. Generate a new IV for each new message
$nonEncryptedMessage = 'this message is secret';
// example to encode a message
// encrypt and encode the message
$encryptedMessage = openssl_encrypt($nonEncryptedMessage, ENCRYPT_METHOD, SECRET_KEY, 0, IV);
@rtio
rtio / Dokerfile
Last active July 1, 2020 23:04
Docker
FROM debian
RUN mkdir -p /var/www/server.dev/web
WORKDIR /var/www/server.dev
RUN apt-get update && apt-get install -y \
aptitude \
apt-utils \
pkg-config \
@rtio
rtio / jobclear.cs
Last active February 10, 2017 13:41
private void clear(Scheduler scheduler) {
Object quartzScheduler = getFieldValue(scheduler, "sched");
Object jobMgr = getFieldValue(quartzScheduler, "jobMgr");
@SuppressWarnings("unchecked")
Map<String, JobExecutionContext> executingJobs = (Map<String, JobExecutionContext>)getFieldValue(jobMgr, "executingJobs");
List<String> removalList = new ArrayList<String>();
for(Map.Entry<String, JobExecutionContext> entry : executingJobs.entrySet()) {
if(entry.getValue().getNextFireTime().before(new Date())) {
removalList.add(entry.getKey());
/**
* Zip a folder (include itself).
* Usage:
* HZip::zipDir('/path/to/sourceDir', '/path/to/out.zip');
*
* @param string $sourcePath Path of directory to be zip.
* @param string $outZipPath Path of output zip file.
*/
public static function zipDir($sourcePath, $outZipPath)
{