Click here to Skip to main content
15,886,110 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Both Weird & Wonderful - a W10 Surprise Pin
Saša Ćetković21-Aug-20 1:46
professionalSaša Ćetković21-Aug-20 1:46 
GeneralRe: Both Weird & Wonderful - a W10 Surprise Pin
Adar Wesley21-Aug-20 4:19
Adar Wesley21-Aug-20 4:19 
GeneralRe: Both Weird & Wonderful - a W10 Surprise Pin
F Margueirat21-Aug-20 4:16
F Margueirat21-Aug-20 4:16 
GeneralRe: Both Weird & Wonderful - a W10 Surprise Pin
Rick York21-Aug-20 5:07
mveRick York21-Aug-20 5:07 
GeneralRe: Both Weird & Wonderful - a W10 Surprise Pin
TnTinMn21-Aug-20 7:22
TnTinMn21-Aug-20 7:22 
GeneralRe: Both Weird & Wonderful - a W10 Surprise Pin
Rick York21-Aug-20 9:16
mveRick York21-Aug-20 9:16 
GeneralRe: Both Weird & Wonderful - a W10 Surprise Pin
patbob21-Aug-20 14:19
patbob21-Aug-20 14:19 
GeneralGoogle Docs and inline images (CP related) Pin
raddevus12-Aug-20 10:34
mvaraddevus12-Aug-20 10:34 
I write docs and grab screenshots and paste them into Google Docs.

Sometimes those documents end up being articles I post to CodeProject.

Images
However, CP wants the images to be uploaded to CP servers as separate image files.

Google Doc HTML Creator (Save as...)
You can download the document as a zipped HTML and Google Docs will pull out every image from your document and save them in a \images directory. That's very cool.

That's very nice because now you have all of the images saved as PNGs and you didn't have to do any work.

The Problem With The Images
The problem is that the images are all out of order.
They're named like: imageXXX.png in consecutive order (image1.png, image2.png).

Not Same Order As Your Document
However, the order that they are numbered in is not the order they appear in your Google Docs document. I have no idea why that would be true. What is wrong with some devs' minds? Laugh | :laugh:

Finally, i haz teh Codz!!
Here are the steps.
1. Download your Google Doc as a zip html
2. unzip it to a local directory
3. Open in your favorite browser (It's FireFox, right? Mine too.)
4. Hit F12 to open dev tools / console.
5. Run the following script**:
JavaScript
document.querySelectorAll("img").forEach((s, counter=1) => (console.log("mv " + s.src.substring(s.src.lastIndexOf("/")+1,s.src.length) + " 0"+counter++ + ".png")))

This will generate output on your console that looks like the following:*
mv image38.png 00.png
mv image3.png 01.png
mv image36.png 02.png
mv image28.png 03.png
mv image9.png 04.png
mv image29.png 05.png
mv image11.png 06.png
mv image37.png 07.png
etc...

6. Copy all of those lines, go to your images folder and run it.
Now all of your images are renamed in order that they appear in the Document.
This will make it far easier when you copy your Google document to CP and upload the images.
You can insert them back into your document in order. It's much easier.

* If you are on a Windows machine (sorry for you Cool | :cool: ) then simply use the following script (changes mv to ren).
Windows Version
JavaScript
document.querySelectorAll("img").forEach((s, counter=1) => (console.log("ren " + s.src.substring(s.src.lastIndexOf("/")+1,s.src.length) + " 0"+counter++ + ".png")))

** Yes, you can make the script even better by cleaning up some things, but this gets you there and is good enough for what I need.
Generalinvert if : visual studio code helper Pin
raddevus4-Aug-20 5:15
mvaraddevus4-Aug-20 5:15 
GeneralRe: invert if : visual studio code helper Pin
honey the codewitch4-Aug-20 5:41
mvahoney the codewitch4-Aug-20 5:41 
GeneralRe: invert if : visual studio code helper Pin
raddevus4-Aug-20 6:02
mvaraddevus4-Aug-20 6:02 
GeneralRe: invert if : visual studio code helper Pin
Mircea Neacsu4-Aug-20 8:23
Mircea Neacsu4-Aug-20 8:23 
GeneralRe: invert if : visual studio code helper Pin
Nelek4-Aug-20 19:42
protectorNelek4-Aug-20 19:42 
GeneralRe: invert if : visual studio code helper Pin
SteakhouseLuke5-Aug-20 4:44
SteakhouseLuke5-Aug-20 4:44 
GeneralRe: invert if : visual studio code helper Pin
Nelek5-Aug-20 6:55
protectorNelek5-Aug-20 6:55 
GeneralRe: invert if : visual studio code helper Pin
englebart23-Aug-20 8:01
professionalenglebart23-Aug-20 8:01 
GeneralRe: invert if : visual studio code helper Pin
Mircea Neacsu23-Aug-20 9:03
Mircea Neacsu23-Aug-20 9:03 
GeneralRe: invert if : visual studio code helper Pin
Maximilien4-Aug-20 5:52
Maximilien4-Aug-20 5:52 
GeneralRe: invert if : visual studio code helper Pin
raddevus4-Aug-20 6:04
mvaraddevus4-Aug-20 6:04 
GeneralRe: invert if : visual studio code helper Pin
Nelek4-Aug-20 8:18
protectorNelek4-Aug-20 8:18 
GeneralRe: invert if : visual studio code helper Pin
raddevus4-Aug-20 8:39
mvaraddevus4-Aug-20 8:39 
GeneralRe: invert if : visual studio code helper Pin
Jon McKee4-Aug-20 10:44
professionalJon McKee4-Aug-20 10:44 
GeneralRe: invert if : visual studio code helper Pin
raddevus4-Aug-20 11:40
mvaraddevus4-Aug-20 11:40 
GeneralRe: invert if : visual studio code helper Pin
Jon McKee4-Aug-20 12:11
professionalJon McKee4-Aug-20 12:11 
GeneralRe: invert if : visual studio code helper Pin
raddevus4-Aug-20 16:43
mvaraddevus4-Aug-20 16:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.