Skip to content

Instantly share code, notes, and snippets.

@alexpilugin
alexpilugin / React-tips-and-hints.md
Last active March 13, 2017 23:50
React tips and hints

Functional stateless (dumb) React component

function Hello(props) {
  return <div>Hello {props.name} </div>;
}

ES6+

const Hello = props => <div>Hello {props.name}</div>;
@alexpilugin
alexpilugin / Install-Express-with-npm.md
Last active April 20, 2017 23:13
Install Express.js using npm (Node Package Manager)
  1. $ mkdir app          /* create app folder */
  2. $ cd app          /* move inside the app folder / /
  • Before to install express.js you need to have minimum one of them:
  • package.json or node_modules */
  1. $ npm init          /* create package.json */
  2. $ npm install express --save          /* install express.js locally */
  3. $ npm install          /* install requested modules */
  4. $ npm ls          /* [optinal] show a list of installed packages */
@alexpilugin
alexpilugin / hello-from-node.js
Last active May 22, 2017 00:19
OReilly. Ethan Brown. Web Development With Node And Express
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('<h1>Hello world!</h1>');
}).listen(3000);
console.log('Server started on localhost:3000; press Ctrl-C to terminate....');
@alexpilugin
alexpilugin / node-routing.js
Created May 22, 2017 00:18
OReilly. Ethan Brown. Web Development With Node And Express
var http = require('http');
http.createServer(function (req, res) {
// normalize url by removing querystring, optional
// trailing slash, and making it lowercase
var path = req.url.replace(/\/?(?:\?.*)?$/, '').toLowerCase();
switch (path) {
case '':
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('<h1>Homepage</h1>');
function isEven(a) {
if (a < 0) a = -a;
if (a == 0) return true;
if (a == 1) return false;
return isEven(a - 2)
}
var log = console.log;
var number = 8;
var line = " ";
var counter = 0, counter2 = 0;
while (counter < number-1) {
counter++;
line = counter % 2 ? " " : "#";
counter2 = 0;
while (counter2 < number-1) {
var letter = (line[counter2] == " ") ? "#" : " ";
function remove(array, index) {
return array.slice(0, index).concat(array.slice(index + 1));
}
Array.prototype.remove = function (index) {
return this.slice(0, index).concat(this.slice(index + 1));
}
//random 0 or 1:
Math.floor(Math.random()+0.5)
var obj = {
a: "a",
b: "b",
c: [0, 1, 2]
}
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
console.log(key + ': ' + obj[key]);
}
var DATA = []; //or {}
//universal javascript module
// This makes sure the data is exported in node.js
// `require('./{your_path}/data.js')` will get your data:
if (typeof module != "undefined" && module.exports) {
module.exports = DATA;
}
//returns array which includes all numbers from start to end (included)
function range(start, end, step) {
if(step < 0) step = -step;
if(!step) step = 1;
if(end == undefined) {
end = start;
start = 0;
}
var result = [];