Skip to content

Instantly share code, notes, and snippets.

View dmi3y's full-sized avatar
🌵
Dill with it

Dmitry Lapshukov dmi3y

🌵
Dill with it
  • Planet Earth
View GitHub Profile
@dmi3y
dmi3y / index.js
Created November 14, 2014 17:11
Events precedence across browsers http://jsbin.com/zidap/2/edit
// Chrome 41 a>b>c
// FF 31 a>b>c
// IE10 a>b>c
// IE9 a>b>c
// IE8 b>c>a (opposite order, taking events wtih .onclick with higher precedence)
(function() {
var
myDiv = document.getElementById('myDiv'),
evt = 'click';
td {
height: 50px;
width: 50px;
border: 1px solid gray;
text-align: center;
}
@dmi3y
dmi3y / seqSumFinder.js
Created December 15, 2014 23:51
Find sequence of numbers which form specified sum
function checkNumSeq(sum, chunks) {
var
i,
hchunks,
chunk,
out = [];
if ( sum % chunks === 0 && chunks % 2 ) {
chunk = sum / chunks;
@dmi3y
dmi3y / invert.jl
Created January 4, 2015 17:55
invert number mathematically
function invert(num)
rev = 0
while num >= 10
rev = (rev + num % 10) * 10
num = fld(num, 10)
end
return (rev + num)
end
function findSumPairs(arr, sum) {
'use strict';
var
i = 0,
j = 0,
isum,
imatch,
out = [],
larr;
@dmi3y
dmi3y / factorial.js
Created February 24, 2015 01:20
Reccursive factorial finder
function factorial(n) {
var
out = 1;
if ( n > 1 ) {
out = n * factorial(n - 1);
}
return out;
@dmi3y
dmi3y / closure.js
Last active August 29, 2015 14:23
Countdowns
function setCountDown(n) {
n = n || 5;
for ( var i = 0; i <= n; i++ ) {
(function() {
var j = n - i;
setTimeout(function() {
console.log(j);
}, 1000 * i);
}());
}
@dmi3y
dmi3y / uber.js
Created June 17, 2015 21:03
`uber` (super) method from Douglas Crockford - http://www.crockford.com/javascript/inheritance.html
Function.method('inherits', function (parent) {
this.prototype = new parent();
var d = {},
p = this.prototype;
this.prototype.constructor = parent;
this.method('uber', function uber(name) {
if (!(name in d)) {
d[name] = 0;
}
var f, r, t = d[name], v = parent.prototype;
@dmi3y
dmi3y / findintersections.js
Last active August 29, 2015 14:25
Find intersections
// http://jsbin.com/mapena/edit?js,console
// http://stackoverflow.com/questions/1885557/simplest-code-for-array-intersection-in-javascript
function findIntersctions(a, b) {
var ai = 0;
var bi = 0;
var out = [];
while( ai < a.length && bi < b.length ) {
if( a[ai] > b[bi] ) {
function calcFromStr(str) {
var ops = ['*','/','+','-'];
var reg = /(\b\D)/;
var calc = str.split(reg);
function calculator(l, op, r) {
switch( op ) {
case '*':
return l*r;