Skip to content

Instantly share code, notes, and snippets.

@chrisdavies
chrisdavies / toggle-checkbox.html
Created December 3, 2014 02:25
A CSS-only (no JS) checkbox toggle control. Might make the label text (yes/no) markkup rather than CSS injected content.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Toggle Example</title>
<style>
body {
font-family: sans-serif;
}
@chrisdavies
chrisdavies / qunit-zombie.js
Last active April 12, 2016 18:20
Gulp task for running qUnit with zombiejs
// This is what your gulp task should look like
gulp.task('qunit', function(done) {
var files = glob.sync('./test/**/*.html');
runAllQunits(files);
});
// Runs through each qunit file (one at a time, though this could be relatively easily parallelized)
function runAllQunits(testFiles) {
var browser = new Zombie();
@chrisdavies
chrisdavies / bad-markup.html
Created January 17, 2015 16:14
This markup has a problem. Can you spot it?
<!-- Notice that the quoatation marks are not consistent. They should all be
" but some are “ Note, this last one is slanted. I'm not even sure how that
one got in, but I noticed some students had those slanty quotes! That's not
valid HTML! -->
<form method=“get" action=“/save-user”>
<div class="form_div personal">
<label>Name<br><input type=“text” name=“userName” required="required"></label>
</div>
</form>
@chrisdavies
chrisdavies / sorted-router-example.js
Last active December 16, 2016 13:41
A naive wrapper around Backbone router to make it understand route specificity (so route order doesn't matter)...
// Example usage of SortedRouter
var SortedRouter = require('./sortedrouter');
var router = new SortedRouter();
// Supports multiple URLs
router.route('', 'books', show('<h1>Books</h1>'));
router.route('books/new', show('<h1>New Book</h1>'));
router.route('books/:id', show('<h1>Show Book</h1>'));
@chrisdavies
chrisdavies / theme-blue.scss
Created August 20, 2015 16:23
File-scoped variables in SASS
// A single mixin per file allows file-scoped variables
@mixin theme-blue {
// File-scoped variables
$main-bg: white;
$main-fg: #333;
$accent-bg: #00B4EF;
$accent-fg: white;
$content-width: 700px;
$gutter-width: 1rem;
@chrisdavies
chrisdavies / open_struct_perf_test.rb
Created June 23, 2016 13:41
A perf test of Ruby's OpenStruct vs a few other options
# OpenStruct is slow. But if you need/want similar functionality,
# you can achieve it with really good perf results. See the impl
# of NotificationEvent below.
#
# Benchmark results from my Macbook (2.6 GHz Intel Core i5)
#
# Rehearsal -----------------------------------------------------
# Literal 1.060000 0.020000 1.080000 ( 1.080056)
# NotificationEvent 1.350000 0.000000 1.350000 ( 1.367066)
# OpenStruct 11.500000 0.110000 11.610000 ( 11.646464)
@chrisdavies
chrisdavies / stripe-currencies.js
Created November 7, 2016 14:53
A handy list of currency codes and descriptions for use with Stripe.
'use strict';
// The STRIPE-supported currencies, sorted by code
export const currencies = [
{
'code':'AED',
'description':'United Arab Emirates Dirham'
},
{
'code':'AFN',
Look for `// CHRIS:` comments to get some inline thoughts.
Well, I learned something new. I've never seen "text/babel" as a script type. How are you transpiling your JSX?
I think if I were interviewing you, I'd ask why you didn't use ES6 modules or TypeScript, and something like Webpack to bundle them. It's something you should familiarize yourself with, since every production stack you will work with will be using some equivalent. (TypeScript + VS Code is a great combo, by the way.)
You'll also benefit from using a linter on your JavaScript. It catches bugs, and ensures you format things nicely (which helps when someone's interviewing / reviewing your code!)
So here's what I'd recommend after a quick scan:

Migrations

Plugins

  • Expose their mappings so that they are programmatically consumable and easily associated w/ the right plugin
  • Expose a list of migrations, which are one of:
    • Transform: Migrate a document from one version to the next
    • Seed: Create a new document
  • Old data which is imported will be run through the migrations before being persisted