Last active
April 12, 2021 04:10
-
-
Save claus/dd909c81d6057fdd1a690e8f6aa92775 to your computer and use it in GitHub Desktop.
Revisions
-
claus revised this gist
Apr 12, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ In that folder, run: npm init npm i guess-file-type tmp png-js Change OUTGUESS_APP, WORK_DIR, SOURCE and VERBOSE below as you need them. Add your keys to the keys array below. -
claus revised this gist
Apr 12, 2021 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,16 +36,16 @@ const allKeys = keys .flat() .filter((item, i, arr) => arr.indexOf(item) == i); console.log(`Testing ${allKeys.length} keys...`); outguessAll(); async function outguessAll() { for (let i = 0; i < allKeys.length; i++) { await outguess(allKeys[i]); } } function outguess(key) { const promise = new Promise((resolve, reject) => { const out = tmp.fileSync(); -
claus revised this gist
Apr 12, 2021 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,15 +36,15 @@ const allKeys = keys .flat() .filter((item, i, arr) => arr.indexOf(item) == i); async function outguessAll() { for (let i = 0; i < allKeys.length; i++) { await outguess(allKeys[i]); } } console.log(`Testing ${allKeys.length} keys...`); outguessAll(); function outguess(key) { const promise = new Promise((resolve, reject) => { -
claus revised this gist
Apr 12, 2021 . 1 changed file with 13 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,16 +31,20 @@ const keys = [ 'Zurich, Switzerland', ]; const allKeys = keys .map(key => permutations(key)) .flat() .filter((item, i, arr) => arr.indexOf(item) == i); console.log(`Testing ${allKeys.length} keys...`); allKeys.reduce( (acc, key) => acc.then(() => { return outguess(key); }), Promise.resolve() ); function outguess(key) { const promise = new Promise((resolve, reject) => { -
claus revised this gist
Apr 12, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ /* Make sure you have Node.JS and Outguess.app installed. Copy this file as 'outguess.js' into an empty folder. -
claus revised this gist
Apr 12, 2021 . 1 changed file with 46 additions and 40 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,35 +1,34 @@ /* Make sure you have Node.JS installed. Copy this file as 'outguess.js' into an empty folder. In that folder, run: npm init npm i guess-file-type tmp Change OUTGUESS_APP, WORK_DIR, SOURCE and VERBOSE below as you need them. Add your keys to the keys array below. Then run: node outguess Note: guess-file-type might yield false positives */ const { spawn } = require('child_process'); const fileGuesser = require('guess-file-type'); const tmp = require('tmp'); const fs = require('fs'); const OUTGUESS_APP = '/Applications/Outguess.app/Contents/outguess'; const WORK_DIR = '/Users/claus/Downloads/'; const SOURCE = WORK_DIR + 'Syphon-Signal-Registered-VIVIVICIVICIIVIII.jpg'; const VERBOSE = true; const keys = [ 'Gorham, New Hampshire', 'Zurich, Switzerland', ]; keys.map(key => permutations(key)) @@ -47,29 +46,25 @@ function outguess(key) { const promise = new Promise((resolve, reject) => { const out = tmp.fileSync(); const child = spawn(OUTGUESS_APP, ['-k', key, '-r', SOURCE, out.name]); child.on('close', async code => { const mime = await fileGuesser.guessByFileSignature(out.name); if (mime != null && mime !== 'unknown') { const ext = fileGuesser.getExtensionFromMime(mime); const file = `${WORK_DIR}${key}.${ext}`; fs.renameSync(out.name, file); resolve({ key, mime, file }); return; } reject({ key, code }); }); }); return promise .then(result => { console.log(`🎉🎉 ${result.key}: ${result.file} (${result.mime})`); return result; }) .catch(e => { VERBOSE && console.log(`👎 ${e.key}`); return e; }); } @@ -95,11 +90,22 @@ function permutator(inputArr) { } } }; combinations(inputArr).forEach(arr => permute(arr)); return result; } function combinations(arr) { var fn = function (active, rest, a) { if (active.length === 0 && rest.length === 0) { return; } if (rest.length === 0) { a.push(active); } else { fn([...active, rest[0]], rest.slice(1), a); fn(active, rest.slice(1), a); } return a; }; return fn([], arr, []); } -
claus revised this gist
Apr 12, 2021 . 1 changed file with 13 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ const imageType = require('image-type'); const tmp = require('tmp'); const fs = require('fs'); const VERBOSE = true; const OUTGUESS_APP = '/Applications/Outguess.app/Contents/outguess'; const WORK_DIR = '/Users/claus/Downloads/'; const SOURCE = WORK_DIR + 'Syphon-Signal-Registered-VIVIVICIVICIIVIII.jpg'; @@ -28,17 +28,20 @@ const keys = [ 'Mt washington valley', 'Mount washington, gorham', 'Mount washington, new hampshire', 'zurich, switzerland', 'gorham, new hampshire', ]; keys.map(key => permutations(key)) .flat() .filter((item, i, arr) => arr.indexOf(item) == i) .reduce( (acc, key) => acc.then(() => { return outguess(key); }), Promise.resolve() ); function outguess(key) { const promise = new Promise((resolve, reject) => { -
claus revised this gist
Apr 11, 2021 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,7 @@ const imageType = require('image-type'); const tmp = require('tmp'); const fs = require('fs'); const VERBOSE = false; const OUTGUESS_APP = '/Applications/Outguess.app/Contents/outguess'; const WORK_DIR = '/Users/claus/Downloads/'; const SOURCE = WORK_DIR + 'Syphon-Signal-Registered-VIVIVICIVICIIVIII.jpg'; @@ -20,6 +21,13 @@ const keys = [ 'Jura, Mountains', 'La Chaux de Fonds', 'Watch Valley', 'gorham, retro, railroad, museum', 'Cascade, Alpine, Brook', 'Moose, Brook', 'Presidential rail trail', 'Mt washington valley', 'Mount washington, gorham', 'Mount washington, new hampshire', ]; Promise.all( @@ -58,7 +66,7 @@ function outguess(key) { return result; }) .catch(e => { VERBOSE && console.log(` ${e.key}: FAIL`); return e; }); } -
claus revised this gist
Apr 11, 2021 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ // $ npm init // $ npm i read-chunk image-type tmp // $ node outguess const { spawn } = require('child_process'); const readChunk = require('read-chunk'); const imageType = require('image-type'); @@ -86,6 +90,5 @@ function permutator(inputArr) { permute(arr); } } return result; } -
claus created this gist
Apr 11, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,91 @@ const { spawn } = require('child_process'); const readChunk = require('read-chunk'); const imageType = require('image-type'); const tmp = require('tmp'); const fs = require('fs'); const OUTGUESS_APP = '/Applications/Outguess.app/Contents/outguess'; const WORK_DIR = '/Users/claus/Downloads/'; const SOURCE = WORK_DIR + 'Syphon-Signal-Registered-VIVIVICIVICIIVIII.jpg'; const keys = [ 'cyma', 'berlin', 'geneva, switzerland', 'Le Locle, Neuchatel, Switzerland', 'Jura, Mountains', 'La Chaux de Fonds', 'Watch Valley', ]; Promise.all( keys .map(key => permutations(key)) .flat() .filter((item, i, arr) => arr.indexOf(item) == i) .map(key => outguess(key)) ).then(() => { console.log('done.'); }); function outguess(key) { const promise = new Promise((resolve, reject) => { const out = tmp.fileSync(); const child = spawn(OUTGUESS_APP, ['-k', key, '-r', SOURCE, out.name]); child.on('close', code => { const buffer = readChunk.sync(out.name, 0, 12); const type = imageType(buffer); if (type != null && typeof type === 'object') { const file = `${WORK_DIR}${key}.${type.ext}`; fs.renameSync(out.name, file); resolve({ ...type, file, key, }); return; } reject({ key, code }); }); }); return promise .then(result => { console.log(`### ${result.key}: ${result.file}`); return result; }) .catch(e => { console.log(` ${e.key}: FAIL`); return e; }); } function permutations(input) { const rawKeys = input .split(',') .map(rawKey => rawKey.replace(/\s+/g, '').toLowerCase()); const keys = permutator(rawKeys).map(key => key.join('')); return keys; } function permutator(inputArr) { const result = []; const permute = (arr, m = []) => { if (arr.length === 0) { result.push(m); } else { for (let i = 0; i < arr.length; i++) { let curr = arr.slice(); let next = curr.splice(i, 1); permute(curr.slice(), m.concat(next)); } } }; for (let i = inputArr.length; i > 0; i--) { for (let j = 0; j <= inputArr.length - i; j++) { const arr = inputArr.slice(j, j + i); permute(arr); } } console.log(result); return result; }