Skip to content

Instantly share code, notes, and snippets.

@olsgreen
olsgreen / bus.ts
Last active February 3, 2023 13:16
Minimal javascript event bus
export class Events {
bus: HTMLElement
constructor() {
this.bus = document.createElement('div')
}
on(event: string, callback: Function) {
this.bus.addEventListener(event, callback as EventListenerOrEventListenerObject)
}
@olsgreen
olsgreen / query.sql
Created October 15, 2021 07:08
Orphan Page Query
SELECT Orphans.cID FROM Pages AS Orphans LEFT JOIN Pages AS Parents ON Orphans.cParentID = Parents.cID WHERE Parents.cID IS NULL AND Orphans.cID <> 1 AND Orphans.cIsSystemPage = 0 AND Orphans.cParentID <> 0;
@olsgreen
olsgreen / compress.sh
Created April 8, 2021 15:29
Compress an MP4 video with FFMPEG
ffmpeg -i video-in.mp4 -vcodec libx264 -crf 34 video-out-compressed.mp4
@olsgreen
olsgreen / tyre_sizes.json
Last active March 30, 2018 20:13
Common Tyre \ Tire Sizes JSON
{
"10": ["165/70"],
"12": ["155/80"],
"13": [
"155/80",
"175/70",
"175/80",
"185/60",
"185/70",
"185/80",
@olsgreen
olsgreen / strip-tags.php
Last active April 29, 2018 07:02
Strip all tags from an HTML fragment except selected tags and their attributes.
<?php
/*
* Strip all tags from an HTML fragment except selected tags and their attributes.
*
* $content = 'Hello world. <script>alert("XSS");</script>';
* $content .= But you can still click on this <a href="http://gog.gl" onclick="alert(\'XSS\')">link</a>';
*
* cleanHtml($content, $whitelist = ['a' => ['href']])
*
@olsgreen
olsgreen / sphp.sh
Created November 15, 2016 09:41 — forked from w00fz/sphp.sh
PHP switcher
#!/bin/bash
# Check if command was ran as root.
if [[ $(id -u) -eq 0 ]]; then
echo "The command \"sphp\" should not be executed as root or via sudo directly."
echo "When a service requires root access, you will be prompted for a password as needed."
exit 1
fi
# Usage
@olsgreen
olsgreen / mysql_backup.php
Created September 24, 2016 17:10
mysqli version of David Walsh's PHP MySQL backup script
/* backup the db OR just a table
* See original: https://davidwalsh.name/backup-mysql-database-php
*/
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
$link = mysqli_connect($host,$user,$pass,$name);
//get all of the tables
if($tables == '*')
@olsgreen
olsgreen / gist:fe87c4394f6fb3c19bd7
Last active August 29, 2015 14:23
Concrete 5.7.x Multiple File Selection
// Wire the trigger to show the file manager dialog
$('#addImageBtn').click(function () {
// Launch the dialog
ConcreteFileManager.launchDialog(function (data) {
// Parse the callback data to get more file detail
ConcreteFileManager.getFileDetails(data.fID, function(r) {
// Loop over each file and do whatever you want with it
@olsgreen
olsgreen / password-complexity.js
Created January 30, 2014 11:25
jQuery Password Complexity Meter
/**
* jQuery Password Complexity Meter
*/
(function ($) {
$(document).ready(function () {
$('.check-complexity').complexify({minimumChars:6, strengthScaleFactor:0.3}, function(valid, complexity){
$('.password-complexity > .progress-bar').css('width', complexity + '%');
#!/bin/sh
#
# /etc/rc.d/init.d/supervisord
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36