Top-rated Tcl recipes http://code.activestate.com/recipes/langs/tcl/top/2017-04-10T13:51:58-07:00ActiveState Code RecipesInserts thousand separators into a number (Tcl)
2002-08-22T15:58:31-07:00andreas kuprieshttp://code.activestate.com/recipes/users/117230/http://code.activestate.com/recipes/146220-inserts-thousand-separators-into-a-number/
<p style="color: grey">
Tcl
recipe 146220
by <a href="/recipes/users/117230/">andreas kupries</a>
(<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>).
</p>
<p>This piece of code inserts a thousandth separator into a decimal number, i.e. every 3 digits the separator character is inserted. courtesy Jeff Hobbs's bag of utilities.</p>
Repeat procedure every X seconds (Tcl)
2001-09-10T15:20:39-07:00Jeff Hobbshttp://code.activestate.com/recipes/users/98167/http://code.activestate.com/recipes/68393-repeat-procedure-every-x-seconds/
<p style="color: grey">
Tcl
recipe 68393
by <a href="/recipes/users/98167/">Jeff Hobbs</a>
(<a href="/recipes/tags/debugging/">debugging</a>).
</p>
<p>This is a cheap rescheduler that uses the built-in after command to repeat a command every X milliseconds. It has cancel and info commands similar to the after command.</p>
iTunes control (Tcl)
2010-03-30T04:06:56-07:00Frank Bannonhttp://code.activestate.com/recipes/users/4167503/http://code.activestate.com/recipes/577165-itunes-control/
<p style="color: grey">
Tcl
recipe 577165
by <a href="/recipes/users/4167503/">Frank Bannon</a>
(<a href="/recipes/tags/itunes/">itunes</a>, <a href="/recipes/tags/tcom/">tcom</a>).
</p>
<p>Simple TCL commands can control your iTunes player, add network control, or create an alternate interface. This recipe uses the tcom package on Windows.</p>
diff_copy.tcl Utility for daily differential backups of large windows directory structures (Tcl)
2017-04-10T13:51:58-07:00John Brearleyhttp://code.activestate.com/recipes/users/4184423/http://code.activestate.com/recipes/580779-diff_copytcl-utility-for-daily-differential-backup/
<p style="color: grey">
Tcl
recipe 580779
by <a href="/recipes/users/4184423/">John Brearley</a>
(<a href="/recipes/tags/backup/">backup</a>, <a href="/recipes/tags/daily/">daily</a>, <a href="/recipes/tags/tcl/">tcl</a>).
</p>
<p>When you have terrabytes of data with 100,000+ files, it is no longer practical to blindly copy the entire data structure on a daily basis. I wrote this utility diff_copy.tcl to sort out what has been changed/updated and what new files have been added and only copy the changed & new items. If the date/time of the source file is newer, the file will be copied. If the date/time of the source file is the same as the destination, the file sizes in bytes are checked to decide if a copy is necessary. If the source file is not present on the destination directory, the file is copied. There are options to remove old files from the destination directory or show what would be copied, but not actually do the copy.</p>
Recursive fc/diff for Windows, optionally copy missing/different files (Tcl)
2017-04-08T16:40:25-07:00John Brearleyhttp://code.activestate.com/recipes/users/4184423/http://code.activestate.com/recipes/580776-recursive-fcdiff-for-windows-optionally-copy-missi/
<p style="color: grey">
Tcl
recipe 580776
by <a href="/recipes/users/4184423/">John Brearley</a>
(<a href="/recipes/tags/compare/">compare</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/tcl/">tcl</a>).
</p>
<p>Utility to add recursive capability to fc.exe on Windows. Will optionally copy/update missing or older files as needed. If you have a diff.exe in your path, say from having installed TkDiff utility, the diff.exe will be used as the prirmary compare tool, with fc.exe as the backup tool.</p>
Pronouncable password generator (Tcl)
2008-02-03T15:35:46-08:00Rob Haeuslerhttp://code.activestate.com/recipes/users/4119868/http://code.activestate.com/recipes/544293-pronouncable-password-generator/
<p style="color: grey">
Tcl
recipe 544293
by <a href="/recipes/users/4119868/">Rob Haeusler</a>
.
</p>
<p>I wanted a GUI pronouncable password generator that was not Internet based, that would meet the password rules required by the various systems that I work with. I've used a basic python program (non-GUI) modified to tcl/tk.</p>
WSCP - showServerStatus (Tcl)
2002-10-01T04:42:31-07:00Patrick Finneganhttp://code.activestate.com/recipes/users/475144/http://code.activestate.com/recipes/154433-wscp-showserverstatus/
<p style="color: grey">
Tcl
recipe 154433
by <a href="/recipes/users/475144/">Patrick Finnegan</a>
.
</p>
<p>Display current status of application server.</p>
Check creditcard numbers for wellformed-ness. (Tcl)
2002-08-22T16:03:11-07:00andreas kuprieshttp://code.activestate.com/recipes/users/117230/http://code.activestate.com/recipes/146221-check-creditcard-numbers-for-wellformed-ness/
<p style="color: grey">
Tcl
recipe 146221
by <a href="/recipes/users/117230/">andreas kupries</a>
(<a href="/recipes/tags/text/">text</a>).
</p>
<p>The command below checks if the specified creditcard number is syntactically valid. This code does __not__ check if there is actually creditcard with this number. Only that the number in itself is well-formed according to the rules of the creditcard companies. See the comments preceding the code for a list of the rules.</p>
Inline GIF image into code (Tcl)
2002-03-18T13:47:20-08:00Jeff Hobbshttp://code.activestate.com/recipes/users/98167/http://code.activestate.com/recipes/117247-inline-gif-image-into-code/
<p style="color: grey">
Tcl
recipe 117247
by <a href="/recipes/users/98167/">Jeff Hobbs</a>
(<a href="/recipes/tags/binding/">binding</a>).
</p>
<p>This recipe shows how to inline a GIF image directly into your Tcl code.</p>
Flexible string splitting/parsing routine (Tcl)
2005-07-06T06:44:26-07:00Joe Mistachkinhttp://code.activestate.com/recipes/users/141324/http://code.activestate.com/recipes/116653-flexible-string-splittingparsing-routine/
<p style="color: grey">
Tcl
recipe 116653
by <a href="/recipes/users/141324/">Joe Mistachkin</a>
(<a href="/recipes/tags/text/">text</a>).
Revision 2.
</p>
<p>This routine allows you to split a string on multiple characters. Additionally, you can specify the maximum number of elements to return. The final element will contain the remainder of the string.</p>
Multi-character split (Tcl)
2001-09-10T10:07:20-07:00Jeff Hobbshttp://code.activestate.com/recipes/users/98167/http://code.activestate.com/recipes/68386-multi-character-split/
<p style="color: grey">
Tcl
recipe 68386
by <a href="/recipes/users/98167/">Jeff Hobbs</a>
(<a href="/recipes/tags/text/">text</a>).
</p>
<p>The split command splits a string based on each character that is in the splitString. This version handles the splitString as a combined string, splitting the string into constituent parts.</p>
Add Commas to a Number (Tcl)
2001-09-09T21:21:34-07:00Keith Vetterhttp://code.activestate.com/recipes/users/130056/http://code.activestate.com/recipes/68381-add-commas-to-a-number/
<p style="color: grey">
Tcl
recipe 68381
by <a href="/recipes/users/130056/">Keith Vetter</a>
(<a href="/recipes/tags/text/">text</a>).
</p>
<p>Takes a number and inserts a comma (or separator of your choice) between
every third digit.</p>
Socket based communication (Tcl)
2001-06-21T17:02:20-07:00Jeff Hobbshttp://code.activestate.com/recipes/users/98167/http://code.activestate.com/recipes/65436-socket-based-communication/
<p style="color: grey">
Tcl
recipe 65436
by <a href="/recipes/users/98167/">Jeff Hobbs</a>
(<a href="/recipes/tags/distributed/">distributed</a>).
</p>
<p>Here we write the most simple socket based server application we
can think of. Starting from this minimal example it is very easy to
extend it to the actually wanted functionality</p>
A minimal debugger (Tcl)
2001-06-21T16:47:46-07:00Jeff Hobbshttp://code.activestate.com/recipes/users/98167/http://code.activestate.com/recipes/65431-a-minimal-debugger/
<p style="color: grey">
Tcl
recipe 65431
by <a href="/recipes/users/98167/">Jeff Hobbs</a>
(<a href="/recipes/tags/debugging/">debugging</a>).
</p>
<p>Of course, Tcl's most minimal debugger is puts. But here is a cute
little piece of code that offers some more debugging functionality (if
you have stdin and stdout available - so not for wish on Windows)</p>
Text to HTML (Tcl)
2001-06-21T16:27:26-07:00Jeff Hobbshttp://code.activestate.com/recipes/users/98167/http://code.activestate.com/recipes/65428-text-to-html/
<p style="color: grey">
Tcl
recipe 65428
by <a href="/recipes/users/98167/">Jeff Hobbs</a>
(<a href="/recipes/tags/text/">text</a>).
</p>
<p>Scan the files in the current directory and wrap them into html/body tags so that netscape will display them as HTML and not as text.</p>
A Simple Calculator (Tcl)
2014-09-06T13:36:35-07:00Mike Manilonehttp://code.activestate.com/recipes/users/4190728/http://code.activestate.com/recipes/578929-a-simple-calculator/
<p style="color: grey">
Tcl
recipe 578929
by <a href="/recipes/users/4190728/">Mike Manilone</a>
(<a href="/recipes/tags/calculator/">calculator</a>, <a href="/recipes/tags/gui/">gui</a>).
</p>
<p>A simple calculator. Calculation is done by [expr].</p>
Stopwatch in 26 lines (Tcl)
2014-09-05T13:33:13-07:00Mike Manilonehttp://code.activestate.com/recipes/users/4190728/http://code.activestate.com/recipes/578927-stopwatch-in-26-lines/
<p style="color: grey">
Tcl
recipe 578927
by <a href="/recipes/users/4190728/">Mike Manilone</a>
(<a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/time/">time</a>).
</p>
<p>This stopwatch works on Tcl/Tk 8.5 and higher. It makes use of the [clock] command and reduced the amount of code by -textvariable. A simple one, indeed. Nevertheless, it is still easy-to-read and easy-to-understand and it does show the power that Tcl has.</p>
Track Debug Package argument(s) are option(s) and/or a debug message to be saved to a file (Tcl)
2014-03-23T22:31:40-07:00Bert Byfieldhttp://code.activestate.com/recipes/users/4188497/http://code.activestate.com/recipes/578855-track-debug-package-arguments-are-options-andor-a-/
<p style="color: grey">
Tcl
recipe 578855
by <a href="/recipes/users/4188497/">Bert Byfield</a>
(<a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/pdisplay/">pdisplay</a>, <a href="/recipes/tags/ptrack/">ptrack</a>, <a href="/recipes/tags/trace/">trace</a>, <a href="/recipes/tags/track/">track</a>, <a href="/recipes/tags/tracklst/">tracklst</a>).
</p>
<h4 id="package-require-tracks">package require tracks</h4>
<h4 id="ptrack-on-off-clear-overflow-overflowgo-abend-104-message-text">pTrack ?-on? ?-off? ?-clear? ?-overflow? ?-overflowGo? ?-abend? ?"104 message text"?</h4>
<p>A user-specified text message is written to a file "tracklst.txt" in the same directory as the source program. Tracking can be turned on or off, and the clear option sets the file to zero bytes. The program defaults to raise an error if the tracklst.txt file gets too big (default is one megabyte), but the overflowGo option will cause it to just turn off tracking and continue. The abend option will raise an optional error. The message is whatever the user wants it to be, but suggested usage is to always start with three digits that identify a proc and a fourth alphabetic character that marks the track uniquely and allows searching for a specific track. Also includes pDisplay, which writes a debug message to a tk_messageBox dialog window.</p>
<p>e.g.: pTrack -clear "Start a new test by emptying the track file" <br>
pTrack "140d date adjusted to $tMon of $tYear"
pTrack "135b Current working directory is [pwd]"</p>
Poker hand calculation and comparison (Tcl)
2013-06-24T05:03:10-07:00Magnus Åhmanhttp://code.activestate.com/recipes/users/4180631/http://code.activestate.com/recipes/578539-poker-hand-calculation-and-comparison/
<p style="color: grey">
Tcl
recipe 578539
by <a href="/recipes/users/4180631/">Magnus Åhman</a>
(<a href="/recipes/tags/poker/">poker</a>).
Revision 2.
</p>
<p>Calculates 1. the category of the hand (high card, one pair, etc...) and 2. the "kicker" values that act as tiebreakers to (possibly) distinguish two hands of the same category from each other. These two attributes, category and kickers, are then used by the cmp method to compare two hand objects and return -1, 0 or 1.</p>
Sample script for TCL socket load distribution across many CPUs / hosts (Tcl)
2012-11-29T17:27:20-08:00John Brearleyhttp://code.activestate.com/recipes/users/4184423/http://code.activestate.com/recipes/578351-sample-script-for-tcl-socket-load-distribution-acr/
<p style="color: grey">
Tcl
recipe 578351
by <a href="/recipes/users/4184423/">John Brearley</a>
(<a href="/recipes/tags/distribution/">distribution</a>, <a href="/recipes/tags/load/">load</a>, <a href="/recipes/tags/socket/">socket</a>, <a href="/recipes/tags/tcl/">tcl</a>).
</p>
<p>Here is a demo script for others to reuse / learn from. The server process hands out work assignments to multiple children process to do load balancing across multiple CPUs / hosts. The children process in this sample script dont do any real work, but occasionally create an error to demonstrate the error handling and recovery. Enjoy!</p>