snipt

Ctrl+h for KB shortcuts

Bash

Backup mysql with date and time...

mysqldump -u user_name -p database > /path/to/backupfolder/database_backup_$(date +%Y-%m-%d-%H.%M.%S).sql
https://snipt.net/embed/3ec753bbeba4eee1f212b8d98ea5a6fe/
/raw/3ec753bbeba4eee1f212b8d98ea5a6fe/
3ec753bbeba4eee1f212b8d98ea5a6fe
bash
Bash
1
2019-07-10T16:24:30
True
False
False
Jan 22, 2013 at 11:35 AM
/api/public/snipt/54243/
backup-mysql-with-date-and-time
<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>mysqldump -u user_name -p database &gt; /path/to/backupfolder/database_backup_<span class="k">$(</span>date +%Y-%m-%d-%H.%M.%S<span class="k">)</span>.sql </span></pre></div> </td></tr></table>
"mysql backup", "mysql export"

MySQL

Take mysql backup and import (overwrite) existing database

source /path/to/file/file.sql;
https://snipt.net/embed/26d5737b8cd5a8235c7288ea4c68d8b7/
/raw/26d5737b8cd5a8235c7288ea4c68d8b7/
26d5737b8cd5a8235c7288ea4c68d8b7
mysql
MySQL
1
2019-07-10T00:01:45
True
False
False
/api/public/snipt/54242/
take-mysql-backup-and-import-overwrite-existing-database
<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="n">source</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="k">to</span><span class="o">/</span><span class="n">file</span><span class="o">/</span><span class="n">file</span><span class="p">.</span><span class="k">sql</span><span class="p">;</span> </span></pre></div> </td></tr></table>
"mysql import", mysql

Bash

Remote install wordpress via SSH

