Skip to content

Instantly share code, notes, and snippets.

View AndersDJohnson's full-sized avatar

Anders D. Johnson AndersDJohnson

View GitHub Profile
@AndersDJohnson
AndersDJohnson / statuses.json
Last active June 5, 2019 13:36
HTTP Status Codes from Node's http.STATUS_CODES
{
"100": "Continue",
"101": "Switching Protocols",
"102": "Processing",
"200": "OK",
"201": "Created",
"202": "Accepted",
"203": "Non-Authoritative Information",
"204": "No Content",
"205": "Reset Content",
@AndersDJohnson
AndersDJohnson / index.css
Last active June 5, 2019 13:36
CSS Ratios
/* ELEMENT RATIOS
=============================================== */
/**
* To force an element to keep a certain ratio.
* Use as follows:
*
* <div class="ratio ratio-square">
* <div class="ratio-inner">
* <!-- contents, e.g. image -->
* </div>
handlebars : {
options : {
processAST: function(ast) {
var Handlebars = require('handlebars');
ast.statements.forEach(function(statement, i) {
if (statement.type === 'partial') {
var partialFile = grunt.util._.find(grunt.task.current.files, function (file) {
return file.src[0].indexOf(statement.partialName.name) !== -1;
});
if (partialFile) {
[
{
"id": "6046423",
"slug": "first-testing"
},
{
"id": "6047758",
"slug": "orientation-for-meta-viewport"
},
{

This is a Test

Are you testing?

  1. One
  2. Two
  3. Three
alert("Hello!");
@AndersDJohnson
AndersDJohnson / gh-pages.sh
Last active June 5, 2019 13:35
For GitHub Pages, copy a subtree to root of gh-pages branch.
#!/bin/bash
DIR=dist
parent_sha=$(git show-ref -s refs/heads/gh-pages)
doc_sha=$(git ls-tree -d HEAD "$DIR" | awk '{print $3}')
new_commit=$(echo "Auto-update docs." | git commit-tree $doc_sha -p $parent_sha)
git update-ref refs/heads/gh-pages $new_commit
@AndersDJohnson
AndersDJohnson / inverse-regex-operator.groovy
Last active June 5, 2019 13:35
groovy inverse regex operator?
// as expected:
println ("string" ==~ "str.*")
// => true
// compiles, but not as expected:
println ("string" !=~ "str.*")
// => true
// does not compile:
//println ("string" !==~ "str.*")
@AndersDJohnson
AndersDJohnson / ordinal-classes.js
Last active June 5, 2019 13:35
ordinal classes in javascript - updates to come!
/**
* Updates classes on items indicating their order in repeating sets from `2` thru `options.upTo`.
* e.g. "ordinal-1-of-3" for every third item.
* Optionally filter only visible elements.
* Couldn't use :nth-of-type() pseudo-selectors, since they don't count visibility.
*/
var updateOrdinalClasses = function ($items, options) {
var defaults = {
onlyVisible: true,
upTo: 4
@AndersDJohnson
AndersDJohnson / example.js
Last active June 5, 2019 13:35
jQuery event ratio offsets
$('.area').on('mousemove', function (e) {
$.event.ratioOffsets(e);
console.log(e.ratioOffsetX, e.ratioOffsetY);
});
@AndersDJohnson
AndersDJohnson / example.js
Last active June 5, 2019 13:35
jQuery event normalize offsets
$('.area').on('mousemove', function (e) {
$.event.normalizeOffsets(e);
console.log(e.normalizedOffsetX, e.normalizedOffsetY);
});