Skip to content

Instantly share code, notes, and snippets.

View lewisrodgers's full-sized avatar

Lewis Rodgers lewisrodgers

View GitHub Profile
@lewisrodgers
lewisrodgers / sticky-footer.html
Last active November 8, 2016 05:12
CSS solution to keep footer at the bottom of the page even when there is not enough content to do so normally. http://codepen.io/lewis-rodgers/pen/RoPgdN
/**
* Add to run block of angular module
*/
$rootScope.$on('$stateChangeSuccess', function() {
document.body.scrollTop = document.documentElement.scrollTop = 0;
}
@lewisrodgers
lewisrodgers / master-detail service pattern.js
Last active January 29, 2017 22:21
Boilerplate service for getting 1 or all records of a type.
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.
*/
@lewisrodgers
lewisrodgers / simple-httprequest.js
Last active January 29, 2017 22:14
Just enough javascript to do a GET request.
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();
@lewisrodgers
lewisrodgers / reducer-count-unique-items.js
Last active January 27, 2017 13:54
Reducer: Count number of unique items in a list
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
@lewisrodgers
lewisrodgers / pub-sub.js
Created January 29, 2017 22:12
Simple publish/subscribe implementation.
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
*/
@lewisrodgers
lewisrodgers / organize-by.js
Created January 31, 2017 20:16
Splits an array of objects into groups
/**
* 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] = [];
@lewisrodgers
lewisrodgers / README.md
Last active April 4, 2018 17:00
Deploying Cloud Functions to schedule a Python Dataflow pipeline.

Deploying Cloud Functions to schedule a Python Dataflow pipeline.

Use this as a guide. But instead of using the java runtime, we'll use python.

The setup can be accomplish with virtualenv to create an isolated environment.

The project folder structure will look like this:

cloudfunction/
@lewisrodgers
lewisrodgers / tD19.bitbucket-piplines.yml
Last active February 26, 2019 11:36
Chrome extension basic pipeline
pipelines:
branches:
develop:
- step:
name: Update
script:
- apt-get update
- apt-get -y install jq zip
- FILE_NAME=crx.zip
- zip -r $FILE_NAME ./app
# 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