Skip to content

Instantly share code, notes, and snippets.

#Node - Running in Production This gist is based on the excellent post by @hacksparrow which is found at http://www.hacksparrow.com/running-express-js-in-production-mode.html. The main principle is that you want the application to detect that it is running on a production server and to use the production configuration. The way to do this is to set the NODE_ENV=production. To do this you need to do the following:

$ export NODE_ENV=production

But we have a little problem here. The NODE_ENV environment variable will be lost if the server restarts, so it is safer to put it in the .bash_profile file. That way the variable will set again every time the system reboots. You will find the file in your home directory. It's a hidden file, so you can't see it unless you do a ls -la. We will append the export command to the .bash_profile file.

// NOTE: I added the .js extension to this gist so it would have syntax highlighting. This file should have NO file extension
{
// Settings
"passfail" : false, // Stop on first error.
"maxerr" : 100, // Maximum error before stopping.
// Predefined globals whom JSHint will ignore.
"browser" : true, // Standard browser globals e.g. `window`, `document`.
[
// Move OPen File to Window Group
{
"keys": ["super+alt+up"],
"command": "set_layout",
"args":
{
"cols": [0.0, 1.0],
"rows": [0.0, 1.0],
(function() {
'use strict';
// this function is strict...
}());
module.exports = function(grunt) {
// AUTO TASK LOADER + EXECUTION TIME LOG
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
@djcommandline
djcommandline / gist:620e3150115b3dfa1d0a
Created October 4, 2014 17:39
Simple HTTP server is python on Mac
# Start an HTTP server from a directory, optionally specifying the port
function server() {
local port="${1:-8000}";
sleep 1 && open "http://localhost:${port}/" &
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
# And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port";
}
background-image: linear-gradient(40deg, rgba(252, 0, 0, 0.1225) 0%, rgba(211, 184, 76, 0.1225) 47%, rgba(107, 199, 218, 1) 100%);
@djcommandline
djcommandline / gist:5111883
Last active December 14, 2015 15:59
JS :: Decode URI
decodeURIComponent(QueryString.utm_medium).replace(/\+/g, ' ')
@djcommandline
djcommandline / gist:5111846
Last active December 14, 2015 15:59
JS :: Query String Parser
var QueryString = function () {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var query_string = {};
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 first entry with this name
if (typeof query_string[pair[0]] === "undefined") {
@djcommandline
djcommandline / WP :: PHP :: wp-config.php
Last active December 15, 2015 17:38
WP :: PHP :: wp-config
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') ) {
define('ABSPATH', dirname(__FILE__) . '/');
}
/** Check if there is a local configuration settings file
if(file_exists(ABSPATH . 'wp-config.local.php')){
require_once(ABSPATH . 'wp-config.local.php');
} else {
@djcommandline
djcommandline / JS :: HTML5 :: OLD BROWSER SUPPORT
Created May 6, 2013 19:03
JS :: HTML5 :: OLD BROWSER SUPPORT
;("header footer section aside nav article figure figcaption hgroup time").replace(/\w+/g,function(a){document.createElement(a)})