Skip to content

Instantly share code, notes, and snippets.

View simondell's full-sized avatar

Simon Dell simondell

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@simondell
simondell / custom_poster.html
Created April 9, 2017 21:32
A friend asked me how to provide a custom poster image for a youtube video. The API doesn't permit this (and you'd likely have to be the video owner even if it did). My friend's research suggested setting the player's iframe opacity to 0 at load, and then 1 when the video plays. This seems to work. A noticeable delay occurs before the video load…
<!DOCTYPE html>
<html>
<head>
<title>Transparent YT player experiment</title>
<meta charset="UTF-8">
<style>
#wrapper {
position: relative;
width: 640px;
@simondell
simondell / vector_2d.js
Last active January 12, 2017 17:57
A very simple 2d vector implementation.
function Vector2D (x, y) {
this.x = x || 0;
this.y = y || 0;
}
Vector2D.prototype = {
constructor: Vector2D,
set: function set (arg1, y) {
if( arg1 instanceof Vector2D ) {
@simondell
simondell / chains_of_then.js
Last active November 2, 2016 17:43
Getting a handle on JS Promises
function timedPromise ( t, label ) {
console.info( 'making promise for ' + label );
return ( res,rej ) => {
setTimeout( () => {
console.log( label );
res( label )
}, t );
}
}
@simondell
simondell / hover.js
Last active March 29, 2016 14:42
Another way to do hover states, using JavaScript. Normally I'd prefer CSS `:hover` or similar, but I wanted a way to move a `.selected` class around the DOM.
var hover = (function () {
var previousTarget = null;
return function (event) {
var currentTarget = event.srcElement;
if(currentTarget === previousTarget) return;
if(previousTarget) previousTarget.classList.remove('selected');
@simondell
simondell / _simple_sprite.scss
Last active August 29, 2015 13:56
A simple SASS mixin for sprites.
// text-hiding for hipsters, http://www.zeldman.com/2012/03/01/replacing-the-9999px-hack-new-image-replacement/
.hide-text{
overflow: hidden;
text-indent: 100%;
white-space: nowrap;
}
/*
A simple sprite mixin
Pass it the path to the sprite file and the left and top co-ords of the frame/icon
@simondell
simondell / simple_factory.js
Last active January 1, 2016 17:59
A simplistic pattern for objects with private members
var Obj = function () {
return {
foo : foo,
foop : foo,
bar : bar
}
// private functions
function foo () { console.log('foo') }
function bar () { console.log('bar') }
@simondell
simondell / .jshintrc
Last active December 31, 2015 10:19
Coding style and code lint habits for developing browser-based projects. Some of the options are simply using the default values, but I felt it was worthwhile to actually encode my preferences explicitly.
{
"predef" : [],
"camelcase" : 1,
"curly" : 1,
"eqeqeq" : 1,
"forin" : 1,
"freeze": 0,
"immed" : 1,
"indent": 2,
"latedef" : "nofunc",
var arg_ary = [ 1, 2, 3 ];
var arg_obj = { foo: 'bar' };
function reset( param ) {
param[0] = undefined;
console.log( "in reset", param );
}
console.log( arg_ary ); // [ 1, 2, 3 ]
reset( arg_ary ); // [ undefined, 2, 3 ]
@simondell
simondell / easy_to_read_module.js
Created October 18, 2013 09:37
An example "class", or a "type", or a "module". The example was created to highlight "private static functions", and their placement in the file. General JS community dialog favours highlighting the effect of variable and function "hoisting" by writing such object definitions at the top of their scope. For larger objects intended as classes or m…
var MyStructure = (function () {
return {
str: 'rush',
go: function () {
doThisFirst();
doThisNext( this );
return this;
}
}