Skip to content

Instantly share code, notes, and snippets.

View Stanback's full-sized avatar

Brian Stanback Stanback

  • Demand.io
  • Los Angeles, California
View GitHub Profile
@Stanback
Stanback / ip_conversions.scala
Last active June 10, 2022 10:46
Scala example for converting an IPv4 or IPv6 address to a base 10 decimal/long/BigInt w/ netmask range calculation
import java.net.{Inet4Address, Inet6Address, InetAddress}
import scala.util.Try
sealed trait IPAddressException {
self: Throwable => val message: String
}
case class IPAddressParseException(message: String) extends Exception(message) with IPAddressException
trait IPAddress {
@Stanback
Stanback / samsung_remote.js
Last active September 29, 2022 05:13 — forked from danielfaust/samsung_remote.py
Samsung TV Remote Control Node.js Script
const net = require('net');
//
// A Node.js port of this original Gist: https://gist.github.com/danielfaust/998441
// To find hosts on the network: nmap -Pn -p55000 192.168.12.1/24
//
// Note: This is for Samsung TVs circa 2012-2015 that use a service running on port 55000
// Samsung TV's circa 2016 and later use a WebSocket service on port 8001 which is different
//
@Stanback
Stanback / animation.css
Created April 12, 2018 16:12
CSS animation example
body {
padding: 5rem;
}
.animation {
height: 1.25rem;
margin: .625rem 0 0;
}
.animation-dot {
@Stanback
Stanback / compress.sh
Created December 8, 2017 18:57
PDF Compression w/ Ghostscript
gs \
-dNOPAUSE \
-dQUIET \
-dBATCH \
-dSAFER \
-dPDFSETTINGS=/printer \
-dCompatibilityLevel=1.3 \
-dPDFA=2 \
-dPDFACompatibilityPolicy=1 \
-dSimulateOverprint=true \
@Stanback
Stanback / preactDomRenderer.js
Last active June 28, 2017 21:39
Preact DOM render using undom
// src/app/preactDomRenderer.js
import { h, render } from 'preact';
import undom from 'undom';
const VOID_ELEMENTS = [
'area',
'base',
'br',
'col',
@Stanback
Stanback / fixuri.scala
Last active December 14, 2016 16:59
Regex for fixing improperly formatted URIs
/*
* Snippet to encode invalid characters from improperly formatted URIs
*
* RFC 3986 defines that URIs may contain the following characters:
* ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=`.```
*/
import java.net.URLEncoder
"""[^A-Za-z0-9-._~:/?#\[\]@!$&'\(\)*+,;=%`]|%[^0-9a-fA-F]{2}]""".r.
@Stanback
Stanback / getOrdinal.js
Created August 23, 2016 20:14
Convert integer to an ordinal number (e.g. 1st, 2nd, 3rd, etc)
function getOrdinal(value) {
const suffixes = ['th', 'st', 'nd', 'rd'];
const normalized = value % 100;
return value + (suffixes[(normalized - 20) % 10] || suffixes[normalized] || suffixes[0]);
}
@Stanback
Stanback / emblem2hbs.sh
Created December 1, 2015 05:04
Convert all emblem files to handlebars format (emblem2hbs.sh)
#!/bin/bash
# Install emblem2hbs cli
npm -g install emblem2hbs
# Convert all emblem files to handlebars
for f in $(ls -1 {,**/}*.emblem); do; emblem2hbs $f; done;
# Optionally delete original emblem files
find . -name "*.emblem" -exec rm {} \;
@Stanback
Stanback / coffee2js.sh
Last active July 11, 2019 10:30
Convert all CoffeeScript files to Javascript (coffee2js)
#!/bin/sh
# Install coffeescript cli
npm -g install coffee-script
# Convert all coffeescript files to javascript
find . -name "*.coffee" -exec coffee --no-header --bare -c {} \;
# Optionally delete original coffee files
find . -name "*.coffee" -exec rm {} \;