Skip to content

Instantly share code, notes, and snippets.

View RebootJeff's full-sized avatar
🐮
https://github.com/RebootJeff/cowGoesMoo

Jeff Lee RebootJeff

🐮
https://github.com/RebootJeff/cowGoesMoo
View GitHub Profile
@RebootJeff
RebootJeff / formatHelpers.js
Last active December 19, 2018 18:45
OWL API parsing for SFS 2019 season schedule
const moment = require('moment')
const momentTz = require('moment-timezone')
const getWeek = (timestamp, stage) => {
// Use momentjs to get number of weeks since start of stage
return ' ??? '
}
const getOpponent = competitors => {
@RebootJeff
RebootJeff / promiseExamples.js
Last active September 27, 2018 16:45
Examples of common patterns for promises in JS
// =============================================================================
// Example for unit testing an async func that doesn't already support promises
var Q = require('q'); // You must do `npm install q` first
// Async function that uses callbacks instead of promises
function authenticate(dataToSubmit, callback) {
// blah blah blah
}
@RebootJeff
RebootJeff / reactReduxDynamicInitialStateExample.js
Created June 28, 2017 20:39
Illustrating a question on how to initialize state in redux
// How do I initialize state when I do *NOT* want to use hard-coded values?
// in MyComponent.js ...
const mapStateToProps = (state, ownProps) => {
return {
usernames: state.MyComponent.usernames,
selectedDesserts: state.MyComponent.selectedDesserts || ownProps.availableDesserts
};
};
@RebootJeff
RebootJeff / example.css
Last active June 20, 2017 21:55
rendering different message "things"
.foo {
margin: 10px;
}
.banner {
padding: 10px;
text-align: center;
}
.error {
@RebootJeff
RebootJeff / combineKeyedArrays.js
Last active February 28, 2016 12:32
Beginner-friendly example of refactoring JavaScript to functional programming style
// See this blog post for full explanation:
// https://rebootjeff.github.io/blog/2015/12/11/example-refactoring-to-functional-js-combine-keyed-lists/
// Dependencies
var _ = require('lodash');
var R = require('ramda');
// Example input
var usersBySocialNetwork = {
twitter: [
@RebootJeff
RebootJeff / cottage_garden.html
Last active August 29, 2015 14:25
HTML CSS example (for teaching)
<!DOCTYPE html>
<html>
<head>
<style>
body, h1, p {
border: 2px solid red;
}
h1, p {
margin: 10px;
@RebootJeff
RebootJeff / gist:c2f9752360591f7b784c
Last active August 29, 2015 14:15
Function composition for type conversion
function makeConverter(pairs) {
function converter(value) {
for(var i = 0; i < pairs.length; i++) {
var predicate = pair[0];
var func = pair[1];
if(predicate(value)) {
return converter(func(value));
}