<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: convert code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 02:45:06 GMT</pubDate>
    <description>DZone Snippets: convert code</description>
    <item>
      <title>Howto resize multiple pictures, graphics, images</title>
      <link>http://snippets.dzone.com/posts/show/5440</link>
      <description>&lt;code&gt;&lt;br /&gt;for k in $(ls *.jpg); do convert -resize 800 -quality 80 $k r800-$k; done&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 29 Apr 2008 16:41:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5440</guid>
      <author>flynets (Flynets is an italian student of computer science with passion for GNU/Linux and hacktivism.)</author>
    </item>
    <item>
      <title>date_select conversion</title>
      <link>http://snippets.dzone.com/posts/show/5376</link>
      <description>function to convert a value from a date_select into a more sql-friendly value&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;%=date_select(:date,'',:start_year =&gt; 1950,:include_blank =&gt; false, :default =&gt; { :year =&gt; '1970' })%&gt;&lt;br /&gt;&lt;br /&gt;def convert_date(obj) &lt;br /&gt;  return &#8220;#{obj[&#8216;(1i)&#8217;]}-#{obj[&#8216;(2i)&#8217;]}-#{obj[&#8216;(3i)&#8217;]}&#8221; &lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 17 Apr 2008 13:20:35 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5376</guid>
      <author>indiehead (John)</author>
    </item>
    <item>
      <title>Output JavaScript variables from PHP</title>
      <link>http://snippets.dzone.com/posts/show/5342</link>
      <description>Class with useful static methods for outputting PHP values into JavaScript format.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com&lt;br /&gt;&lt;br /&gt;class JS{&lt;br /&gt;	//generic and maybe not the desired results xD&lt;br /&gt;	function value($o){&lt;br /&gt;		if($o === null)&lt;br /&gt;			return 'null';&lt;br /&gt;		$t = strtolower(gettype($o));&lt;br /&gt;		if($t == 'string' &amp;&amp; is_numeric($o) &amp;&amp; ($o[0] || strlen($o) == 1) || in_array($t, array('double', 'integer')))&lt;br /&gt;			$t = 'number';&lt;br /&gt;		elseif($t == 'string' &amp;&amp; preg_match('@^\d{4}(?:-\d{1,2}){1,2}(?: (?:\d{1,2}:){2}\d{1,2})?$@', $o)) //strtotime works also with "strange" values strtotime('x')&lt;br /&gt;			$t = 'date';&lt;br /&gt;		elseif($t == 'array' &amp;&amp; ($c = count($k = array_keys($o))) &amp;&amp; $k !== range(0, $c - 1))&lt;br /&gt;			$t = 'object';&lt;br /&gt;		elseif(!in_array($t, array('boolean', 'string', 'array', 'object')))&lt;br /&gt;			$t = 'string';&lt;br /&gt;		$t = 'from' . $t;&lt;br /&gt;		return self::$t($o);&lt;br /&gt;	}&lt;br /&gt;	function fromNumber($o){&lt;br /&gt;		return +$o . '';&lt;br /&gt;	}&lt;br /&gt;	function fromObject($o){&lt;br /&gt;		$r = array();&lt;br /&gt;		foreach($o as $n =&gt; $v)&lt;br /&gt;			$r[] = self::fromString($n) . ':' . self::value($v);&lt;br /&gt;		return '{' . implode(',', $r) . '}';&lt;br /&gt;	}&lt;br /&gt;	function fromBoolean($o){&lt;br /&gt;		return $o ? 'true' : 'false';&lt;br /&gt;	}&lt;br /&gt;	//$q = should quote? &lt;br /&gt;	//$c = char that will be used to quote&lt;br /&gt;	function fromString($o, $q = true, $c = '"'){&lt;br /&gt;		return ($p = $q ? $c : '') . preg_replace('/\r\n|\n\r|\r/', '\n', str_replace($c, '\\' . $c, str_replace('\\', '\\\\', $o))) . $p;&lt;br /&gt;	}&lt;br /&gt;	function fromArray($o){&lt;br /&gt;		$s = '';&lt;br /&gt;		foreach($o as $v)&lt;br /&gt;			$s .= ($s ? ',' : '') . self::value($v);&lt;br /&gt;		return '[' . $s . ']';&lt;br /&gt;	}&lt;br /&gt;	function fromDate($o){&lt;br /&gt;		(is_numeric($o) &amp;&amp; $o = +$o) || ($o = strtotime($o)) &gt; 0 || ($o = mktime());&lt;br /&gt;		$o = explode(',', date('Y,n,j,G,i,s', $o));&lt;br /&gt;		foreach($o as $i =&gt; $v)&lt;br /&gt;			$o[$i] = +$v;&lt;br /&gt;		return 'new Date(' . implode(',', $o)  . ')';&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Example&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$o = new stdClass;&lt;br /&gt;$o-&gt;abc = 123;&lt;br /&gt;echo implode("\n&lt;br /&gt;", array(&lt;br /&gt;	JS::value('1984-07-22 11:30:12'),&lt;br /&gt;	JS::value('Test'),&lt;br /&gt;	JS::value(1234),&lt;br /&gt;	JS::value(true),&lt;br /&gt;	JS::value(array(1,2,3)),&lt;br /&gt;	JS::value(array('lala' =&gt; 'x')),&lt;br /&gt;	JS::value($o)&lt;br /&gt;));&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 09 Apr 2008 23:57:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5342</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
    <item>
      <title>Batch re-size a collection of images from the command line</title>
      <link>http://snippets.dzone.com/posts/show/5298</link>
      <description>&lt;code&gt;&lt;br /&gt;for img in $(ls *.png); do convert $img -resize 75% smaller-$img; done;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 01 Apr 2008 09:33:24 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5298</guid>
      <author>27stars (27stars)</author>
    </item>
    <item>
      <title>UTF-8 Converter //JavaScript Object</title>
      <link>http://snippets.dzone.com/posts/show/5294</link>
      <description>&lt;br /&gt;&lt;br /&gt;&lt;a href="http://jsfromhell.com/geral/utf-8"&gt;&lt;br /&gt;Converts a sequence of ANSI characters to UTF-8 and vice-versa.&lt;br /&gt;&lt;br /&gt;[UPDATED CODE AND HELP CAN BE FOUND HERE]&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com/geral/utf-8 [v1.0]&lt;br /&gt;&lt;br /&gt;UTF8 = {&lt;br /&gt;	encode: function(s){&lt;br /&gt;		for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i &lt; l;&lt;br /&gt;			s[i] = (c = s[i].charCodeAt(0)) &gt;= 127 ? o(0xc0 | (c &gt;&gt;&gt; 6)) + o(0x80 | (c &amp; 0x3f)) : s[i]&lt;br /&gt;		);&lt;br /&gt;		return s.join("");&lt;br /&gt;	},&lt;br /&gt;	decode: function(s){&lt;br /&gt;		for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i &lt; l;&lt;br /&gt;			((a = s[i][c](0)) &amp; 0x80) &amp;&amp;&lt;br /&gt;			(s[i] = (a &amp; 0xfc) == 0xc0 &amp;&amp; ((b = s[i + 1][c](0)) &amp; 0xc0) == 0x80 ?&lt;br /&gt;			o(((a &amp; 0x03) &lt;&lt; 6) + (b &amp; 0x3f)) : o(128), s[++i] = "")&lt;br /&gt;		);&lt;br /&gt;		return s.join("");&lt;br /&gt;	}&lt;br /&gt;};&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Example&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var s = "a&#225;&#233;&#237;&#243;&#250;e";&lt;br /&gt;document.write(&lt;br /&gt;	('UTF8.encode("' + s + '") = ').bold(), UTF8.encode(s), "&lt;br /&gt;",&lt;br /&gt;	('UTF8.decode(UTF8.encode("' + s + '"))) = ').bold(), UTF8.decode(UTF8.encode(s))&lt;br /&gt;);&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 30 Mar 2008 16:52:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5294</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
    <item>
      <title>Increment a date using Ruby</title>
      <link>http://snippets.dzone.com/posts/show/5200</link>
      <description>This Ruby code converts a string into a date and increments the day, week, month, quarter or year.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def date_add(sdate='', unit='',i=0)&lt;br /&gt;&lt;br /&gt;  sdate[/(\d+)\/(\d+)\/(\d+)\s(\d+):(\d+):(\d+)/]&lt;br /&gt;  iyear = $3.to_i; imonth = $2.to_i; iday = $1.to_i; ihour = $4.to_i; imin = $5.to_i; isec = $6.to_i&lt;br /&gt;  &lt;br /&gt;  case  unit&lt;br /&gt;    when 'days'&lt;br /&gt;      t1 = Time.local(iyear,imonth,iday,ihour,imin,isec)&lt;br /&gt;      t1 += (60 * 60 * 24 * i)&lt;br /&gt;    when 'weeks'&lt;br /&gt;      t1 = Time.local(iyear,imonth,iday,ihour,imin,isec)&lt;br /&gt;      t1 += (60 * 60 * 24 * 7 * i) &lt;br /&gt;    when 'months'&lt;br /&gt;      imonth += i&lt;br /&gt;      if imonth &lt; 12 then&lt;br /&gt;        t1 = Time.local(iyear,imonth+i,iday,ihour,imin,isec)&lt;br /&gt;      else&lt;br /&gt;        t1 = Time.local(iyear+=1,imonth -12,iday,ihour,imin,isec)&lt;br /&gt;      end&lt;br /&gt;    when 'quarter'&lt;br /&gt;      imonth += 3&lt;br /&gt;      if imonth &lt;= 12 then&lt;br /&gt;        t1 = Time.local(iyear,imonth,iday,ihour,imin,isec)&lt;br /&gt;      else&lt;br /&gt;        t1 = Time.local(iyear+=1,imonth - 12,iday,ihour,imin,isec)&lt;br /&gt;      end    &lt;br /&gt;    when 'years'&lt;br /&gt;      t1 = Time.local(iyear+i,imonth,iday,ihour,imin,isec)&lt;br /&gt;    else&lt;br /&gt;      raise 'not a valid date unit'&lt;br /&gt;  end&lt;br /&gt;  t1&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;date_add("17/03/2008 17:48:00",'months',2)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;output: Sat May 17 17:48:00 +0100 2008&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 05 Mar 2008 13:43:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5200</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Convert from HTML to XHTML with HTML Tidy</title>
      <link>http://snippets.dzone.com/posts/show/5121</link>
      <description>This HTML Tidy example converts an html file into an xml file.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;tidy -asxhtml -numeric &lt; index.html &gt; index.xml&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;example found from &lt;a href="http://www.ibm.com/developerworks/library/x-tiptidy.html"&gt;Tip: Convert from HTML to XML with HTML Tidy&lt;/a&gt; [ibm.com]</description>
      <pubDate>Fri, 08 Feb 2008 16:51:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5121</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Convert a UTF-8 string to ISO-8859-1</title>
      <link>http://snippets.dzone.com/posts/show/5019</link>
      <description>Convert a utf string to iso, used this when generating a pdf with pdf-writer in Rails, all my text is UTF8 but pdf-writer does not support this.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#add this to environment.rb&lt;br /&gt;#call to_iso on any UTF8 string to get a ISO string back&lt;br /&gt;#example : "C&#233;dez le passage aux fran&#231;ais".to_iso&lt;br /&gt;&lt;br /&gt;class String&lt;br /&gt;  require 'iconv' #this line is not needed in rails !&lt;br /&gt;  def to_iso&lt;br /&gt;    Iconv.conv('ISO-8859-1', 'utf-8', self)&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 21 Jan 2008 14:35:26 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5019</guid>
      <author>drcorbeille (Christian Meichtry)</author>
    </item>
    <item>
      <title>Convert a video file to an audio file (.mp4 to .mp3)</title>
      <link>http://snippets.dzone.com/posts/show/4649</link>
      <description>Convert an mp4 file to avi, then to mp3 (including mixing the stereo down to mono). This code was executed from the command-line on Ubuntu 7.04.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;mencoder video.mp4 -ovc lavc -vf scale=123:100 -oac lavc -o video.avi&lt;br /&gt;ffmpeg -i video.avi -ac 1 audio1.mp3 &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 13 Oct 2007 10:37:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4649</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Convert a string to a character array</title>
      <link>http://snippets.dzone.com/posts/show/4608</link>
      <description>// converts a string into a character array, then displays the output 1 character at a time from the array.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;y = 'testing'.scan(/./)&lt;br /&gt;y.each do |c|&lt;br /&gt;	puts c&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 03 Oct 2007 13:32:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4608</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
  </channel>
</rss>
