Skip to content

Instantly share code, notes, and snippets.

View sbrl's full-sized avatar

Starbeamrainbowlabs sbrl

View GitHub Profile
@sbrl
sbrl / render-cross.js
Last active January 30, 2018 22:58
A simple function for rendering crosses on a HTML5 canvas. Depends on my earlier Vector class. #debugging #function
function renderCross(context, pos, size)
{
var radius = size / 2;
context.beginPath();
context.moveTo(pos.x - radius, pos.y - radius);
context.lineTo(pos.x + radius, pos.y + radius);
context.moveTo(pos.x + radius, pos.y - radius);
context.lineTo(pos.x - radius, pos.y + radius);
context.lineWidth = 3;
@sbrl
sbrl / ResizeImage.sh
Last active September 17, 2017 09:35
Bash script to resize an image using imagemagick. Uses yad to provide a simple GUI. #bash #cli
#!/usr/bin/env bash
width=$(identify -ping -format "%w" "$1")
height=$(identify -ping -format "%h" "$1")
raw_options=$(yad --center --title "Resize image" --form --float-precision 0 --field "Filename":RO --field "Width":NUM --field "Height":NUM --field "Preserve aspect ratio":CHK "$1" "$width" "$height" true)
# 0: Filename
# 1: Width
# 2: Height
@sbrl
sbrl / resizeImage.php
Last active September 17, 2017 09:35
Resize a GD image to fit inside a square of the given size. #php
<?php
/*******************************************************************************
******************************* resizeImage.php *******************************
*******************************************************************************
* Resizes a GD image to fit inside a square of the given size.
******************************************************************************/
function resize_image($image, $size)
{
$cur_width = imagesx($image);
$cur_height = imagesy($image);
@sbrl
sbrl / sslinfo.php
Last active September 17, 2017 09:34
A simple SSL certificate status panel for tracking the expiry of your (many) TLS certificates. #php #microservice
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>SSL Certificate Status Panel</title>
</head>
<body>
<h1>SSL Certificate Status Panel</h1>
<?php
@sbrl
sbrl / string.PadBoth.cs
Last active January 30, 2018 23:07
Center pad a string in C♯. #function
namespace System
{
public static class StringExtensions
{
/// <summary>
/// Pads the string on both sides.
/// </summary>
/// <param name="length">The length to pad the string to.</param>
public static string PadBoth(this string str, int length)
{
@sbrl
sbrl / MobileMeta.html
Last active September 17, 2017 09:32
The mobile meta tag that makes alters the scaling of a page to make it readable on all devices. #html
<meta name="viewport" content="width=device-width, initial-scale=1" />
@sbrl
sbrl / GetContainingElement.js
Last active January 30, 2018 22:55
[GetContainingElement] Traverses up the DOM tree to find the first containing parent element of a given type for a given child element. #dom #search #find
/**
* Gets the first containing parent element of a given type for a given child element.
* @param {HTMLElement} element The child element to find the parent of.
* @param {string} type The name of the element containing parent to search for.
*/
function GetContainingElement(element, type)
{
while(element !== null && element.tagName.toLowerCase() !== type.toLowerCase()) {
element = element.parentNode;
}
@sbrl
sbrl / BadgeText.css
Last active September 17, 2017 09:30
Displays the contents of the `data-badge-content` attribute as a badge on an icon. Built to loosely mimic what amazon used to do with their basket. #css
.badge-text:after
{
content: attr(data-badge-content);
z-index: 10000;
position: absolute;
top: 60%; left: 50%;
width: 1em; height: 1em;
background: white;
@sbrl
sbrl / WebSocketStates.js
Last active January 30, 2018 22:56
[WebSocketStates] An ES6 module mapping the various WebSocket state constants onto their meanings. Could easily be refactored out to a regular javascript file. #es6 #module #microlibrary #websockets
"use strict";
/**
* Constants for the different readyStates that a WebSocket can be in.
* @type {Object}
*/
const WebSocketStates = {
/**
* Indicates that the WebSocket is connecting to the remote server.
* @type {Number}
@sbrl
sbrl / JsonConfig.php
Last active March 5, 2018 17:59
[JsonConfig] A simple PHP class to manage your app's settings. #settings #microlibrary
<?php
namespace SBRL\Utilities;
use \stdClass;
/**
* Handles the loading and saving of settings from a file.
* Supports loading default settings from a separate file.
* @author Starbeamrainbowlabs