Skip to content

Instantly share code, notes, and snippets.

View BideoWego's full-sized avatar
:octocat:
Yarp

BideoWego BideoWego

:octocat:
Yarp
View GitHub Profile
@BideoWego
BideoWego / spec_helper.js
Created April 7, 2017 22:03
Jasmine Node `beforeAll`
var SpecHelper = {};
var _flags = {
didRun: {}
};
@BideoWego
BideoWego / helpers.url.index.js
Created April 16, 2017 07:37
Code for recursively requiring helpers and allows extending them
// Requires the `qs` package
var qs = require('qs');
var path = require('path');
var url = require('url');
module.exports = (helpers) => {
helpers.registerDirectory('url/', (helper) => {
Object.keys(helper).forEach((key) => {
@BideoWego
BideoWego / us_states.json
Last active April 19, 2017 13:55
The 50 States of the USA in JSON
[
{ "name": "Alabama" },
{ "name": "Alaska" },
{ "name": "Arizona" },
{ "name": "Arkansas" },
{ "name": "California" },
{ "name": "Colorado" },
{ "name": "Connecticut" },
{ "name": "Delaware" },
{ "name": "Florida" },
@BideoWego
BideoWego / pagination.js
Created April 19, 2017 21:16
A simple an effective pagination algorithm with an O(n) time complexity where n is the number of pages in the range `(current - delta) ... (current + delta) + 2`
// Pagination algorithm
// Refactored by https://github.com/BideoWego
// Originally from:
// https://gist.github.com/kottenator/9d936eb3e4e3c3e02598
function pagination(current, max, delta) {
// Return nada if we got
// no pages
@BideoWego
BideoWego / helpers.pagination_helper.js
Created April 19, 2017 22:06
Pagination algo in a project context
const _ = require('lodash');
function _createPages(current, max, delta) {
// Return nada if we got
// no pages
if (!max) {
return [];
}
@BideoWego
BideoWego / submlime-emmet-jsx-tab-trigger.js
Last active April 29, 2017 20:11 — forked from wesbos/tab-trigger.js
How to properly get a TAB trigger working with Emmet inside of JSX
{
"keys": ["tab"],
"command": "expand_abbreviation_by_tab",
// put comma-separated syntax selectors for which
// you want to expandEmmet abbreviations into "operand" key
// instead of SCOPE_SELECTOR.
// Examples: source.js, text.html - source
"context": [
{
@BideoWego
BideoWego / algos.js
Created September 26, 2017 19:42
Algo Problems
/*
String Permutations Tree
Devise a class that when instantiated it create a tree that maps out all of the possible permutations of a given string.
- The root node will have a value of `undefined`
- The direct children of the root node will be each char of the string
- This pattern will continue until it maps out each unique permutation of the string
@BideoWego
BideoWego / ternary_if_else_if_else.js
Last active December 1, 2017 20:59
Ternary if, else if, else... chain
const fn = num => (
num >= 0 && num < 10 ? '1-9' :
num >= 10 && num < 20 ? '10-19' :
num >= 20 && num < 30 ? '20-29' :
num >= 30 && num < 40 ? '30-39' :
num >= 40 && num < 50 ? '40-49' :
num >= 50 && num < 60 ? '50-59' :
num >= 60 && num < 70 ? '60-69' :
num >= 70 && num < 80 ? '70-79' :
num >= 80 && num < 90 ? '80-89' :
@BideoWego
BideoWego / command-line_args.js
Created November 25, 2017 21:39
Regex to capture command-line arguments separated by spaces but group strings surrounded in quotes
/*
Modified from this SO post:
https://stackoverflow.com/questions/24069344/split-spaces-avoiding-double-quoted-js-strings-from-a-b-c-d-to-a
*/
/('|")(?:\\('|")|\\\\|[^'|"])*('|")|\S+/
"a b 'c d'".match(/('|")(?:\\('|")|\\\\|[^'|"])*('|")|\S+/g)
//=> [ 'a', 'b', '\'c d\'' ]
@BideoWego
BideoWego / random-date.js
Created December 8, 2017 05:04 — forked from miguelmota/randomDate.js
Random date in JavaScript
function randomDate(start, end) {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}
console.log(randomDate(new Date(2012, 0, 1), new Date()));