Popular recipes by Antoni Gual http://code.activestate.com/recipes/users/4182514/2017-04-28T08:22:08-07:00ActiveState Code RecipesCount lines and words in a text file (Batch)
2017-04-28T08:22:08-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/580791-count-lines-and-words-in-a-text-file/
<p style="color: grey">
Batch
recipe 580791
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/word_count/">word_count</a>).
Revision 2.
</p>
<p>Returns number of lines and words (separed by spaces) of a text file dragged to the script. Does'nt count blank lines. </p>
Batch prime generator (Batch)
2017-04-25T11:44:27-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/580789-batch-prime-generator/
<p style="color: grey">
Batch
recipe 580789
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/primes/">primes</a>).
Revision 3.
</p>
<p>Here is a radically differnt approach to generating primes in pure batch that overperforms everything else I have found . The idea comes from an exercise in Knuth's TAOCP Vol 3 page 617.</p>
File selector dialog in batch (Batch)
2017-03-27T13:20:41-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/580665-file-selector-dialog-in-batch/
<p style="color: grey">
Batch
recipe 580665
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/batch/">batch</a>, <a href="/recipes/tags/directory/">directory</a>).
Revision 2.
</p>
<p>Runs mshta hidden to open a file dialog and get the path of the file selected. No parameters can be passed to the dialog.
EDITED: I did a subroutine with the snippet</p>
Add days to a calendar date- Julian date (Batch)
2016-08-17T10:32:03-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/580683-add-days-to-a-calendar-date-julian-date/
<p style="color: grey">
Batch
recipe 580683
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/calendar/">calendar</a>).
</p>
<p>The trick to add days to a date is to convert the date to a serial, do a normal addition then convert the result back to a date. The serial I use here is the Julian day number used by the astronomers because its conversion formulas arewell documented. If you check the julian day number on internet the result can vary by a day, because julian days start at noon and i'm not making this distinction. </p>
Get text length - Column left center and right alignement (Batch)
2016-06-15T06:42:00-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/580682-get-text-length-column-left-center-and-right-align/
<p style="color: grey">
Batch
recipe 580682
by <a href="/recipes/users/4182514/">Antoni Gual</a>
.
</p>
<p>The recipe parses some lines of text (separator=$), calculates the width of each column and prints the text in columns with lefr, right and center alignment. I have put the strlen and the alignment routines in separate procedures, to ease the reuse. The alignement procedures work in place, the result is returned in the same variable as the original string.</p>
Send and retrieve text to/from clipboard (Batch)
2016-05-27T09:56:56-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/580669-send-and-retrieve-text-tofrom-clipboard/
<p style="color: grey">
Batch
recipe 580669
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/batch/">batch</a>, <a href="/recipes/tags/clipboard/">clipboard</a>).
</p>
<p>Sending uses the command line tool clip.exe that may not be available in Windows XP. There is no standard tool to retrieve from clipboard so I use javascript via mshta.</p>
ASCII art Sphere with integer square root (Batch)
2016-06-06T10:09:38-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/580673-ascii-art-sphere-with-integer-square-root/
<p style="color: grey">
Batch
recipe 580673
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/ascii/">ascii</a>, <a href="/recipes/tags/graphics/">graphics</a>).
Revision 2.
</p>
<p>The code draws a sphere in ASCII Art. Square root routine bt Aacini</p>
Permutations by recursive Heap's method (Batch)
2016-06-11T08:42:41-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/580678-permutations-by-recursive-heaps-method/
<p style="color: grey">
Batch
recipe 580678
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/permutation/">permutation</a>, <a href="/recipes/tags/recursion/">recursion</a>).
</p>
<p>Setlocal / endlocal allow for recursion in batch.
Values can be passed by value and by reference, the later can return a value to the caller.</p>
Last sunday of each month for a given year (Batch)
2016-06-07T20:25:00-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/580677-last-sunday-of-each-month-for-a-given-year/
<p style="color: grey">
Batch
recipe 580677
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/calendar/">calendar</a>).
Revision 2.
</p>
<p>Includes batch routines for day of week, is leap year and last dat of the month</p>
Timing a batch program (Batch)
2016-05-29T10:50:33-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/580670-timing-a-batch-program/
<p style="color: grey">
Batch
recipe 580670
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/batch/">batch</a>, <a href="/recipes/tags/timing/">timing</a>).
</p>
<p>It uses %time% to time a function to the hundredth of second.</p>
Batch priority queue (Batch)
2016-05-26T11:00:21-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/580666-batch-priority-queue/
<p style="color: grey">
Batch
recipe 580666
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/batch/">batch</a>).
</p>
<p>The fact the environment sorts itself by key allows us to implement a PQ using the prefix "queu" added to the priority value as a key</p>
Python Mandelbrot Fractal with Tkinter (Python)
2015-05-06T09:57:27-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/579048-python-mandelbrot-fractal-with-tkinter/
<p style="color: grey">
Python
recipe 579048
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 9.
</p>
<p>Displays in a Tk window a pretty coloured 640x480 Mandelbrot set in 6 seconds. Calculates each one of the 300K pixels with a maximum of 256 iterations. <br>
Only Tkinter used. Tested with Python 3.4 <br>
I will test any contribution and add it to the code if worthy.</p>
generates a set of binary files by doing ASCII replacements on a master binary file, controlled by a csv file (Python)
2015-09-16T16:25:49-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/579099-generates-a-set-of-binary-files-by-doing-ascii-rep/
<p style="color: grey">
Python
recipe 579099
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/ascii/">ascii</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/replace/">replace</a>).
</p>
<p>A hack that saved me a lot of time. Well perhaps not so much, but it was funnier than to do it manually. </p>
Run OS command with timeout on a list of files using several threads (Python)
2015-05-19T19:31:59-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/579056-run-os-command-with-timeout-on-a-list-of-files-usi/
<p style="color: grey">
Python
recipe 579056
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/threading/">threading</a>).
Revision 3.
</p>
<p>This hack runs a command sequentially on a list of files using two simultaneous threads. If one of the commands takes more than a set time, it's killed and the program goes for the next file. EDITED to add some exception handling.</p>
Prime factors of an integer by Brent algorithm (Python)
2015-05-28T06:47:01-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/579049-prime-factors-of-an-integer-by-brent-algorithm/
<p style="color: grey">
Python
recipe 579049
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This recipe uses trial division to get factors below 1 milion then switches to Brent's algorithm to get bigger factors. No fast enough to break a RSA key :)</p>
Animated raster graphics demo in Tkinter (Python)
2015-05-05T20:26:41-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/579052-animated-raster-graphics-demo-in-tkinter/
<p style="color: grey">
Python
recipe 579052
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/animation/">animation</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 4.
</p>
<p>EDITED:
A small animated graphics demo in Tkinter, displaying a 1990's style Rotozoom, more interesting than the TV snow I posted previously. The Tkinter management part is just the same. The code is a little longer as some trig tables must be precalculated for speed. The window size corresponds to the resolution of the old DOS screen 13, as I originally coded the demo for Qbasic. </p>