Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

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/
https://snipt.net/raw/97045465de6acb2481341d25e5854f3e/
97045465de6acb2481341d25e5854f3e
js
JavaScript
3
2016-12-07T06:09:13
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

Making Cross Browser Functions

1
2
3
4
5
6
7
8
 var getMyText = function(myDiv) {
    getMyText =
        myDiv.innerText !== undefined ? // innerText not supported in FF
       &nbsp;    function(myDiv) {return myDiv.innerText} :
            function(myDiv) {return myDiv.textContent};

    return getMyText(myDiv);
}
https://snipt.net/embed/24d1a45a338ec296f38e229cf1ccc8be/
https://snipt.net/raw/24d1a45a338ec296f38e229cf1ccc8be/
24d1a45a338ec296f38e229cf1ccc8be
js
JavaScript
8
2016-12-02T20:27:58
True
False
False
/api/public/snipt/35322/
making-cross-browser-functions
<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> <a href="#L-7">7</a> <a href="#L-8">8</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">getMyText</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">myDiv</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">getMyText</span> <span class="o">=</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">myDiv</span><span class="p">.</span><span class="nx">innerText</span> <span class="o">!==</span> <span class="kc">undefined</span> <span class="o">?</span> <span class="c1">// innerText not supported in FF</span> </span><span id="L-4"><a name="L-4"></a> <span class="o">&amp;</span><span class="nx">nbsp</span><span class="p">;</span> <span class="kd">function</span><span class="p">(</span><span class="nx">myDiv</span><span class="p">)</span> <span class="p">{</span><span class="k">return</span> <span class="nx">myDiv</span><span class="p">.</span><span class="nx">innerText</span><span class="p">}</span> <span class="o">:</span> </span><span id="L-5"><a name="L-5"></a> <span class="kd">function</span><span class="p">(</span><span class="nx">myDiv</span><span class="p">)</span> <span class="p">{</span><span class="k">return</span> <span class="nx">myDiv</span><span class="p">.</span><span class="nx">textContent</span><span class="p">};</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a> <span class="k">return</span> <span class="nx">getMyText</span><span class="p">(</span><span class="nx">myDiv</span><span class="p">);</span> </span><span id="L-8"><a name="L-8"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
javascript, tips, tricks

Text only

Eclipse exclude folders from search (eg. target folder)

1
2
3
4
5
6
Create a working set with the folders you want to include in the search:

    * Open Search dialog (ctrl+h)
    * Change search scope to Working Set
    * Click Choose ...
    * Click New to create a new Working Set with the what you want searched (or Add All and then remove the ones you want filtered)
https://snipt.net/embed/e5bf634088ef87c732ffd817938ed4d6/
https://snipt.net/raw/e5bf634088ef87c732ffd817938ed4d6/
e5bf634088ef87c732ffd817938ed4d6
text
Text only
7
2016-12-08T17:08:30
True
False
False
/api/public/snipt/22298/
eclipse-exclude-folders-from-search-eg-target-folder
<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>Create a working set with the folders you want to include in the search: </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a> * Open Search dialog (ctrl+h) </span><span id="L-4"><a name="L-4"></a> * Change search scope to Working Set </span><span id="L-5"><a name="L-5"></a> * Click Choose ... </span><span id="L-6"><a name="L-6"></a> * Click New to create a new Working Set with the what you want searched (or Add All and then remove the ones you want filtered) </span></pre></div> </td></tr></table>
eclipse, tips

PHP

add a msg in wp admin..

1
2
3
4
5
6
7
<?php
function my_admin_msg($text) {
		$text="hi..";
		echo '<div id="update-nag">'.$text.'</div>';
}
add_action( 'admin_notices', 'my_admin_msg', 4 );
?>
https://snipt.net/embed/948c4162151c821182877722ba69b4c1/
https://snipt.net/raw/948c4162151c821182877722ba69b4c1/
948c4162151c821182877722ba69b4c1
php
PHP
8
2016-12-10T08:27:49
True
False
False
/api/public/snipt/12270/
add-a-msg-in-wp-admin
<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> <a href="#L-7">7</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 class="k">function</span> <span class="nf">my_admin_msg</span><span class="p">(</span><span class="nv">$text</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$text</span><span class="o">=</span><span class="s2">&quot;hi..&quot;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">echo</span> <span class="s1">&#39;&lt;div id=&quot;update-nag&quot;&gt;&#39;</span><span class="o">.</span><span class="nv">$text</span><span class="o">.</span><span class="s1">&#39;&lt;/div&gt;&#39;</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span><span id="L-6"><a name="L-6"></a><span class="nx">add_action</span><span class="p">(</span> <span class="s1">&#39;admin_notices&#39;</span><span class="p">,</span> <span class="s1">&#39;my_admin_msg&#39;</span><span class="p">,</span> <span class="mi">4</span> <span class="p">);</span> </span><span id="L-7"><a name="L-7"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
code, tips, wordpress
Copyrighted, illegal, or inappropriate content? Email [email protected].