Skip to content

Instantly share code, notes, and snippets.

View brandonbarringer's full-sized avatar

Brandon Barringer brandonbarringer

View GitHub Profile
@brandonbarringer
brandonbarringer / snow.sass
Created October 31, 2016 21:42
Sass Function and Styles to make awesome animated snow
@function makeSnow($n)
$value: '#{random(2000)}px #{random(2000)}px rgba(255, 255, 255, .9)'
@for $i from 2 through $n
$value: '#{$value} , #{random(2000)}px #{random(2000)}px rgba(255, 255, 255, .9)'
@return unquote($value)
$snow-small: makeSnow(700)
$snow-medium: makeSnow(500)
@brandonbarringer
brandonbarringer / attacks.json
Created August 4, 2016 02:38
Attack Data for NobleBot Turn Based RPG
{
"type": [{
"CS": [{
"Pixels of Fury": {
"type": "damage",
"power": 1
},
"Critique": {
"type": "damage",
"power": 1
/*
You are given a string s composed of letters and numbers, which was compressed with some algorithm.
Every letter in s is followed by a number (possibly with leading zeros),
which represents the number of times this letter occurs consecutively. For example, "aaaaaaaabbbbbbcc"
would be given as "a8b6c2".
*/
Expand_It = (s, k) => s.split(/(\d+|\D+)/g).filter(n => !!n).map( (v, i, a) => v.repeat( a[i+1] ) ).sort().join("")[k-1]
@brandonbarringer
brandonbarringer / subsetSum.js
Last active August 6, 2019 19:46
subset sum
/*
You are given an array of integers ARR and an integer SUM.
Your task is to find the number of subsets of the array ARR, such that the sum of their elements equals SUM
Example:
SubsetSum([1,2,3,4,5], 5) = 3
These subsets are [1,4], [2,3] and [5].
SubsetSum([1,2,3,4,-5], 0) = 3
@brandonbarringer
brandonbarringer / goldmine.js
Created March 16, 2016 15:45
Codefights Problem
GoldMineRace = (c, s, g) => {
a = []
c.forEach( (e, i) => {
x = c[i][0]-g[0]
y = c[i][1]-g[1]
a[i] = Math.sqrt(x*x + y*y)/s[i]
})
return a.indexOf( a.slice().sort( (a,b) => a-b ).filter( (n, p, s) => n != s[p+1] && n!= s[p-1] )[0] )
@brandonbarringer
brandonbarringer / doubleLine.js
Last active August 6, 2019 19:47
Code Wars Problem
/*
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine;
there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles!
The resulting two Sheldons go to the end of the queue.
Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on.
For example, Penny drinks the third can of cola and the queue will look like this:
[Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny]
Write a program that will return the name of a man who will drink the n-th cola.
@brandonbarringer
brandonbarringer / allianceVersusMonster.js
Last active July 6, 2016 01:43
A ridiculous function that pits Alliance members against a Monster in a turn based game. Given the monster health( healthPoints[0] ) and attack( attackDamage[0] ) and our party stats (the rest of the arrays per party member) find how many party members are left standing given they use the optimal strategy
function allianceVersusMonster(healthPoints, attackDamage) {
var warriors = [];
var monsterAttack = attackDamage[0];
var monsterLife = healthPoints[0];
var monsterIsDead = false;
var partyNum = healthPoints.length - 1;
var equalStats = false
//Warrior Template
@brandonbarringer
brandonbarringer / Load.js
Last active August 6, 2019 19:47
Page Load controller
// Portfolio.load(page)
// Loads a requested page
// Decides whether the page requested
// needs just a preview pane update
// a grid update or both
// @public
// @param {String} page - the page being requested
// @param {Boolean} addHistory - Do we need a new history state?
var Load = (function(page, addHistory) {