Skip to content

Instantly share code, notes, and snippets.

View mpdroog's full-sized avatar

MP Droog mpdroog

View GitHub Profile
?php
/**
* import debounce CSV
*/
require __DIR__ . '/../vendor/autoload.php';
core\Unsafe::init();
require_once __DIR__ . '/../vendor/mpdroog/core/init-cli.php';
use core\Cli;
use core\Helper;
brew install mariadb
$(brew --prefix mariadb)/bin/mysqladmin -u root password
@mpdroog
mpdroog / curl-domain.sh
Created July 26, 2023 09:02
Test domain on specific IP
curl -4 -svo /dev/null --resolve www.example.com:443:1.2.3.4 https://www.example.com
@mpdroog
mpdroog / grecaptcha.php
Created July 5, 2023 12:43
Google Recaptcha verify
<?php
$ch = curl_init();
if ($ch === false) {
user_error("curl_init fail");
}
$opt = 1;
$opt &= curl_setopt($ch, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
$opt &= curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$opt &= curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$opt &= curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
@mpdroog
mpdroog / kayako-ticket.php
Created July 4, 2023 14:31
Kayako API add ticket
<?php
const API_KEY = "a-b-c-d";
const SECRET_KEY = "SuperSecretKeyFromKayako";
const HTTP_AUTH = "base64user:pass"; // Leave empty if none
const HTTP_URL = "https://www.yourwebsite.com/kayako/api/index.php?e=";
function has_prefix($s, $prefix) {
return mb_substr($s, 0, mb_strlen($prefix)) === $prefix;
}
// Small (vanilla) JS to make div scroll with the view
// Saving this code for historical purposes
// Note: In 2022 this is also possible with CSS through position: sticky
var dom = {
off: function ($node) {
var sum = $node.offsetTop;
if ($node.offsetParent) {
sum += dom.off($node.offsetParent);
}
@mpdroog
mpdroog / bootstrap-carousel.js
Created March 4, 2022 14:02
Minimal JS to implement bootstrap carousel
@mpdroog
mpdroog / once.sh
Created August 31, 2021 13:48
Ensure only one instance at the same time
#!/usr/bin/env bash
# Using lock-file to ensure only one instance can be running
# at the same time.
# DevNote: The trap is used to ensure we ALWAYS remove the lock upon completion
set -x
set -e
if ! mkdir /tmp/MYSCRIPT.lock; then
printf "MYSCRIPT already running.\n" >&2
exit 1
fi
@mpdroog
mpdroog / StringMap
Last active June 3, 2021 17:04
golang XML map[string]string encode/decode
// https://stackoverflow.com/questions/30928770/marshall-map-to-xml-in-go
// https://stackoverflow.com/questions/33486725/golang-xml-unmarshal-interface-types
package main
import (
"fmt"
"encoding/xml"
)
// StringMap is a map[string]string.
<?php
/**
* PO to JSON.
*/
$lang = "fr";
$lines = explode("\n", file_get_contents(__DIR__ . "/text.po"));
array_shift($lines); array_shift($lines); // Ignore first two lines
$out = [];