Top-rated JavaScript recipes http://code.activestate.com/recipes/langs/javascript/top/2017-06-06T03:48:09-07:00ActiveState Code RecipesMacro to Quick find (ctrl+f3) on double click (JavaScript) 2011-07-22T07:46:26-07:00Adamhttp://code.activestate.com/recipes/users/4173315/http://code.activestate.com/recipes/577801-macro-to-quick-find-ctrlf3-on-double-click/ <p style="color: grey"> JavaScript recipe 577801 by <a href="/recipes/users/4173315/">Adam</a> (<a href="/recipes/tags/editor/">editor</a>, <a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/scintilla/">scintilla</a>). Revision 3. </p> <p>This does a search for the selected word when you double click it. Functionality similar to Notepad++. Faster that ctrl-f3.</p> Komodo JS Macro - show svn blame for the current editor line (JavaScript) 2013-05-02T22:28:50-07:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/577013-komodo-js-macro-show-svn-blame-for-the-current-edi/ <p style="color: grey"> JavaScript recipe 577013 by <a href="/recipes/users/2666241/">Todd Whiteman</a> (<a href="/recipes/tags/blame/">blame</a>, <a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/scc/">scc</a>, <a href="/recipes/tags/subversion/">subversion</a>, <a href="/recipes/tags/svn/">svn</a>, <a href="/recipes/tags/toddw/">toddw</a>). Revision 4. </p> <p>A <a href="http://www.activestate.com/komodo">Komodo</a> JavaScript macro that can show the SCC repository information for who last changed the current line in the Komodo editor - see the screenshot below.</p> <p><img src="http://community.activestate.com/files/images/svn_blame.png" alt="svn blame image" /></p> Interactive Mandelbrot Fractal Using HTML5 Canvas (JavaScript) 2017-06-06T03:48:09-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/580804-interactive-mandelbrot-fractal-using-html5-canvas/ <p style="color: grey"> JavaScript recipe 580804 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/canvas/">canvas</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Interactive Mandelbrot Fractal Using HTML5 Canvas.</p> <p>(Download and save as html file and open it.)</p> <p>(Tested only using Firefox browser.)</p> Komodo JS Macro: smart quotes and smart braces (JavaScript) 2013-06-24T13:38:55-07:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/577790-komodo-js-macro-smart-quotes-and-smart-braces/ <p style="color: grey"> JavaScript recipe 577790 by <a href="/recipes/users/2666241/">Todd Whiteman</a> (<a href="/recipes/tags/braces/">braces</a>, <a href="/recipes/tags/brackets/">brackets</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/scintilla/">scintilla</a>, <a href="/recipes/tags/smart/">smart</a>, <a href="/recipes/tags/toddw/">toddw</a>). Revision 5. </p> <p>With this macro, you can make a text/word selection, then press one of ", ', (, [ or { and the matching set of quotes/braces will be added around the selection.</p> <p>Example (where | denotes the selection): This is |myselectedword|. then pressing "{" you'll get: This is {myselectedword}.</p> nicerest: pretty-print JSON output (JavaScript) 2011-01-18T22:59:12-08:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/577549-nicerest-pretty-print-json-output/ <p style="color: grey"> JavaScript recipe 577549 by <a href="/recipes/users/4173505/">Trent Mick</a> (<a href="/recipes/tags/curl/">curl</a>, <a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/node/">node</a>, <a href="/recipes/tags/nodejs/">nodejs</a>, <a href="/recipes/tags/rest/">rest</a>). Revision 3. </p> <p>Save this to "nicerest", <code>chmod +x</code>-it, and pipe your REST API <code>curl</code> calls through this for nicer output. It will notice HTTP headers (curl's <code>-i</code> option) and skips those before attempting to pretty-print the following JSON.</p> <p>Note: This is currently using node 0.2. I should update for 0.3 changes (I think <code>process.openStdin</code> changed).</p> Post code to Pastebin.com (JavaScript) 2010-12-06T17:56:41-08:00Nathan Rambeckhttp://code.activestate.com/recipes/users/4171896/http://code.activestate.com/recipes/577489-post-code-to-pastebincom/ <p style="color: grey"> JavaScript recipe 577489 by <a href="/recipes/users/4171896/">Nathan Rambeck</a> (<a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/pastebin/">pastebin</a>). </p> <p>This is an updated version of another recipe (#577170) to post selected text to <a href="http://pastebin.com" rel="nofollow">pastebin.com</a>. This version uses the latest API. You'll want to change the following variables to your preferences: email, nick, expiry.</p> Komodo JS Macro - use vertical editor tabs positioned to the right (JavaScript) 2010-09-10T02:53:33-07:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/577386-komodo-js-macro-use-vertical-editor-tabs-positione/ <p style="color: grey"> JavaScript recipe 577386 by <a href="/recipes/users/2666241/">Todd Whiteman</a> (<a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/layout/">layout</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/tab/">tab</a>). </p> <p>A <a href="http://www.activestate.com/komodo-ide">Komodo</a> JavaScript macro that can be used to position the editor tabs on the right side and shown vertically.</p> <p>Additional layouts (left, right, up, down, vertical, horizontal) can be made with different combinations, see here for the Mozilla tabbox positioning documentation: <a href="https://developer.mozilla.org/en/XUL_Tutorial/Tabboxes#Position_of_the_tabs" rel="nofollow">https://developer.mozilla.org/en/XUL_Tutorial/Tabboxes#Position_of_the_tabs</a></p> Komodo JS Macro - insert a relative path from the current editor file (JavaScript) 2012-02-24T00:23:09-08:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/577306-komodo-js-macro-insert-a-relative-path-from-the-cu/ <p style="color: grey"> JavaScript recipe 577306 by <a href="/recipes/users/2666241/">Todd Whiteman</a> (<a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/relative/">relative</a>). Revision 3. </p> <p>A <a href="http://www.activestate.com/komodo">Komodo</a> JavaScript macro that can be used to generate a relative path from the current editor file location, which works great for HTML when linking to relative style sheets, images, etc...</p> <p>Upon execution of this macro, you will be prompted to browse and select the target file, then upon selecting the target path, the relative path location will be inserted into the editor at the current position.</p> <p>To best use this macro - assign a custom key-binding to the macro and then trigger the macro at will.</p> Sierpinski Triangle Fractal using HTML5 Canvas (JavaScript) 2010-07-07T15:07:30-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577294-sierpinski-triangle-fractal-using-html5-canvas/ <p style="color: grey"> JavaScript recipe 577294 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Sierpinski Triangle Fractal using Line Automaton (1D CA). The 1D CA rule used is actually Pascal's Triangle Mod 2. Tested only using Firefox 3.5.</p> Komodo Macro - Copy to clipboard code selection in HTML format (JavaScript) 2010-04-14T07:17:59-07:00Davide Ficanohttp://code.activestate.com/recipes/users/4166571/http://code.activestate.com/recipes/577193-komodo-macro-copy-to-clipboard-code-selection-in-h/ <p style="color: grey"> JavaScript recipe 577193 by <a href="/recipes/users/4166571/">Davide Ficano</a> (<a href="/recipes/tags/clipboard/">clipboard</a>, <a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>). </p> <p>This macro makes easy to paste on documents (MS Office, Open Office, iWorks Pages) code snippets with syntax highlight and/or line numbers.</p> <p>This macro copies the selected code text or whole document if no selection is present on clipboard in HTML format.</p> <p>On OSX you need at least Komodo 6 because previous versions don't support data flavors</p> Komodo JS Macro - Submit text selection to pastebin.mozilla.com service (JavaScript) 2010-03-31T06:34:21-07:00Davide Ficanohttp://code.activestate.com/recipes/users/4166571/http://code.activestate.com/recipes/577170-komodo-js-macro-submit-text-selection-to-pastebinm/ <p style="color: grey"> JavaScript recipe 577170 by <a href="/recipes/users/4166571/">Davide Ficano</a> (<a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/pastebin/">pastebin</a>). </p> <p>Submit the select text to pastebin and copy to clipboard the URL returned from service.</p> <p>The programming language is auto-detected.</p> <p>The statusbar will show the message about submission status.</p> <p><strong>Setting username</strong></p> <p>By default the post is submitted with 'anonymous' user, to change it set the <strong>nick</strong> variable to a different value </p> Komodo JS Macro - increase the number of code completion items shown (JavaScript) 2012-03-15T23:20:25-07:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/577163-komodo-js-macro-increase-the-number-of-code-comple/ <p style="color: grey"> JavaScript recipe 577163 by <a href="/recipes/users/2666241/">Todd Whiteman</a> (<a href="/recipes/tags/codeintel/">codeintel</a>, <a href="/recipes/tags/completions/">completions</a>, <a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/toddw/">toddw</a>). Revision 2. </p> <p>A <a href="http://www.activestate.com/komodo">Komodo</a> JavaScript macro that can be used to set the number of code completion items shown in the list.</p> <p>If you set the macro to Trigger on the Komodo "After file open" event - then this setting will be always be applied to every file code completion list.</p> A Komodo macro for duplicating the current file (Komodo 5 only!) (JavaScript) 2011-02-03T23:45:02-08:00Eric Promislowhttp://code.activestate.com/recipes/users/4166930/http://code.activestate.com/recipes/577085-a-komodo-macro-for-duplicating-the-current-file-ko/ <p style="color: grey"> JavaScript recipe 577085 by <a href="/recipes/users/4166930/">Eric Promislow</a> (<a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/komodo/">komodo</a>). </p> <p>Komodo projects look like file managers, but don't always offer the same functionality directly. Here's a macro that makes a copy of the current selected file in a project. To use it, create a new macro in the Komodo toolbox, copy this code, paste it in the macro, and save it. Then you can select a file, double-click the macro icon (or assign it to a keybinding), and Komodo will create a copy of the file called "Copy of &lt;basename&gt;.&lt;extension&gt;".</p> The Matrix Effect (JavaScript) 2009-07-28T10:13:20-07:00Panda Moniomhttp://code.activestate.com/recipes/users/4171270/http://code.activestate.com/recipes/576861-the-matrix-effect/ <p style="color: grey"> JavaScript recipe 576861 by <a href="/recipes/users/4171270/">Panda Moniom</a> (<a href="/recipes/tags/dynamic_drive/">dynamic_drive</a>, <a href="/recipes/tags/effect/">effect</a>, <a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/matrix/">matrix</a>, <a href="/recipes/tags/text/">text</a>). </p> <p>This code is and opensource code from Dynamic Drive.</p> <p>Add the Matrix effect to any text. I have displayed the code for and entire demo page. Any text that you want to have the Matrix effect, put it inside &lt;div id="matrix&gt; and &lt;/div&gt;.</p> Reversing string (JavaScript) 2013-02-18T09:27:33-08:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578464-reversing-string/ <p style="color: grey"> JavaScript recipe 578464 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/reverse/">reverse</a>, <a href="/recipes/tags/string/">string</a>). </p> <p>Two ways reverse string.</p> Komodo JS Macro: move tabs (JavaScript) 2012-04-10T17:39:47-07:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/578093-komodo-js-macro-move-tabs/ <p style="color: grey"> JavaScript recipe 578093 by <a href="/recipes/users/2666241/">Todd Whiteman</a> (<a href="/recipes/tags/editor/">editor</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/position/">position</a>, <a href="/recipes/tags/tabs/">tabs</a>, <a href="/recipes/tags/toddw/">toddw</a>). </p> <p>This Komodo macro is an example to show how to programmatically re-position a Komodo editor tab. This macro moves the currently selected tab to the start of the tab list.</p> Komodo JS Macro: colorize the output console with a different color scheme (JavaScript) 2011-06-24T17:52:48-07:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/577770-komodo-js-macro-colorize-the-output-console-with-a/ <p style="color: grey"> JavaScript recipe 577770 by <a href="/recipes/users/2666241/">Todd Whiteman</a> (<a href="/recipes/tags/color/">color</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/scintilla/">scintilla</a>, <a href="/recipes/tags/toddw/">toddw</a>). </p> <p>It's possible to colorize any Scintilla based widget (the editor part) in Komodo using a color scheme. In Komodo there is the "Fonts and Color" preferences that get applied to all scintilla widgets, but you can manually change individual scintilla widgets as you wish.</p> <p>This macro changes the color scheme of the Command Output tab to use the "Dark" scheme.</p> Komodo JavaScript Macro - wrap the current word under the cursor (JavaScript) 2011-02-02T23:28:37-08:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/577561-komodo-javascript-macro-wrap-the-current-word-unde/ <p style="color: grey"> JavaScript recipe 577561 by <a href="/recipes/users/2666241/">Todd Whiteman</a> (<a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/toddw/">toddw</a>, <a href="/recipes/tags/wrap/">wrap</a>). </p> <p>A <a href="http://www.activestate.com/komodo">Komodo</a> JavaScript macro that can be used to wrap the current word under the cursor position (or current selection) with arbitrary text.</p> <p>For example, if I'm editing a HTML file and have the selected text "This is my heading", I can quickly use this macro to wrap this text into "&lt;h1&gt;This is my heading&lt;/h1&gt;".</p> A Template for Crash-Resistant Toggle-Macros (JavaScript) 2010-10-07T00:51:42-07:00Eric Promislowhttp://code.activestate.com/recipes/users/4166930/http://code.activestate.com/recipes/577418-a-template-for-crash-resistant-toggle-macros/ <p style="color: grey"> JavaScript recipe 577418 by <a href="/recipes/users/4166930/">Eric Promislow</a> (<a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/snippet/">snippet</a>, <a href="/recipes/tags/template/">template</a>). </p> <p>If you've followed my postings here lately (<a href="http://code.activestate.com/recipes/users/4166930/" rel="nofollow">http://code.activestate.com/recipes/users/4166930/</a>), you'll see that I've been playing with what I call "toggle macros", macros that toggle a state on and off, with different behaviors for each state. Unfortunately I found that it was easy to get Komodo to crash on shutdown. Meanwhile I wanted to build a framework to make it easier to build these.</p> <p>This recipe accomplishes both. It looks like putting a listener on a view object can trigger this crash, but so can storing a method on a view object, even with a unique name. So while I wanted to use the "view.view_closing" event, I can't, and I notice no other core Komodo code is. The template instead uses a global hash, ko.extensions.togglers, to store the code objects. And now I'm not getting a crash.</p> node.js quicklog method to log to a file (JavaScript) 2010-08-11T05:08:57-07:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/577351-nodejs-quicklog-method-to-log-to-a-file/ <p style="color: grey"> JavaScript recipe 577351 by <a href="/recipes/users/4173505/">Trent Mick</a> (<a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/nodejs/">nodejs</a>). </p> <p>I tend to have a "quicklog" method for a few of the languages I'm working in to do logging when stdout/stderr isn't necessarily available (GUI app) or convenient (lots of other output on stdout, etc.). My usage with <a href="http://nodejs.org">nodejs</a> was while working on the node REPL. Log output to stdout interfered with the REPL.</p>