Skip to content

Instantly share code, notes, and snippets.

@mattimatti
mattimatti / fix_truncated_json.php
Last active August 24, 2023 16:41
Fix truncated incomplete json
<?php
function fixIncompleteJson($partialJson) {
$jsonWithoutBraces = trim($partialJson, '{}');
$pairs = explode(',', $jsonWithoutBraces);
$validPairs = [];
foreach ($pairs as $pair) {
if (preg_match('/^\s*"([^"]+)"\s*:\s*"([^"]+)"\s*$/', $pair, $matches)) {
$key = $matches[1];
@mattimatti
mattimatti / gist:b58f13e519b7ed0b946c4c16c9dac6a5
Created May 14, 2023 18:53
Delete all lables in github repo matching a regexp pattern
Given regexp pattern:
^1\..*?\s
gh label list --sort name | grep -o -E '^1\..*?\s' | xargs -I% gh label delete --yes %
#!/bin/bash
SerialNumber=$(/usr/sbin/system_profiler SPHardwareDataType | grep "Serial Number (system)" | awk '{print $4}')
log stream --style syslog -predicate 'subsystem == "com.apple.Authorization" AND eventMessage contains "authenticated as user queenofclubs"' | while read LINE; do
echo "$LINE" && curl -X POST --silent --data-urlencode \
"payload={\"text\": \"$(echo $LINE | sed "s/\"/'/g")\"}" https://hooks.slack.com/services/xxxxxx/xxxxx/xxxxx;
done
@mattimatti
mattimatti / ChatGPTService.php
Created March 21, 2023 09:20 — forked from whoisthisstud/ChatGPTService.php
ChatGPT written Laravel Service class for interacting with ChatGPT's API.
<?php
namespace App\Services;
use GuzzleHttp\Client;
class ChatGPTService
{
private $apiKey;
private $baseUrl;
@mattimatti
mattimatti / README.md
Created March 19, 2023 21:00 — forked from heywoodlh/README.md
Auth logging on MacOS using the log command
mkdir -p /opt/scripts
mkdir -p /var/log/custom
mkdir -p /var/root/Library/LaunchAgents


curl 'https://gist.githubusercontent.com/heywoodlh/0295135b9e24ec0729571497c9ab5a77/raw/b3032d9a563c956f574176c39cb2a5382f8c579c/auth-log.sh' -o /opt/scripts/auth-log.sh
chmod +x /opt/scripts/auth-log.sh

@mattimatti
mattimatti / TemplateProcessor.php
Created March 15, 2022 06:28 — forked from jeffsrepoaccount/TemplateProcessor.php
PHPOffice/PHPWord - Injecting AltChunks in word document using placeholders in template file
<?php namespace My\Namespace;
use DOMDocument;
use Parsedown;
use PhpOffice\PhpWord\TemplateProcessor as PhpWordTemplateProcessor;
class TemplateProcessor extends PhpWordTemplateProcessor
{
/**
* Injects a markdown snippet as HTML into the word document.
@mattimatti
mattimatti / README.md
Created September 21, 2021 10:35 — forked from m1keil/README.md
Configure Kibana to use SAML with GSuite (Google Apps, GApps, G Suite)

The following worked with Elastic Cloud, Elasticsearch & Kibana v7.6.0. It should be pretty close for other kinds of deployments. Before starting, make sure you have the right license level that allows SAML.

Create SAML App in GSuite:

  • Navigate to the SAML apps section of the admin console
  • Click the Add button and choose to "SETUP MY OWN CUSTOM APP"
  • Write down the Entity ID and download the Idp metadata file
  • Choose application name, description and add logo
  • In the "Service Provider Details" screen add the following:
@mattimatti
mattimatti / Docverter PHP-CURL example
Created November 28, 2019 12:57 — forked from tim-peterson/Docverter PHP-CURL example
Docverter PHP-CURL example
//set POST variables
$url = 'http://c.docverter.com/convert';
$fields = array('from' => 'markdown',
'to' => 'pdf',
'input_files[]' => "@/".realpath('markdown.md').";type=text/x-markdown; charset=UTF-8"
);
//open connection
$ch = curl_init();
@mattimatti
mattimatti / AwakenSpotify.scpt
Created July 19, 2018 13:43 — forked from alisonailea/AwakenSpotify.scpt
AppleScript to automate the Spotify playlist launch based on the time of day
--current time in seconds since midnight
set currentTime to (time of (current date))
## Morning
-- (04:00 - 10:30)
set morning to 37800
set morningVolume to 80
-- Happy: Wake Up in a Good Mood
set morningTrack to "spotify:user:116779154:playlist:5sYrf2RnhPY22meUSS5fUu"
@mattimatti
mattimatti / nginx.conf.j2
Last active June 25, 2018 13:30
nginx.conf to proxy pass google storage engine bucket with https support
events {
}
http {
# Proxy Cache
# Cache 10GB for 1 Month
#proxy_cache_path /var/cache/nginx keys_zone=GS:10m inactive=720h max_size=10240m;