<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Toxi's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 26 Jul 2008 19:43:27 GMT</pubDate>
    <description>DZone Snippets: Toxi's Code Snippets</description>
    <item>
      <title>Customizable sigmoid function</title>
      <link>http://snippets.dzone.com/posts/show/2620</link>
      <description>&lt;code&gt;&lt;br /&gt;/**&lt;br /&gt; * Calculates S-curve for point x in the interval 0 .. normV&lt;br /&gt; * &lt;br /&gt; * @param x input coordinate&lt;br /&gt; * @param normV scale value which corresponds to 1.0 if x is normalized&lt;br /&gt; * @param sharpness adjusts steepness of curve (value of 1 equals undistorted sigmoid)&lt;br /&gt; *&lt;br /&gt; * @return sigmoid for point X&lt;br /&gt; */&lt;br /&gt;public float sigmoid(float x, float normV, float sharpness) {&lt;br /&gt;  x=(x/normV*2-1)*5*sharpness;&lt;br /&gt;  return 1.0f / (1.0f + (float)Math.exp(-x));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public double sigmoid(double x, double normV, double sharpness) {&lt;br /&gt;  x=(x/normV*2-1)*5*sharpness;&lt;br /&gt;  return 1.0 / (1.0 + Math.exp(-x));&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 18 Sep 2006 17:23:30 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2620</guid>
      <author>toxi (karsten schmidt)</author>
    </item>
    <item>
      <title>baseX converter</title>
      <link>http://snippets.dzone.com/posts/show/483</link>
      <description>you can use this function to convert an integer into any number system upto base36 (e.g. for TinyURL generation coupled with a global ID counter)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;function int2baseX($val,$base=16) {&lt;br /&gt;  if (0==$val) return 0;&lt;br /&gt;  $symbols='0123456789abcdefgihjklmnopqrstuvwxyz';&lt;br /&gt;  $result='';&lt;br /&gt;  $exp=$oldpow=1;&lt;br /&gt;  while($val&gt;0 &amp;&amp; $exp&lt;10) {&lt;br /&gt;    $pow=pow($base,$exp++);&lt;br /&gt;    $mod=($val % $pow);&lt;br /&gt;    $result=substr($symbols,$mod/$oldpow,1).$result;&lt;br /&gt;    $val-=$mod;&lt;br /&gt;    $oldpow=$pow;&lt;br /&gt;  }&lt;br /&gt;  return $result;&lt;br /&gt;}&lt;/code&gt;</description>
      <pubDate>Tue, 19 Jul 2005 19:55:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/483</guid>
      <author>toxi (karsten schmidt)</author>
    </item>
    <item>
      <title>create pre-styled/populated DOM elements</title>
      <link>http://snippets.dzone.com/posts/show/61</link>
      <description>&lt;code&gt;&lt;br /&gt;/*&lt;br /&gt; * create a new DOM element with (optionally) specified className, CSS and text/html content&lt;br /&gt; * if text contains any markup, it's used as innerHTML value - else a child text node is attached&lt;br /&gt; * if there's also a parent node given, the new element will be appended as child node&lt;br /&gt; */&lt;br /&gt;function createStyledElement(tag, parent, cls, css, txt) {&lt;br /&gt;    var el = document.createElement(tag);&lt;br /&gt;    if(cls) el.className = cls;&lt;br /&gt;    if(css) for(var s in css) el.style[s]=css[s];&lt;br /&gt;    if(txt) {&lt;br /&gt;        if (txt.indexOf('&lt;')!=-1) el.innerHTML=txt;&lt;br /&gt;        else el.appendChild(document.createTextNode(txt));&lt;br /&gt;    }&lt;br /&gt;    if(parent) parent.appendChild(el);&lt;br /&gt;    return el;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// usage example...&lt;br /&gt;// 1st define some style params&lt;br /&gt;var style1={&lt;br /&gt;    background: '#def',&lt;br /&gt;    color: '#f00',&lt;br /&gt;    padding: '0.5em',&lt;br /&gt;    border: '1px black dotted'&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;createStyledElement(&lt;br /&gt;  'div',&lt;br /&gt;  document.getElementsByTagName('body').item(0),&lt;br /&gt;  null,&lt;br /&gt;  style1,&lt;br /&gt;  'hello &lt;em&gt;world&lt;/em&gt;!'&lt;br /&gt;);&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 07 Apr 2005 23:18:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/61</guid>
      <author>toxi (karsten schmidt)</author>
    </item>
  </channel>
</rss>
