Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

JavaScript

Inject jQuery into Chrome console

1
2
3
4
5
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type.
jQuery.noConflict();
https://snipt.net/embed/f550f796f2c31b07a2a64f57e29ca03d/
https://snipt.net/raw/f550f796f2c31b07a2a64f57e29ca03d/
f550f796f2c31b07a2a64f57e29ca03d
js
JavaScript
5
2016-12-05T02:59:27
True
False
False
Apr 04, 2016 at 02:09 PM
/api/public/snipt/145151/
inject-jquery-into-chrome-console
<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></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">jq</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s1">&#39;script&#39;</span><span class="p">);</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">jq</span><span class="p">.</span><span class="nx">src</span> <span class="o">=</span> <span class="s2">&quot;https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js&quot;</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s1">&#39;head&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">].</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">jq</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="c1">// ... give time for script to load, then type.</span> </span><span id="L-5"><a name="L-5"></a><span class="nx">jQuery</span><span class="p">.</span><span class="nx">noConflict</span><span class="p">();</span> </span></pre></div> </td></tr></table>
Chrome, jQuery, javascript

JavaScript

Wait for array of Deferred (Promises) in jQuery

1
2
3
4
5
var arrayOfDeferredObjects = [ $.ajax('someUrl'), ... ];

$.when.apply($, arrayOfDeferredObjects).then(function() {
    // Do my stuff
});
https://snipt.net/embed/8847e05d1e792920607343481f042ef0/
https://snipt.net/raw/8847e05d1e792920607343481f042ef0/
8847e05d1e792920607343481f042ef0
js
JavaScript
5
2016-12-04T10:54:44
True
False
False
May 30, 2014 at 02:25 AM
/api/public/snipt/135203/
wait-for-array-of-deferred-promises-in-jquery-71f7153e
<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></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">arrayOfDeferredObjects</span> <span class="o">=</span> <span class="p">[</span> <span class="nx">$</span><span class="p">.</span><span class="nx">ajax</span><span class="p">(</span><span class="s1">&#39;someUrl&#39;</span><span class="p">),</span> <span class="p">...</span> <span class="p">];</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="nx">$</span><span class="p">.</span><span class="nx">when</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nx">$</span><span class="p">,</span> <span class="nx">arrayOfDeferredObjects</span><span class="p">).</span><span class="nx">then</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="c1">// Do my stuff</span> </span><span id="L-5"><a name="L-5"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
Deferred, Promise, array, jQuery, wait
Copyrighted, illegal, or inappropriate content? Email [email protected].