Skip to content

Instantly share code, notes, and snippets.

View pid's full-sized avatar

Sascha pid

  • Baden-Württemberg, Germany
View GitHub Profile

Memory Management and Performance

JavaScript engines such as Google’s V8 (Chrome, Node) are specifically designed for the fast execution of large JavaScript applications. As you develop, if you care about memory usage and performance, you should be aware of some of what’s going on in your user’s browser’s JavaScript engine behind the scenes.

Continue reading Writing Fast, Memory-Efficient JavaScript, great general overview of a Google employee

Videos

GIT Version Control System

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Git is easy to learn and has a tiny footprint with lightning fast performance. It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows.

Tools

/**
* Performs a binary search on the host array. This method can either be
* injected into Array.prototype or called with a specified scope like this:
* binaryIndexOf.call(someArray, searchElement);
*
* @param {*} searchElement The item to search for within the array.
* @return {Number} The index of the element which defaults to -1 when not found.
*/
function binaryIndexOf(searchElement) {
'use strict';

This is a small collection of scripts showing how to use require.js. It's only one of several ways of setting up a require.js project, but it's enough to get started.

At its core, require.js is about three things:

  1. Dependency management
  2. Modularity
  3. Dynamic script loading

The following files show how these are achieved.

jQuery.fn.brightness = function() {
var bg_color, rgba, y;
bg_color = this.css('background-color');
if ((bg_color != null) && bg_color.length) {
rgba = bg_color.match(/^rgb(?:a)?\(([0-9]{1,3}),\s([0-9]{1,3}),\s([0-9]{1,3})(?:,\s)?([0-9]{1,3})?\)$/);
if (rgba != null) {
if (rgba[4] === '0') {
if (this.parent().length) return this.parent().brightness();
} else {
y = 2.99 * rgba[1] + 5.87 * rgba[2] + 1.14 * rgba[3];

REST Ideology & Rants

I am getting frustrated by the number of people calling any HTTP-based interface a REST API. Today’s example is the SocialSite REST API. That is RPC. It screams RPC. There is so much coupling on display that it should be given an X rating.

REST APIs must be hypertext-driven


Roy Fielding writes a PhD dissertation describing the architectural style of the World Wide Web. He coins the term ‘Representational State Transfer’ (REST) to describe it – after all, if you’re going to talk about something, you need to give it a name. Somehow, in a semantic shift of epic fail proportions, the term REST has also come to mean something completely different to most people, a ‘style’ of writing web services. This style has no agreed protocol.

@pid
pid / dabblet.css
Created November 10, 2013 11:45 — forked from LeaVerou/dabblet.css
/**
* Google-style progress indicator
*/
@keyframes progress {
50% { border-width: .5em 0; }
to { border-width: .5em 0 0 0; }
}
@keyframes rotate {
@pid
pid / browser.md
Created November 20, 2013 14:44 — forked from defunctzombie/browser.md

The browser field is provided by a module author as a hint to javascript bundlers or component tools when preparing modules for client side use.

terms

Below are common terms used in the rest of the document

server

This is a non-dom based javascript execution environment. It usually only contains the base javascript language spec libraries and objects along with modules to communicate with OS features (available through commonjs require).

client

@pid
pid / gist:7813255
Last active December 30, 2015 09:59 — forked from liamcurry/gist:2597326
Moving from jQuery to VanillaJS

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})