Skip to content

Instantly share code, notes, and snippets.

View benhowdle89's full-sized avatar

Ben Howdle benhowdle89

View GitHub Profile
@benhowdle89
benhowdle89 / app.js
Created November 1, 2016 10:51
Redirect non-HTTPS -> HTTPS in your Express app
const requireHTTPS = (req, res, next) => {
if(req.headers['x-forwarded-proto'] !== 'https' && process.env.NODE_ENV === 'production') {
var secureUrl = "https://" + req.headers['host'] + req.url
res.writeHead(301, { "Location": secureUrl })
res.end()
}
next()
}
app.use(requireHTTPS)
@benhowdle89
benhowdle89 / ShareButton.jsx
Created May 17, 2016 21:04 — forked from jamesslock/ShareButton.jsx
ReactJS Share Buttons
import React, { PropTypes } from 'react';
import Button from '../components/Button.jsx';
import Icon from '../components/Icon.jsx';
module.exports = React.createClass({
render: function () {
const {
className,
classNameIcon,
children,
@benhowdle89
benhowdle89 / app.jsx
Last active September 24, 2015 21:56
import React from 'react';
import ItemsCollection from './../collections/items';
const Items = React.createClass({
getInitialState() {
return {
items: []
};
var h = new Headers()
h.append('Authorization', 'Bearer xxx');
h.append('Cookie', 'xxx');
h.append('Content-Type', 'application/json');
fetch('http://localhost:4567/api/reviews', {
headers: h,
method: 'POST',
body: JSON.stringify({ "foo": "bar" })
}).then(function (res) {
return res.json().then(function (json) {
@benhowdle89
benhowdle89 / index.js
Created March 2, 2015 17:55
requirebin sketch
var $ = require('jquery');
$('body').css('background-color', 'red');
@benhowdle89
benhowdle89 / foo.js
Last active March 13, 2021 12:22
Easy Singleton instances using Browserify
var _vent = require('./vent.js').shared();
_vent.trigger('blah');
@benhowdle89
benhowdle89 / base-view.js
Created July 15, 2014 13:49
CommonJS Backbone inheritence
var Backbone = require('backbone');
var $ = require('jquery');
var Handlebars = require('handlebars');
var HandlebarsHelpers = require('base/utils/template-helpers');
var templateCache = require('base/utils/template-cache');
module.exports = Backbone.View.extend({
initialize: function(options) {
this.templates = templateCache.get();
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
var livereload = require('gulp-livereload');
var hbsfy = require("hbsfy").configure({
extensions: ["html"]
});
gulp.task('scripts', function() {
@benhowdle89
benhowdle89 / index.js
Created June 12, 2014 12:45
requirebin sketch
var $ = require('jquery');
$('body').css('background-color', 'red');
Had a similar question a few weeks ago, so might as well forward you that!
http://addyosmani.com/resources/essentialjsdesignpatterns/book/
http://shop.oreilly.com/product/0636920025245.do
http://shop.oreilly.com/product/0636920018421.do
http://shop.oreilly.com/product/9780596806767.do