Skip to content

Instantly share code, notes, and snippets.

View icodesido's full-sized avatar

Ivan icodesido

View GitHub Profile
@icodesido
icodesido / count-all-chars-in-body
Created October 19, 2016 11:16
Count all the characters in the body of the page
var charsInBody = (function counter(elm) {
if (elm.nodeType == 3) { // TEXT_NODE
return elm.nodeValue.length;
}
var count = 0;
for (var i = 0, child; child = elm.childNodes[i]; i++) {
count += counter(child);
}
return count;
})(document.body);
@icodesido
icodesido / lazy-loading-vanilla-js.htm
Created October 17, 2016 13:19
Lazy loading vanilla js
<html>
<head>
<style>
.item {width:300px; display: inline-block; }
.item .itemtitle {font-weight:bold; font-size:2em;}
.hidden {display:none;}
</style>
</head>
<body>
<h1>Amalgam Comics Characters</h1>
@icodesido
icodesido / break-the-frame
Created October 12, 2016 10:57
Break out of the frame
// super cool shortcut
this.top.location !== this.location && (this.top.location = this.location);
@icodesido
icodesido / cont-vs-nested-arr
Created October 11, 2016 15:35
Continue vs Nested Arrays
var someArray=['blah',5,'stuff',7];
for(var i=0;i<someArray.length;i++){
if(typeof someArray[i]!=='number'){
continue;
}
for(var j=0;j<someArray[i];j++){
console.log(j);
}
}
@icodesido
icodesido / simple-axis-graph
Last active October 10, 2016 19:04
Simple axis graph
// http://jsfiddle.net/crzyman/nshX6/1/
<canvas id="graph"></canvas>
<script> // add the load event listener
var graph;
var xPadding = 30;
var yPadding = 30;
// Notice I changed The X values
var data = { values:[
@icodesido
icodesido / rand-val-from-arr
Created October 7, 2016 15:47
Random val from array
var myArray = ["Ivan","Juan","John","Joseph"]
var rand = parseInt(Math.random() * myArray.length);
console.log("My name is " + myArray[rand]);
@icodesido
icodesido / movebox.js
Created October 7, 2016 15:40
Move the Box
(function(){
var speed = 10,
movebox = function() {
var el = documentGetElementById("box"),
left = el.leftOffset,
moveBy = 3;
el.style.left = left + moveBy + 'px';
if(left > 399) {
@icodesido
icodesido / old-css-hacks.css
Created March 8, 2016 14:35
Ancient Browsers CSS hacks
/***** Selector though hack ******/
/* Only for IE6 and below */
* html div { color: gray }
/* Only for IE7 */
*:first-child+html div { color: gray }
@icodesido
icodesido / Say a colour
Created February 5, 2016 10:45
Speech API
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1>Say a colour</h1>
<p>Easy</p>
@icodesido
icodesido / css animation yellow fade
Created February 4, 2016 12:34
Yellow fade CSS animation
@keyframes yellowfade {
from { background: yellow; }
to { background: transparent; }
}
.new-item {
animation-name: yellowfade;
animation-duration: 1.5s;
}