Skip to content

Instantly share code, notes, and snippets.

View justinmc's full-sized avatar

Justin McCandless justinmc

View GitHub Profile
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
@justinmc
justinmc / anchor_smooth_scroll.js
Last active May 14, 2019 19:52
Anchor Smooth Scroll - Angular Directive
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Anchor Smooth Scroll - Smooth scroll to the given anchor on click
* adapted from this stackoverflow answer: http://stackoverflow.com/a/21918502/257494
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
angular.module('yourapp').directive('anchorSmoothScroll', function($location) {
'use strict';
return {
restrict: 'A',
replace: false,
@justinmc
justinmc / sharing.js
Created October 13, 2014 01:08
A simple example of how to share code between the front and back ends. This file could be run in either environment and work in both, without code duplication.
var config = {
version: '3.1.4'
};
// Frontend
if (window) {
window.config = config;
// Backend
} else if (typeof module !== 'undefined' && module.exports) {
@justinmc
justinmc / index.js
Last active August 29, 2015 14:08
requirebin sketch
var getJSON = require('get-json');
var APIs = [
'http://lullabytunes.org/api.json',
'http://tevlihev.org/api.json',
'http://kizilok.org/api.json'
];
var Song = function(title, album, url) {
this.title = title;
@justinmc
justinmc / main.js
Last active August 29, 2015 14:19
ES6 Generator Example: Game Dialog
class Game {
constructor() {
...
// kick off our generator game flow
this.flowGen = this.flow();
this.flowGen.next();
...
}
...
@justinmc
justinmc / benchmark_array_removal.js
Last active October 28, 2016 23:05
Benchmark array element removal using Array.prototype.splice.
const size = parseInt(process.argv[2], 10);
const index = parseInt(process.argv[3], 10);
if (!size) {
throw new Error('Must provide size of array as first argument.');
}
if (index < 0 || index >= size) {
throw new Error('Must provide a valid index to remove at as second argument.');
}
@justinmc
justinmc / benchmark_array_insertion.js
Created October 28, 2016 23:04
Benchmark inserting an element into an array using Array.prototype.splice.
const size = parseInt(process.argv[2], 10);
const index = parseInt(process.argv[3], 10);
if (!size) {
throw new Error('Must provide size of array as first argument.');
}
if (index < 0 || index > size) {
throw new Error('Must provide a valid index to insert at as second argument.');
}
@justinmc
justinmc / benchmark_array_access.js
Created October 28, 2016 23:09
Benchmark for accessing an element of an array.
const size = parseInt(process.argv[2], 10);
const index = parseInt(process.argv[3], 10);
if (!size) {
throw new Error('Must provide size of array as first argument.');
}
if (index < 0 || index >= size) {
throw new Error('Must provide a valid index to access at as second argument.');
}
@justinmc
justinmc / benchmark_object_random_access.js
Last active October 28, 2016 23:27
Benchmark random access of an object, with keys created as random hash strings
const md5 = require('md5');
const size = parseInt(process.argv[2], 10);
if (!size) {
throw new Error('Must provide size of object as first argument.');
}
console.log(`Initializing object of size ${size}...`);
@justinmc
justinmc / main.dart
Last active February 10, 2022 13:54
Example of an iOS13-style draggable scrollbar in Flutter
import 'package:flutter/cupertino.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
static List<Widget> _getList(int length) {
final List<Widget> list = List<Widget>(length);
for (int i = 0; i < length; i++) {
list[i] = _getListItem(i);
}