Skip to content

Instantly share code, notes, and snippets.

@thysultan
thysultan / index.html
Created July 24, 2012 05:49
A web page created at CodePen.io.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>simple minimal calculator &middot; CodePen</title>
<!--
Copyright (c) 2012 Sultan Tarimo, http://codepen.io/sultantarimo
Permission is hereby granted, free of charge, to any person obtaining
@thysultan
thysultan / $.ajaxPagination.js
Last active October 10, 2015 09:21
$.ajaxPagination
$.ajaxPagination = function(el, container, e){
e.preventDefault();
var oldLink, newLink, selectors, page;
el = $(el);
selectors = {
loading: "loading",
pageName: "data-page-name",
@thysultan
thysultan / grid.css
Created December 4, 2015 14:21
css grid
/**
* Grid
*
* useage:
// 25% vs 75%
<div class="grid-row">
<div class="grid-span-1/4"></div>
<div class="grid-span-3/4"></div>
</div>

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 / stack.js
Created June 13, 2016 19:59
try to push to the end of the event stack
requestAnimationFrame(function () {
setTimeout(function () {
fn()
}, 0)
})