Skip to content

Instantly share code, notes, and snippets.

View sbrl's full-sized avatar

Starbeamrainbowlabs sbrl

View GitHub Profile
@sbrl
sbrl / 0_reuse_code.js
Created December 20, 2015 19:48
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@sbrl
sbrl / zoom.js
Last active December 20, 2015 20:30
An (almost perfect) zoom function that zooms into the mouse cursor pointer. Assumes that the canvas is full screen - adjusting for this shouldn't be too tough.
/*
* An (almost perfect) zoom function that zooms into the mouse cursor pointer.
* Assumes that the canvas is full screen - adjusting for this shouldn't be too
* tough.
*
* Attaches a zoom level update function to the mouse wheel event of
* the document. Calling this activates zooming via the mouse wheel.
*
* Assumes that it is part of a class of sorts.
*
@sbrl
sbrl / Class.cpp
Last active March 2, 2016 10:28
A template C++ class.
#include <string>
#include <iostream>
#include "ClassName.h"
using namespace std;
ClassName::ClassName()
{
}
@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 / 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 / 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 / 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 / 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 / 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 / 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}