All posts by JamesIsIn

Bookmarklets

Err… what’s a Bookmarklet?

A bookmarklet is a bit of JavaScript disguised as a bookmark that, when run, can perform a specific bit of work via your browser.  These below are generally built to satisfy some search need, to make these searches easier, more seamless, and less annoying.  Try one; try them all!

I have tested these and they all work as-is in the latest (2023-01-19) versions of Opera, Chrome, and Firefox.

If you run into trouble, try updating your browser or disabling all extensions before altering the JavaScript.

(If clicking the bookmarklet dialog does not spawn a new tab with your target, I have seen Firefox act a fool and need changed to %27.  But probably check your updates and extensions.)

HowTo:  Install and Use a Bookmarklet

The short version:

  • Triple-click the line of JavaScript code to highlight it.
  • Drag and drop that line of code to your browser’s Bookmarks Bar to create a bookmark.
    • If drag-and-drop doesn’t work, created any bookmark and edit to substitute the js as the destination and name it accordingly.
  • Right-click that newly created bookmark to edit the name.
    • Suggested names are provided above each JS line.  I like to keep the names short so more fit on the bar.
  • Rinse and repeat for all you’d like below.  Or create your own.

Usage

Once you have a bookmarklet installed, there are two ways to use it.  You can either highlight any text on the page and click the bookmarklet, or (if no text is highlighted on the page) a search dialog appears when the bookmarklet is clicked.

Of note, iframe contents cannot be seen, only the wrapping page.  In these circumstances a dialog will always spawn.

These are all built to open a new tab, which should open next to (to the right of) your current working tab.

These can be leveraged for many searches one does throughout the day, thus greatly increasing the efficiency of said searches.  I’ve been building and using them since 1999 and will continue to do so.

Bookmarklets

GitHub

// 
// GitHub https://github.com/search?q=searchthis 
// gitH 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Search GitHub for… ").replace(/\s\+/g,"%252B");if(q!=null)window.open("https://github.com/search?q="+q);void(0); 
// 

Amazon

// 
// Amazon https://www.amazon.com/s?k=searchthis&crid=2SHRP43MFNSJ8&sprefix=searchthis%2Caps%2C386&ref=nb_sb_noss 
// Amazon+s 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Search Amazon for… ").replace(/\s\+/g,"%252B");if(q!=null)window.open("https://www.amazon.com/s?k="+q);void(0); 
// 

LinkedIn

// 
// LinkedIn https://www.linkedin.com/search/results/all/?keywords=searchthis&origin=GLOBAL_SEARCH_HEADER&sid=cVD  
// LI+s 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Search Amazon for… ").replace(/\s\+/g,"%252B");if(q!=null)window.open("https://www.linkedin.com/search/results/all/?keywords="+q);void(0); 
// 

Confluence

Adjust URL for your instance.

// 
// Confluence 
// https://esentire.atlassian.net/wiki/search?text=narf 
// C+s 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Confluence [try words]…").replace(/\s\+/g,"%252B");if(q!=null)window.open('https://esentire.atlassian.net/wiki/search?text='+q);void(0); 
// 

SolarWinds

Adjust URL for your instance.

// 
// SolarWinds https://YOURINSTANCE/ui/search?q=%s 
// SW+s 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("SolarWinds [try a sensor number]…").replace(/\s\+/g,"%252B");if(q!=null)window.open('https://YOURINSTANCE/ui/search?q='+q);void(0); 
// 

ServiceNow

Adjust URL for your instance.

// 
// ServiceNow ticket search https://YOURINSTANCE.service-now.com/nav_to.do?uri=%2F$sn_global_search_results.do%3Fsysparm_search%3D%s 
// SN+s 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Service-Now [try a sensor number]…").replace(/\s\+/g,"%252B");if(q!=null)window.open('https://YOURINSTANCE.service-now.com/nav_to.do?uri=%2F$sn_global_search_results.do%3Fsysparm_search%3D'+q);void(0); 

// ServiceNow direct ticket search (no iframe) 
// this takes you to a ticket directly if search results are unique 
// SN+cs 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("ServiceNow Case Number: ").replace(/\s\+/g,"%252B");if(q!=null)window.open('https://YOURINSTANCE.service-now.com/text_search_exact_match.do?sysparm_search='+q);void(0); 

