Skip to content

Instantly share code, notes, and snippets.

View hawkeye64's full-sized avatar

Jeff Galbraith hawkeye64

View GitHub Profile
@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 / 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 / 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.
<q-tree
ref="folders"
:nodes="rootDir"
label-key="label"
node-key="nodeKey"
accordion
default-expand-all
:selected.sync="selected"
@lazy-load="lazyLoad"
/>
@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)
},
@hawkeye64
hawkeye64 / gist:841f35b8f1b9de7d81dd0815bf986e56
Created November 18, 2018 19:12
calling getWindowsDrives
if (process.platform === 'win32') {
getWindowsDrives((error, drives) => {
if (!error) {
this.drives = drives
// work through the drives backwards
for (let index = this.drives.length - 1; index >= 0; --index) {
try {
const stat = fs.statSync(this.drives[index] + path.sep)
let fileInfo = {}
fileInfo.rootDir = this.drives[index]
webPreferences: {
webSecurity: true
}
import { app, BrowserWindow, ipcMain } from 'electron'
const nativeImage = require('electron').nativeImage
const path = require('path')
const http = require('http')
const express = require('express')
const expressApp = express()
const cors = require('cors')
const router = express.Router()
let fileFolder
@hawkeye64
hawkeye64 / gist:a141341b6ba422ec0b8d09b881c922e6
Created November 18, 2018 19:17
electron-main end snippet
ipcMain.on('folder', (event, folder) => {
fileFolder = folder
})
expressApp.use(cors())
router.get('/file/:name', function (req, res) {
let filename = fileFolder + path.sep + req.params.name
console.log('Serving file:', filename)
res.sendFile(filename)
@hawkeye64
hawkeye64 / gist:e0dfcc1aeb253ce0c1f918fe9e229874
Created November 18, 2018 19:18
Electron - get image from main process
else if (type === 'image') {
return 'http://localhost:8000/file/' + this.node.label
}