1
2
3
4
5
6
wget http://wordpress.org/latest.tar.gz
tar xfz latest.tar.gz
mv wordpress/* ./
rmdir ./wordpress/
rm -f latest.tar.gz
#then go do your install via the folder you have this in...
https://snipt.net/embed/b03bce9b650866da5f00ea5d5793b95a/
/raw/b03bce9b650866da5f00ea5d5793b95a/
b03bce9b650866da5f00ea5d5793b95a
bash
Bash
6
2019-07-18T17:30:35
True
False
False
Nov 28, 2012 at 04:20 PM
/api/public/snipt/50914/
remote-install-wordpress-via-ssh
<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>wget http://wordpress.org/latest.tar.gz </span><span id="L-2"><a name="L-2"></a>tar xfz latest.tar.gz </span><span id="L-3"><a name="L-3"></a>mv wordpress/* ./ </span><span id="L-4"><a name="L-4"></a>rmdir ./wordpress/ </span><span id="L-5"><a name="L-5"></a>rm -f latest.tar.gz </span><span id="L-6"><a name="L-6"></a><span class="c1">#then go do your install via the folder you have this in...</span> </span></pre></div> </td></tr></table>
SSH, wordpress

VimL

Regex find until next Quote

:job_title => "(.*?)", 
#this would match all instances of :job_title => "blah blah"
https://snipt.net/embed/159e33f89abcf85636b46db7477f32a6/
/raw/159e33f89abcf85636b46db7477f32a6/
159e33f89abcf85636b46db7477f32a6
vim
VimL
2
2019-07-20T01:44:58
True
False
False
Nov 26, 2012 at 06:45 PM
/api/public/snipt/50790/
regex-find-until-next-quote
<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="p">:</span>job_title <span class="p">=&gt;</span> <span class="s2">&quot;(.*?)&quot;</span><span class="p">,</span> </span><span id="L-2"><a name="L-2"></a>#this would <span class="k">match</span> <span class="k">all</span> instances of :job_title <span class="p">=&gt;</span> <span class="s2">&quot;blah blah&quot;</span> </span></pre></div> </td></tr></table>
regex, vim

Bash

Flush DNS in Mountain Lion

sudo killall -HUP mDNSResponder 
https://snipt.net/embed/ef1f0e1260e914ea90a69a91427ec43e/
/raw/ef1f0e1260e914ea90a69a91427ec43e/
ef1f0e1260e914ea90a69a91427ec43e
bash
Bash
2
2019-07-20T13:32:01
True
False
False
Aug 10, 2012 at 05:15 PM
/api/public/snipt/45531/
flush-dns-in-mountain-lion
<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 killall -HUP mDNSResponder </span></pre></div> </td></tr></table>
"mac os 10.8", flushdns

Ruby

Convert to local datetime in Ruby (and Rails)

1
2
3
#Assuming a local active record model named Lead...
lead.created_at.strftime("%m/%d/%y %l:%M %p")
#outputs this as 07/07/12  6:04 PM
https://snipt.net/embed/41ff922a9adb08fe295ac63eceb8516f/
/raw/41ff922a9adb08fe295ac63eceb8516f/
41ff922a9adb08fe295ac63eceb8516f
rb
Ruby
3
2019-07-20T07:54:55
True
False
False
Jul 21, 2012 at 10:34 PM
/api/public/snipt/44278/
convert-to-local-datetime-in-ruby-and-rails
<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">#Assuming a local active record model named Lead...</span> </span><span id="L-2"><a name="L-2"></a><span class="n">lead</span><span class="o">.</span><span class="n">created_at</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;%m/%d/%y %l:%M %p&quot;</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a><span class="c1">#outputs this as 07/07/12 6:04 PM</span> </span></pre></div> </td></tr></table>
date_format, datetime, rails, ruby

Bash

SCP (secure copy) file from local machine to remote server over SSH

scp /local-file/folder/name.zip [email protected]:path-to-post-too/subfolder/
https://snipt.net/embed/caf9a9fd1a7a1e3fa7ff1616bd01af69/
/raw/caf9a9fd1a7a1e3fa7ff1616bd01af69/
caf9a9fd1a7a1e3fa7ff1616bd01af69
bash
Bash
1
2019-07-19T03:56:12
True
False
False
/api/public/snipt/42328/
scp-secure-copy-file-from-local-machine-to-remote-server-over-ssh
<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>scp /local-file/folder/name.zip [email protected]:path-to-post-too/subfolder/ </span></pre></div> </td></tr></table>
bash, scp, ssh
https://snipt.net/embed/f01ee94b4d460dcc68dc89102c4eb77f/
/raw/f01ee94b4d460dcc68dc89102c4eb77f/
f01ee94b4d460dcc68dc89102c4eb77f
bash
Bash
1
2019-07-09T10:35:19
True
False
False
/api/public/snipt/41995/
shutdown-rails-webrick-server-locally-running-outside-of-console
<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>killall -9 ruby </span></pre></div> </td></tr></table>
rails, webrick

Bash

zip up a directory on linux

zip -r archive_name.zip directory_to_compress
https://snipt.net/embed/492a3ef716b400919af5177a3b08880b/
/raw/492a3ef716b400919af5177a3b08880b/
492a3ef716b400919af5177a3b08880b
bash
Bash
2
2019-07-10T09:55:25
True
False
False
/api/public/snipt/37663/
zip-up-a-directory-on-linux
<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>zip -r archive_name.zip directory_to_compress </span></pre></div> </td></tr></table>
bash, linux, terminal, zip

MySQL

mysql add new user

GRANT ALL PRIVILEGES ON *.* TO 'user_name'@'localhost'
IDENTIFIED BY 'password' WITH GRANT OPTION;
https://snipt.net/embed/53f476428018303e2f9e0a20734d7542/
/raw/53f476428018303e2f9e0a20734d7542/
53f476428018303e2f9e0a20734d7542
mysql
MySQL
2
2019-07-08T06:03:01
True
False
False
/api/public/snipt/37443/
mysql-add-new-user
<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="k">GRANT</span> <span class="k">ALL</span> <span class="n">PRIVILEGES</span> <span class="k">ON</span> <span class="o">*</span><span class="p">.</span><span class="o">*</span> <span class="k">TO</span> <span class="s1">&#39;user_name&#39;</span><span class="o">@</span><span class="s1">&#39;localhost&#39;</span> </span><span id="L-2"><a name="L-2"></a><span class="n">IDENTIFIED</span> <span class="k">BY</span> <span class="s1">&#39;password&#39;</span> <span class="k">WITH</span> <span class="k">GRANT</span> <span class="k">OPTION</span><span class="p">;</span> </span></pre></div> </td></tr></table>
"new user", bash, mysql