<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Jakob's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 03:03:11 GMT</pubDate>
    <description>DZone Snippets: Jakob's Code Snippets</description>
    <item>
      <title>Batch loop for wave to mp3 (using lame)</title>
      <link>http://snippets.dzone.com/posts/show/5464</link>
      <description>It keeps the input files and sorts both mp3 and wave files nicely in two separate directories.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;@echo off&lt;br /&gt;if NOT EXIST MP3 md MP3&lt;br /&gt;if NOT EXIST WAV md WAV&lt;br /&gt;&lt;br /&gt;for %%f in (*.wav) do (&lt;br /&gt;	cls&lt;br /&gt;	lame -b 96 -V 5 -B 128 -m j --vbr-new -q 5 "%%f" "MP3\%%f.mp3"&lt;br /&gt;	move "%%f" WAV&lt;br /&gt;)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 05 May 2008 19:57:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5464</guid>
      <author>jakob ()</author>
    </item>
    <item>
      <title>Update DynDNS hostname</title>
      <link>http://snippets.dzone.com/posts/show/5463</link>
      <description>See DynDNS Update Specifications &lt;http://www.dyndns.com/developers/specs/syntax.html&gt;.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;curl -v -k -u jakobm "https://members.dyndns.org/nic/update?hostname=jakobm.dyndns.org&amp;myip=217.80.116.128&amp;wildcard=NOCHG&amp;mx=NOCHG&amp;backmx=NOCHG"&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 05 May 2008 19:45:30 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5463</guid>
      <author>jakob ()</author>
    </item>
    <item>
      <title>Filesize with nice units</title>
      <link>http://snippets.dzone.com/posts/show/5434</link>
      <description>Simple function to format filesizes in bytes to human-readable units.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def prettySize(size):&lt;br /&gt;	suffixes = [("B",2**10), ("K",2**20), ("M",2**30), ("G",2**40), ("T",2**50)]&lt;br /&gt;	for suf, lim in suffixes:&lt;br /&gt;		if size &gt; lim:&lt;br /&gt;			continue&lt;br /&gt;		else:&lt;br /&gt;			return round(size/float(lim/2**10),2).__str__()+suf&lt;br /&gt;&lt;br /&gt;print prettySize(213458923)&lt;br /&gt;# Output: 203.57M&lt;br /&gt;&lt;br /&gt;print prettySize(1234)&lt;br /&gt;# Output: 1.21K&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 27 Apr 2008 11:16:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5434</guid>
      <author>jakob ()</author>
    </item>
    <item>
      <title>Calculate Pi</title>
      <link>http://snippets.dzone.com/posts/show/5433</link>
      <description>This script presents a way to compute Pi using a statistic method.&lt;br /&gt;See http://en.wikipedia.org/wiki/Computing_&#960; for further algorithms.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import random, math&lt;br /&gt;&lt;br /&gt;class calcPi:&lt;br /&gt;    def __init__(self):&lt;br /&gt;        self.times = pow(10,6)&lt;br /&gt;        self.i = 0&lt;br /&gt;        self.isnot = 0&lt;br /&gt;&lt;br /&gt;    def IsOnCircle(self,x,y):&lt;br /&gt;        if math.sqrt(x**2+y**2) &lt; 1:&lt;br /&gt;            return True&lt;br /&gt;        else:&lt;br /&gt;            return False&lt;br /&gt;    &lt;br /&gt;    def run(self):&lt;br /&gt;        for x in range(self.times):&lt;br /&gt;            x,y = random.random(),random.random()&lt;br /&gt;            if self.IsOnCircle(x,y):&lt;br /&gt;                self.i+=1&lt;br /&gt;            else:&lt;br /&gt;                self.isnot+=1&lt;br /&gt;    &lt;br /&gt;    def getResults(self):&lt;br /&gt;        return (float(self.i), float(self.isnot))&lt;br /&gt;&lt;br /&gt;    def getPi(self):&lt;br /&gt;        self.run()&lt;br /&gt;        r = self.getResults()&lt;br /&gt;        return r[0]/(r[0]+r[1])*4&lt;br /&gt;&lt;br /&gt;if __name__ == '__main__':&lt;br /&gt;    print calcPi().getPi()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 26 Apr 2008 14:57:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5433</guid>
      <author>jakob ()</author>
    </item>
    <item>
      <title>Progress bar</title>
      <link>http://snippets.dzone.com/posts/show/5432</link>
      <description>This is a simple class to generate char-based progress bars.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;code&gt;[++++++      ]&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Bar:&lt;br /&gt;	def __init__(self):&lt;br /&gt;		self.len = 80&lt;br /&gt;		self.chars = (' ', '+')&lt;br /&gt;		self.wrap = ('[', ']')&lt;br /&gt;		self.filledc = 0&lt;br /&gt;&lt;br /&gt;	def fill(self, i):&lt;br /&gt;		assert not (i &gt; 100) or (i &lt; 0)&lt;br /&gt;		self._setP(i)&lt;br /&gt;&lt;br /&gt;	def _setP(self, p):&lt;br /&gt;		self.filledc = int(round(float(self.len*p)/100))&lt;br /&gt;&lt;br /&gt;	def show(self):&lt;br /&gt;		out = []&lt;br /&gt;		out.append(self.wrap[0])&lt;br /&gt;		out.append(self.filledc*self.chars[1])&lt;br /&gt;		out.append((self.len-self.filledc)*self.chars[0])&lt;br /&gt;		out.append(self.wrap[1])&lt;br /&gt;		return "".join(out)&lt;br /&gt;&lt;br /&gt;b = Bar()&lt;br /&gt;b.len = 20&lt;br /&gt;b.fill(20)&lt;br /&gt;print b.show()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 26 Apr 2008 14:41:49 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5432</guid>
      <author>jakob ()</author>
    </item>
  </channel>
</rss>
