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 list = ["foo", "foo", "bar", "bar", "bar"]; | |
var results = list.reduce(reducer, {}); | |
console.log(results); // {"foo": 2, "bar": 3} | |
/** | |
* Callback function for the `reduce()` method. | |
* | |
* @param acc accumulated value previously returned in the last invocation of the 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
var Eventbus = { | |
topics: {}, | |
/** | |
* Adds topic to `topics` object if it doesn't exist | |
* and adds listener to same topic. | |
* | |
* @param {string} topic | |
* @param {function} listener | |
*/ |
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
/** | |
* Add to run block of angular module | |
*/ | |
$rootScope.$on('$stateChangeSuccess', function() { | |
document.body.scrollTop = document.documentElement.scrollTop = 0; | |
} |
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 endpoint = 'https://jsonplaceholder.typicode.com/users'; | |
// 1. https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest | |
var request = new XMLHttpRequest(); | |
request.addEventListener('load', function() { | |
console.log(this.responseText); | |
}) | |
request.open('GET', endpoint); | |
request.send(); |
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
angular | |
.module('app') | |
.service('MyService', myService); | |
function myService($http) { | |
/** | |
* First, send a get request for all records of a type, | |
* then filter response down to specific record. | |
*/ |
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
/** | |
* Expects data to be an array of objects. | |
* The key will be one of the keys in the objects. | |
*/ | |
function organizeBy(key, data) { | |
var results = {}; | |
data.forEach(function(obj) { | |
var value = obj[key]; | |
if (!results[value]) { | |
results[value] = []; |
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
# Possible versioning stratgy. | |
# Only integers are allowed with the `version` property of the manifest.json. | |
script: | |
- GIT_HASH=$(git rev-parse --short HEAD) | |
- jq ".version_name = \"build-$GIT_HASH\"" manifest.json | spong manifest.json |
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
#!/bin/bash | |
# This script is used to update a chrome extension that's already | |
# been uploaded to the Chrome Web Store. You'll need to know the | |
# chrome extension's ID that you want to update. | |
# To find the app ID see: https://developer.chrome.com/webstore/publish#get-the-app-id | |
# | |
# usage: | |
# ./chrome-web-store-api-update-utility.sh $APP_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
#!/bin/bash | |
# This script generates a `tokens.json` file. | |
# | |
# example: | |
# { | |
# "access_token" : "ya29.Glst...", | |
# "expires_in" : 3600, | |
# "refresh_token" : "1/dd3t...", | |
# "token_type" : "Bearer" |
OlderNewer