Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tsouk
tsouk / quirky.js
Last active January 21, 2018 21:58
Quirky JS
var a = {
i: 1,
// toString: function () {
// return a.i++;
// }
valueOf: function () {
return a.i++;
}
// When using loose equality, due to type coersion, if one of the operands is of a different type than the other, the engine will attempt to convert one to the other. In the case of an object on the left and a number on the right, it will attempt to convert the object to a number by first calling valueOf if it is callable, and failing that, it will call toString
// every time one of these is called, i is being incemented. The == operator calls valueOf then toString
@tsouk
tsouk / html2graph_colors.js
Created December 10, 2017 13:57
html2graph colors in console
function hashCode(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
return hash;
}
function intToRGB(i) {
var c = (i & 0x00FFFFFF)
@tsouk
tsouk / functional.js
Last active November 1, 2017 12:09
Some functional JS we like
const pipe = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x); //x = form
const curry = fn => (...args) => fn.bind(null, ...args);
const map = curry((fn, arr) => arr.map(fn));
const join = curry((str, arr) => arr.join(str));
const toLowerCase = str => str.toLowerCase();
@tsouk
tsouk / jekyll-and-liquid.md
Created June 28, 2017 23:45 — forked from magicznyleszek/jekyll-and-liquid.md
Jekyll & Liquid Cheatsheet

Jekyll & Liquid Cheatsheet

A list of the most common functionalities in Jekyll (Liquid). You can use Jekyll with GitHub Pages, just make sure you are using the proper version.

Running

Running a local server for testing purposes:

@tsouk
tsouk / dom-to-json.js
Created February 29, 2016 21:12 — forked from sstur/dom-to-json.js
Stringify DOM nodes using JSON (and revive again)
function toJSON(node) {
node = node || this;
var obj = {
nodeType: node.nodeType
};
if (node.tagName) {
obj.tagName = node.tagName.toLowerCase();
} else
if (node.nodeName) {
obj.nodeName = node.nodeName;
@tsouk
tsouk / gist:4730530
Last active December 12, 2015 06:38
/** @lint */
/**
* @module orb/features/_orbevents
*/
define('orb/features/_orbevents', ['orb/lib/_event'], function (event) {
'use strict';
var win;
(function () {
var $,
clockLoaded = false,
_environment = null,
_flagpoles = {},
labels = {
searchSuggestion: "Search"
},
@tsouk
tsouk / HowJSWorks.js
Created January 10, 2012 15:37
JavaScript Blunders
// Oh what a tangled web we stare, when first we practice to declare
// ----------------------------------------------------------------
// When var statement become longer than a page, there are some problems
var a,
b,
c, <- take this line out and the rest vars are now global
d,
e;
@tsouk
tsouk / getNearestAnchorElement.js
Created July 14, 2011 07:55
Get nearest anchor element
/**
@name getNearestAnchorElement
@private
@method
@param {Object} startNode The node to start the scan from
@param {Object} endNode The node to end on
@description Find the ancestor of startNode that is an anchor link (keeps searching up until the endNode)
*/
function getNearestAnchorElement(startNode, endNode){
@tsouk
tsouk / simulateClick.js
Created July 14, 2011 07:53
Simulate Click
function simulateClick(element) {
var evt,
oldOnclick = element.onclick;
element.onclick = function() {
if (typeof oldOnclick === 'function' ) {
return oldOnclick.apply(element);
}
return false;
};