snipt

Ctrl+h for KB shortcuts

Bash

rails add column to table

$ rails generate migration AddEmailColumnToUsers email:string
https://snipt.net/embed/486ebd44a665eb3ca87e8157e4987864/
https://snipt.net/raw/486ebd44a665eb3ca87e8157e4987864/
486ebd44a665eb3ca87e8157e4987864
bash
Bash
1
2016-09-29T11:13:15
True
False
False
Apr 18, 2013 at 02:40 AM
/api/public/snipt/59484/
rails-add-column-to-table
<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 id="L-1"><a name="L-1"></a><span class="nv">$ </span>rails generate migration AddEmailColumnToUsers email:string </span></pre></div> </td></tr></table>
bash, database, postgresql, rails, ruby, sqlite

Ruby

ruby > sqlite > escape string for insert

# this converts single ' quotes to double '' which sqlite treats as single o__O
mystring.gsub(/\\/, '\&\&').gsub(/'/, "''")
https://snipt.net/embed/b98d4881a5ebe77e80d50bea7b91a262/
https://snipt.net/raw/b98d4881a5ebe77e80d50bea7b91a262/
b98d4881a5ebe77e80d50bea7b91a262
rb
Ruby
3
2016-09-29T07:49:53
True
False
False
Apr 11, 2013 at 01:00 AM
/api/public/snipt/59111/
ruby-sqlite-escape-string-for-insert
<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 id="L-1"><a name="L-1"></a><span class="c1"># this converts single &#39; quotes to double &#39;&#39; which sqlite treats as single o__O</span> </span><span id="L-2"><a name="L-2"></a><span class="n">mystring</span><span class="o">.</span><span class="n">gsub</span><span class="p">(</span><span class="sr">/\\/</span><span class="p">,</span> <span class="s1">&#39;\&amp;\&amp;&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">gsub</span><span class="p">(</span><span class="sr">/&#39;/</span><span class="p">,</span> <span class="s2">&quot;&#39;&#39;&quot;</span><span class="p">)</span> </span></pre></div> </td></tr></table>
ruby, sqlite, sqlite3

Text only

Display Column Titles SQLite3

1
2
3
4
5
sqlite> .mode column
sqlite> .headers on

.mode column
.headers on
https://snipt.net/embed/22eb8c30597897f28f33ab8b87d09f47/
https://snipt.net/raw/22eb8c30597897f28f33ab8b87d09f47/
22eb8c30597897f28f33ab8b87d09f47
text
Text only
5
2016-09-30T10:22:26
True
False
False
/api/public/snipt/38757/
-66
<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 id="L-1"><a name="L-1"></a>sqlite&gt; .mode column </span><span id="L-2"><a name="L-2"></a>sqlite&gt; .headers on </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a>.mode column </span><span id="L-5"><a name="L-5"></a>.headers on </span></pre></div> </td></tr></table>
"column headers", "display columns", "pretty print", column, sqlite, sqlite3

Bash

build postfix + sqlite + sasl + ssl

1
2
3
4
5
6
7
8
# download Cyrus SASL (SQLite3 requires >= 2.1.24)
wget http://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.24rc1.tar.gz

# configure Cyrus
./configure --enable-plain --enable-login --enable-sql --with-configdir=/etc/postfix/sasl/

# configure Postfix for SQLite3 and SASL support
make -f Makefile.init makefiles 'CCARGS=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -DUSE_TLS -DHAS_SQLITE -I/usr/local/include -I/usr/local/include/sasl' 'AUXLIBS=-L/usr/local/lib -lsasl2 -lssl -lcrypto -lsqlite3 -lpthread'
https://snipt.net/embed/4aea3542888fb5400230e47b78bc7168/
https://snipt.net/raw/4aea3542888fb5400230e47b78bc7168/
4aea3542888fb5400230e47b78bc7168
bash
Bash
8
2016-09-30T08:26:00
True
False
False
/api/public/snipt/29242/
postfix-build
<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 id="L-1"><a name="L-1"></a><span class="c"># download Cyrus SASL (SQLite3 requires &gt;= 2.1.24)</span> </span><span id="L-2"><a name="L-2"></a>wget http://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.24rc1.tar.gz </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c"># configure Cyrus</span> </span><span id="L-5"><a name="L-5"></a>./configure --enable-plain --enable-login --enable-sql --with-configdir<span class="o">=</span>/etc/postfix/sasl/ </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="c"># configure Postfix for SQLite3 and SASL support</span> </span><span id="L-8"><a name="L-8"></a>make -f Makefile.init makefiles <span class="s1">&#39;CCARGS=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -DUSE_TLS -DHAS_SQLITE -I/usr/local/include -I/usr/local/include/sasl&#39;</span> <span class="s1">&#39;AUXLIBS=-L/usr/local/lib -lsasl2 -lssl -lcrypto -lsqlite3 -lpthread&#39;</span> </span></pre></div> </td></tr></table>
postfix, sasl, sqlite, ssl

SQL

This query shows each time spent on ticket 10346 in minutes

1
2
3
4
SELECT a.name, f.description, start_time, (strftime('%s', end_time)-strftime('%s', start_time))/60 
FROM facts f 
    INNER JOIN activities a ON a.id = f.activity_id 
WHERE a.name LIKE '%10346%';
https://snipt.net/embed/f0eb6e4b004291e93019e26f96768a1a/
https://snipt.net/raw/f0eb6e4b004291e93019e26f96768a1a/
f0eb6e4b004291e93019e26f96768a1a
sql
SQL
4
2016-09-29T03:59:23
True
False
False
/api/public/snipt/15082/
this-query-shows-each-time-spent-on-ticket-10346-in-minutes
<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 id="L-1"><a name="L-1"></a><span class="k">SELECT</span> <span class="n">a</span><span class="p">.</span><span class="n">name</span><span class="p">,</span> <span class="n">f</span><span class="p">.</span><span class="n">description</span><span class="p">,</span> <span class="n">start_time</span><span class="p">,</span> <span class="p">(</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%s&#39;</span><span class="p">,</span> <span class="n">end_time</span><span class="p">)</span><span class="o">-</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%s&#39;</span><span class="p">,</span> <span class="n">start_time</span><span class="p">))</span><span class="o">/</span><span class="mi">60</span> </span><span id="L-2"><a name="L-2"></a><span class="k">FROM</span> <span class="n">facts</span> <span class="n">f</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">INNER</span> <span class="k">JOIN</span> <span class="n">activities</span> <span class="n">a</span> <span class="k">ON</span> <span class="n">a</span><span class="p">.</span><span class="n">id</span> <span class="o">=</span> <span class="n">f</span><span class="p">.</span><span class="n">activity_id</span> </span><span id="L-4"><a name="L-4"></a><span class="k">WHERE</span> <span class="n">a</span><span class="p">.</span><span class="n">name</span> <span class="k">LIKE</span> <span class="s1">&#39;%10346%&#39;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
hamster, project, sqlite

Bash

Vacuum the Firefox DB

1
2
3
4
# First change the working directory to you profile directory:
# cd ~/.mozilla/firefox/<your_profile_dir>/

for i in *.sqlite; do echo "VACUUM;" | sqlite3 $i ; done
https://snipt.net/embed/b250257102f53a62febbf14c96224006/
https://snipt.net/raw/b250257102f53a62febbf14c96224006/
b250257102f53a62febbf14c96224006
bash
Bash
4
2016-09-30T13:28:39
True
False
False
/api/public/snipt/14702/
vacuum-the-firefox-db
<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 id="L-1"><a name="L-1"></a><span class="c"># First change the working directory to you profile directory:</span> </span><span id="L-2"><a name="L-2"></a><span class="c"># cd ~/.mozilla/firefox/&lt;your_profile_dir&gt;/</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="k">for</span> i in *.sqlite<span class="p">;</span> <span class="k">do</span> <span class="nb">echo</span> <span class="s2">&quot;VACUUM;&quot;</span> <span class="p">|</span> sqlite3 <span class="nv">$i</span> <span class="p">;</span> <span class="k">done</span> </span></pre></div> </td></tr></table>
firefox, sqlite, vacuum
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.