Skip to content

Instantly share code, notes, and snippets.

@lamchau
lamchau / _extract-mixin.js
Last active February 25, 2016 15:43
mixin for underscore/lodash to deeply extract values with a given key/predicate
// deep _.pluck/_.map combined with a _.compact
_.mixin({
extract: function(object, predicate, values) {
values = _.isArray(values) ? values : [];
_.each(object, function(value, key, hash) {
if (_.isObject(value)) {
_.extract(hash[key], predicate, values);
}
{
"folders":
[
{
"path": "."
}
],
"virtualenv": "$project_path",
"build_systems": [
{
$pip_file = "requirements.txt"
try {
pip freeze > $pip_file
# PowerShell creates UTF16 LE with Windows line endings so we must convert
# for pip to consume
# http://stackoverflow.com/questions/8852682/convert-file-from-windows-to-unix-through-powershell-or-batch
Get-ChildItem $pip_file | ForEach-Object {
$contents = [IO.File]::ReadAllText($_) -replace "`r`n?", "`n"
Function NormalizeString(Optional ByVal value As Variant) As String
If value = vbNullString Then
NormalizeString = ""
Else
NormalizeString = StrConv(value, vbUpperCase)
End If
End Function
Function getPhoneDigit(Optional ByVal value As Variant) As Variant
getPhoneDigit = NormalizeString(value)
var checkOption = function(optionName) {
return process.argv.some(function(option) {
if (option.indexOf("--", 0) === 0 && optionName) {
return option.substr(2).toLowerCase() === optionName.toLowerCase();
}
return false;
});
};
// a1Foo => a1_foo
function getRange(start, end) {
return [start.charCodeAt(0), end.charCodeAt(0)];
}
function inRange(value, start, end) {
return value >= start && value <= end;
}
function Stats(data, precision) {
var PRECISION = precision || 2;
var length = data.length;
var mean = (function() {
var sum = data.reduce(function(a, b) {
return a + b;
}, 0);
return sum / length;
})();
function getPath(object, path) {
if (typeof object === 'undefined' || typeof path !== 'string') {
return undefined;
}
var index = path.trim().indexOf('.');
if (index < 0) {
return object[path];
}
function findBalancePoint(array) {
if (array.length === 0) {
return 0;
}
if (array.length === 1) {
return 1;
}
// initial sums
var left = 0;
var right = 0;
(function(Factory, Lorem, underscore) {
var SHA_CHARS = "0123456789abcdef";
var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var CATEGORIES = ["Low", "Medium", "High"];
var ONE_YEAR_IN_MILLISECONDS = 31536000000;
var _ = underscore;
var methods;
// http://www.ssa.gov/oact/babynames/decades/century.html
var FIRST_NAME = ["James", "John", "Robert", "Michael", "William", "David", "Richard", "Joseph", "Charles", "Thomas", "Christopher", "Daniel", "Matthew", "Donald", "Anthony", "Mark", "Paul", "Steven", "George", "Kenneth", "Mary", "Patricia", "Jennifer", "Elizabeth", "Linda", "Barbara", "Susan", "Margaret", "Jessica", "Sarah", "Dorothy", "Karen", "Nancy", "Betty", "Lisa", "Sandra", "Ashley", "Kimberly", "Donna", "Helen"];
// https://en.wikipedia.org/wiki/List_of_most_common_surnames_in_North_America