Skip to content

Instantly share code, notes, and snippets.

View AndrejGajdos's full-sized avatar

Andrej Gajdos AndrejGajdos

View GitHub Profile
@AndrejGajdos
AndrejGajdos / server.js
Last active June 24, 2018 07:36
Adding required modules and creating new koa application for user authentication project. Whole file is available https://github.com/AndrejGajdos/auth-flow-spa-node-react/blob/master/script/server.js
require('dotenv').config({ path: require('find-config')('.env') });
const Koa = require('koa');
const Router = require('koa-router');
const koaLogger = require('koa-logger');
const cors = require('@koa/cors');
const bodyParser = require('koa-bodyparser');
const serve = require('koa-static');
const send = require('koa-send');
const path = require('path');
const session = require('koa-session');
@AndrejGajdos
AndrejGajdos / package.json
Last active June 24, 2018 07:35
Project dependencies for implementing user authentication in Node.js, Passport, React, Redux. Whole file is available https://github.com/AndrejGajdos/auth-flow-spa-node-react/blob/master/package.json
{
"dependencies": {
"@koa/cors": "^2.2.1",
"axios": "^0.18.0",
"bcrypt": "^2.0.0",
"bootstrap": "^4.1.0",
"classnames": "^2.2.5",
"dotenv": "^6.0.0",
"find-config": "^1.0.0",
"jquery": "^3.3.1",
@AndrejGajdos
AndrejGajdos / scrollTo.js
Created August 21, 2017 13:40 — forked from joshcanhelp/scrollTo.js
Animated scrollTo for specific element or top of page
//
// Smooth scroll-to inspired by:
// http://stackoverflow.com/a/24559613/728480
//
module.exports = function (scrollTo, scrollDuration) {
//
// Set a default for where we're scrolling to
//
@AndrejGajdos
AndrejGajdos / .eslintrc.js
Created August 8, 2017 12:50 — forked from nkbt/.eslintrc.js
Strict ESLint config for React, ES6 (based on Airbnb Code style)
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"plugins": ["react"],
"ecmaFeatures": {
@AndrejGajdos
AndrejGajdos / flatten.js
Created March 20, 2016 19:34
Function for flattening nested array
/**
* Flatten nested array
* @param {Array} array Nested array
* @return {Array} Flat array
*/
function flatten(array) {
return array.reduce(function (flat, toFlatten) {
// if current item is array flatten it, otherwise concatenate value to processed flat array
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
@AndrejGajdos
AndrejGajdos / gulpfile.js
Created February 27, 2016 21:23
Second part of gulp tak – converting SVG Sprite to separate files
var gulp = require('gulp');
var config = require('./config.json');
var del = require('del');
var svg2png = require('gulp-svg2png');
var graphicsmagick = require('gulp-gm');
...
gulp.src("./build/svg_files_" + colorName + "/*.svg")
.pipe(svg2png())
.pipe(gulp.dest("./build/png_files_" + colorName))
@AndrejGajdos
AndrejGajdos / gulpfile.js
Last active February 27, 2016 20:52
First part of gulp tak – converting SVG Sprite to separate files
var fs = require('fs');
var DOMParser = require('xmldom').DOMParser;
var timestamp = require('console-timestamp');
var config = require('./config.json');
// open svg sprite file
fs.readFile(config.paths.svg_sprite, 'utf8', function (err, data) {
if (err) {
return console.log(timestamp('[hh:mm:ss] ') + "Read file " + config.paths.svg_sprite + " error: " + err);
}
@AndrejGajdos
AndrejGajdos / config.json
Created February 27, 2016 20:33
Config file for a gulp task to convert SVG Sprite into PNG images
{
"image": {
"color": "#BFBFBF",
"width": 36,
"height": 36
},
"paths": {
"svg_sprite": "./src/icons.svg"
}
}
@AndrejGajdos
AndrejGajdos / webpack.config.js
Last active September 3, 2018 00:40
A sample project to demonstrate bundling ES6, React, SASS and Bootstrap with Webpack (http://andrejgajdos.com/setting-up-webpack-for-es6-react-sass-and-bootstrap/)
var webpack = require('webpack');
var merge = require('webpack-merge');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var NpmInstallPlugin = require('npm-install-webpack-plugin');
var autoprefixer = require('autoprefixer');
const TARGET = process.env.npm_lifecycle_event;
console.log("target event is " + TARGET);
var common = {
@AndrejGajdos
AndrejGajdos / DataGrid.jsx
Last active January 31, 2016 17:53
Data props diffing in a React component and re-initialize a cell of jQuery object without re-initializing jQuery grid object in the componentDidUpdate method (and without re-rendering the whole React component). Code snippet in blog post http://andrejgajdos.com/how-to-avoid-refactoring-in-your-first-react-application/
let diff = require('immutablediff');
shouldComponentUpdate(nextProps, nextState) {
let propsDiff = diff(this.props.data, nextProps.data);
if (propsDiff.size === 1) {
let operation = propsDiff.get(0).get("op");
let replacedObj = propsDiff.get(0).get("value");
switch (operation) {
case "replace":
if (Immutable.Map.isMap(replacedObj)) {