Skip to content

Instantly share code, notes, and snippets.

View taylor8294's full-sized avatar

Alex Taylor taylor8294

View GitHub Profile
@taylor8294
taylor8294 / wslubuntu2204-desktop.md
Created August 10, 2022 13:52
A guide to setting up an Ubuntu 22.04 Gnome desktop session within WSL2 on a windows machine, including audio support by using VcXsrv and PulseAudio.
@taylor8294
taylor8294 / dimmer.js
Last active June 10, 2020 23:15
Javascript utility to highlight multiple elements in a HTML page whilst dimming the rest of the page, also smoothly transitions between highlighting different elements. Uses a canvas overlay (no box-shadow or z-index stuff) and no dependencies (but works nicely if passed a jQuery object).
(function(window,document,undefined){
var Dimmer = function(options){
this.options = Object.assign({}, Dimmer.defaults, options)
if(!this.isDomNode(this.options.parent)) this.options.parent = Dimmer.defaults.parent
if(this.options.opacity > 1 && this.options.opacity <= 100) this.options.opacity = this.options.opacity/100
else if(this.options.opacity > 1 && this.options.opacity <= 255) this.options.opacity = this.options.opacity/255
else if(this.options.opacity < 0 || (this.options.opacity > 1 && this.options.opacity > 255)) this.options.opacity = Dimmer.defaults.opacity
@taylor8294
taylor8294 / jquery.appbanner.js
Last active June 10, 2020 15:10
Small utility to produce native-looking app install banners (like https://i.imgur.com/Qu3hoGh.png) in mobile browsers. Relies on jQuery being present in the page. Initiate like `new AppBanner({ios:{id:'1500000000',title:'My App',store:'gb'},android:{id:'com.example.app',title:'My App'},showAfter:30});`
/* Native App Install Banner v1 ~ (c) 2020 Alex Taylor */
(function (window, document, $, undefined) {
var AppBanner = function (options) {
var OS = AppBanner.OS;
// merge default options with user config
this.options = $.extend(true, {}, AppBanner.defaults, options);
if (this.options.debug) {
@taylor8294
taylor8294 / Matter.RenderSVG.js
Last active May 26, 2024 05:08
The `RenderSVG` module is an SVG alternative to the Matter.js built-in canvas-based renderer.
/**
* Overwrite `Common.isElement` to allow for SVG elements also
*/
Matter.Common.isElement = function(obj) {
try {
return obj instanceof HTMLElement || obj instanceof SVGElement;
} catch (e) {
return (typeof obj === "object") &&
(obj.nodeType === 1) && (typeof obj.style === "object") &&
(typeof obj.ownerDocument === "object");
@taylor8294
taylor8294 / mypanelmenu.component.ts
Created February 4, 2019 20:39
How to add badges to PrimeNG panelMenu MenuItem's
/**
* Usage: just add "add-badge-X badge-class-Y" to the icon proporty of the item.
* Where "X" is any content for the badge (eg. "add-badge-1" "add-badge-unread-mail" "add-badge-!" etc) can use anything
* separate words with a dash ("-") and if you want to use a dash in the badge content just escape it with a backslash
* (eg "add-badge-ages-16\\-24").
* Where "Y" is any Bootstrap style class (eg. "info", "danger", etc)
* Requires bootstrap/_badges.scss
*/
import { Component, OnInit, AfterViewInit } from '@angular/core';
// Postinstall script to ensure jQuery loads in the window object when using in Electron (not in module.exports)
// See https://stackoverflow.com/questions/32621988/electron-jquery-is-not-defined
const fs = require('fs');
const f_jquery = 'node_modules/jquery/dist/jquery.min.js';
fs.readFile(f_jquery, 'utf8', function (err, contents) {
if (err) {
return console.log(err);
}
var result = contents.replace('"use strict";"object"==typeof module&&"object"==typeof module.exports?', '"use strict";false?');
fs.writeFile(f_jquery, result, 'utf8', function (err) {
@taylor8294
taylor8294 / jquery.fullwidth.js
Last active January 22, 2019 10:05
A jQuery plugin to enable full width containers in limited width parents
/**
* A jQuery plugin to enable full width containers in limited width parents
* @external "jQuery.fn"
* @see {@link http://docs.jquery.com/Plugins/Authoring The jQuery Plugin Guide}
* @example
* $('img.full-width').fullWidth('.container');
* $('img.full-width').each(function(){ $(this).data('fullWidth').removeFullWidth() });
*/
// Closure - BEGIN
@taylor8294
taylor8294 / GameOfLife.py
Last active April 22, 2018 17:25
Conway's Game Of Life in 'Pythonista for iOS'
#!python3
# coding: utf-8
'''
A "Conway's Game Of Life" implementation for use with (Pythonista for iOS)[http://omz-software.com/pythonista/] (v3).
Features include:
* Start menu with ability to choose from a selection of intial states
* Pause button
* Tap the screen to bring cells to life
* Tap with two fingers to pause the game (without the menu) to allow you to draw cells. Tap again with two fingers to play.
Roadmap / Needed / To do: