Skip to content

Instantly share code, notes, and snippets.

View timmywil's full-sized avatar
🚀
Working on @spokestack

Timmy Willison timmywil

🚀
Working on @spokestack
View GitHub Profile
@timmywil
timmywil / index.d.ts
Last active August 14, 2020 22:19
react-native-track-player types
import { Component } from 'react'
import { NativeModules } from 'react-native'
export = RNTrackPlayer
declare namespace RNTrackPlayer {
export type EventType =
| 'playback-state'
| 'playback-error'
| 'playback-queue-ended'
@timmywil
timmywil / what-forces-layout.md
Created June 17, 2016 17:22 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@timmywil
timmywil / PostgresStore.js
Last active August 29, 2015 14:01
Connect-based postgres session storage for the latest pg module
/**
* Connect-based Postgres session storage
* Based off https://github.com/brianc/postgres-session
*/
'use strict';
var assert = require('assert');
var pg = require('pg');
var Store = require('express-session').Store;
@timmywil
timmywil / config.json
Created March 17, 2014 20:11
Building an optimized module that goes blank.
{
"appDir": "./website/public/",
"baseUrl": "js",
"dir": "./build",
"optimizeCss": "standard",
"fileExclusionRegExp": "(?:^\\.)|node_modules",
"mainConfigFile": "./website/public/js/main.js",
"modules": [
var foo = function foo() {
foo = 5;
console.log(foo);
};
foo();
// outputs: [Function foo]
@timmywil
timmywil / jquery.factory.js
Last active December 19, 2015 15:49
Using jQuery in a CommonJS-like environment and multiple contexts.
// This can be done with what is currently in github (but has not yet been released)
// Using jsdom
var dom = jsdom.jsdom();
var window = dom.createWindow();
var window2 = dom.createWindow();
var factory = require('jquery');
var jquery1 = factory( window );
var jquery2 = factory( window2 );
@timmywil
timmywil / shared.js
Created February 7, 2013 15:20
This is a shared module between server and client. It has one extra dependency in the browser because it should not be used on the server. This pattern was arrived at because it was the only one I found that worked after building with r.js. I'd like to suggest removing the entire if statement even if it has extra content such as defining empty m…
// For node
if (typeof define !== "function") {
var define = require("amdefine")( module );
// Define base64 as empty
define("libs/base64", function() {});
}
define([ "node-uuid", "libs/base64" ],
function( uuid, base64 ) {
function awesome() {
@timmywil
timmywil / backPushState.js
Created November 18, 2011 16:07
A simple pushState plugin that falls back to hashChange (only for going back)
/**
* @license backPushState.js
* A simple pushState library that falls back to hashChange (only for going back)
* Copyright (c) 2011 timmy willison
* Dual licensed under the MIT and GPL licenses.
* http://timmywillison.com/licence/
*/
define([ 'jquery' ],
function( $ ) {
<body>
<div id="foo">...</div>
<script src="jquery.js"></script>
<script>
$( "#foo" ).offset();
</script>
</body>
@timmywil
timmywil / minimal-event.js
Created October 28, 2011 17:01
Fire an event cross-browser
var fire;
if ( document.createEvent ) {
fire = function( node, type ) {
var event = document.createEvent('HTMLEvents');
event.initEvent( type, true, true );
node.dispatchEvent( event );
};
} else {
fire = function( node, type ) {
var event = document.createEventObject();