Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Python

Import with try

1
2
3
4
5
try:
    import BeautifulSoup
except ImportError:
    print 'Import not installed'
    sys.exit()
https://snipt.net/embed/a9d61db0750077f415f432dc688590ab/
https://snipt.net/raw/a9d61db0750077f415f432dc688590ab/
a9d61db0750077f415f432dc688590ab
python
Python
5
2016-12-07T12:15:00
True
False
False
Aug 04, 2012 at 08:26 AM
/api/public/snipt/45132/
import-with-try
<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="k">try</span><span class="p">:</span> </span><span id="L-2"><a name="L-2"></a> <span class="kn">import</span> <span class="nn">BeautifulSoup</span> </span><span id="L-3"><a name="L-3"></a><span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">print</span> <span class="s1">&#39;Import not installed&#39;</span> </span><span id="L-5"><a name="L-5"></a> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">()</span> </span></pre></div> </td></tr></table>
catch, errors, import, python, try

Text only

Import database from file

mysql -u username -p -h chuabiet.com databaseName < /path/to/database.sql
mysql -u username -p databaseName < /path/to/database.sql # localhost
https://snipt.net/embed/05591dc893d6835a7498e629c5d15801/
https://snipt.net/raw/05591dc893d6835a7498e629c5d15801/
05591dc893d6835a7498e629c5d15801
text
Text only
2
2016-12-07T19:16:02
True
False
False
/api/public/snipt/28918/
import-database-from-file
<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>mysql -u username -p -h chuabiet.com databaseName &lt; /path/to/database.sql </span><span id="L-2"><a name="L-2"></a>mysql -u username -p databaseName &lt; /path/to/database.sql # localhost </span></pre></div> </td></tr></table>
import, mysql

Bash

Import database as bz2 in MySQL

bunzip2 < my_database.sql.bz2 | mysql -h localhost -u root -p my_database
https://snipt.net/embed/d573c7db45b8611369552f1e2d714797/
https://snipt.net/raw/d573c7db45b8611369552f1e2d714797/
d573c7db45b8611369552f1e2d714797
bash
Bash
1
2016-12-09T13:01:55
True
False
False
/api/public/snipt/25091/
import-database-as-bz2-in-mysql
<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>bunzip2 &lt; my_database.sql.bz2 <span class="p">|</span> mysql -h localhost -u root -p my_database </span></pre></div> </td></tr></table>
bz2, import, mysql

SQL

mysql file into db

mysql -p -h DBSERVER dbname < dbname.sql
https://snipt.net/embed/13853083a708e55b35cd78695bdd5b32/
https://snipt.net/raw/13853083a708e55b35cd78695bdd5b32/
13853083a708e55b35cd78695bdd5b32
sql
SQL
2
2016-12-08T05:41:52
True
False
False
/api/public/snipt/17681/
mysql-file-into-db
<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">mysql</span> <span class="o">-</span><span class="n">p</span> <span class="o">-</span><span class="n">h</span> <span class="n">DBSERVER</span> <span class="n">dbname</span> <span class="o">&lt;</span> <span class="n">dbname</span><span class="p">.</span><span class="k">sql</span> </span></pre></div> </td></tr></table>
dump, import, mysql

MySQL

Import CSV data into mysql table

