snipt

Ctrl+h for KB shortcuts

JavaScript

Change initial page state based on location.hash

1
2
3
4
5
6
$(function() {
	// Hash state determination
	if (location.hash && location.hash != "") {
		$('a[href$="'+location.hash+'"]').click();
	}
});
https://snipt.net/embed/6dc1eb95da7421f98aa8ba196994977e/
/raw/6dc1eb95da7421f98aa8ba196994977e/
6dc1eb95da7421f98aa8ba196994977e
js
JavaScript
6
2019-07-08T02:26:31
True
False
False
/api/public/snipt/5784/
change-initial-page-state-based-on-locationhash
<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="nx">$</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="c1">// Hash state determination</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">if</span> <span class="p">(</span><span class="nx">location</span><span class="p">.</span><span class="nx">hash</span> <span class="o">&amp;&amp;</span> <span class="nx">location</span><span class="p">.</span><span class="nx">hash</span> <span class="o">!=</span> <span class="s2">&quot;&quot;</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;a[href$=&quot;&#39;</span><span class="o">+</span><span class="nx">location</span><span class="p">.</span><span class="nx">hash</span><span class="o">+</span><span class="s1">&#39;&quot;]&#39;</span><span class="p">).</span><span class="nx">click</span><span class="p">();</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">}</span> </span><span id="L-6"><a name="L-6"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
javascript, jquery, state

Bash

Drop all tables from PostgreSQL DB without superuser

1
2
3
4
5
6
7
psql -t -d my_dbname -c "SELECT 'DROP TABLE ' || n.nspname || '.' ||
c.relname || ' CASCADE;' FROM pg_catalog.pg_class AS c LEFT JOIN
pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE relkind =
'r' AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND
pg_catalog.pg_table_is_visible(c.oid)" >/tmp/droptables

psql -d my_dbname -f /tmp/droptables
https://snipt.net/embed/d4e3c9b96cbc3fd791b8ee43a7edb971/
/raw/d4e3c9b96cbc3fd791b8ee43a7edb971/
d4e3c9b96cbc3fd791b8ee43a7edb971
bash
Bash
7
2019-07-18T10:42:22
True
False
False
/api/public/snipt/5372/
drop-all-tables-from-postgresql-db-without-superuser
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>psql -t -d my_dbname -c <span class="s2">&quot;SELECT &#39;DROP TABLE &#39; || n.nspname || &#39;.&#39; ||</span> </span><span id="L-2"><a name="L-2"></a><span class="s2">c.relname || &#39; CASCADE;&#39; FROM pg_catalog.pg_class AS c LEFT JOIN</span> </span><span id="L-3"><a name="L-3"></a><span class="s2">pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE relkind =</span> </span><span id="L-4"><a name="L-4"></a><span class="s2">&#39;r&#39; AND n.nspname NOT IN (&#39;pg_catalog&#39;, &#39;pg_toast&#39;) AND</span> </span><span id="L-5"><a name="L-5"></a><span class="s2">pg_catalog.pg_table_is_visible(c.oid)&quot;</span> &gt;/tmp/droptables </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a>psql -d my_dbname -f /tmp/droptables </span></pre></div> </td></tr></table>
bash, db, postgresql