// ServiceNow knowledge base article search 
// SN+KB 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Search for a KB").replace(/\s\+/g,"%252B");if(q!=null)window.open('https://esentire.service-now.com/selfservice?id=search&spa=1&q='+q);void(0); 
// 

Under the Hood

As you will note from the JavaScript, each of these bookmarklets performs a variable substitution (here named q) into the URL sent back to the server performing the search.  As such, one would perform any URL substitution.

For example, at one job I was able to create several bookmarklets for accessing various config pages on devices by substituting the device names.

// 
// so if you begin with a URL like  
// https://devicename.company.internal:5555/path/to/configX 
// you can massage that into a bookmarklet something like  
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Config X for device…").replace(/\s\+/g,"%252B");if(q!=null)window.open("https://"+q+".company.internal:8834/path/to/configX");void(0); 
// 

The possibilities are pretty limitless.

Share

Quickly Make Directories Based on Files in Location

I needed to make a bunch of folders for a slew of singles I’d downloaded.  I wanted each single to have its own folder but when you download singles they tend to offer just the flac file and no containing folder.  Reasonable, I suppose.

Anyway, I wrote this to create the folders.

##
for f in ./* ; do ff=$( printf '%s\n' "${f//.\//}" ) ; mkdir "${ff//.flac/}" ; done 
##

Good enough.  I could have added something to move each file (“${f}”) into the newly created folder (./”${ff}”) but didn’t think of that until I was done.  Probably an addition like this (untested):

##
for f in ./* ; do ff=$( printf '%s\n' "${f//.\//}" ) ; mkdir "${ff//.flac/}" ; mv "${f}" "./${ff}/${f}" ; done 
##

Enjoy! Maybe I’ll get around to testing the move version at some point.

Share

Sorting Lines in VSCode

Stay tuned for a more elegant version…

copy some lines then

This comes up at the top of searches still so I’ll add this latest solution. If you are running a current VS Code (and why wouldn’t you?) you can use the built-in sorter by hitting ctrl-shift-p (Mac is cmd-shift-p) and type “sort” in the subsequent search box. There are many options.

https://stackoverflow.com/questions/3350793/sort-selected-text-from-visual-studio-context-menu

Share

High Bitrate ISO Music to FLAC

Here is the process I used to convert some DVD-audio ISO files into proper FLAC files for inclusion in my main collection.  No compromise in channels nor in audio quality required.

These instructions are for Ubuntu but will likely work on most Linux distributions (since ffmpeg and flac are so common).  Mac?  Maybe.  Win10 with bash?  Probably.

The basics are as follows:

  • mount the ISO
  • use ffmpeg to extract audio data into wav files
  • stitch multiple wav files together using Audacity
  • split that full-album wav into individual songs
  • convert those wav songs into FLAC files
  • tag and move into the main collection

Often mounting an ISO is a matter of right-clicking and choosing Mount; regardless I leave it up to you to make that happen in whatever manner you choose.  All that matters is that we can access the files through a specific file path.

You will need to fun ffmpeg against each audio file from the mounted ISO in order to get a complete collection of wav files to conjoin.  My most recent ISO had two and this command is for the second extraction:

##
ffmpeg -i ~/Desktop/ISO/AUDIO_TS/ATS_01_2.AOB ~/Desktop/RW/02_end.wav 
# run this line for each file containing audio and with a unique file name (in order) 
##

Now open all your files in Audacity (or whatever you’d like) and past each track against the end of the previous track until you have one project containing the entire audio content.  Export that as a single wav file.

Audacity will default to exporting as a two-channel 16×44 wav file.   You can change the bitrate in the lower-left of the project window.  For multi-channel exports, you’ll need to navigate to Edit –> Preferences –> Import/Export –> When exporting tracks to an audio file –> Use custom mix (radio button).  Now you are set to wave the full wave file.

Next you get to struggle with dividing the full file into individual songs.  This can be made all the more challenging if your album is progressive rock.  Who needs gaps between so-called songs?  Anyway, I can not offer much advice though there is this handy page from Audacity that could help.

You can do it!

Converting into FLAC is really easy.  It’s probably the easiest step in the whole process.  (Splitting into individual songs is probably the least easy if you’re keeping track.)

##
# cd into the folder where your newly created wav files are located and run flac itself 
flac --best --channel-map=none -V *.wav 
# you only need --channel-map=none if your full-length file has more than two tracks  
##

Once that has finished, you can tag your music.  I use EasyTag because it’s easy.

Share

Password Chaos

Creating a memorable password runs against most of the rules implemented for creating a strong password.  Much fine work has been done parodying this interesting fact.  That being said, the folks who implement the rules and subsequently announce those rules to the users have lost their minds.  Take a look at this description of the required rules I happened upon recently.

Required Overlap
Required Overlap

Let’s pair some of these.

Length:

Between 8 and 64 characters

Increase the length from 12-20 characters

Case:

Use both uppercase and lowercase letters.

A lowercase or uppercase letter

Repetition:

Not repeat any character more than 3 times in a row.

Not be a sequence of 4 characters in a row.

In each of the above pairs, the first line is all that is required to articulate the apparent rule.  The second line can be dropped as superfluous (and confusing).

In the length pair, the “increase” line is essentially unparsable.  This is to say I can formulate no meaning for that line which aligns that line with the other lines in a logically consistent fashion.  If the minimum is 8 then there would never be a reason to increase by 12.  If you are 20 away from 64 (the maximum) there is no reason to increase the length.

In the case pair, the and and the or cannot be conjoined.  If you must use both (and) then you cannot use one or the other (or).

In the repetition pair, if you cannot have three in a row you necessarily can’t have four in a row.  Further, if the minimum is 8 it must be longer than 4 regardless.

Then there is the order of the list.  Makes me wonder if that order could have been arrayed in a way that would be more confusing.  Could it?

Never mind that five lines are sentences (ending in periods) and the other three lines are not (unpunctuated).

It’s like they took a poll of the IT staff and just listed out selections from their various responses.

Just… think it through a bit.  UI/UX isn’t something that requires a specialized developer.  Think.

2024 Update

I came across this lovely gem of password instructions and wanted to share it as well.

Password Policy
Password Policy

Why limit a password to 18 characters?  That’s just plain silly.  It’s not even a power of two.  “Hey, let’s arbitrarily limit passwords!”.  Idiots.

Why restrict spaces?  Again, arbitrary and silly.

Both of these rules limit passwords making them less secure rather than more.  Stop it.  Just don’t.  Fix your shit.

Share

Renaming in Python

I needed to rename several files.  I thought perhaps using a script would make it a little faster.  Well, the renaming went faster.  Writing the script of course took much longer.  But I suppose I learned something.

The image files were individual pages from a book of about 64 pages.  They were named one number off from their actual page numbers.  You can imagine how annoying that can be.  You can’t?  Well, try harder.  It’s pretty annoying when 3 isn’t three but 4.  Three isn’t four!

That doesn’t irritate you?  Well, I wrote a script to fix it nonetheless.

You can find the script over at my GitHub.

It’s modifiable enough so perhaps it can suit your needs.  Feedback is always welcome.

Share

Useful bash Line for Debugging

I’ve started using this little code snippet to help debug problems within a bash script. It just shouts out the line where it appears when called. This is useful when you are trying to determine where a problem is located within the various twists and turns of the function calls within a script.

##
# Here is a print statement useful in debugging:  
printf '%s\n' "" "${LINENO}" "" 
# Pepper a script with those to see where your having trouble line-by-line! 
##

Have fun with that!

Share

A Couple Recent Conversions for Audio and Video

I’ve had to make a couple of unusual conversion of late and wanted to make note of the solutions for my future self.  Hey, future self, git with it!

First, converting dsf (and I think also dff) files into flac files I just used ffmpeg as follows:

## 
# first cd into the directory containing the dsf files in question, then… 
ffmpeg -i 15-Penny\ Lane.dsf 15-Penny\ Lane.flac 
##

Then I also needed to convert an ISO into some constituent mkv files. For this I used makemkv.

## 
# first you'll need to install it from the Snap repositories.  
snap install makemkv 
# then open the graphical application and point it at your ISO.
##

Both pretty handy, easy, and fool-proof. I’m the fool. I’m the proof. Good hunting.

Share