Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

HTML

AngularJS: ng-style with variable

<div ng-style="{'background-image': 'url(' + book.cover + ')'}"></div>
https://snipt.net/embed/f361a1f79ab16a484bede2fa39b7dc22/
https://snipt.net/raw/f361a1f79ab16a484bede2fa39b7dc22/
f361a1f79ab16a484bede2fa39b7dc22
html
HTML
1
2016-12-05T16:25:45
True
False
True
Jan 21, 2014 at 05:46 PM
/api/public/snipt/107609/
angularjs-ng-style-with-variable
<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></span><span id="L-1"><a name="L-1"></a><span class="p">&lt;</span><span class="nt">div</span> <span class="na">ng-style</span><span class="o">=</span><span class="s">&quot;{&#39;background-image&#39;: &#39;url(&#39; + book.cover + &#39;)&#39;}&quot;</span><span class="p">&gt;&lt;/</span><span class="nt">div</span><span class="p">&gt;</span> </span></pre></div> </td></tr></table>
angularjs, ng-style, variable

Python

How to test if a variable exists in Python?

1
2
3
4
5
6
try:
    print x
except NameError:
    x = 0
 
assert x == 0
https://snipt.net/embed/2ce366cbc6fa411fee4c53d9d527eacb/
https://snipt.net/raw/2ce366cbc6fa411fee4c53d9d527eacb/
2ce366cbc6fa411fee4c53d9d527eacb
python
Python
6
2016-12-05T12:40:36
True
False
False
Apr 20, 2013 at 07:23 PM
/api/public/snipt/59657/
how-to-test-if-a-variable-exists-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> <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="k">try</span><span class="p">:</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">print</span> <span class="n">x</span> </span><span id="L-3"><a name="L-3"></a><span class="k">except</span> <span class="ne">NameError</span><span class="p">:</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">x</span> <span class="o">=</span> <span class="mi">0</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="k">assert</span> <span class="n">x</span> <span class="o">==</span> <span class="mi">0</span> </span></pre></div> </td></tr></table>
python, variable

Ruby

Variable interpolation in Ruby

1
2
3
4
#Variable interpolation in Ruby

name = "Sam"
puts "Hello #{name}, please to meet you"
https://snipt.net/embed/42c9147d84f490ab3567b2d7a5476d53/
https://snipt.net/raw/42c9147d84f490ab3567b2d7a5476d53/
42c9147d84f490ab3567b2d7a5476d53
rb
Ruby
4
2016-12-05T12:43:00
True
False
False
/api/public/snipt/22860/
variable-interpolation-in-ruby
<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><span class="c1">#Variable interpolation in Ruby</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="nb">name</span> <span class="o">=</span> <span class="s2">&quot;Sam&quot;</span> </span><span id="L-4"><a name="L-4"></a><span class="nb">puts</span> <span class="s2">&quot;Hello </span><span class="si">#{</span><span class="nb">name</span><span class="si">}</span><span class="s2">, please to meet you&quot;</span> </span></pre></div> </td></tr></table>
interpolation, replace, ruby, variable

PHP

IP

1
2
3
4
5
6
7
<?

$ip = $_SERVER['REMOTE_ADDR'];

echo "Su dirección IP es: $ip";

?>
https://snipt.net/embed/26bf50f1b55c4acb0013e07d0669ef70/
https://snipt.net/raw/26bf50f1b55c4acb0013e07d0669ef70/
26bf50f1b55c4acb0013e07d0669ef70
php
PHP
7
2016-12-05T12:44:12
True
False
False
/api/public/snipt/15930/
ip-1
<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;?</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="nv">$ip</span> <span class="o">=</span> <span class="nv">$_SERVER</span><span class="p">[</span><span class="s1">&#39;REMOTE_ADDR&#39;</span><span class="p">];</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="k">echo</span> <span class="s2">&quot;Su dirección IP es: </span><span class="si">$ip</span><span class="s2">&quot;</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="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
ip, saber, server, variable

Python

Python syntax to set multiple variables to a single value on one line

1
2
3
4
5
6
# Sweet shortcut variable setting syntax
#
>>> price, count, unit = ("string",)*3
>>> print price, count, unit
string string string
>>> 
https://snipt.net/embed/adc7222e13bdb5e095e3a8dcc32a9528/
https://snipt.net/raw/adc7222e13bdb5e095e3a8dcc32a9528/
adc7222e13bdb5e095e3a8dcc32a9528
python
Python
7
2016-12-05T12:45:23
True
False
False
/api/public/snipt/2596/
python-syntax-to-set-multiple-variables-to-a-single-value-on-one-line
<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="c1"># Sweet shortcut variable setting syntax</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">#</span> </span><span id="L-3"><a name="L-3"></a><span class="o">&gt;&gt;&gt;</span> <span class="n">price</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="n">unit</span> <span class="o">=</span> <span class="p">(</span><span class="s2">&quot;string&quot;</span><span class="p">,)</span><span class="o">*</span><span class="mi">3</span> </span><span id="L-4"><a name="L-4"></a><span class="o">&gt;&gt;&gt;</span> <span class="k">print</span> <span class="n">price</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="n">unit</span> </span><span id="L-5"><a name="L-5"></a><span class="n">string</span> <span class="n">string</span> <span class="n">string</span> </span><span id="L-6"><a name="L-6"></a><span class="o">&gt;&gt;&gt;</span> </span></pre></div> </td></tr></table>
consol, equal, multiple, python, set, shortcut, to, variable
Copyrighted, illegal, or inappropriate content? Email [email protected].