snipt

Ctrl+h for KB shortcuts

JavaScript

Pad numbers to fixed places

1
2
3
4
function zeroPad(num, places) {
    var zero = places - num.toString().length + 1;
    return Array(+(zero > 0 && zero)).join("0") + num;
}
https://snipt.net/embed/e7ba08b4a2a6ccb74e3f6633346c8e18/
/raw/e7ba08b4a2a6ccb74e3f6633346c8e18/
e7ba08b4a2a6ccb74e3f6633346c8e18
js
JavaScript
4
2019-06-13T17:42:00
True
False
False
/api/public/snipt/107386/
pad-numbers-to-fixed-places
<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></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">zeroPad</span><span class="p">(</span><span class="nx">num</span><span class="p">,</span> <span class="nx">places</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">zero</span> <span class="o">=</span> <span class="nx">places</span> <span class="o">-</span> <span class="nx">num</span><span class="p">.</span><span class="nx">toString</span><span class="p">().</span><span class="nx">length</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="nb">Array</span><span class="p">(</span><span class="o">+</span><span class="p">(</span><span class="nx">zero</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="nx">zero</span><span class="p">)).</span><span class="nx">join</span><span class="p">(</span><span class="s2">&quot;0&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="nx">num</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
js, number, pad, places

SQL

Get Facebook's places nearby

SELECT page_id, name, description, latitude, longitude, checkin_count, distance(latitude, longitude, '24.746296265934', '121.74880073232') FROM place WHERE distance(latitude, longitude, '24.746296265934', '121.74880073232') < 1000
https://snipt.net/embed/4505b8e2a8be1ede10b0b2f9372bae12/
/raw/4505b8e2a8be1ede10b0b2f9372bae12/
4505b8e2a8be1ede10b0b2f9372bae12
sql
SQL
1
2019-06-14T02:08:40
True
False
False
/api/public/snipt/31272/
get-facebooks-places-nearby
<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="k">SELECT</span> <span class="n">page_id</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">description</span><span class="p">,</span> <span class="n">latitude</span><span class="p">,</span> <span class="n">longitude</span><span class="p">,</span> <span class="n">checkin_count</span><span class="p">,</span> <span class="n">distance</span><span class="p">(</span><span class="n">latitude</span><span class="p">,</span> <span class="n">longitude</span><span class="p">,</span> <span class="s1">&#39;24.746296265934&#39;</span><span class="p">,</span> <span class="s1">&#39;121.74880073232&#39;</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">place</span> <span class="k">WHERE</span> <span class="n">distance</span><span class="p">(</span><span class="n">latitude</span><span class="p">,</span> <span class="n">longitude</span><span class="p">,</span> <span class="s1">&#39;24.746296265934&#39;</span><span class="p">,</span> <span class="s1">&#39;121.74880073232&#39;</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1000</span> </span></pre></div> </td></tr></table>
checkin, facebook, fql, places