Skip to content

Instantly share code, notes, and snippets.

@timothyjellison
timothyjellison / speech-navigation.html
Last active May 16, 2019 14:27
Basic navigation with the Web Speech API
<!DOCTYPE html>
<html lang="en">
<head>
<title>Speech Test</title>
</head>
<body>
<button id="recordButton">🔴</button>
<script>
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition
fetch(new Request('https://api.github.com/users/timothyjellison')).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
@timothyjellison
timothyjellison / templateTag
Last active October 18, 2018 15:32
A generic tag expression creator
const templateTag = transformer => (strings, ...args) => {
if (args.length === 0) {
return strings.toString();
}
const transformed = [];
strings.forEach((val, i) => {
transformed.push(val);
if (args[i]) {
@timothyjellison
timothyjellison / gist:67292dd299973be49b7e583aed88b510
Created September 21, 2018 18:03
Lodash Debounce + React Example
import React from 'react';
import _ from 'lodash';
class DebounceExample extends React.Component {
constructor() {
super();
this.state = {
on: false
};
@timothyjellison
timothyjellison / App.mockImplementation.test.js
Created May 5, 2018 16:45
Mocking a component constructor with Jest
// An answer for this stackoverlow question: https://stackoverflow.com/questions/48831701/jest-how-to-mock-default-export-component-when-same-module-also-has-named-expor
import React from 'react';
import { shallow } from 'enzyme';
import App, { myUtilityFunction } from './App';
jest.mock('./App');
App.mockImplementation(() => {
return {
@timothyjellison
timothyjellison / csvtoyaml.js
Last active January 25, 2018 14:27
CSV to YAML
const csv = require('csvtojson');
const YAML = require('json2yaml');
const fs = require('fs');
const _ = require('lodash');
const camelcase = require('camelcase');
const inp = process.argv[2];
const otp = process.argv[3];
const rawData = [];
@timothyjellison
timothyjellison / gist:b2e6cf3e54201bbf1afade40da3e780d
Created December 13, 2017 16:00
Show spinner until background image is loaded
// all credit to stackoverflow user "Useless Code"
// see https://stackoverflow.com/questions/42998327/preloading-background-images
var myImages = ['https://www.nationalparks.org/sites/default/files/yosemite-merced.jpg'];
var banner = document.getElementById('banner');
var spinner = document.getElementById('spinner');
function loadImages (images) {
let loader = function (src) {
return new Promise(function (resolve, reject) {
@timothyjellison
timothyjellison / index.js
Last active December 3, 2017 22:51
Basic express server with express-validator
const express = require('express');
const bodyParser = require('body-parser');
const {check, validationResult} = require('express-validator/check')
const {sanitize} = require('express-validator/filter');
const app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.post('*', [
check('inputValue').isLength({max: 5}),
@timothyjellison
timothyjellison / Bonfire_18.js
Created January 6, 2016 01:06
Great Caesar's Ghost!!
function rot13(encodedStr) {
var codeArr = encodedStr.split(""); // String to Array
var decodedArr = []; // Your Result goes here
// Only change code below this line
codeArr.forEach(function(letter){
oldCode = letter.charCodeAt(0);
if (oldCode >= 65 && oldCode <= 90) {
newCode = oldCode + 13;
if (newCode > 90) {
newCode -= 26;