Archive
Sorting connection profiles in the Secure Shell Chrome extension
I have been using the Secure Shell Chrome extension for a while now when I’m in a non-Linux OS for one reason or another. It isn’t very well documented, and it doesn’t have a lot of directly configurable options, but it works fairly well without installing anything other than a Chrome extension, and it allows me to stay in the browser with tabs and all that, so its handy. One of the irritants is that you can’t easily sort the list of saved connections. You can set the order in the javascript console, but the methods I found mentioned on the Internet to do this are multi-step processes, so I wrote a little function that does this for me as needed. I can just paste this function into my javascript console and my connections are sorted for me. I wanted them sorted by the label/description field. Its just as easy to sort them by any other field in the profile.
This is using undocumented features of the extension, which might change at any time. It then calls the set method to save the sorted list back to the settings. You should backup your preferences before doing this, and use it at your own risk. Please don’t blame me if you melt your preferences.
(function(){ var list = nassh_.prefs_.get('profile-ids'); list = list.slice(0); var out = []; var doprofile = function(){ var id = list.pop(); console.log(id); if(id){ var p = nassh_.prefs_.getProfile(id); out.push({k: id, v: p.prefRecords_.description.currentValue}); doprofile(); } else { out.sort(function(a,b){ if (a.v < b.v) return -1; if (a.v > b.v) return 1; return 0; }); for(var i=0;i<out.length;i++){ out[i] = out[i].k; } if(out.length){ nassh_.prefs_.set('profile-ids', out); console.log('done'); } else { console.log('result set empty, please refresh the page and try again.'); } } }; doprofile(); })();
Diff compressed Javascript files
I periodically need to find the differences between two javascript files that have been run through something like uglifyjs. There are a variety of ways to do this, but I haven’t found a solution that really gets me what I am looking for succinctly.
For a while I used git’s diff, but I found this to be cumbersome and not always available.
Then for a while I used wdiff with colordiff. That would look like this:
wdiff /path/file1.js /path/file2.js | colordiff
The problem with that is that the output is often really long because compressed js doesn’t have many line feeds, and wdiff doesn’t recognize non-word characters as word boundaries, and compressed js often doesn’t have whitespace to deliniate word boundaries, so the strength of wdiff is somewhat thwarted.
What I really wanted was to split the files into their smaller pieces for diffing. My latest solution is a bash alias, which looks like this in my .bash_alias file:
alias diffjs='function _diffjs(){ diff -w <(uglifyjs "$1" -b) <(uglifyjs "$2" -b); };_diffjs'
Its not perfect, but in many situations it gets me what I want, assuming of course that uglifyjs is available.