Skip to content

Instantly share code, notes, and snippets.

View hawkeye64's full-sized avatar

Jeff Galbraith hawkeye64

View GitHub Profile
@hawkeye64
hawkeye64 / gist:09e5e19afe9ec71ec1ee96f5d05651bd
Last active November 19, 2018 14:39
'expand-tree' message on Vue global event bus
created: function () {
this.$root.$on('expand-tree', this.expandTree)
},
beforeDestroy: function () {
this.$root.$off('expand-tree', this.expandTree)
},
<q-tree
ref="folders"
:nodes="rootDir"
label-key="label"
node-key="nodeKey"
accordion
default-expand-all
:selected.sync="selected"
@lazy-load="lazyLoad"
/>
@hawkeye64
hawkeye64 / expandTree.vue
Created November 18, 2018 19:04
expand QTree method
expandTree: function (absolutePath) {
// get parts for the path
let parts = absolutePath.split(path.sep)
let path2 = ''
let lastNodeKey
// iterate through the path parts.
// This code will get the node. If the node is not found,
// it forces lazy-load by programmatically expanding
// the parent node.
@hawkeye64
hawkeye64 / getWindowsDrives.js
Last active February 23, 2019 14:00
A function that returns in a callback (error, results) an array of Windows drives in use ['C:', 'D:'] etc
const exec = require('child_process').exec
const fs = require('fs')
const path = require('path')
function getWindowsDrives (callback) {
if (!callback) {
throw new Error('getWindowsDrives called with no callback')
}
if (process.platform !== 'win32') {
throw new Error('getWindowsDrives called but process.plaform !== \'win32\'')
@hawkeye64
hawkeye64 / walkFolders.js
Created November 18, 2018 15:08
Generator function that lists all files in a folder recursively in a synchronous fashion
const path = require('path')
const fs = require('fs')
/**
* Generator function that lists all files in a folder recursively
* in a synchronous fashion
*
* @param {String} folder - folder to start with
* @param {Number} recurseLevel - number of times to recurse folders
* @returns {IterableIterator<String>}
@hawkeye64
hawkeye64 / gist:8bd5c1a7eba8fb4d58b6df223ee115ea
Created September 5, 2018 14:31
Linux command to run "classify" on images (with Color in name and extension .jpg)
find . -type f -name "*Color*.jpg" -exec classify --image "{}" --confidence 30 \;
@hawkeye64
hawkeye64 / update_image_example.js
Created August 27, 2018 19:18
Update Image Example
/**
* Generate a random color
*/
const getRandomColor = () => new cv.Vec(Math.random() * 255, Math.random() * 255, Math.random() * 255);
/**
* Returns a function that, for each prediction, draws a rect area with rndom color
* @param {Arry} predictions Array of predictions
*/
const makeDrawClassDetections = (predictions) => (drawImg, getColor, thickness = 2) => {
@hawkeye64
hawkeye64 / extract_results_example.js
Created August 27, 2018 19:10
Extract Results Example
/**
* Extracts results from a network OutputBob
* @param {Object} outputBlob The outputBlob returned from net.forward()
* @param {Object} img The image used for classification
*/
const extractResultsCoco = (outputBlob, img) => {
return Array(outputBlob.rows).fill(0)
.map((res, i) => {
// get class index
const classIndex = outputBlob.at(i, 1);
@hawkeye64
hawkeye64 / predict_function.js
Last active August 27, 2018 21:46
The "predict" function
/**
* Predicts classifications based on passed in image
* @param {Object} img The image to use for predictions
*/
const predict = (img) => {
// white is the better padding color
const white = new cv.Vec(255, 255, 255)
// resize to model size
const theImage = img.resizeToMax(modelData.size, modelData.size).padToSquare(white)
@hawkeye64
hawkeye64 / opencv4nodejs_example.js
Created August 27, 2018 18:57
opencv4nodejs Example
// OpenCV
const cv = require('opencv4nodejs')
// initialize model from prototxt and modelFile
let net
if (dataFile === 'coco300' || dataFile === 'coco512') {
net = cv.readNetFromCaffe(prototxt, modelFile)
}
// read the image