snipt

Ctrl+h for KB shortcuts

Python 3

file extension or '' if there is not one

(filename.rsplit('.', 1)[1:] or [''])[0]
https://snipt.net/embed/40b58c25e7bbf0de7eec7f7edc2b64bf/
/raw/40b58c25e7bbf0de7eec7f7edc2b64bf/
40b58c25e7bbf0de7eec7f7edc2b64bf
python3
Python 3
1
2019-08-22T23:39:53
True
False
False
/api/public/snipt/5369/
file-extension-or-if-there-is-not-one
<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">(</span><span class="n">filename</span><span class="o">.</span><span class="n">rsplit</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]</span> <span class="ow">or</span> <span class="p">[</span><span class="s1">&#39;&#39;</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span> </span></pre></div> </td></tr></table>
extension, file, python

Python 3

date from iso date string

1
2
3
4
5
6
from datetime import date
from time import strptime

...
date(*strptime('2009-03-28', '%Y-%m-%d')[:3])
...
https://snipt.net/embed/01b319b2eb3f0af63746a93bd69b44d9/
/raw/01b319b2eb3f0af63746a93bd69b44d9/
01b319b2eb3f0af63746a93bd69b44d9
python3
Python 3
6
2019-08-24T16:26:14
True
False
False
/api/public/snipt/4549/
date-from-iso-date-string
<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="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">date</span> </span><span id="L-2"><a name="L-2"></a><span class="kn">from</span> <span class="nn">time</span> <span class="k">import</span> <span class="n">strptime</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="o">...</span> </span><span id="L-5"><a name="L-5"></a><span class="n">date</span><span class="p">(</span><span class="o">*</span><span class="n">strptime</span><span class="p">(</span><span class="s1">&#39;2009-03-28&#39;</span><span class="p">,</span> <span class="s1">&#39;%Y-%m-</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)[:</span><span class="mi">3</span><span class="p">])</span> </span><span id="L-6"><a name="L-6"></a><span class="o">...</span> </span></pre></div> </td></tr></table>
date, python

INI

reasonable mysqld default on Ubuntu

1
2
3
4
#this should become /etc/mysql/conf.d/django.cnf
[mysqld]
default-character-set=utf8
default-storage-engine=innodb
https://snipt.net/embed/11e375a52ebc2a17b39df4b69e1a9bb5/
/raw/11e375a52ebc2a17b39df4b69e1a9bb5/
11e375a52ebc2a17b39df4b69e1a9bb5
ini
INI
6
2019-08-23T03:42:21
True
False
False
/api/public/snipt/3247/
reasonable-mysqld-default-on-ubuntu
<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">#this should become /etc/mysql/conf.d/django.cnf</span> </span><span id="L-2"><a name="L-2"></a><span class="k">[mysqld]</span> </span><span id="L-3"><a name="L-3"></a><span class="na">default-character-set</span><span class="o">=</span><span class="s">utf8</span> </span><span id="L-4"><a name="L-4"></a><span class="na">default-storage-engine</span><span class="o">=</span><span class="s">innodb</span> </span></pre></div> </td></tr></table>
configuration, defaults, mysql, ubuntu

Python 3

convert to uppercase in medit

1
2
3
4
5
6
buf = window.get_active_doc().get_buffer()
start, end = buf.get_selection_bounds()
if start:
    selection = buf.get_text(start, end)
    buf.delete_selection(True, True)
    buf.insert_at_cursor(selection.upper())
https://snipt.net/embed/df0da5cb7f35c38c95cb40d5a4927c7f/
/raw/df0da5cb7f35c38c95cb40d5a4927c7f/
df0da5cb7f35c38c95cb40d5a4927c7f
python3
Python 3
7
2019-08-24T04:34:52
True
False
False
/api/public/snipt/3237/
convert-to-uppercase-in-medit
<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="n">buf</span> <span class="o">=</span> <span class="n">window</span><span class="o">.</span><span class="n">get_active_doc</span><span class="p">()</span><span class="o">.</span><span class="n">get_buffer</span><span class="p">()</span> </span><span id="L-2"><a name="L-2"></a><span class="n">start</span><span class="p">,</span> <span class="n">end</span> <span class="o">=</span> <span class="n">buf</span><span class="o">.</span><span class="n">get_selection_bounds</span><span class="p">()</span> </span><span id="L-3"><a name="L-3"></a><span class="k">if</span> <span class="n">start</span><span class="p">:</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">selection</span> <span class="o">=</span> <span class="n">buf</span><span class="o">.</span><span class="n">get_text</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> </span><span id="L-5"><a name="L-5"></a> <span class="n">buf</span><span class="o">.</span><span class="n">delete_selection</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span> </span><span id="L-6"><a name="L-6"></a> <span class="n">buf</span><span class="o">.</span><span class="n">insert_at_cursor</span><span class="p">(</span><span class="n">selection</span><span class="o">.</span><span class="n">upper</span><span class="p">())</span> </span></pre></div> </td></tr></table>
medit, script