snipt

Ctrl+h for KB shortcuts

PHP

export class visually with reflection

1
2
3
4
<?php

// example of exporting ArrayAccess built-in class
Reflection::export(new ReflectionClass('ArrayAccess'));
https://snipt.net/embed/46fd9b21f4a5264880d2533e66d353ec/
/raw/46fd9b21f4a5264880d2533e66d353ec/
46fd9b21f4a5264880d2533e66d353ec
php
PHP
4
2019-07-12T18:53:11
True
False
False
Mar 26, 2014 at 09:37 AM
/api/public/snipt/124962/
export-class-visually-with-reflection
<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="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c1">// example of exporting ArrayAccess built-in class</span> </span><span id="L-4"><a name="L-4"></a><span class="nx">Reflection</span><span class="o">::</span><span class="na">export</span><span class="p">(</span><span class="k">new</span> <span class="nx">ReflectionClass</span><span class="p">(</span><span class="s1">&#39;ArrayAccess&#39;</span><span class="p">));</span> </span></pre></div> </td></tr></table>

JavaScript

Using length to truncate arrary

1
2
3
var foo = [1, 2, 3, 4, 5, 6];
foo.length = 3;
foo; // [1, 2, 3]
https://snipt.net/embed/97045465de6acb2481341d25e5854f3e/
/raw/97045465de6acb2481341d25e5854f3e/
97045465de6acb2481341d25e5854f3e
js
JavaScript
3
2019-07-19T12:53:00
True
False
False
/api/public/snipt/35775/
using-length-to-truncate-arrary
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="nx">foo</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">];</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">foo</span><span class="p">.</span><span class="nx">length</span> <span class="o">=</span> <span class="mi">3</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="nx">foo</span><span class="p">;</span> <span class="c1">// [1, 2, 3]</span> </span></pre></div> </td></tr></table>
javascript, tips, tricks

JavaScript

Quick way to round a number

1
2
3
4
console.log( 104.249834 | 0 ); //104
console.log( 9.999999 | 0 );   // 9

// bitwise operators operators call ToInt32 on each expression to be evaluated
https://snipt.net/embed/01ba65a86688ec64b5927b87b2d139eb/
/raw/01ba65a86688ec64b5927b87b2d139eb/
01ba65a86688ec64b5927b87b2d139eb
js
JavaScript
4
2019-07-22T09:52:07
True
False
False
/api/public/snipt/35404/
quick-way-to-round-a-number
<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="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span> <span class="mf">104.249834</span> <span class="o">|</span> <span class="mi">0</span> <span class="p">);</span> <span class="c1">//104</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span> <span class="mf">9.999999</span> <span class="o">|</span> <span class="mi">0</span> <span class="p">);</span> <span class="c1">// 9</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c1">// bitwise operators operators call ToInt32 on each expression to be evaluated</span> </span></pre></div> </td></tr></table>
javascript