Skip to content

Instantly share code, notes, and snippets.

View dstevensio's full-sized avatar

Dave Stevens dstevensio

View GitHub Profile
@dstevensio
dstevensio / binding.jsx
Created January 7, 2016 18:37
Binding in React with React.Component use
class MyComponent extends React.Component {
constructor(props) {
super(props);
this._myHandlerFunc = this._myHandlerFunc.bind(this);
}
_myHandlerFunc() {
// do something
}
@dstevensio
dstevensio / bash.md
Last active December 9, 2015 21:58
Bash Aliases for bash profile changes

In ~/.bash_profile or ~/.bashrc (whichever you use)

alias ebash="sudo vi ~/.bash_profile"
alias rbash="source ~/.bash_profile"

Change ~/.bash_profile to ~/.bashrc if you're using the latter.

When you need to edit your bash config, you can

@dstevensio
dstevensio / jsonParsing.js
Created November 10, 2015 19:25
Wrap JSON.parse in try/catch
try {
JSON.parse(jsonSource);
} catch (e) {}
@dstevensio
dstevensio / requirehookbabel6plus.md
Last active November 3, 2015 02:06
Require Hook with Babel 6.x+

install presets

npm i babel-preset-stage-0 babel-preset-es2015

create/edit .babelrc

{
  presets: ["es2015", "stage-0"]
}
@dstevensio
dstevensio / mapinJSX.js
Last active September 30, 2015 17:43
Using map in JSX string literal return
class MyComponent extends React.Component {
render() {
return (
<ul>
{this.props.listItems.map((item) => {
return <li>{item}</li>;
})}
</ul>
);
}
@dstevensio
dstevensio / const.js
Created September 24, 2015 23:07
Const is not immutable
const x = 12;
console.log(x); // 12
x = 42;
console.log(x); // 12 (but no error)
const y = {};
y.newProp = "value";
console.log(y); // {newProp: "value"}
@dstevensio
dstevensio / rejoice.md
Last active October 31, 2016 21:17
rejoice + npm = awesome

Brand new project, create dirs "lib/modules", "lib/templates", "config"

lib/modules/home/index.js :

exports.register = function (server, options, next) {

  server.route({
    path: '/',
 method: 'GET',
@dstevensio
dstevensio / express-hapi.js
Created December 4, 2014 00:08
Express vs hapi
// GETTING STARTED:
// Express
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.send('hello world');
});
@dstevensio
dstevensio / joi-issue.js
Created December 3, 2014 22:25
joi issue potential solution
"use strict";
var joi = require("joi");
var data = [{
type : "A",
ip : "123.123.123.123"
},
{
type: "A",
@dstevensio
dstevensio / widthExceeding.js
Created October 17, 2014 21:38
Quick and dirty utility to find all elements in the DOM that exceed a specified width
// Requires jQuery
// Specify a max width. This will return any elements in the DOM on the current page
// with a width greater than that width. Useful when debugging what element is
// screwing up your fluid layout
// NOT PRODUCTION CODE - A QUICK 'N DIRTY UTILITY TO SAVE SOME TIME DEBUGGING!
var maxWidth = 400;
jQuery("*").filter(function () {
if (jQuery(this).width() > maxWidth){