Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Bash

find and delete files older than 15 minutes

$ find /path/to/files/*.json -type f -mmin +15 -delete
https://snipt.net/embed/526b8c150780e8fd47ad7b0adaac0e65/
https://snipt.net/raw/526b8c150780e8fd47ad7b0adaac0e65/
526b8c150780e8fd47ad7b0adaac0e65
bash
Bash
1
2016-12-07T06:39:46
True
False
False
/api/public/snipt/137461/
find-and-delete-files-older-than-15-minutes-e01e1c63
<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>$ find /path/to/files/*.json -type f -mmin +15 -delete </span></pre></div> </td></tr></table>
bash, delete, find, linux

PHP

PDO: Delete

1
2
3
4
5
6
<?php
$stmt = $db->prepare("DELETE FROM table WHERE id=:id");
$stmt->bindValue(':id', $id, PDO::PARAM_STR);
$stmt->execute();
$affected_rows = $stmt->rowCount();
?>
https://snipt.net/embed/d3266a244df1f38eac02526f4a93d918/
https://snipt.net/raw/d3266a244df1f38eac02526f4a93d918/
d3266a244df1f38eac02526f4a93d918
php
PHP
6
2016-12-04T14:00:07
True
False
False
/api/public/snipt/53144/
pdo-delete
<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="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$stmt</span> <span class="o">=</span> <span class="nv">$db</span><span class="o">-&gt;</span><span class="na">prepare</span><span class="p">(</span><span class="s2">&quot;DELETE FROM table WHERE id=:id&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">bindValue</span><span class="p">(</span><span class="s1">&#39;:id&#39;</span><span class="p">,</span> <span class="nv">$id</span><span class="p">,</span> <span class="nx">PDO</span><span class="o">::</span><span class="na">PARAM_STR</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">execute</span><span class="p">();</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$affected_rows</span> <span class="o">=</span> <span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">rowCount</span><span class="p">();</span> </span><span id="L-6"><a name="L-6"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"prepared statements", PDO, delete

Bash

find and delete files older than 5 days

1
2
3
4
5
$ find /path/to/files* -mtime +5 -exec rm {} \;

 
 
 
https://snipt.net/embed/6ba81578b80504eebccf9cbbef117b26/
https://snipt.net/raw/6ba81578b80504eebccf9cbbef117b26/
6ba81578b80504eebccf9cbbef117b26
bash
Bash
5
2016-12-03T23:57:24
True
False
False
/api/public/snipt/49835/
find-and-delete-files-older-than-5-days
<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>$ find /path/to/files* -mtime +5 -exec rm <span class="o">{}</span> <span class="se">\;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> </span></pre></div> </td></tr></table>
delete, find, linux, rm, time, ubuntu, unix

Bash

Remove files from repository

1
2
3
4
git filter-branch --index-filter 'git rm --cached --ignore-unmatch *.mat' HEAD
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git prune
https://snipt.net/embed/74ac4602972211e2a14e81771e12ec12/
https://snipt.net/raw/74ac4602972211e2a14e81771e12ec12/
74ac4602972211e2a14e81771e12ec12
bash
Bash
4
2016-12-05T03:27:29
True
False
False
/api/public/snipt/26793/
remove-files-from-repository
<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>git filter-branch --index-filter <span class="s1">&#39;git rm --cached --ignore-unmatch *.mat&#39;</span> HEAD </span><span id="L-2"><a name="L-2"></a>git <span class="k">for</span>-each-ref --format<span class="o">=</span><span class="s2">&quot;%(refname)&quot;</span> refs/original/ <span class="p">|</span> xargs -n <span class="m">1</span> git update-ref -d </span><span id="L-3"><a name="L-3"></a>git reflog expire --expire<span class="o">=</span>now --all </span><span id="L-4"><a name="L-4"></a>git prune </span></pre></div> </td></tr></table>
delete, git

Bash

delete mysql schema

mysqladmin -u root -p drop <schema_name>
https://snipt.net/embed/09b508817215f659596df4ee26bedd31/
https://snipt.net/raw/09b508817215f659596df4ee26bedd31/
09b508817215f659596df4ee26bedd31
bash
Bash
1
2016-12-06T18:12:59
True
False
False
/api/public/snipt/6419/
delete-mysql-schema
<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>mysqladmin -u root -p drop &lt;schema_name&gt; </span></pre></div> </td></tr></table>
bash, delete, drop, mysql, schema
Copyrighted, illegal, or inappropriate content? Email [email protected].