snipt

Ctrl+h for KB shortcuts
#15345

Python console session

List all tables in psql

\dt
https://snipt.net/embed/7202740db49a14603f66d93814a8f5e8/
https://snipt.net/raw/7202740db49a14603f66d93814a8f5e8/
7202740db49a14603f66d93814a8f5e8
pycon
Python console session
1
2014-04-16T09:44:14
True
False
/api/public/snipt/15345/
list-all-tables-in-psql
<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="go">\dt</span> </span></pre></div> </td></tr></table>
database, postgresql, sql
#15312

Python console session

get temporary root access to a box using the python interpreter

sudo python -c "import os; os.system('bash');"
https://snipt.net/embed/86054cfbddd2191d94f51b0dda578ecd/
https://snipt.net/raw/86054cfbddd2191d94f51b0dda578ecd/
86054cfbddd2191d94f51b0dda578ecd
pycon
Python console session
1
2014-04-12T17:33:50
True
False
/api/public/snipt/15312/
get-temporary-root-access-to-a-box-using-the-python-interpreter
<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="go">sudo python -c &quot;import os; os.system(&#39;bash&#39;);&quot;</span> </span></pre></div> </td></tr></table>
bash, python
#12169

Python

A quick way to add ordinal suffixes to any number

def foo(n):
    str(n) + {1: 'st', 2: 'nd', 3: 'rd'}.get(4 if 10 <= n % 100 < 20 else n % 10, "th")
https://snipt.net/embed/54263725634cd602bfc62892f4ed543d/
https://snipt.net/raw/54263725634cd602bfc62892f4ed543d/
54263725634cd602bfc62892f4ed543d
python
Python
3
2014-04-16T08:46:39
True
False
/api/public/snipt/12169/
a-quick-way-to-add-ordinal-suffixes-to-any-number
<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 id="L-1"><a name="L-1"></a><span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">n</span><span class="p">):</span> </span><span id="L-2"><a name="L-2"></a> <span class="nb">str</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="o">+</span> <span class="p">{</span><span class="mi">1</span><span class="p">:</span> <span class="s">&#39;st&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">:</span> <span class="s">&#39;nd&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">:</span> <span class="s">&#39;rd&#39;</span><span class="p">}</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">4</span> <span class="k">if</span> <span class="mi">10</span> <span class="o">&lt;=</span> <span class="n">n</span> <span class="o">%</span> <span class="mi">100</span> <span class="o">&lt;</span> <span class="mi">20</span> <span class="k">else</span> <span class="n">n</span> <span class="o">%</span> <span class="mi">10</span><span class="p">,</span> <span class="s">&quot;th&quot;</span><span class="p">)</span> </span></pre></div> </td></tr></table>
ordinal, python, suffix