Skip to content

Instantly share code, notes, and snippets.

probably drinking coffee

James Drew jdrew1303

probably drinking coffee
View GitHub Profile
jdrew1303 / 0_reuse_code.js
Created Mar 25, 2014
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
import java.util.HashSet;
import java.util.TreeSet;
public class SetBenchmark extends SimpleBenchmark {
// If you add a main function, you can run it from your IDE.
public static void main(String[] args) throws Exception {
new Runner().run(
View designer.html
<link rel="import" href="../ace-element/ace-element.html">
<link rel="import" href="../core-input/core-input.html">
<link rel="import" href="../paper-button/paper-button.html">
<polymer-element name="my-element">
:host {
position: absolute;

#Lessons From A JavaScript Code Review

I was recently asked to review some code for a new JavaScript application and thought I might share some of the feedback I provided as it includes a mention of JavaScript fundamentals that are always useful to bear in mind. Code reviews are possibly the single biggest thing you can do to improve the overall quality of your solutions and if you're not actively taking advantage of them, you're possibly missing out on bugs you haven't noticed being found or suggestions for improvements that could make your code better.

##Challenges & Solutions

Code reviews go hand-in-hand with maintaining strong coding standards. That said, standards don't usually prevent logical errors or misunderstandings about the quirks of a programming language. Even the most experienced developers can make these kinds of mistakes and code reviews can greatly assist with catching them.

Often the most challenging part of code reviews is actually finding an experienced developer you trust to complete

View mobileURLs.js
// matchMedia is supported and the device has a small screen
if ( "matchMedia" in window
&& window.matchMedia( "(max-device-width: 800px)" )
) {
// for each element matching the selector...
"a[href*=''], a[href*='']"
// ...replace the href with their mobile equivalent
View recog.js
r = new webkitSpeechRecognition;
r.continuous = true;
r.interimResults = true;
r.onresult = function(ev) {
View snippet for someone
# Start an HTTP server from a directory, optionally specifying the port
function server() {
local port="${1:-8000}"
open "http://localhost:${port}/"
# Set the default Content-Type to `text/plain` instead of `application/
# And serve everything as UTF-8 (although not technically correct, this
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTP
View cranium.js
/* Cranium MVC
* A minimalist MVC implementation written for
* demonstration purposes at my workshops
* Copyright (c) 2012 Addy Osmani; Licensed MIT */
var Cranium = Cranium || {};
// Set DOM selection utility
View timeUntil.js
var timeUntil = {
inHours: function(d1, d2) {
return parseInt((d2.getTime()-d1.getTime())/(24*3600), 10);
inDays: function(d1, d2) {
return parseInt((d2.getTime()-d1.getTime())/(24*3600*1000), 10);
View flyweight.js
// Flyweight.js - Copyright Addy Osmani, 2012.
// Consider public domain
// My implementation in JS of this:
// Simulate pure virtual inheritance/'implement' keyword for JS
Function.prototype.implementsFor = function (parentClassOrObject) {
if (parentClassOrObject.constructor == Function) {
// Normal Inheritance
this.prototype = new parentClassOrObject;