Skip to content

Instantly share code, notes, and snippets.

@bartcis
bartcis / api_data_import.js
Created July 17, 2019 12:41
Import snippet for data
// Import of the file where we define/fetch data
const api = require('./server/api');
@bartcis
bartcis / example_apollo_server.js
Created July 17, 2019 10:40
Basic configuration for Apollo Server
const { ApolloServer } = require('apollo-server');
// Import of the file where we define/fetch data
const api = require('./server/api');
// Import of the file where we build data structures/schemas
const typeDefs = require('./server/schema');
// Bind queries from schemas definition to data from API's
const resolvers = {
@bartcis
bartcis / gulpfile.js
Created June 21, 2019 16:22
Example full configuration for Gulp 4
const { watch, src, dest, series, parallel } = require('gulp');
const browserSync = require('browser-sync').create();
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const del = require('del');
const postcss = require('gulp-postcss');
const sass = require('gulp-sass');
const autoprefixer = require('autoprefixer');
@bartcis
bartcis / command_gulpfile.js
Created June 21, 2019 16:21
Example command export in Gulp 4
exports.build = series(cleanUp, parallel(jsTask, cssTask, fontTask, imagesTask, templateTask));
@bartcis
bartcis / css_gulpfile.js
Created June 21, 2019 16:20
Example CSS task in Gulp 4
function cssTask(done) {
src(config.app.scss)
.pipe(sass({ outputStyle: 'expanded' }))
.pipe(rename({ suffix: '.bundle' }))
.pipe(postcss([autoprefixer(), cssnano()]))
.pipe(dest(config.dist.base))
done();
}
@bartcis
bartcis / gulpfile_config.js
Last active June 24, 2019 10:19
Example project configuration file for gulpfile.js
const config = {
app: {
js: [
'./src/scripts/**/*.js',
],
scss: './src/style/**/*.scss',
fonts: './src/fonts/*',
images: './src/images/*.*',
html: './src/*.html'
},
@bartcis
bartcis / loose_comparison.js
Created June 3, 2019 16:54
Simple example for loose comparison
// Coercive / loose comparison
if (5 == '5') {
console.log('Coercion please!');
}
@bartcis
bartcis / assignment_anti_pattern1.js
Created June 3, 2019 16:52
How not to assign values in JS
let boots
// Value assignemnt anti-pattern
if (boots = 'green') {
console.log(boots);
}
@bartcis
bartcis / strict_comaprison.js
Created June 3, 2019 16:39
Simple example of non-coercive comparison
// Non-coercive / strict comparison
if ( 5 === 5 ) {
console.log('No coercion please!');
}
@bartcis
bartcis / explicit_coercion.js
Created June 3, 2019 15:32
Simple example of explicit coercion in JS
// Let's say that bank account
let money = 1E6;
// Your hard work pays off
money = money + Number('.6E6');
// That looks better :)
console.log(money); // 1 600 000