snipt

Ctrl+h for KB shortcuts

JavaScript

Show mouse position

1
2
3
4
5
document.onmousemove = function(e){
var x = e.pageX;
var y = e.pageY;
e.target.title = "X is "+x+" and Y is "+y;
};
https://snipt.net/embed/3fab55f3265b101be9d17e61bfc020be/
https://snipt.net/raw/3fab55f3265b101be9d17e61bfc020be/
3fab55f3265b101be9d17e61bfc020be
js
JavaScript
5
2016-09-22T00:48:08
True
False
False
Mar 20, 2014 at 05:41 AM
/api/public/snipt/123302/
show-mouse-position
<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 id="L-1"><a name="L-1"></a><span class="nb">document</span><span class="p">.</span><span class="nx">onmousemove</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span> </span><span id="L-2"><a name="L-2"></a><span class="kd">var</span> <span class="nx">x</span> <span class="o">=</span> <span class="nx">e</span><span class="p">.</span><span class="nx">pageX</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="kd">var</span> <span class="nx">y</span> <span class="o">=</span> <span class="nx">e</span><span class="p">.</span><span class="nx">pageY</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="nx">e</span><span class="p">.</span><span class="nx">target</span><span class="p">.</span><span class="nx">title</span> <span class="o">=</span> <span class="s2">&quot;X is &quot;</span><span class="o">+</span><span class="nx">x</span><span class="o">+</span><span class="s2">&quot; and Y is &quot;</span><span class="o">+</span><span class="nx">y</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">};</span> </span></pre></div> </td></tr></table>
absolute, coordinates, mouse, position

CSS

Center with Position Absolute

1
2
3
4
5
6
7
#div_to_centre{
    width: 400px;
    position: absolute;
    top: What you want;
    left: 50%;
    margin-left: -200px; /* half of the with (400px) */
}
https://snipt.net/embed/55e0ddc1d1ee00e82d9622f027fe0bf5/
https://snipt.net/raw/55e0ddc1d1ee00e82d9622f027fe0bf5/
55e0ddc1d1ee00e82d9622f027fe0bf5
css
CSS
8
2016-09-23T23:26:34
True
False
False
Oct 02, 2013 at 09:30 AM
/api/public/snipt/84550/
center-with-position-absolute
<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 id="L-1"><a name="L-1"></a><span class="nf">#div_to_centre</span><span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">width</span><span class="o">:</span> <span class="m">400px</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">position</span><span class="o">:</span> <span class="k">absolute</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">top</span><span class="o">:</span> <span class="n">What</span> <span class="n">you</span> <span class="n">want</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">left</span><span class="o">:</span> <span class="m">50%</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a> <span class="k">margin-left</span><span class="o">:</span> <span class="m">-200px</span><span class="p">;</span> <span class="c">/* half of the with (400px) */</span> </span><span id="L-7"><a name="L-7"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
"css position", absolute, center

PHP

Rutas absolutas en Wordpress

<?php echo site_url(); ?>
https://snipt.net/embed/c86faf70aacebd4f5afed270463d14c1/
https://snipt.net/raw/c86faf70aacebd4f5afed270463d14c1/
c86faf70aacebd4f5afed270463d14c1
php
PHP
1
2016-09-25T07:57:43
True
False
False
/api/public/snipt/43092/
rutas-absolutas-en-wordpress
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nx">site_url</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
absolute, ruta, wordpress

Python

absolute directory path in python

1
2
3
4
5
# Find current directory
DIR_ROOT = os.path.dirname(os.path.abspath(__file__))

# Absolute path for subfolder(s)
LOG_ROOT = os.path.join(DIR_ROOT, 'logs')
https://snipt.net/embed/c0504f2f7c262bc718291e7c9f59bc9e/
https://snipt.net/raw/c0504f2f7c262bc718291e7c9f59bc9e/
c0504f2f7c262bc718291e7c9f59bc9e
python
Python
5
2016-09-22T02:25:44
True
False
False
/api/public/snipt/12842/
absolute-directory-path-in-python
<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 id="L-1"><a name="L-1"></a><span class="c"># Find current directory</span> </span><span id="L-2"><a name="L-2"></a><span class="n">DIR_ROOT</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">__file__</span><span class="p">))</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c"># Absolute path for subfolder(s)</span> </span><span id="L-5"><a name="L-5"></a><span class="n">LOG_ROOT</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">DIR_ROOT</span><span class="p">,</span> <span class="s">&#39;logs&#39;</span><span class="p">)</span> </span></pre></div> </td></tr></table>
absolute, directory, os.path, path, python

PHP

PHP Absolute Server Address

<?php $domain = 'http://www.'.$_SERVER["SERVER_NAME"]; ?>
https://snipt.net/embed/3399f6bb63ba3a8d1b29bb653d36268d/
https://snipt.net/raw/3399f6bb63ba3a8d1b29bb653d36268d/
3399f6bb63ba3a8d1b29bb653d36268d
php
PHP
1
2016-09-22T05:38:07
True
False
False
/api/public/snipt/6101/
php-absolute-server-address
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="nv">$domain</span> <span class="o">=</span> <span class="s1">&#39;http://www.&#39;</span><span class="o">.</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">&quot;SERVER_NAME&quot;</span><span class="p">];</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
absolute, domain, php, server
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.