snipt

Ctrl+h for KB shortcuts

Octave

Load OctaveForge packages only under Octave

if exist('OCTAVE_VERSION') ~= 0; pkg load odepkg optim; end 
https://snipt.net/embed/5a0ded235454055f654eee6cef2e348d/
/raw/5a0ded235454055f654eee6cef2e348d/
5a0ded235454055f654eee6cef2e348d
octave
Octave
1
2019-08-20T14:00:08
True
False
False
Aug 21, 2013 at 11:14 AM
/api/public/snipt/75956/
load-octaveforge-packages-only-under-octave
<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="k">if</span> <span class="nb">exist</span><span class="p">(</span><span class="s">&#39;OCTAVE_VERSION&#39;</span><span class="p">)</span> <span class="o">~=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">pkg</span> <span class="nb">load</span> <span class="n">odepkg</span> <span class="n">optim</span><span class="p">;</span> <span class="k">end</span> </span></pre></div> </td></tr></table>
octave

Bash

Use autocutsel to sync all clipboards per http://blog.nelhage.com/2008/09/autocutsel/

autocutsel -fork
autocutsel -selection PRIMARY -fork
https://snipt.net/embed/8626287627d9168d4782e5cb640a5aef/
/raw/8626287627d9168d4782e5cb640a5aef/
8626287627d9168d4782e5cb640a5aef
bash
Bash
2
2019-08-20T14:00:47
True
False
False
Mar 12, 2013 at 10:16 AM
/api/public/snipt/57480/
use-autocutsel-to-sync-all-clipboards-per-httpblognelhagecom200809autocutsel
<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>autocutsel -fork </span><span id="L-2"><a name="L-2"></a>autocutsel -selection PRIMARY -fork </span></pre></div> </td></tr></table>

Python

Continue only when running interactively in IPython

1
2
3
# Continue only when running interactively in IPython
try:              __IPYTHON__
except NameError: raise SystemExit, 0
https://snipt.net/embed/3f3ec65c21a8d51d10028a435c72e984/
/raw/3f3ec65c21a8d51d10028a435c72e984/
3f3ec65c21a8d51d10028a435c72e984
python
Python
4
2019-08-20T14:01:36
True
False
False
Jan 09, 2013 at 11:34 AM
/api/public/snipt/53034/
continue-only-when-running-interactively-in-ipython
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># Continue only when running interactively in IPython</span> </span><span id="L-2"><a name="L-2"></a><span class="k">try</span><span class="p">:</span> <span class="n">__IPYTHON__</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 class="k">raise</span> <span class="ne">SystemExit</span><span class="p">,</span> <span class="mi">0</span> </span></pre></div> </td></tr></table>
ipython, main

Python

Nicer __main__ idiom for Python

# Stop module loading when imported.  Otherwise continue running.
if __name__ != '__main__': raise SystemExit, 0
https://snipt.net/embed/e132f3e5878fda1cddb6f81739e8e208/
/raw/e132f3e5878fda1cddb6f81739e8e208/
e132f3e5878fda1cddb6f81739e8e208
python
Python
2
2019-08-20T14:02:09
True
False
False
Jan 09, 2013 at 11:18 AM
/api/public/snipt/53028/
nicer-__main__-idiom-for-python
<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><span class="c1"># Stop module loading when imported. Otherwise continue running.</span> </span><span id="L-2"><a name="L-2"></a><span class="k">if</span> <span class="n">__name__</span> <span class="o">!=</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span> <span class="k">raise</span> <span class="ne">SystemExit</span><span class="p">,</span> <span class="mi">0</span> </span></pre></div> </td></tr></table>
main