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
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
@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;
@dmi3y
dmi3y / addClass.js
Last active December 14, 2015 20:49
at some point addClass function
function addClass(myElement, classToAdd) {
if (!myElement && !classToAdd) return;
var
myElementIsSting = typeof myElement == 'string',
myElementNode = myElementIsSting? document.getElementById(myElement): myElement,
classes = ' ' + (myElementNode.className || '') + ' ',
classToAdd = ' ' + classToAdd + ' ';
if (!~classes.indexOf(classToAdd)) { // http://stackoverflow.com/questions/12299665/what-does-a-tilde-do-when-it-precedes-an-expression
@dmi3y
dmi3y / handler loop
Created April 4, 2013 13:04
handle onclick in older fashon
// http://jsbin.com/ubugag/2/edit
var allDivs = document.getElementsByTagName("div"),
length = allDivs.length, divDomID,
showCarHandler = function(){
var divDomINT = parseInt(this.id.replace("car_", 0), 10);
console.log(divDomINT);
};
for(;length--;){