Skip to content

Instantly share code, notes, and snippets.

@craigbeck
craigbeck / fixsemi.js
Created March 15, 2016 22:45
automatic fix semicolons from eslint output
#!/usr/bin/env node
var fs = require("fs");
function fixFile(filename, lineNumbers) {
fs.readFile(filename, { encoding: "utf-8", flag: "r" }, function (err, buffer) {
if (err) {
console.error("Could not read", filename, err);
return;
}
@craigbeck
craigbeck / design-elements.md
Created March 11, 2016 22:56
Design pointers and considerations for web apps

Frequently missing components

  • empty view; what about when there is no data?
  • tansitions; animations?
  • busy indicators; spinners, interstitial views
  • error views
    • view?
    • alert?
  • global alerting
  • "new version available"
@craigbeck
craigbeck / webpack.config.js
Created June 12, 2015 00:11
Hot reload webpack configuration
var Webpack = require("webpack");
var path = require("path");
var util = require("util");
var host = process.env.HOST || "localhost";
var port = process.env.PORT || 8080;
module.exports = {
entry: {
app: [
@craigbeck
craigbeck / problem.md
Created June 4, 2015 22:40
Fix hapi.js issue with BadRequest when parsing invalid cookie value

Problem

  • multple apps sharing the same cookie domain
  • one app (express.js) is using a secure cookie express:sess and express:sess.sig
  • the hapi.js app tries to parse these cookies and fails returning 400 BadRequest error to client

I don't want hapi to return an error response to the client just because it gets a cookie it cant parse and doesn't care about. I tried setting

server.config({
@craigbeck
craigbeck / number-formats.js
Created June 3, 2015 17:24
google-libphonenumber examples
var libphonenumber = require("google-libphonenumber");
var formats = libphonenumber.PhoneNumberFormat;
var phoneUtil = libphonenumber.phoneUtil;
var number = phoneUtil.parse("2065557823", "us"); // pass number and country code
// some formats
phoneUtil.format(number, formats.E164);
// '+12065551234`
'use strict';
module.exports = function CustomError(message, extra) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.extra = extra;
};
require('util').inherits(module.exports, Error);
@craigbeck
craigbeck / viewport-info.jsx
Created May 14, 2015 23:15
React ViewportInfo component
var ViewportInfo = React.createClass({
getInitialState: function () {
return {
width: null,
height: null
};
},
@craigbeck
craigbeck / .bash_profile
Last active August 29, 2015 14:19
Quick profile setup
# aliases
alias cls='clear'
alias ls='ls -FG'
alias ll='ls -l'
alias la='ll -a'
# git completion
if [ -f `brew --prefix`/etc/bash_completion.d/git-completion.bash ]; then
. `brew --prefix`/etc/bash_completion.d/git-completion.bash
fi
@craigbeck
craigbeck / git-workflow.md
Created April 1, 2015 16:45
git workflow OS X

First, you have to get your repository. Use git clone to get the repository into your current directory form the terminal

git clone https://github.com/craigbeck/git-workflow-demo.git

The above will create a directory git-workflow-demo in the current directory that contains the "repo" (assuming a real repository, the above URL is just a made-up example). Change to this new directory with cd git-workflow-demo. Your newly cloned repo should look something like this:

$ ls -la
@craigbeck
craigbeck / README.md
Created February 16, 2015 22:19
Fix Mailbox.app crashing on startup

Problem

Mailbox.app crashes on startup every time. This happend after a Gmail account was disabled (account associated with previous job) before it was removed from Mailbox.app. This caused crashes on the iOS and OS X versions of the app that made them both unusable.

iOS

An updated app was relased at some point that allowed me to "delete" the prevoiusly deactivated account and has been working for a number of weeks.

OS X