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 / How to create Node cli executable from npm.md
Created October 10, 2022 06:39 — forked from mritzco/How to create Node cli executable from npm.md
Create Node Package (cli) executable from npm scripts

Creating an executable NPM package and using it

This short guide explains how to create an NPM package that can be called as a script from another project. For clarity: The package to execute will be called: Module The place where you use it: Application

1. Build your module

Create a standard module ignore command line parsing

%reset-Button {
border: none;
margin: 0;
padding: 0;
width: auto;
overflow: visible;
background: transparent;
/* inherit font & color from ancestor */
@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);
};
@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],

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 / 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"]
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, {
data = {
user: {
login: "tomek",
first_name: "Thomas",
last_name: "Mazur",
account: {
status: "active",
expires_at: "2009-12-31"
}
}
/* Nano Templates - https://github.com/trix/nano */
function nano(template, data) {
return template.replace(/\{([\w\.]*)\}/g, function(str, key) {
var keys = key.split("."), v = data[keys.shift()];
for (var i = 0, l = keys.length; i < l; i++) v = v[keys[i]];
return (typeof v !== "undefined" && v !== null) ? v : "";
});
}
// 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') :