This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For a project I needed to find the nearest denominator from a set number and divisor. | |
// I started off hacking it together to see if it would work in my project. | |
// Then I refactored. Refactored code is shown first. | |
// Refactored Code | |
function findNearestInt(num, div){ | |
for(var i = 0; i < div / 2; i++){ | |
if(num % (div - i) == 0){return div - i} | |
if(num % (div + i) == 0){return div + i} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Two ways to use the module pattern to save state. | |
// One with an explicit callback function. | |
(function ( global, callback ) { | |
global.RunMe = callback( global ) | |
})( this, callback ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- A little practice exploring a relatively complex SQL query, | |
-- and comparing it to the ActiveRecord equivelent. | |
-- This is close to something I implemented in a real Rails project. | |
-- This gets the first 10 applications in the database that have 'Games' as their primary genre. | |
SELECT app.title AS 'Application Title', g.name as 'Primary Genre' | |
FROM application AS app | |
JOIN genre_application AS g_app | |
ON app.application_id = g_app.application_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Alerts are easily shown using the below syntax. | |
This HTML snippet can be used to display all Bootstrap alert styles. --> | |
<div ng-show='alert' class="alert alert-{{ alert.type }}"> | |
<p>{{ alert.message }}</p> | |
</div> | |
<!-- I decided to go the fading alert route | |
but you could esily make the alerts dismissable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'); | |
var Entity = require('./server/models/entity') | |
var Q = require('q'); | |
var db = mongoose.connect('mongodb://localhost/lp-test'); | |
test1(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('lodash'), | |
argv = require('yargs').argv, | |
input = _.first(argv._); | |
// everything else will default to 1 | |
var defaults = { | |
ideaCount: 4, | |
questionCount: 2 | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// delimter to join flattened keys | |
var delimiter = ' ' | |
/* | |
* Flattens an object | |
* @param {object} object - object to flatten | |
* @param {boolean} shallow - if true object is only flattened one level | |
* @return {object} - flattened object | |
*/ | |
function flatten(object, shallow) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* JavaScript Constant | |
* | |
* Create constants via Api | |
* Retreive values from window/global without Api | |
* | |
* This will work in both browsers and node | |
* | |
* Enforces standard rules: | |
* Requires uppercase naming conventions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Parser = {}; | |
Parser.parseFields = function(fields) { | |
var parser = new LoadTierParser(), | |
tokenizer = new Tokenizer(fields); | |
return parser.parseTier(tokenizer, false); | |
}; | |
function LoadTierParser(parent) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// place in root launchpad folder | |
var entityDao = require('./server/services/entity-dao'), | |
config = require('./server/config/config'), | |
systemService = require('./server/services/mj-entity-service/mj-entity-service'); | |
entityDao.connect(config.db) | |
.then(actions) | |
.fail(onError); |
OlderNewer