Skip to content

Instantly share code, notes, and snippets.

View daffodilistic's full-sized avatar

T. H. Soh daffodilistic

View GitHub Profile
@daffodilistic
daffodilistic / lazy_random_color.js
Created November 25, 2022 03:06
Lazy JavaScript Random Color
function getRandomColor(excludeHex) {
let rgb = [ 255, 255, 255 ];
return `${excludeHex ? '' : '#'}${rgb.map(x => Math.floor(Math.random() * 255 + 1).toString(16)).join("")}`;
}
@daffodilistic
daffodilistic / luminus_auto_sort_filename.user.js
Last active February 19, 2022 03:39
Auto-sort by filename on page load in LumiNUS
// ==UserScript==
// @name LumiNUSAutoSort
// @description Sorts files alphabetically by default when you view the "Files" section of a module in LumiNUS
// @author Soh Thiam Hing
// @license OSL-3.0
// @version 1.0
// @match https://luminus.nus.edu.sg/*
// @namespace com.daffodilistic.tampermonkey
// @require https://cdn.jsdelivr.net/gh/CoeJoder/waitForKeyElements.js@6b9ca81bf32899b4274086aa9d48c3ce5648e0b6/waitForKeyElements.js
// ==/UserScript==
@daffodilistic
daffodilistic / standup.js
Created October 18, 2021 00:21
Google App Script to automatically post a Slack message for Daily Standups
function doGet(e) {
const slackWebhookUrl = "https://hooks.slack.com/services/";
const meetingUrl = "https://meet.google.com/";
let today = new Date();
today.setHours(today.getHours() + 8);
// Logger.log("Date and time is " + today.toISOString());
if (today.getDay() >= 1 && today.getDay() <= 5) {
const formattedDate = Utilities.formatDate(today, "GMT+8", "E d MMM yyyy");
const text = `*Standup - ${formattedDate} 10.10 AM Video Meeting*\n${meetingUrl}\n`;
@daffodilistic
daffodilistic / shrink.md
Last active September 22, 2021 03:52
Shrink an LVM Volume Online on Synology NAS Devices

Scenario

Synology DS418 on v6.2.4-25556 does not allow shrinking of volumes via the GUI. Thus, this must be done via an SSH terminal. This gist is written as generically as possible so that it works for the general use-case of shrinking volumes formatted with the BTRFS filesystem, and then expanding another one. For this scenario, it's a volume that's being used for Time Machine.

Instructions

  1. SSH into the Synology NAS and switch to root account with sudo su.
  2. Run btrfs filesystem show to list the volumes:
root@SynologyNAS:~# btrfs filesystem show
@daffodilistic
daffodilistic / usbgadget_razer.sh
Created August 23, 2021 04:39 — forked from tothi/usbgadget_razer.sh
Razer USB gadget on Android for Local Privilege Escalation on Windows
# MINIMAL USB gadget setup using CONFIGFS for simulating Razer Gaming HID
# devices for triggering the vulnerable Windows Driver installer
# credits for the Windows Driver install vuln: @j0nh4t
#
# https://twitter.com/j0nh4t/status/1429049506021138437
# https://twitter.com/an0n_r0/status/1429263450748895236
#
# the script was developed & tested on Android LineageOS 18.1
@daffodilistic
daffodilistic / odoo.service
Created May 26, 2021 05:58
Systemd unit to start a docker container with proper logging
[Unit]
Description=Odoo Docker Container Service
Requires=docker.service network.target
After=docker.service network.target
[Service]
Type=exec
User=root
Group=google-sudoers
WorkingDirectory=/var/docker
@daffodilistic
daffodilistic / backup_sql.py
Last active June 23, 2021 07:37
Automatically dump SQL data to Google Cloud Storage
#!/usr/bin/env python
import subprocess
import os
import pipes
import argparse
from zipfile import ZipFile
from google.cloud import storage
from datetime import datetime
parser = argparse.ArgumentParser()
@daffodilistic
daffodilistic / keepalive.py
Last active April 28, 2021 13:13
Keeps a GCP instance alive. Useful for preemptible instances
import os
from googleapiclient import discovery
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "./service-account-key.json"
HOSTNAME = "example.com"
GCP_PROJECT = 'project_name'
GCP_INSTANCE_ZONE = 'instance_zone'
GCP_INSTANCE_NAME = 'instance_name'
@daffodilistic
daffodilistic / copy_es.sh
Created April 13, 2021 09:49
Dump and Restore ElasticSearch documents and indices
#!/bin/bash
elasticdump --input=$1 --output=$2 \
--type=analyzer --concurrencyInterval=500
curl -X POST "$2/_open?pretty"
elasticdump --input=$1 --output=$2 \
--type=mapping --concurrencyInterval=500
elasticdump --input=$1 --output=$2 \
--type=data --concurrencyInterval=500
@daffodilistic
daffodilistic / app_passwd_auth.php
Created March 17, 2021 09:51
Basic plugin to demonstrate enabling application passwords and REST endpoint security via HTTP Basic auth
<?php
/**
* Plugin Name: Application Password and REST Authentication Test Plugin
* Description: Basic plugin to demonstrate enabling application passwords and REST endpoint security via HTTP Basic auth
* Version: 0.1.0
* Requires at least: 5.6
* Author URI: https://github.com/daffodilistic/
* Author: Soh Thiam Hing
* License: The Unlicense