Skip to content

Instantly share code, notes, and snippets.

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@thysultan
thysultan / HEY-YOU.md
Created April 23, 2016 21:33 — forked from cowboy/HEY-YOU.md
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
@thysultan
thysultan / jquery-pubsub.js
Created April 23, 2016 21:41 — forked from bentruyman/jquery-pubsub.js
Simple Pub/Sub Implementation for jQuery
/*
* Simple Pub/Sub Implementation for jQuery
*
* Inspired by work from Peter Higgins (https://github.com/phiggins42/bloody-jquery-plugins/blob/master/pubsub.js)
*
* This is about the simplest way to write a pubsub JavaScript implementation for use with jQuery.
*/
(function( $ ) {
// Cache of all topics
// model
function Model () {
this._state = {}
return this
}
Model.prototype.get = function (key) {
return this._state[key]
}
@thysultan
thysultan / dom-to-json.js
Created June 11, 2016 08:14 — forked from Thaina/dom-to-json.js
Stringify DOM nodes using JSON (and revive again)
/** @param {Node|HTMLElement} node */
function toJSON(node) {
if(!node)
node = this;
var obj = { nodeType: node.nodeType };
if(node.tagName)
obj.tagName = node.tagName.toLowerCase();
else if(node.nodeName)
@thysultan
thysultan / memorySizeOfObject.js
Last active June 13, 2016 19:43
calculate memory size of javascript object, it is not a accurate value!
function memory(obj) {
var bytes = 0;
function size (obj) {
if (obj !== null && obj !== undefined) {
switch (typeof obj) {
case 'number': bytes += 8; break;
case 'string': bytes += obj.length * 2; break;
case 'boolean': bytes += 4; break;
case 'object':
@thysultan
thysultan / frameLoop.js
Created August 27, 2016 15:18 — forked from thebuilder/frameLoop.js
Call a function with a specific FPS. Exposes methods to pause, start and destroy the looper. Uses ES6.
/**
* @param fn {Function} Callback function to trigger on frame
* @param fps {int} Target FPS
* @returns {{pause: pause, start: start, destroy: destroy}}
*/
function frameLoop(fn, fps=60) {
let then = 0;
let interval = 1000 / fps;
let isRunning = true;
let currentFrameId = null;
@thysultan
thysultan / bench-instanceof-versus-typeof-megamorphic.js
Last active January 29, 2019 08:35 — forked from bmeurer/bench-instanceof-versus-typeof-megamorphic.js
Demonstrate the performance impact of using `instanceof` vs. checking for some existing property (in the megamorphic case)
// Copyright 2013-2019 Benedikt Meurer
//
// 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
//
// <https://www.apache.org/licenses/LICENSE-2.0>
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@thysultan
thysultan / gist:6941195937a3dcf7b123995d486ec51b
Created January 30, 2019 15:23 — forked from totherik/gist:3a4432f26eea1224ceeb
v8 --allow-natives-syntax RuntimeFunctions
Per https://code.google.com/p/v8/codesearch#v8/trunk/src/runtime.cc
%CreateSymbol
%CreatePrivateSymbol
%CreateGlobalPrivateSymbol
%NewSymbolWrapper
%SymbolDescription
%SymbolRegistry
%SymbolIsPrivate
@thysultan
thysultan / v8.md
Created January 30, 2019 15:36 — forked from kevincennis/v8.md
V8 Installation and d8 shell usage

Installing V8 on a Mac

Prerequisites

  • Install Xcode (Avaliable on the Mac App Store)
  • Install Xcode Command Line Tools (Preferences > Downloads)
  • Install depot_tools
    • git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
    • sudo nano ~/.bash_profile
  • Add export PATH=/path/to/depot_tools:"$PATH" (it's important that depot_tools comes first here)