snipt

Ctrl+h for KB shortcuts

Python

read and print data from a file (2.5+)

1
2
3
4
5
from __future__ import with_statement

with open('filename') as fp:
    data = fp.read()
print data
https://snipt.net/embed/309fd04dc9673925833c713076cfaf95/
/raw/309fd04dc9673925833c713076cfaf95/
309fd04dc9673925833c713076cfaf95
python
Python
5
2019-05-24T22:37:42
True
False
False
/api/public/snipt/238/
read-and-print-data-from-a-file
<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></span><span id="L-1"><a name="L-1"></a><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">with_statement</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s1">&#39;filename&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">data</span> <span class="o">=</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> </span><span id="L-5"><a name="L-5"></a><span class="k">print</span> <span class="n">data</span> </span></pre></div> </td></tr></table>
python

Text only

recursively remove directories/files

get-childitem C:\your-directory -include .svn -recurse -force | foreach ($_) { remove-item $_.fullname -recurse -force}
https://snipt.net/embed/0efc0887be92922f55c722d00e7d9024/
/raw/0efc0887be92922f55c722d00e7d9024/
0efc0887be92922f55c722d00e7d9024
text
Text only
1
2019-06-10T04:43:59
True
False
False
/api/public/snipt/237/
recursively-remove-directoriesfiles
<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>get-childitem C:\your-directory -include .svn -recurse -force | foreach ($_) { remove-item $_.fullname -recurse -force} </span></pre></div> </td></tr></table>
powershell, windows

HTML

google chart API "hello world" pie

1
2
3
4
5
6
<img src="http://chart.apis.google.com/chart?
chs=250x100
&amp;chd=t:60,40
&amp;cht=p3
&amp;chl=Hello|World"
alt="Sample chart" />
https://snipt.net/embed/195dd2568c6897e6b605c0e33eb934dc/
/raw/195dd2568c6897e6b605c0e33eb934dc/
195dd2568c6897e6b605c0e33eb934dc
html
HTML
6
2019-06-15T21:27:55
True
False
False
/api/public/snipt/232/
google-chart-api-hello-world-pie
<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="p">&lt;</span><span class="nt">img</span> <span class="na">src</span><span class="o">=</span><span class="s">&quot;http://chart.apis.google.com/chart?</span> </span><span id="L-2"><a name="L-2"></a><span class="s">chs=250x100</span> </span><span id="L-3"><a name="L-3"></a><span class="s">&amp;amp;chd=t:60,40</span> </span><span id="L-4"><a name="L-4"></a><span class="s">&amp;amp;cht=p3</span> </span><span id="L-5"><a name="L-5"></a><span class="s">&amp;amp;chl=Hello|World&quot;</span> </span><span id="L-6"><a name="L-6"></a><span class="na">alt</span><span class="o">=</span><span class="s">&quot;Sample chart&quot;</span> <span class="p">/&gt;</span> </span></pre></div> </td></tr></table>
charts, helloworld

Bash

reload apache's configurations on a MediaTemple 3.0 DV

/usr/local/psa/admin/sbin/websrvmng -a -v
https://snipt.net/embed/7595dfed87147627dfc575a211bc1cdf/
/raw/7595dfed87147627dfc575a211bc1cdf/
7595dfed87147627dfc575a211bc1cdf
bash
Bash
1
2019-06-16T22:05:29
True
False
False
/api/public/snipt/229/
reload-apaches-configurations-on-a-mediatemple-30-dv
<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>/usr/local/psa/admin/sbin/websrvmng -a -v </span></pre></div> </td></tr></table>
mediatemple

Bash

add newlines to one-line xml string

sed 's/\(<\/[a-zA-Z0-9]*>\)/\1\
/g'
https://snipt.net/embed/ef54209ac6189b5143e415f98ea033e0/
/raw/ef54209ac6189b5143e415f98ea033e0/
ef54209ac6189b5143e415f98ea033e0
bash
Bash
2
2019-06-12T11:26:18
True
False
False
/api/public/snipt/217/
add-newlines-to-one-line-xml-string
<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>sed <span class="s1">&#39;s/\(&lt;\/[a-zA-Z0-9]*&gt;\)/\1\</span> </span><span id="L-2"><a name="L-2"></a><span class="s1">/g&#39;</span> </span></pre></div> </td></tr></table>
bash, newline, sed, xml

Bash

Add all files marked as '?'

svn status |grep '^?' |sed 's/^?      /svn add "/g' |sed 's/$/"/g' |sh
https://snipt.net/embed/f9f5bfa0d39c724b60f27b7dda0a0650/
/raw/f9f5bfa0d39c724b60f27b7dda0a0650/
f9f5bfa0d39c724b60f27b7dda0a0650
bash
Bash
1
2019-06-16T09:10:28
True
False
False
/api/public/snipt/209/
add-all-files-marked-as
<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>svn status <span class="p">|</span>grep <span class="s1">&#39;^?&#39;</span> <span class="p">|</span>sed <span class="s1">&#39;s/^? /svn add &quot;/g&#39;</span> <span class="p">|</span>sed <span class="s1">&#39;s/$/&quot;/g&#39;</span> <span class="p">|</span>sh </span></pre></div> </td></tr></table>
svn

Bash

Delete all files marked as '!'

svn status |grep '^!' |sed 's/^!      /svn delete "/g' |sed 's/$/"/g' |sh
https://snipt.net/embed/38bb1c28d1998e0357ef01c799027a61/
/raw/38bb1c28d1998e0357ef01c799027a61/
38bb1c28d1998e0357ef01c799027a61
bash
Bash
1
2019-06-13T06:49:32
True
False
False
/api/public/snipt/208/
delete-all-files-marked-as
<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>svn status <span class="p">|</span>grep <span class="s1">&#39;^!&#39;</span> <span class="p">|</span>sed <span class="s1">&#39;s/^! /svn delete &quot;/g&#39;</span> <span class="p">|</span>sed <span class="s1">&#39;s/$/&quot;/g&#39;</span> <span class="p">|</span>sh </span></pre></div> </td></tr></table>
svn

Bash

raid drives status check

mdadm --query --detail /dev/md1
https://snipt.net/embed/24ab27e4c5e18f6957d22cf3c8a19515/
/raw/24ab27e4c5e18f6957d22cf3c8a19515/
24ab27e4c5e18f6957d22cf3c8a19515
bash
Bash
1
2019-06-17T22:55:47
True
False
False
/api/public/snipt/180/
raid-drives-status-check
<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>mdadm --query --detail /dev/md1 </span></pre></div> </td></tr></table>
raid

Bash

cisco vpn client restart on mac os x

sudo /System/Library/StartupItems/CiscoVPN/CiscoVPN restart
https://snipt.net/embed/0ce68bbb0af1d55101b5e808fe12c772/
/raw/0ce68bbb0af1d55101b5e808fe12c772/
0ce68bbb0af1d55101b5e808fe12c772
bash
Bash
1
2019-06-13T06:50:37
True
False
False
/api/public/snipt/135/
cisco-vpn-client-restart-on-mac-os-x
<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>sudo /System/Library/StartupItems/CiscoVPN/CiscoVPN restart </span></pre></div> </td></tr></table>
cisco, osx, vpn