snipt

Ctrl+h for KB shortcuts

Text only

JavaScript iFrame Buster

1
2
3
4
5
6
7
/*
Oftentimes you want to make sure your site isn't being IFRAME'd.  Sometimes it's for security reasons, other times it's so your site's content isn't being skimmed else, and other times it's...oh, who cares, you just want to do it.  Here's a short way to escape frames:
*/

if (top.location != self.location) {
    top.location = self.location.href;
}
https://snipt.net/embed/ec92d1593c098837461fbc10ed5230fe/
/raw/ec92d1593c098837461fbc10ed5230fe/
ec92d1593c098837461fbc10ed5230fe
text
Text only
7
2019-06-16T19:24:59
True
False
False
Feb 18, 2014 at 10:11 AM
/api/public/snipt/114762/
javascript-iframe-buster
<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><span id="L-2"><a name="L-2"></a>Oftentimes you want to make sure your site isn&#39;t being IFRAME&#39;d. Sometimes it&#39;s for security reasons, other times it&#39;s so your site&#39;s content isn&#39;t being skimmed else, and other times it&#39;s...oh, who cares, you just want to do it. Here&#39;s a short way to escape frames: </span><span id="L-3"><a name="L-3"></a>*/ </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>if (top.location != self.location) { </span><span id="L-6"><a name="L-6"></a> top.location = self.location.href; </span><span id="L-7"><a name="L-7"></a>} </span></pre></div> </td></tr></table>
js

MySQL

MYSQL insert random from list

1
2
3
4
5
INSERT INTO `im`
(`im`, `service`)
SELECT LOWER(`last`),
    ELT(0.5 + RAND() * 6, 'AIM', 'ICQ', 'MSN', 'Yahoo', 'GTalk', 'Other')
FROM `contact`
https://snipt.net/embed/8d58c72edaccf531a160855108a72482/
/raw/8d58c72edaccf531a160855108a72482/
8d58c72edaccf531a160855108a72482
mysql
MySQL
6
2019-06-12T02:05:13
True
False
False
Jan 09, 2014 at 04:42 PM
/api/public/snipt/104619/
mysql-insert-random-from-list
<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="k">INSERT</span> <span class="k">INTO</span> <span class="ss">`im`</span> </span><span id="L-2"><a name="L-2"></a><span class="p">(</span><span class="ss">`im`</span><span class="p">,</span> <span class="ss">`service`</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a><span class="k">SELECT</span> <span class="nf">LOWER</span><span class="p">(</span><span class="ss">`last`</span><span class="p">),</span> </span><span id="L-4"><a name="L-4"></a> <span class="nf">ELT</span><span class="p">(</span><span class="mi">0</span><span class="p">.</span><span class="mi">5</span> <span class="o">+</span> <span class="nf">RAND</span><span class="p">()</span> <span class="o">*</span> <span class="mi">6</span><span class="p">,</span> <span class="s1">&#39;AIM&#39;</span><span class="p">,</span> <span class="s1">&#39;ICQ&#39;</span><span class="p">,</span> <span class="s1">&#39;MSN&#39;</span><span class="p">,</span> <span class="s1">&#39;Yahoo&#39;</span><span class="p">,</span> <span class="s1">&#39;GTalk&#39;</span><span class="p">,</span> <span class="s1">&#39;Other&#39;</span><span class="p">)</span> </span><span id="L-5"><a name="L-5"></a><span class="k">FROM</span> <span class="ss">`contact`</span> </span></pre></div> </td></tr></table>
mysql

Text only

Transactions en Laravel 3

1
2
3
4
5
DB::transaction(function(){
    DB::query($sql_portada);
    DB::query($sql_404);
    DB::query($sql_generos);
});
https://snipt.net/embed/6a2db37f27fe3d4e036201e72b1a107e/
/raw/6a2db37f27fe3d4e036201e72b1a107e/
6a2db37f27fe3d4e036201e72b1a107e
text
Text only
5
2019-06-17T07:34:35
True
False
False
Dec 11, 2013 at 03:45 PM
/api/public/snipt/99902/
transactions-en-laravel-3
<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>DB::transaction(function(){ </span><span id="L-2"><a name="L-2"></a> DB::query($sql_portada); </span><span id="L-3"><a name="L-3"></a> DB::query($sql_404); </span><span id="L-4"><a name="L-4"></a> DB::query($sql_generos); </span><span id="L-5"><a name="L-5"></a>}); </span></pre></div> </td></tr></table>
laravel, pdo, php

MySQL

MySQL get missing IDs from table

1
2
3
4
5
6
7
8
SELECT a.id+1 AS start, MIN(b.id) - 1 AS end
FROM testtable AS a, testtable AS b
WHERE a.id < b.id
GROUP BY a.id
HAVING start < MIN(b.id)

-- http://stackoverflow.com/questions/12325132/mysql-get-missing-ids-from-table
-- http://www.codediesel.com/mysql/sequence-gaps-in-mysql/
https://snipt.net/embed/21272b09b0b86923c0a2890e893b1d9a/
/raw/21272b09b0b86923c0a2890e893b1d9a/
21272b09b0b86923c0a2890e893b1d9a
mysql
MySQL
8
2019-06-08T22:48:42
True
False
False
Nov 20, 2013 at 11:49 AM
/api/public/snipt/95552/
mysql-get-missing-ids-from-table
<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="k">SELECT</span> <span class="n">a</span><span class="p">.</span><span class="n">id</span><span class="o">+</span><span class="mi">1</span> <span class="k">AS</span> <span class="n">start</span><span class="p">,</span> <span class="nf">MIN</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">id</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span> <span class="k">AS</span> <span class="n">end</span> </span><span id="L-2"><a name="L-2"></a><span class="k">FROM</span> <span class="n">testtable</span> <span class="k">AS</span> <span class="n">a</span><span class="p">,</span> <span class="n">testtable</span> <span class="k">AS</span> <span class="n">b</span> </span><span id="L-3"><a name="L-3"></a><span class="k">WHERE</span> <span class="n">a</span><span class="p">.</span><span class="n">id</span> <span class="o">&lt;</span> <span class="n">b</span><span class="p">.</span><span class="n">id</span> </span><span id="L-4"><a name="L-4"></a><span class="k">GROUP</span> <span class="k">BY</span> <span class="n">a</span><span class="p">.</span><span class="n">id</span> </span><span id="L-5"><a name="L-5"></a><span class="k">HAVING</span> <span class="n">start</span> <span class="o">&lt;</span> <span class="nf">MIN</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">id</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="c1">-- http://stackoverflow.com/questions/12325132/mysql-get-missing-ids-from-table</span> </span><span id="L-8"><a name="L-8"></a><span class="c1">-- http://www.codediesel.com/mysql/sequence-gaps-in-mysql/</span> </span></pre></div> </td></tr></table>
mysql