Skip to content

Instantly share code, notes, and snippets.

View artemdemo's full-sized avatar
🎯
Focusing

Artem Demo artemdemo

🎯
Focusing
View GitHub Profile
@artemdemo
artemdemo / objectToQueryString.js
Last active August 29, 2015 14:19 — forked from dgs700/objectToQueryString.js
Javascript object to URL encoded query string converter. Code extracted from jQuery.param() and boiled down to bare metal js. Should handle deep/nested objects and arrays in the same manner as jQuery's ajax functionality.
var objectToQueryString = function (a) {
var prefix, s, add, name, r20, output;
s = [];
r20 = /%20/g;
add = function (key, value) {
// If value is a function, invoke it and return its value
value = ( typeof value == 'function' ) ? value() : ( value == null ? "" : value );
s[ s.length ] = encodeURIComponent(key) + "=" + encodeURIComponent(value);
};
if (a instanceof Array) {
@artemdemo
artemdemo / what-forces-layout.md
Created November 16, 2015 11:35 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
// TemplateEngine - AbsurdJS
// https://github.com/krasimir/absurd/blob/master/lib/processors/html/helpers/TemplateEngine.js
module.exports = function(html, options) {
var re = /<%(.+?)%>/g,
reExp = /(^( )?(var|if|for|else|switch|case|break|{|}|;))(.*)?/g,
code = 'with(obj) { var r=[];\n',
cursor = 0,
result;
var add = function(line, js) {
js? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') :
data = {
user: {
login: "tomek",
first_name: "Thomas",
last_name: "Mazur",
account: {
status: "active",
expires_at: "2009-12-31"
}
}
const template =
`My skills:
<%if(this.showSkills) {%>
<%for(var index in this.skills) {%>
<a href="#"><%this.skills[index]%></a>
<%}%>
<%} else {%>
<p>none</p>
<%}%>`;
console.log(TemplateEngine(template, {
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
@artemdemo
artemdemo / Jasmine-and-Babel6.md
Created June 15, 2017 19:14 — forked from mauvm/Jasmine-and-Babel6.md
Jasmine ES6 run script for use with Babel 6
$ npm install --save babel-cli babel-preset-es2015
$ npm install --save-dev jasmine

.babelrc:

{
 "presets": ["es2015"]

What this PR does / why we need it:

Which issue(s) this PR fixes:

  • BACKEND-

How has this been tested:

Special notes for your reviewer:

@artemdemo
artemdemo / game-of-life-v01.js
Created February 10, 2020 08:05
Game of life - v.01
// https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
const generateMatrix = (width, height) => {
return Array.from({length: height}, () => Array.from({length: width}, () => Math.random() >= 0.5));
};
const nextCellState = (matrix, rowIdx, colIdx) => {
const numberOfLiveNeighbors = [
[-1, -1], [-1, 0], [-1, 1],
[ 0, -1], [ 0, 1],
@artemdemo
artemdemo / game-of-life-v02.js
Created February 10, 2020 08:05
Game of life - v.02
// https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
const populate = (matrix) => {
return matrix.map(row => row.map(_ => Math.random() >= 0.5));
};
const createMatrix = (width, height) => {
const matrix = Array.from(new Array(height)).map(_ => Array.from(new Array(width)));
return populate(matrix);
};