Skip to content

Instantly share code, notes, and snippets.

@Quacky2200
Quacky2200 / Program.cs
Last active September 3, 2021 19:45
C# Edition of Base62 integer encode/decode originally from https://gist.github.com/sebastien-p/1170594
using System;
using System.Linq;
using System.Text;
namespace ConsoleApp1
{
class Program
{
public static string Base62EncodeInt(int Original)
{
@Quacky2200
Quacky2200 / Request.php
Last active July 24, 2020 17:39
Generic request class, mostly for API requests
<?php
/**
* REST test scripts
* @license MIT
*/
class Request {
public $protocol;
public $host;
public $path;
@Quacky2200
Quacky2200 / unit-measurement-checks.js
Created January 2, 2020 06:58
Test JavaScript file to test measurements are valid
/**
* This function returns whether the given values are valid measurements.
*
* @param string|string[] inputArray List or string of measures
* @param string|string[] validUnits List or string of valid units
* @param mixed opts Options
* @return boolean Whether measure(s) is valid
*/
function checkValidUnits(inputArray, validUnits, opts) {
@Quacky2200
Quacky2200 / tag.ts
Created September 29, 2019 17:51
This is a tag.js alternative written in TypeScript; most specifically for react development. You'd likely use JSX, but this is here as I was used to using pug-like strings before.
import 'core-js';
import React from 'react';
const matchAll = require('string.prototype.matchall');
interface iTagObject {
name: string,
attributes: any,
content: any
}
@Quacky2200
Quacky2200 / repermute.py
Last active February 13, 2024 18:31 — forked from mdeous/repermute.py
Generate all possible permutations of a regex (Python v3)
# -*- coding: utf-8 -*-
#
# Used like this:
#
# from repermute import ipermute
#
# for s in ipermute('[A-Z]\d'):
# print s
#
# Almost all regular expression constructs are supported except for '*'
@Quacky2200
Quacky2200 / tag.js
Last active August 29, 2019 17:12
Simple JavaScript template/view/HTML building function.
/**
* Tags by Argument
*
* Creates a HTML string from the element name, attributes and content given
* as part of the arguments provided.
*
* The name argument can be null, which will produce a standard div element.
* If the name is prefixed with a hash, and an id is not provided as an
* attribute, then the id attribute will be added. Classes can be described
* by using dot notation and will get prefixed to the class attribute. This
@Quacky2200
Quacky2200 / promises.js
Last active August 15, 2019 17:13
My own take on JavaScript promises. It was a challenge but just about got it to work. There's probably a few bugs but the tests should help for debugging and testing
Promise = function(fn) {
var value = undefined;
var stack = [];
var state = 'pending'
var triggered = false;
var error = undefined;
var id = (function (len, chars) {
len = len || 10;
chars = chars || "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var text = "";
@Quacky2200
Quacky2200 / isValidColor.js
Created April 23, 2019 10:58
Tests if a given string matches a valid color format
/**
* isValidColor
* Tests whether a given color is in a valid format when used for CSS/form validation.
* Mostly written by copying colors and regexes (because of laziness, and it's been
* written n-times before).
*
* @author Matthew
* @copyright MIT 2019+
*/
var isValidColor = function(color) {
@Quacky2200
Quacky2200 / uptime.py
Last active November 30, 2018 01:18
Creates a log, useful for dodgy internet. Checks every minute and creates an empty lock file to stop being run more than once. Add to cron or set as a service to make it start automatically
import time
import sys
import datetime
from os.path import isfile as file_exists
from os import remove as file_delete
import os
from ping3 import ping
import signal
import sys
@Quacky2200
Quacky2200 / WebServer.cs
Last active October 18, 2018 20:44
Do you ever need a tiny C# web server in your back pocket?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Net;
using System.Diagnostics;
using System.Net.Sockets;
// Created a temporary web server as part of a payment SDK example