Skip to content

Instantly share code, notes, and snippets.

/**
* Original idea: https://github.com/necolas/normalize.css/tree/master
* Added box-sizing based on https://css-tricks.com/box-sizing/
**/
/**
* 1. Correct the line height in all browsers.
* 2. Prevent adjustments of font size after orientation changes in iOS.
*/
@Shwartz
Shwartz / gatsby-config.js
Created August 26, 2019 03:39
gatsbyjs remark images and mdx config example
const path = require("path")
module.exports = {
/* Your site config here */
siteMetadata: {
title: "Generic Site Title",
},
pathPrefix: `/gby1`,
plugins: [
`gatsby-transformer-sharp`,
export const simple = {
method: (param) => {
return `my param: ${param}`
}
};
export const shorter = {
method(param1) {
return `my param1: ${param1}`
}
@Shwartz
Shwartz / curry.js
Created November 7, 2018 12:46
Helpers for curry, compose, apply to make functional approach to code
const {assign} = Object;
const pipe = (fn, ...fns) => (param, ...staticArgs) => fns.reduce((acc, f) => f(acc), fn(param, ...staticArgs));
const compose = (...fns) => pipe(...fns.reverse());
const pipeAsync = (fn, ...fns) => (param, ...staticArgs) => fns.reduce((acc, f) => acc.then(_ => f(_, ...staticArgs)), fn(param, ...staticArgs));
const composeAsync = (...fns) => pipeAsync(...fns.reverse());
const apply = (...fns) => (...args) => fns.map(fn => fn(...args));
const curry = (fn, ...args) => (fn.length <= args.length) ? fn(...args) : (...more) => curry(fn, ...args, ...more);
const match = (guard) => (left = _ => _, right = _ => _) => (...args) => (..._) => guard(...args) ? right(..._, ...args) : left(..._, ...args);
const extract = (_) => (...methods) => methods.reduce((acc, method) => assign(acc, {[method]: (...args) => _[method](...args)}), {});
@Shwartz
Shwartz / sorting.js
Last active June 20, 2018 10:16
ES6 style sorting helpers for objects
const asc = (left, right) => left < right ? -1 : left > right ? 1 : 0;
const desc = (left, right) => left > right ? -1 : left < right ? 1 : 0;
const sort = (array, column, order) => array.sort(({[column]: left}, {[column]: right}) => order(left, right));
export const sortAsc = (array, column) => sort(array, column, asc);
export const sortDesc = (array, column) => sort(array, column, desc);
@Shwartz
Shwartz / gulpfile.js
Created December 4, 2017 11:47
Mini handlebar with a Gulp. Works similar like php include(), can pass variable as well
/**
Task will run through /src/html/ folder and will loop through each html file
When it finds {{head}}, it will be replaced with a content from /src/inc/head.html
Example of src/inc/breadcrumb.html
<ul>
<li><a href="link/page">Home</a></li>
<li>{{content}}</li>
</ul>
(function () {
const subClassExample = {
Person: function(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
this.gender = 'male';
}
}
const clark = new subClassExample.Person('Clark', 'Kent');
@Shwartz
Shwartz / events.js
Created February 13, 2017 16:44
For testing clickable elements add preventDefault() to all of them
window.addEventListener("load", function () {
console.warn('------------------- EAGLE LANDED -------------------')
let arr = Array.from(document.getElementsByTagName('a'));
console.warn('A TAGS', arr.length);
arr.forEach(function (a) {
a.addEventListener('click', function (e) {
console.warn('CLICK ELEM', e.target);
e.preventDefault();
});
});
@Shwartz
Shwartz / listener.js
Created January 10, 2017 16:05
addEventListner with requestAnimationFrame
(function() {
"use strict";
var ticking = false;
window.addEventListener('scroll', function () {
if (!ticking) {
window.requestAnimationFrame(function () {
runYourMethod();
ticking = false;
});
@Shwartz
Shwartz / gulp.js
Created January 10, 2017 15:01
Using Gulp and Node to change file content based on a string pattern
gulp.task('update-content-file', function () {
"use strict";
var fs = fs || require('fs');
var path = 'path/to/folder';
// example of CSS path change and adding new css
var oldContent = /<link href="(.*)dev\/css\/main.css" rel="stylesheet">/;
var newContent = '<link href="/dev/css/main.css" rel="stylesheet"><link href="/dev/css/specific.css" rel="stylesheet">';
fs.readdir(path, function(err, files) {