Skip to content

Instantly share code, notes, and snippets.

View thecolorblue's full-sized avatar

Brad Davis thecolorblue

  • University Heights, Ohio
View GitHub Profile
function transpose(array) {
// split rows
array = array.map(r=>r.split(''));
// transpose
array = array[0].map((r, i)=> array.map(c=>c[i]));
// merge rows
return array.map(r=> r.join(''));
}
@thecolorblue
thecolorblue / listen.py
Last active August 28, 2018 16:37
nlp example
from __future__ import unicode_literals, print_function
import spacy
import json
from spacy.matcher import PhraseMatcher
from spacy.tokens import Doc, Span, Token
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0">
<channel>
<title>![CDATA[ BW - Welcome Center - Content ]]</title>
<link>http://rootdcs.rootintegration.com/carouselapi/v1/zones/107/syndication</link>
<description>Provides a list of active bulletins on your Carousel system.</description>
<language>en-us</language>
<publicationDate>Tue, 22 May 2018 10:05:35 GMT</publicationDate>
<copyright>Copyright 2018 Tightrope Media Systems, Inc.</copyright>
<item>
@thecolorblue
thecolorblue / Valdiation reducer
Created January 28, 2018 18:19
Form Field Factory
function reducerFactory(fieldReducers) {
return function formReducer(state={}, action) {
if (/UPDATE_/.test(action.type) {
// validate field change
var [form, field] = /UPDATE_{[a-z]}_{[a-z}/.match(action.type);
if (state[form][field]) {
return {
...state,
[form]: {
...state[form],
fetch('http://files.olo.com/pizzas.json')
.catch(e=>console.error(e.message))
.then(r=>r.json())
.then((sales)=>sales.reduce((totals, sale)=>{
var topCombo = sale.toppings.join(' - ');
if (totals[topCombo] > 0) totals[topCombo]++;
else totals[topCombo] = 1;
return totals;
},{}))
.then(r=>Object.keys(r).map(toppings=>{ return { toppings:toppings, total: r[toppings] }}))
@thecolorblue
thecolorblue / redux resources
Last active October 27, 2017 17:06
First attempt at creating re-usable redux resources.
class CatalogItem {
name = 'CATALOGITEM'
constructor(item) {
Object.assign(this, {
...item,
...item.Attributes.map(a => a.ExpandedAttributeName.split(' : ')).reduce((o, a) => { o[a[0]] = a[1]; return o; }, {}),
Currency: 'USD'
})
}
@thecolorblue
thecolorblue / redux resources
Created October 27, 2017 17:02
First attempt at creating re-usable redux resources.
class CatalogItem {
name = 'CATALOGITEM'
constructor(item) {
Object.assign(this, {
...item,
...item.Attributes.map(a => a.ExpandedAttributeName.split(' : ')).reduce((o, a) => { o[a[0]] = a[1]; return o; }, {}),
Currency: 'USD'
})
}
function CourseCatalogBody({ gridOnly, gotoDetails, items, view, toggleCourse, purchaseCourses }) {
if (view === 'table' && gridOnly != 'true') {
return <CoursesTable items={items} gotoDetails={gotoDetails} toggleCourse={toggleCourse} purchaseCourses={purchaseCourses} />;
}
return <CoursesGrid items={items} gotoDetails={gotoDetails} />;
}
function factory(View, inject, dispatch) {
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script src="https://fb.me/react-0.14.0.min.js"></script>
<script src="https://fb.me/react-dom-0.14.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.0.4/redux.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-redux/4.0.0/react-redux.min.js"></script>
</head>
@thecolorblue
thecolorblue / convert_orders.js
Last active January 5, 2017 14:39
Receive a webhook from WooCommerce and push each product/line item into Zapier (which then puts them into a Google Spreadsheet). This is a great example, not because its particularly well written, but because it is so function.
'use strict';
var https = require('https');
var request = require('request-promise');
var Promise = require("bluebird");
/**
* Pass the data to send as `event.data`, and the request options as
* `event.options`. For more information see the HTTPS module documentation
* at https://nodejs.org/api/https.html.