Skip to content

Instantly share code, notes, and snippets.

View smithcommajoseph's full-sized avatar

Joseph (Jos) Smith smithcommajoseph

View GitHub Profile
@smithcommajoseph
smithcommajoseph / Gruntfile.js
Last active December 20, 2015 19:09
adding Handlebars helpers in a Rendr app
// ...
rendr_stitch: {
// ...
files: [{
// ...
src: [
// ...
// add your handlebars helpers to the src array to be stitched
'assets/handlebars/*.js'
]
@smithcommajoseph
smithcommajoseph / app.js
Created August 6, 2013 14:07
the sockets.io example in Rendr (not working)
var express = require('express'),
http = require('http'),
rendr = require('rendr'),
config = require('config'),
mw = require('./server/middleware'),
DataAdapter = require('./server/lib/data_adapter'),
io = require('socket.io'),
ioServer,
webSocket,
app,
//could look more like
function _getGeoJson(req, res) {
GeoJsonModel.findByOptions(req.params.lsad, req.query)
.then(function success (stream) {
if (req.query.asGeoJSON === true) {
utils.streamApiDataAsGeoJson(res, stream);
} else {
utils.streamApiDataAsArray(res, stream);
{{! APPDIR/app/templates/__layout.hbs }}
<script>
(function() {
var App = window.App = new (require('app/app'))({{json appData}});
App.bootstrapData({{json bootstrappedData}});
App.start();
})();
</script>
@smithcommajoseph
smithcommajoseph / rendrBuildRoutes.js
Created July 24, 2013 17:04
What is the chain of middleware that fires off when Express responds to a Rendr route.
//Building RendrRoutes
// given
[ '/', { controller: 'maps', action: 'index' }, [Function]
//render.server.initApp.js (sole export)
function (req, res, next) {
var App, app;
App = require(rendr.entryPath + '/app/app');
@smithcommajoseph
smithcommajoseph / constantize.js
Last active March 12, 2021 02:43
A JS implementation of Ruby's constantize
// A basic example of how Ruby's constantize _could_ work in JS
// See https://apidock.com/rails/String/constantize
function constantize (str) {
if (typeof str !== 'string') {
throw new TypeError('must pass in type of string');
}
if (str.match(/\W|\d/)) {
throw new SyntaxError('must pass in a valid Javascript name');
}
@smithcommajoseph
smithcommajoseph / extendsVsextend.js
Created September 16, 2012 18:32
js extends vs extend
//A rough demo of extends vs extend
/*
* Extends - the second object needs to already be initialized
* after that, it will extend the first object
*
* var o1 = {"a": 1, "b": 2};
* var o2 = {};
* o2.extends(o1);
*/
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
function superprompt {
local RED="\[\033[0;31m\]"
local LIGHT_RED="\[\033[1;31m\]"
export PS1="\[\e]2;\u@\h\a[\[\e[37;44;1m\]\t\[\e[0m\]]$RED\$(parse_git_branch) \[\e[32m\]\W\[\e[0m\] \$ "
PS2='> '
@smithcommajoseph
smithcommajoseph / .my.cnf
Created March 26, 2012 23:45
MAMP Mysql from the command-line
[client]
user="root"
pass="root"
port=8889
socket="/Applications/MAMP/tmp/mysql/mysql.sock"
@smithcommajoseph
smithcommajoseph / train.actions.js
Created March 26, 2012 23:36
MTA-STYLE TRAIN STOP LIST
var mta = {}; //simple object w/ a few properties
mta.visibleStops = 10; //10 visible items/stops at time
mta.unformattedStops = []; // will hold the FULL array of stops
mta.formattedStops = []; // will hold the formatted array of stops
mta.sint = 0; //starting int
//wrapper function that calls everything else
mta.startTrain = function(){
//format if not already formatted
if($('#next').children().length === 0){