Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

JavaScript

JS php like bytes to human size kb mb gb

1
2
3
4
5
6
function bytesToSize(bytes) {
    var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
    if (bytes == 0) return 'n/a';
    var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
    return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
};
https://snipt.net/embed/5e621dc351af43c8f21c14967822798e/
https://snipt.net/raw/5e621dc351af43c8f21c14967822798e/
5e621dc351af43c8f21c14967822798e
js
JavaScript
7
2016-12-07T12:14:35
True
False
False
Oct 23, 2012 at 05:08 AM
/api/public/snipt/48904/
js-php-like-bytes-to-human-size-kb-mb-gb
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kd">function</span> <span class="nx">bytesToSize</span><span class="p">(</span><span class="nx">bytes</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">var</span> <span class="nx">sizes</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;Bytes&#39;</span><span class="p">,</span> <span class="s1">&#39;KB&#39;</span><span class="p">,</span> <span class="s1">&#39;MB&#39;</span><span class="p">,</span> <span class="s1">&#39;GB&#39;</span><span class="p">,</span> <span class="s1">&#39;TB&#39;</span><span class="p">];</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">if</span> <span class="p">(</span><span class="nx">bytes</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="s1">&#39;n/a&#39;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> <span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nb">Math</span><span class="p">.</span><span class="nx">floor</span><span class="p">(</span><span class="nb">Math</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">bytes</span><span class="p">)</span> <span class="o">/</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="mi">1024</span><span class="p">)));</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">return</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">round</span><span class="p">(</span><span class="nx">bytes</span> <span class="o">/</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">pow</span><span class="p">(</span><span class="mi">1024</span><span class="p">,</span> <span class="nx">i</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="nx">sizes</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span> </span><span id="L-6"><a name="L-6"></a><span class="p">};</span> </span></pre></div> </td></tr></table>
bytes, js, round

CSS

CSS Round Corners

http://snipplr.com/view/830/css-rounded-corners/
https://snipt.net/embed/8c7ffa6b468467d8bc4dc545fa7b8f61/
https://snipt.net/raw/8c7ffa6b468467d8bc4dc545fa7b8f61/
8c7ffa6b468467d8bc4dc545fa7b8f61
css
CSS
1
2016-12-06T05:17:45
True
False
False
/api/public/snipt/9804/
css-round-corners
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nt">http</span><span class="o">://</span><span class="nt">snipplr</span><span class="nc">.com</span><span class="o">/</span><span class="nt">view</span><span class="o">/</span><span class="nt">830</span><span class="o">/</span><span class="nt">css-rounded-corners</span><span class="o">/</span> </span></pre></div> </td></tr></table>
corners, round
Copyrighted, illegal, or inappropriate content? Email [email protected].