1
2
3
4
5
6
7
8
load data infile '/var/lib/mysql/your_db/yourcsv.csv' into table magento_orders
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
// if csv exported from linux - use lines terminated by '\n'
// if csv exported from windows use lines terminated by '\r\n'
// if csv exported from mac - use lines terminated by '\r'
(OrderDate,ShippingState,ShippingStateName,ShippingCountry,ShippingCountryName,ItemName,ItemOptions,ItemQtyOrdered)
https://snipt.net/embed/38a111f635185e6302190f57cd525175/
https://snipt.net/raw/38a111f635185e6302190f57cd525175/
38a111f635185e6302190f57cd525175
mysql
MySQL
8
2016-12-09T05:14:03
True
False
False
/api/public/snipt/17582/
import-csv-data-into-mysql-table
<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> <a href="#L-7">7</a> <a href="#L-8">8</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">load</span> <span class="n">data</span> <span class="k">infile</span> <span class="s1">&#39;/var/lib/mysql/your_db/yourcsv.csv&#39;</span> <span class="k">into</span> <span class="k">table</span> <span class="n">magento_orders</span> </span><span id="L-2"><a name="L-2"></a><span class="n">fields</span> <span class="k">terminated</span> <span class="k">by</span> <span class="s1">&#39;,&#39;</span> </span><span id="L-3"><a name="L-3"></a><span class="k">enclosed</span> <span class="k">by</span> <span class="s1">&#39;&quot;&#39;</span> </span><span id="L-4"><a name="L-4"></a><span class="k">lines</span> <span class="k">terminated</span> <span class="k">by</span> <span class="s1">&#39;\n&#39;</span> </span><span id="L-5"><a name="L-5"></a><span class="o">//</span> <span class="k">if</span> <span class="n">csv</span> <span class="n">exported</span> <span class="k">from</span> <span class="n">linux</span> <span class="o">-</span> <span class="k">use</span> <span class="k">lines</span> <span class="k">terminated</span> <span class="k">by</span> <span class="s1">&#39;\n&#39;</span> </span><span id="L-6"><a name="L-6"></a><span class="o">//</span> <span class="k">if</span> <span class="n">csv</span> <span class="n">exported</span> <span class="k">from</span> <span class="n">windows</span> <span class="k">use</span> <span class="k">lines</span> <span class="k">terminated</span> <span class="k">by</span> <span class="s1">&#39;\r\n&#39;</span> </span><span id="L-7"><a name="L-7"></a><span class="o">//</span> <span class="k">if</span> <span class="n">csv</span> <span class="n">exported</span> <span class="k">from</span> <span class="n">mac</span> <span class="o">-</span> <span class="k">use</span> <span class="k">lines</span> <span class="k">terminated</span> <span class="k">by</span> <span class="s1">&#39;\r&#39;</span> </span><span id="L-8"><a name="L-8"></a><span class="p">(</span><span class="n">OrderDate</span><span class="p">,</span><span class="n">ShippingState</span><span class="p">,</span><span class="n">ShippingStateName</span><span class="p">,</span><span class="n">ShippingCountry</span><span class="p">,</span><span class="n">ShippingCountryName</span><span class="p">,</span><span class="n">ItemName</span><span class="p">,</span><span class="n">ItemOptions</span><span class="p">,</span><span class="n">ItemQtyOrdered</span><span class="p">)</span> </span></pre></div> </td></tr></table>
csv, data, import, mysql

Text only

gpg key import

1
2
3
4
5
6
7
8
MySQL.com, you must first import and register their public GPG key:

   1. Download public key named [email protected] from http://www.keyserver.net/ with one of two methods:
          * wget --output-document=pubkey_mysql.asc http://keyserver.veridis.com:11371/export?id=-8326718950139043339
            (Saves key 0x5072E1F5 as file pubkey_mysql.asc)
          * gpg --keyserver keyserver.veridis.com --recv-key 5072e1f5
            gpg --export -a 5072e1f5 > pubkey_mysql.asc 
   2. Import key: rpm --import pubkey_mysql.asc 
https://snipt.net/embed/045bf903920fe2d9f906897d0ced6b34/
https://snipt.net/raw/045bf903920fe2d9f906897d0ced6b34/
045bf903920fe2d9f906897d0ced6b34
text
Text only
8
2016-12-07T17:40:31
True
False
False
/api/public/snipt/15974/
gpg-key-import
<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> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>MySQL.com, you must first import and register their public GPG key: </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a> 1. Download public key named [email protected] from http://www.keyserver.net/ with one of two methods: </span><span id="L-4"><a name="L-4"></a> * wget --output-document=pubkey_mysql.asc http://keyserver.veridis.com:11371/export?id=-8326718950139043339 </span><span id="L-5"><a name="L-5"></a> (Saves key 0x5072E1F5 as file pubkey_mysql.asc) </span><span id="L-6"><a name="L-6"></a> * gpg --keyserver keyserver.veridis.com --recv-key 5072e1f5 </span><span id="L-7"><a name="L-7"></a> gpg --export -a 5072e1f5 &gt; pubkey_mysql.asc </span><span id="L-8"><a name="L-8"></a> 2. Import key: rpm --import pubkey_mysql.asc </span></pre></div> </td></tr></table>
gpg, import, key
Copyrighted, illegal, or inappropriate content? Email [email protected].