Skip to content

Instantly share code, notes, and snippets.

@jbmoelker
jbmoelker / gulp-postcss.js
Created May 10, 2016 07:04
PostCSS setup (imports, vars, autoprefix, minify) with and without Gulp
const gulp = require('gulp');
const postcss = require('gulp-postcss');
const rename = require('gulp-rename');
const sourcemaps = require('gulp-sourcemaps');
gulp.src('./src/index.css')
.pipe(sourcemaps.init())
.pipe(postcss([
require('postcss-import'), // combine imports into one file
require('postcss-css-variables'), // replace variables by their values
@jbmoelker
jbmoelker / svg2gif.js
Created April 5, 2016 07:49
[POC] Animated SVG to GIF
'use strict';
/**
* Script converts an animated SVG (`fileIn`) into an animated GIF (`fileOut`)
* with the given `duration`, `fps`, `width` and `height.
* This is just a proof-of-concept. Script needs an API etc etc.
*/
// config which should come from cli args
const fileIn = 'animation.svg';
@jbmoelker
jbmoelker / riotjs-style-guide-badge.svg
Last active March 24, 2016 13:38
[WIP] RiotJS Style Guide badge
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jbmoelker
jbmoelker / lightweight-front-end-servers.md
Created March 18, 2016 13:35
[Notes] Lightweight front-end servers
@jbmoelker
jbmoelker / jquery-style-guide.md
Last active April 18, 2016 12:29
[WIP] Opinionated jQuery Style Guide for teams.

jQuery Style Guide

This guide applies to jQuery 1-3, or Zepto, or Shoestring, or ...

  • prefer native / avoid jQuery (if it's just as easy Vanilla JS, do that)
  • prefer lastest jQuery (jQuery 3, smaller, closer to standars)
  • avoid $.ready (inject script just before </body>)
  • avoid $(window).load()
  • use (function($){ }(jQuery)) (avoid conflict, show what $ is)
  • prefix jQuery object vars with $
@jbmoelker
jbmoelker / riotjs-style-guide.md
Last active March 9, 2016 15:56
[WIP] Opinionated RiotJS Style Guide

Note: These are just my personal notes. Rules which are formalised are moved to voorhoede/riotjs-style-guide

RiotJS Style Guide

Opinionated RiotJS Style Guide for teams by De Voorhoede.

Purpose

This guide provides a uniform way to structure your RiotJS code. Making it

@jbmoelker
jbmoelker / async-submit-form.ts
Created January 9, 2016 18:02
Submit an HTMLFormElement asynchronously and receive a Promise which resolves with the response data.
export default function asyncSubmitForm (form:HTMLFormElement): Promise<Response> {
return window.fetch(formRequest(form))
.then(checkStatus)
.then(response => response.json());
}
export function formRequest(form:HTMLFormElement): Request {
return new Request(form.action, {
method: form.method,
headers: {
@jbmoelker
jbmoelker / HTMLDialogElement.d.ts
Created December 15, 2015 13:56
TypeScript definition for HTMLDialogElement based on MDN documentation
/**
* HTMLDialogELement
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement
*/
interface HTMLDialogElement extends HTMLElement {
/**
* Reflects the open HTML attribute,
* indicating that the dialog is available for interaction.
*/
open:boolean;
@jbmoelker
jbmoelker / gulpfile.js
Created October 12, 2015 17:10
Watch and compile Sass with notifications on error; Serve generated files independently using BrowserSync;
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync').create();
var gulp = require('gulp');
var gulpIf = require('gulp-if');
var notify = require('gulp-notify');
var sass = require('gulp-sass');
var plumber = require('gulp-plumber');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('build:css', buildCss);
@jbmoelker
jbmoelker / bootstrap.js
Last active January 15, 2016 19:22
requirejs-bootstrap-plugin
// Create shim for requested bootstrap component and require
// and return jQuery so you do not have to inject it separately
// every time you use a bootstrap component.
define({
load: function (name, req, onload, config) {
// Set this path to wherever the bootstrap components live.
// Contents should match https://github.com/twbs/bootstrap/tree/master/js
var component = 'path/to/bootstrap/js/'+name;
var shim = {};