Skip to content

Instantly share code, notes, and snippets.

View david-j-davis's full-sized avatar
🏠
Working from home

David J. Davis david-j-davis

🏠
Working from home
View GitHub Profile
@david-j-davis
david-j-davis / mac-setup-redis.md
Created October 21, 2022 17:19 — forked from tomysmile/mac-setup-redis.md
Brew install Redis on Mac

type below:

brew update
brew install redis

To have launchd start redis now and restart at login:

brew services start redis
@david-j-davis
david-j-davis / flattenArray.js
Created September 22, 2019 19:20
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4]
// Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
function flattenArray(arr) {
if (!Array.isArray(arr)) {
return 'Please enter an array'
}
return arr.reduce((acc, val) => Array.isArray(val) ? acc.concat(flattenArray(val)) : acc.concat(val), [])
}
// console.log(flattenArray(4)) // will return 'Please enter an array'
@david-j-davis
david-j-davis / App.vue
Created September 14, 2019 01:28
vue-chat-widget example frontend using websockets
<template>
<div id="app">
<Chat
iconColorProp="#e6e6e6"
messageOutColorProp="#4d9e93"
messageInColorProp="#f1f0f0"
messageBackgroundColorProp="#ffffff"
:messageListProp="messageList"
:initOpenProp="initOpen"
@onToggleOpen="handleToggleOpen"
@david-j-davis
david-j-davis / app.js
Created July 26, 2019 20:26
Node.js chat app to sms using socket.io and Twilio
const express = require('express')
const app = express()
const cors = require('cors')
const twilio = require('twilio')
const socketUtils = require('./utils/socketUtils')
const server = require('http').Server(app)
const io = require('socket.io')(server)
let socketStack = []
@david-j-davis
david-j-davis / chat.js
Created July 26, 2019 20:18
Chat App Frontend with React-chat-window
import React from 'react'
import { Launcher } from 'react-chat-window'
import io from 'socket.io-client'
import config from '../../config.json'
import './form-chat-bot.scss'
import checkWorkingHours from '../utils/checkWorkingHours'
import handleFetch from '../utils/fetch'
const socketUrl = 'https://<your-app>.herokuapp.com'
let socket
@david-j-davis
david-j-davis / README.md
Last active April 5, 2019 17:00
ES6 class for a roll-your-own jQuery

Roll your own lightweight, build-what-you-need jQuery with an ES6 Class.

@david-j-davis
david-j-davis / Contract Killer 3.md
Created September 21, 2018 04:49
The latest version of my ‘killer contract’ for web designers and developers

Contract Killer

The popular open-source contract for web professionals by Stuff & Nonsense

  • Originally published: 23rd December 2008
  • Revised date: March 15th 2016
  • Original post

@david-j-davis
david-j-davis / gulpfile.js
Created April 17, 2017 22:40
Takes retina images and downsizes them inside to non-retina images in the same folder using gulp-retinize
var retinize = require('gulp-retinize');
gulp.task('retiniizing', function(file) {
/* NOTE: Retinize accepts @4x and @2x resolutions, outputting to @4x, @2x, and @1x.
Overrides may be implemented by manually creating lower resolution copies in the source directory. */
const retinizeOpts = {
// Your options here.
};
console.log('Retinizing images...');
@david-j-davis
david-j-davis / gulpfile.js
Created April 17, 2017 22:36
Create sprite sheets with gulp.spritesmith and GraphicsMagick to create spritesheets for both retina and non-retina devices
var spritesmith = require('gulp.spritesmith'),
gm = require('gm');
gulp.task('sprite', function () {
console.log('Creating sprite(s)...');
var spriteData = gulp.src('./path/to/your/image/sprites/*.png')
.pipe(spritesmith({
// Filter out `-2x` (retina) images to separate spritesheet
// e.g. `github-2x.png`, `twitter-2x.png`
retinaSrcFilter: './path/to/your/image/sprites/*@2x.png',
@david-j-davis
david-j-davis / gulpfile.js
Last active April 17, 2017 22:25
Creates an svg spritesheet from svgs located in a project folder using gulp-svg-sprite module
var svgSprite = require('gulp-svg-sprite');
gulp.task('svg-sprite', function () {
console.log('Creating svg sprite...');
// Basic configuration example
var config = {
mode: {
css: {
dest: '.',
sprite: './img/sprite.svg',