snipt

Ctrl+h for KB shortcuts

PHP

Create an array with all query string params

1
2
3
4
5
6
$input_string = explode('&', $_SERVER["QUERY_STRING"]);

foreach ($input_string as $string_value) {
    $item = explode('=', $string_value);
    $input_array[$item[0]] = $item[1];
}
https://snipt.net/embed/bf5f396d2357d38cd8a41392efcc5fd8/
/raw/bf5f396d2357d38cd8a41392efcc5fd8/
bf5f396d2357d38cd8a41392efcc5fd8
php
PHP
6
2019-06-24T00:54:07
True
False
False
Mar 20, 2013 at 07:41 AM
/api/public/snipt/57993/
create-an-array-with-all-query-string-params
<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><span class="x">$input_string = explode(&#39;&amp;&#39;, $_SERVER[&quot;QUERY_STRING&quot;]);</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="x">foreach ($input_string as $string_value) {</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> $item = explode(&#39;=&#39;, $string_value);</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> $input_array[$item[0]] = $item[1];</span> </span><span id="L-6"><a name="L-6"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
"query string", arguments, parameters

Text only

Youtube parameters to force video quality

1
2
3
4
5
6
Append the following parameters to the Youtube-URL:

240p: &vq=small 
360p: &vq=medium 
480p: &vq=large 
720p: &vq=hd720 
https://snipt.net/embed/6d8ea372f2eefbc28414d0980af79b42/
/raw/6d8ea372f2eefbc28414d0980af79b42/
6d8ea372f2eefbc28414d0980af79b42
text
Text only
6
2016-12-27T13:47:37
True
False
True
Feb 07, 2013 at 06:50 AM
/api/public/snipt/55351/
youtube-parameters-to-force-video-quality
<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>Append the following parameters to the Youtube-URL: </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>240p: &amp;vq=small </span><span id="L-4"><a name="L-4"></a>360p: &amp;vq=medium </span><span id="L-5"><a name="L-5"></a>480p: &amp;vq=large </span><span id="L-6"><a name="L-6"></a>720p: &amp;vq=hd720 </span></pre></div> </td></tr></table>
embed, quality, youtube

Text only

.htaccess allowing access from one IP only

1
2
3
4
order deny, allow
deny from all
allow from a.b.d.c
# Where a.b.c.d is the allowed IP
https://snipt.net/embed/9d0210f5e69feb4b316ade61882efb03/
/raw/9d0210f5e69feb4b316ade61882efb03/
9d0210f5e69feb4b316ade61882efb03
text
Text only
4
2019-06-19T17:52:31
True
False
False
/api/public/snipt/48588/
htaccess-allowing-access-from-one-ip-only
<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>order deny, allow </span><span id="L-2"><a name="L-2"></a>deny from all </span><span id="L-3"><a name="L-3"></a>allow from a.b.d.c </span><span id="L-4"><a name="L-4"></a># Where a.b.c.d is the allowed IP </span></pre></div> </td></tr></table>
.htaccess, server, web

Bash

Reset git repo to last commit

git reset HEAD --hard
git clean -fd
https://snipt.net/embed/67db1d0c1247a58258f9e01787738035/
/raw/67db1d0c1247a58258f9e01787738035/
67db1d0c1247a58258f9e01787738035
bash
Bash
2
2019-06-25T09:58:32
True
False
False
Sep 05, 2012 at 04:35 AM
/api/public/snipt/46710/
reset-git-repo-to-last-commit
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>git reset HEAD --hard </span><span id="L-2"><a name="L-2"></a>git clean -fd </span></pre></div> </td></tr></table>
commit, git, reset

JavaScript

Adjust Youtube embeds to correct ratio

1
2
3
4
5
/* Remind to delete all width & height inline references on embed code */

//var ratio = 3/4;
var ratio = 9/16;
$(".youtube > iframe").height($(".youtube > iframe").width() * ratio);
https://snipt.net/embed/5285ded976edb025f5acd9bfd03acf21/
/raw/5285ded976edb025f5acd9bfd03acf21/
5285ded976edb025f5acd9bfd03acf21
js
JavaScript
5
2019-06-20T02:30:12
True
False
False
Aug 08, 2012 at 06:20 AM
/api/public/snipt/45374/
adjust-youtube-embeds-to-correct-ratio
<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="cm">/* Remind to delete all width &amp; height inline references on embed code */</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c1">//var ratio = 3/4;</span> </span><span id="L-4"><a name="L-4"></a><span class="kd">var</span> <span class="nx">ratio</span> <span class="o">=</span> <span class="mi">9</span><span class="o">/</span><span class="mi">16</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;.youtube &gt; iframe&quot;</span><span class="p">).</span><span class="nx">height</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;.youtube &gt; iframe&quot;</span><span class="p">).</span><span class="nx">width</span><span class="p">()</span> <span class="o">*</span> <span class="nx">ratio</span><span class="p">);</span> </span></pre></div> </td></tr></table>
jquery, ratio, youtube

JavaScript

Javascript device detection

1
2
3
4
5
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
	// Do something on devices
} else {
	// Do something on laptop
}
https://snipt.net/embed/9b93a8a4c26172cb121e0f065b9d53b5/
/raw/9b93a8a4c26172cb121e0f065b9d53b5/
9b93a8a4c26172cb121e0f065b9d53b5
js
JavaScript
5
2019-06-23T06:48:15
True
False
False
/api/public/snipt/45291/
jquery-device-detection
<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">if</span><span class="p">(</span> <span class="sr">/Android|webOS|iPhone|iPad|iPod|BlackBerry/i</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">navigator</span><span class="p">.</span><span class="nx">userAgent</span><span class="p">)</span> <span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="c1">// Do something on devices</span> </span><span id="L-3"><a name="L-3"></a><span class="p">}</span> <span class="k">else</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="c1">// Do something on laptop</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
devices, mobile