Skip to content

Instantly share code, notes, and snippets.

View dankahle's full-sized avatar

Dan Kahle dankahle

View GitHub Profile
@dankahle
dankahle / listNodeModulesWithSemvers.js
Last active August 29, 2015 14:18
Read node module versions for inclusion into package.json
var fs = require("fs");
function main() {
fs.readdir("./node_modules", function (err, dirs) {
if (err) {
console.log(err);
return;
}
dirs.forEach(function(dir){
if (dir.indexOf(".") !== 0) {
@dankahle
dankahle / dbConn.js
Last active August 29, 2015 14:17
winston-mongodb log dropping bug
var mongodb = require('mongodb'),
MongoClient = mongodb.MongoClient,
Q = require('q'),
def = Q.defer(),
db,
initialized
module.exports = function(init) {
form error message strategies in angular

Forms can be quite tedious in angular, mostly having to do with messages. There's several options: highight the invalid fields or show messages, show messages only when dirty, disable submit button, etc. I don't like the disabled submit button as it leaves the user guessing which field is invalid, and... if they're not guessing which field is invalid, then all invalid fields or messages are "always" shown, I don't care for that as well. My solution this time around was to show messages only when dirty, leaving the submit button enabled, then setting all fields to dirty upon submission. So, no messages shown until the submit button is hit or they visit the field Upon submit all messages are shown for invalid fields. This feels right.

Also, played around a bit with ng-module-options.updateOn and have to say, blur isn't cool. You just can't wait for a blur event for error message updates or even field updates (a select won't change it's value after you select an o

@dankahle
dankahle / repository using sessionStorage or cookies.html
Last active August 29, 2015 14:05
An example that stores session info on the client in sessionStorage if it exists, otherwise falls back to session cookies.
<!DOCTYPE html>
<html ng-app="app">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.18/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.18/angular-cookies.min.js"></script>
</head>
<body ng-controller="ctrl">
<button ng-click="set()">set</button><br>
<button ng-click="get()">get</button><br>
<button ng-click="remove()">remove</button><br>
@dankahle
dankahle / using the same js file in your html page and node project.js
Last active August 29, 2015 14:05
An example of how to share code between the browser and node. You need to "module.exports" the arrays in node, but not in the browser.
var users = [
{id:'dk', name: 'dank', age:50},
{id:'cy', name: 'carl', age:60},
{id:'js', name: 'jim', age:40}
];
if(!window && typeof module != 'undefined'){
module.exports.friends = friends;
module.exports.users = users;
}