Skip to content

Instantly share code, notes, and snippets.

@jbmoelker
jbmoelker / idLabsStaticSocialShare.class.php
Last active December 17, 2015 14:18
Instead of using javascript heavy widgets to provide an option to share a webpage via social media, consider using static links (urls) instead. These will work regardless of whether the user has javascript is enabled. They improve the load speed of your page and are less of a hit on the battery of your users' devices.This gist contains static ur…
<?php
/**
* @example
*
* $url = 'http://www.example.com/a-specific-page';
* $options = array(
* 'title' => 'A specific page',
* 'text' => 'short descriptive summary of the page',
* 'source' => 'Example.com',
* );
@jbmoelker
jbmoelker / grunt-prompt-builder.js
Last active January 3, 2016 00:39
The Grunt Task Wizard prompts user all available grunt tasks, and asks the user for optional arguments to run the task with. When prompt closes `task-wizard:run-task` is executed, which runs the selected task with the given arguments.This way users don't need to know tasks by heart, just type: `grunt task-wizard` to get started. To make it even …
var grunt = require('grunt');
/**
* Prompt, utility to configure and run grunt-prompt.
* @see https://github.com/dylang/grunt-prompt
*
* @example
* var prompt = require('prompt');
* prompt('create-component')
* .addQuestion({
@jbmoelker
jbmoelker / angular-attribute-if-directive.js
Last active August 29, 2015 13:57
attributeIf is an AngularJS directive which adds an HTML attribute if a given condition is satisfied. Should be used for boolean attributes which are not already supported by Angular's native BOOLEAN_ATTR directive: https://github.com/angular/angular.js/blob/8b395ff3/src/ng/directive/booleanAttrs.js#L331
angular
.module('directives.attributeIf', [])
.directive('attributeIf', [
/**
* @ngdoc directive
* @name directives.attributeIf:attributeIf
* @description
* Adds an HTML attribute if a given condition is satisfied. Should be used for boolean
* attributes which are not already supported by Angular's native BOOLEAN_ATTR directive:
* https://github.com/angular/angular.js/blob/8b395ff3/src/ng/directive/booleanAttrs.js#L331
@jbmoelker
jbmoelker / angular-view-box-directive.js
Last active August 6, 2020 20:49
viewBox is an AngularJS directive which adds support for using an expression for the SVG viewBox, by using `data-view-box` which sets `viewBox` attribute. Code borrowed from http://stackoverflow.com/a/14596319
angular
.module('directives.viewBox', [])
.directive('viewBox', [
/**
* @ngdoc directive
* @name directives.viewBox.directive:viewBox
* @description
* Supports using expression for SVG viewBox, by
* using `data-view-box` which sets `viewBox` attribute.
* Code borrowed from http://stackoverflow.com/a/14596319
@jbmoelker
jbmoelker / nunjucks-filter-limit-to.js
Created March 21, 2014 19:12
Nunjucks limitTo filter. Creates a new array or string containing only a specified number of elements. The elements are taken from either the beginning or the end of the source array or string, as specified by the value and sign (positive or negative) of limit.
/**
* @module limitTo
*
* Creates a new array or string containing only a specified number of elements.
* The elements are taken from either the beginning or the end of the source array
* or string, as specified by the value and sign (positive or negative) of limit.
*
* Same behavior as AngularJS limitTo filter: http://docs.angularjs.org/api/ng/filter/limitTo
*
* To use this filter in a template, first register it in the Nunjucks environment:
@jbmoelker
jbmoelker / markdown-with-yaml-metadata.md
Created March 28, 2014 19:10
Example of wiki article at De Voorhoede in Markdown format enhanced with metadata in YAML format.
Error in user YAML: (<unknown>): found character that cannot start any token while scanning for the next token at line 1 column 1
---
	title: Writing Wiki Articles
	description: How to properly author (structure & format) a wiki article.
	tags: [wiki, article, markdown, yaml, syntax, format]
	authors: 
		- Jasper Moelker
		- Someone Else
---

Writing Wiki Articles

@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 = {};
@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 / 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 / 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: {