Skip to content

Instantly share code, notes, and snippets.

View richtr's full-sized avatar

Rich Tibbett richtr

View GitHub Profile
@richtr
richtr / Element.js
Created February 3, 2012 14:25
DOM Element Constructor wrapper
/**
* DOM Element constructor helper class.
*
* Usage:
* -------
* var newDiv = Element.create('div');
* var newDiv = Element.create('div', {text: "Hi"});
* var newDiv = Element.create('div', {text: "Hi "}, [
* Element.create('span', {style: 'color: #CC0000', html:"<b>you</b>"}, [
* // Infinitely chainable
@richtr
richtr / orientationChange.js
Last active February 26, 2021 09:11
JavaScript shim of iOS's window.orientation + orientationchange events for other (typically mobile) browsers
/*
* OrientationChange Event Shim
* http://github.com/richtr
*
* Copyright (c) 2012, Rich Tibbett
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@richtr
richtr / style_scoped_shim.js
Created November 8, 2012 15:12
<style scoped> polyfill
/*!
* <style scoped> shim
* http://github.com/richtr
*
* Copyright 2012 Rich Tibbett
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
* Date: 8th November 2012
*/
@richtr
richtr / advertiser.html
Last active August 29, 2015 13:57
BroadcastWebSocket (#1): Pure P2P advertisement, discovery and establishment of a full-duplex messaging channel between previously isolated web pages within a local network (updated strawman proposal can be found at https://gist.github.com/richtr/9683905)
<!DOCTYPE html>
<html>
<head>
<title>Pure P2P messaging channel establishment: Advertiser</title>
</head>
<body>
<h1>Pure P2P messaging channel establishment: Advertiser</h1>
<script>
@richtr
richtr / broadcastwebsocket_basic_example.html
Last active August 29, 2015 13:57
BroadcastWebSocket: advertising, discovering and communicating between web pages and devices running in the current local network
<!DOCTYPE html>
<html>
<head>
<title>BroadcastWebSocket usage demo</title>
</head>
<body>
<h1>BroadcastWebSocket usage demo</h1>
<script>
@richtr
richtr / broadcastwebsocket_basic_example.html
Last active August 29, 2015 13:57
BroadcastWebSocket: advertising, discovering and communicating between web pages and devices running in the current local network
<!DOCTYPE html>
<html>
<head>
<title>BroadcastWebSocket usage demo</title>
</head>
<body>
<h1>BroadcastWebSocket usage demo</h1>
<script>
@richtr
richtr / NormalVariablesFunctions.js
Last active August 29, 2015 13:59
Variable-bound Functions: JIT (Just In Time) function binding as an alternative to inline conditional statements within fast render loops
/**
*
* Normal method w/ inline conditional statements placed within each render loop
*
*/
var myVariable = true;
function normalLoop() {
if ( myVariable === true ) {
@richtr
richtr / handbrake_nas.applescript
Last active January 1, 2017 23:00
Synology NAS (or any other AFP-based shared folder) to Handbrake auto-conversion of avi/mkv files to mp4
-- AppleScript that mounts an AFP service (e.g. a Synology NAS Diskstation) then
-- searches for any .avi or .mkv files in the requested volume and converts all
-- the files it finds to .mp4 via HandbrakeCLI (which must be installed on your
-- machine at /Applications/HandbrakeCLI)
-- IMPORTANT: You may need to make sure your NAS does not sleep until ~4 hours of
-- inactivity has passed so it doesn't interrupt the mp4 conversion process of
-- this script.
-- Based loosely on the script published at http://cybernetnews.com/batch-convert-videos-handbrake-applescript/
@richtr
richtr / SensorCheck.js
Created September 23, 2014 14:21
A reliable DeviceOrientation and DeviceMotion Events API feature detection library
/**
* DeviceOrientation and DeviceMotion Events Detection API
*
* Example API Usage (Promise-based API):
*
* supportsDeviceOrientationEvents().then(function() {
* console.log("Platform DeviceOrientation Events support OK");
* }, function(error) {
* console.error("Platform DeviceOrientation Events support KO");
* });
@richtr
richtr / gist:2235fdae25c74186297d
Last active August 29, 2015 14:13
General considerations for Media Focus scoping, lifecycle and events

Media Focus Scope

  • At what level should Media Focus be requested and granted/revoked?

    • Per Tab(s)
      • Per Origin(s)
        • Per Document(s)
          • Per Media Grouping(s)
            • Per Media Object(s)
  • High-level vs. Low-level scope - what are the pros and cons of setting the media focus scope at these different levels? Do we want audio focus to be set and applied implicitly to tab/document/origin content or explicitly to in-page media groupings or elements?