Skip to content

Instantly share code, notes, and snippets.

@timw4mail
timw4mail / json-parser.js
Last active Jan 19, 2021
Pure JS JSON Parser
View json-parser.js
/**
* Pure JS JSON Parser
*
* @see https://lihautan.com/json-parser-with-javascript/
* @param {string} str
*/
function parseJSON(str) {
let i = 0;
const value = parseValue();
@timw4mail
timw4mail / GetLibrary.graphql
Created Dec 30, 2020
Kitsu Library GraphQL Query
View GetLibrary.graphql
query (
$slug: String!,
$type: MediaTypeEnum!,
$status: [LibraryEntryStatusEnum!],
$after: String
) {
findProfileBySlug(slug: $slug) {
library {
all(first: 100, after: $after, mediaType: $type, status: $status) {
pageInfo {
@timw4mail
timw4mail / index.php
Last active Nov 12, 2020
Image Viewer
View index.php
<!DOCTYPE html>
<html>
<head>
<title>Image Viewer</title>
<style>
* {margin: 0}
img {
max-width: 100%;
<?php if (empty($_GET['zoom'])): ?>
max-height: 900px;
@timw4mail
timw4mail / kernel-update.sh
Created Feb 28, 2020
Gentoo Grub2 on OpenFirmware (PowerPC) New Kernel Update Script
View kernel-update.sh
#!/bin/bash
set -euo pipefail
# Adapted from: https://wiki.gentoo.org/wiki/GRUB_on_Open_Firmware_(PowerPC)
# Re-generate grub.cfg
grub-mkconfig -o /boot/grub/grub.cfg
# Make new OF grub img
grub-mkimage --prefix=/boot/grub --format=powerpc-ieee1275 --config=/boot/NWBB/grub-initial.cfg --output=/boot/NWBB/grub.img `cat /boot/NWBB/grub_mod-minimal.list`
View emoji-functions.php
<?php declare(strict_types=1);
function createDataObject (int $min, int $max, array $blacklist = []): array
{
$output = [];
$index = 0;
for ($i = $min; $i <= $max; $i++)
{
$n = base_convert((string)$i, 10, 16);
@timw4mail
timw4mail / optimize-images.sh
Last active Jan 24, 2020
Image Optimization script
View optimize-images.sh
#!/usr/bin/env bash
set -euo pipefail
declare threads=`getconf _NPROCESSORS_ONLN`
optimise () {
declare -a exts=("${!1}")
declare msg=$2
for ext in ${exts[@]}
@timw4mail
timw4mail / build-php-ext.sh
Created Sep 9, 2019
PHP Extension source build boilerplate
View build-php-ext.sh
#!/bin/sh
make clean; # For those rebuilds
phpize;
autoreconf --install --force; # Stupid autotools/libtool version incompatibilities
./configure;
make;
sudo make install;
View backup.php
<?php
function Zip($source, $destination)
{
if (extension_loaded('zip') === true)
{
if (file_exists($source) === true)
{
$zip = new ZipArchive();
@timw4mail
timw4mail / minify.php
Created Nov 3, 2011
HTML Minification
View minify.php
<?php
define('SAFE', 1);
define('EXTREME', 2);
define('EXTREME_SAVE_COMMENTS', 4);
define('EXTREME_SAVE_PRE', 3);
function minify($html, $level=2)
{
switch((int)$level)
@timw4mail
timw4mail / index.php
Created Aug 18, 2011
PHP Kana transliterator
View index.php
<?php
include("kana.php");
if(isset($_GET['in']) && isset($_GET['action']))
{
$in = $_GET['in'];
if($_GET['action'] == "to_hira")
{
$out = Kana::to_hiragana($in);