Top-rated Java recipes http://code.activestate.com/recipes/langs/java/top/2013-02-17T12:54:44-08:00ActiveState Code RecipesRomanNumeral to Integers (viceversa) (Java) 2010-07-18T11:20:19-07:00st0lehttp://code.activestate.com/recipes/users/4174421/http://code.activestate.com/recipes/577313-romannumeral-to-integers-viceversa/ <p style="color: grey"> Java recipe 577313 by <a href="/recipes/users/4174421/">st0le</a> (<a href="/recipes/tags/conversions/">conversions</a>, <a href="/recipes/tags/java/">java</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/roman/">roman</a>). </p> <p>Converts Roman Symbols to Integers and back.</p> Number To Words Converter (100 => One Hundred) (Java) 2010-07-18T11:17:52-07:00st0lehttp://code.activestate.com/recipes/users/4174421/http://code.activestate.com/recipes/577312-number-to-words-converter-100-one-hundred/ <p style="color: grey"> Java recipe 577312 by <a href="/recipes/users/4174421/">st0le</a> (<a href="/recipes/tags/conversions/">conversions</a>, <a href="/recipes/tags/integer/">integer</a>, <a href="/recipes/tags/java/">java</a>, <a href="/recipes/tags/number/">number</a>). </p> <p>Converts Integers to Words.</p> Ali (Java) 2013-02-17T12:54:44-08:00Alireza Hosseinihttp://code.activestate.com/recipes/users/4185286/http://code.activestate.com/recipes/578461-ali/ <p style="color: grey"> Java recipe 578461 by <a href="/recipes/users/4185286/">Alireza Hosseini</a> . </p> <h5 id="httpcodeactivestatecomrecipes578439-r1">{{{ <a href="http://code.activestate.com/recipes/578439/" rel="nofollow">http://code.activestate.com/recipes/578439/</a> (r1)</h5> <h4 id="just-a-try-using-the-thread-modules">Just a try using the thread modules.</h4> <p>import urllib as ul import bs4 as bs import urlparse as up import re as re import os.path as op import Queue as que import time import threading</p> <p>pat = re.compile('.<em>[\d]{4,7}.</em>')</p> <p>count=0</p> <p>class dldfile(threading.Thread): def __init__(self,qu1): threading.Thread.__init__(self) self.qu1=qu1 self.ad='download/1/'</p> <pre class="prettyprint"><code>def run(self): try: url,filename=self.qu1.get() url =url+self.ad #comment this line in case need to download whole web page instead of recipe ONLY... ul.urlretrieve(url,filename) global count except: print " RE-TRYING ", count= count - 1 self.qu1.put((url,filename)) self.run() finally: count= count +1 print str(count)+"("+str( threading.activeCount()) +")",filename self.qu1.task_done() </code></pre> <p>class dload(threading.Thread ): def __init__(self,qu,url = "http://code.activestate.com/recipes/langs/python/?page=" ): threading.Thread.__init__(self) self.url= url self.q =que.Queue() self.qu=qu</p> <pre class="prettyprint"><code>def run(self): ind=self.qu.get() url=self.url+str(ind) soup =bs.BeautifulSoup(''.join( ul.urlopen(url).readlines() )) bu = up.urlsplit(self.url) print 'started with the ' ,str(url).split('/')[-1], for i in soup.find_all(attrs = { "class" : "recipe-title"}): sp = up.urlsplit(i.a.get('href')) path = sp.path print path if re.search(pat, path): path = bu.scheme+'://'+bu.netloc+path filename = str(path).split('/')[-2] filename = op.join(op.abspath(op.curdir),filename+'.py') # recipe will be stored in given location </code></pre> <h4 id="filename-opjoinopabspathopcurdirfilenamehtml">filename = op.join(op.abspath(op.curdir),filename+'.html')</h4> <h4 id="uncomment-the-above-line-if-downloading-the-web-page-for-teh-recipe">uncomment the above line if downloading the web page for teh recipe</h4> <pre class="prettyprint"><code> print path self.q.put((path,filename)) self.fetch_data() time.sleep(1) self.qu.task_done() self.q.join() print 'done with the ' ,str(url).split('/')[-1], def fetch_data(self): Que1 = que.Queue() minitask =10 while not self.q.empty(): for i in range(minitask): x = dldfile(Que1) x.setDaemon(True) x.start() for j in range(minitask): Que1.put(self.q.get()) Que1.join() del x </code></pre> <p>if __name__ =='__main__': task=5 Que = que.Queue() for k in range(1,190,task): # no. of pages included under the python tag. 188 is current count and 3700+ python recipes print "\n PAGE # : {0} \t \nDeploying Fresh threads\n".format(k) for i in range(task): t = dload(Que) t.start() for j in range(task): Que.put(k+j) Que.join() Que.queue.clear() del t print "DONE\n" time.sleep(2) del Que print "Our buisness finished"</p> <h5 id="end-of-httpcodeactivestatecomrecipes578439">end of <a href="http://code.activestate.com/recipes/578439/" rel="nofollow">http://code.activestate.com/recipes/578439/</a> }}}</h5> jeesoo's coding (Java) 2011-06-21T09:09:43-07:00Jeesoohttp://code.activestate.com/recipes/users/4178376/http://code.activestate.com/recipes/577765-jeesoos-coding/ <p style="color: grey"> Java recipe 577765 by <a href="/recipes/users/4178376/">Jeesoo</a> . </p> <p>jeesoo's coding</p> Langton's Ant Automaton (Java) 2011-02-17T21:53:36-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577576-langtons-ant-automaton/ <p style="color: grey"> Java recipe 577576 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/applet/">applet</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>(Generalized) Langton's Ant Automaton.</p> <p>Langton's ant is a 2D Turing machine. In this version, at each new x,y location the ant reads the byte value and replaces it w/ another, and chooses a new direction (one of 8 possible directions) to move.</p> <p>Byte replacement and direction values are read from random arrays.</p> C# String.Replace with a char array (Java) 2010-12-24T09:58:35-08:00John Hurlimanhttp://code.activestate.com/recipes/users/4174599/http://code.activestate.com/recipes/577516-c-stringreplace-with-a-char-array/ <p style="color: grey"> Java recipe 577516 by <a href="/recipes/users/4174599/">John Hurliman</a> (<a href="/recipes/tags/csharp/">csharp</a>, <a href="/recipes/tags/replace/">replace</a>, <a href="/recipes/tags/string/">string</a>). </p> <p>Takes a string and replaces all characters matching a given array with a given string</p> C# Surface Normal (Java) 2010-08-06T21:00:07-07:00John Hurlimanhttp://code.activestate.com/recipes/users/4174599/http://code.activestate.com/recipes/577348-c-surface-normal/ <p style="color: grey"> Java recipe 577348 by <a href="/recipes/users/4174599/">John Hurliman</a> (<a href="/recipes/tags/csharp/">csharp</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/normal/">normal</a>). </p> <p>Calculates a surface normal given three position vectors in clockwise order. Written in C#</p> C# Image Resize (Java) 2010-08-06T20:56:16-07:00John Hurlimanhttp://code.activestate.com/recipes/users/4174599/http://code.activestate.com/recipes/577347-c-image-resize/ <p style="color: grey"> Java recipe 577347 by <a href="/recipes/users/4174599/">John Hurliman</a> (<a href="/recipes/tags/csharp/">csharp</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/resize/">resize</a>). </p> <p>Resize a GDI+ image using C#</p> Next Lexographic Word (Java) 2010-07-18T11:33:38-07:00st0lehttp://code.activestate.com/recipes/users/4174421/http://code.activestate.com/recipes/577315-next-lexographic-word/ <p style="color: grey"> Java recipe 577315 by <a href="/recipes/users/4174421/">st0le</a> (<a href="/recipes/tags/bruteforce/">bruteforce</a>, <a href="/recipes/tags/java/">java</a>, <a href="/recipes/tags/password/">password</a>). </p> <p>Generates next lexographically occuring word, say "aaa" -> "aab" -> "aac"</p> <p>Can be used for password cracking....</p> Sudoku Solver (Bruteforce) (Java) 2010-07-18T11:31:10-07:00st0lehttp://code.activestate.com/recipes/users/4174421/http://code.activestate.com/recipes/577314-sudoku-solver-bruteforce/ <p style="color: grey"> Java recipe 577314 by <a href="/recipes/users/4174421/">st0le</a> (<a href="/recipes/tags/java/">java</a>, <a href="/recipes/tags/sudoku/">sudoku</a>). </p> <p>A simple Sudoku Solver, use 0 for blank cells.</p> Snowflake Fractal Applet using Cellular Automaton (Java) 2010-07-17T00:42:13-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577311-snowflake-fractal-applet-using-cellular-automaton/ <p style="color: grey"> Java recipe 577311 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/applet/">applet</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Snowflake fractal applet using Cellular Automaton (2d CA). </p> Multi-threaded Mandelbrot Fractal Applet (Java) 2010-03-27T16:09:42-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577158-multi-threaded-mandelbrot-fractal-applet/ <p style="color: grey"> Java recipe 577158 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/applet/">applet</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Number of threads can be chosen freely.</p> Gravity Simulation Fractal Applet (Java) 2010-03-26T17:49:13-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577152-gravity-simulation-fractal-applet/ <p style="color: grey"> Java recipe 577152 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/applet/">applet</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/physics/">physics</a>). </p> <p>It produces a fractal image from an N particle gravity simulation. Warning: The calculation takes about a minute!</p> Gravity Simulation Applet (Java) 2010-03-26T17:50:43-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577151-gravity-simulation-applet/ <p style="color: grey"> Java recipe 577151 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/applet/">applet</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/physics/">physics</a>). </p> <p>It displays the trajectories of N mass particles moving under the force of gravity in 2D space. The repeating patterns mean particles started orbiting each other.</p> Color-cycling Plasma Fractal Applet (Java) 2010-03-26T05:06:53-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577148-color-cycling-plasma-fractal-applet/ <p style="color: grey"> Java recipe 577148 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/applet/">applet</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Color-cycling plasma fractal applet.</p> Morphing Plasma Fractal Applet (Java) 2010-03-26T04:58:36-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577147-morphing-plasma-fractal-applet/ <p style="color: grey"> Java recipe 577147 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/applet/">applet</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>It displays a continuously changing plasma fractal.</p> Moving Plasma Fractal Applet (Java) 2010-03-26T01:28:58-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577146-moving-plasma-fractal-applet/ <p style="color: grey"> Java recipe 577146 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Moving Plasma Fractal Applet.</p> CPU Usage Graph Applet (Java) 2010-03-26T01:12:44-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577145-cpu-usage-graph-applet/ <p style="color: grey"> Java recipe 577145 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/applet/">applet</a>, <a href="/recipes/tags/cpu_usage/">cpu_usage</a>, <a href="/recipes/tags/graphics/">graphics</a>). </p> <p>It calculates CPU speed w/o using any system calls etc. Instead it simply uses a timed counter.</p> HI-LO game (Java) 2010-02-23T15:56:05-08:00Ohm Patelhttp://code.activestate.com/recipes/users/2329187/http://code.activestate.com/recipes/388133-hi-lo-game/ <p style="color: grey"> Java recipe 388133 by <a href="/recipes/users/2329187/">Ohm Patel</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>This program is a game in which someone will try and guess a number between 1-100 in 4 tries. It will also give out instructions of how to play using methods and will also tell the person if their guess was too low or too high.</p> Curve fitting to N random points (Java) 2010-03-26T17:21:53-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577150-curve-fitting-to-n-random-points/ <p style="color: grey"> Java recipe 577150 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/applet/">applet</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>It creates a curve that passes through N random points using inverse distance weighted averages.</p>