Skip to content

Instantly share code, notes, and snippets.

View andrewjmead's full-sized avatar

Andrew Mead andrewjmead

View GitHub Profile
@andrewjmead
andrewjmead / app.js
Last active December 22, 2016 03:41
An AngularJs directive for smart inline editing.
/* demo app that uses the inline directive */
var myApp = angular.module('inlineDemo', ['inline']);
myApp.config(function ($routeProvider) {});
myApp.controller('names', function ($scope) {
console.log('controller');
$scope.masterName = $scope.name = '46';
@andrewjmead
andrewjmead / reduce.js
Last active September 14, 2016 20:34
JavaScript: Reduce an object by the supplied identifiers.
/**
* Andrew Mead
*
* object.reduce(objToMatch)
*
* A simple way to return specific properties from an object
*
* EXAMPLE
* var obj = {
* name: "andrew",
<!doctype html>
<!-- I ran with php -S localhost:3007 -->
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<script src="./angular.js"></script>
@andrewjmead
andrewjmead / server.js
Last active December 27, 2015 19:59
static express server
var express = require('express');
var app = express()
app.configure(function () {
app.use(express.static(__dirname + '/app'));
});
app.listen(3003, function () {
console.log('listening on port 3003');
})
@andrewjmead
andrewjmead / center
Created November 18, 2013 18:30
fluid-center
/* =============================================================================
Fluid Center
========================================================================== */
// Given the following DOM structure, elements are centered relative to the parent
// and can accomodate varied-width inner content
// <div class="fluid-center">
// <div class="inner-wrap">
// <div class="offset">
// Any content here
@andrewjmead
andrewjmead / gist:5f608fb2ef358f12284d
Created August 27, 2014 12:26
Gulp Race Condition
gulp.watch('public/js/main.js', ['scripts']).on('change', function () {
// I would expect the scripts task to be done
});
@andrewjmead
andrewjmead / QueryParams.js
Last active November 29, 2017 14:32
Get Query Params By Name
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
@andrewjmead
andrewjmead / todo.js
Created November 27, 2015 20:07
Custom Sequelize Validation
module.exports = function(sequelize, DataTypes) {
return sequelize.define('todo', {
description: {
type: DataTypes.STRING,
allowNull: false,
validate: {
len: [1, 250]
}
},
completed: {
@andrewjmead
andrewjmead / blocking.js
Created November 27, 2015 20:25
Non-blocking vs blocking example
var fs = require('fs')​;
fs.writeFileSync('message.txt', 'Hello Node.js');
console.log('This will not print until the file is saved. Sync means do not use non-blocking.');
@andrewjmead
andrewjmead / styles.css
Created November 27, 2015 20:44
Vertical Center Auto-prefixed
.vertical-center {
min-height: 100vh;
margin: 0;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;