snipt

Ctrl+h for KB shortcuts

PHP

Using the l() function example Drupal

print l($update_link, 'node/add/update/'.$view->args[0], array('html' => TRUE, 'query' => array('destination' => 'node/'.$view->args[0]),'attributes' => array('class'=>'add-update')));
https://snipt.net/embed/d32259abcd88298236a1f2be66a8269d/
/raw/d32259abcd88298236a1f2be66a8269d/
d32259abcd88298236a1f2be66a8269d
php
PHP
1
2019-06-22T04:35:26
True
False
False
/api/public/snipt/88481/
using-the-l-function-example-drupal
<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="x">print l($update_link, &#39;node/add/update/&#39;.$view-&gt;args[0], array(&#39;html&#39; =&gt; TRUE, &#39;query&#39; =&gt; array(&#39;destination&#39; =&gt; &#39;node/&#39;.$view-&gt;args[0]),&#39;attributes&#39; =&gt; array(&#39;class&#39;=&gt;&#39;add-update&#39;)));</span> </span></pre></div> </td></tr></table>
drupal, php

MySQL

Disable drupal securepages after importing db

UPDATE variable SET value = 's:1:"0";' WHERE name = 'securepages_enable';
https://snipt.net/embed/06dada149801ea162d92481a0bd62304/
/raw/06dada149801ea162d92481a0bd62304/
06dada149801ea162d92481a0bd62304
mysql
MySQL
1
2019-06-23T06:49:34
True
False
False
Oct 18, 2013 at 06:31 AM
/api/public/snipt/88480/
disable-drupal-securepages-after-importing-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="k">UPDATE</span> <span class="n">variable</span> <span class="kt">SET</span> <span class="n">value</span> <span class="o">=</span> <span class="s1">&#39;s:1:&quot;0&quot;;&#39;</span> <span class="k">WHERE</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;securepages_enable&#39;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
db, drupal, mysql

PHP

Read in a csv file

1
2
3
4
5
6
$file = fopen('/var/www/mycsv.csv', 'r');
print '<pre>';
while (($line = fgetcsv($file,1000, ";")) !== FALSE) {
  //$line is an array of the csv elements
  print_r($line);
}
https://snipt.net/embed/96959093c7f8879b25c5434eb60c2f50/
/raw/96959093c7f8879b25c5434eb60c2f50/
96959093c7f8879b25c5434eb60c2f50
php
PHP
6
2019-06-13T06:12:24
True
False
False
/api/public/snipt/88479/
read-in-a-csv-file
<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="x">$file = fopen(&#39;/var/www/mycsv.csv&#39;, &#39;r&#39;);</span> </span><span id="L-2"><a name="L-2"></a><span class="x">print &#39;&lt;pre&gt;&#39;;</span> </span><span id="L-3"><a name="L-3"></a><span class="x">while (($line = fgetcsv($file,1000, &quot;;&quot;)) !== FALSE) {</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> //$line is an array of the csv elements</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> print_r($line);</span> </span><span id="L-6"><a name="L-6"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
php

Bash

Move files with a specific string to another folder

find -maxdepth 1 | grep '.pem' | xargs -I {} mv {} backups/
https://snipt.net/embed/60b7f517744d77123b9c38210ea02014/
/raw/60b7f517744d77123b9c38210ea02014/
60b7f517744d77123b9c38210ea02014
bash
Bash
2
2019-06-22T16:32:04
True
False
False
Oct 18, 2013 at 06:24 AM
/api/public/snipt/88476/
move-files-with-a-specific-string-to-another-folder
<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 -maxdepth <span class="m">1</span> <span class="p">|</span> grep <span class="s1">&#39;.pem&#39;</span> <span class="p">|</span> xargs -I <span class="o">{}</span> mv <span class="o">{}</span> backups/ </span></pre></div> </td></tr></table>
linux

Bash

Remove all files with certain string

find -maxdepth 1 | grep '.tar.gz' | xargs rm -f
https://snipt.net/embed/e71f31ff261d13069680453f0845e985/
/raw/e71f31ff261d13069680453f0845e985/
e71f31ff261d13069680453f0845e985
bash
Bash
1
2019-06-10T00:44:10
True
False
False
Oct 18, 2013 at 06:23 AM
/api/public/snipt/88475/
remove-all-files-with-certain-string
<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 -maxdepth <span class="m">1</span> <span class="p">|</span> grep <span class="s1">&#39;.tar.gz&#39;</span> <span class="p">|</span> xargs rm -f </span></pre></div> </td></tr></table>
linux

Bash

Linux - kill processes which have a certain string

sudo kill `ps -ef | grep my_search_term | grep -v grep | awk '{print $2}'`
https://snipt.net/embed/29140a4ac71becfc546981a34bcc1ca0/
/raw/29140a4ac71becfc546981a34bcc1ca0/
29140a4ac71becfc546981a34bcc1ca0
bash
Bash
2
2019-06-08T05:09:02
True
False
False
Oct 18, 2013 at 06:21 AM
/api/public/snipt/88473/
linux-kill-processes-which-have-a-certain-string
<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 <span class="nb">kill</span> <span class="sb">`</span>ps -ef <span class="p">|</span> grep my_search_term <span class="p">|</span> grep -v grep <span class="p">|</span> awk <span class="s1">&#39;{print $2}&#39;</span><span class="sb">`</span> </span></pre></div> </td></tr></table>
linux

Bash

Octal file listings - linux

stat -c '%A %a %n' *
https://snipt.net/embed/c660713d185be6863839b50c48b920f0/
/raw/c660713d185be6863839b50c48b920f0/
c660713d185be6863839b50c48b920f0
bash
Bash
1
2019-06-13T00:37:14
True
False
False
Oct 18, 2013 at 06:19 AM
/api/public/snipt/88472/
octal-file-listings-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>stat -c <span class="s1">&#39;%A %a %n&#39;</span> * </span></pre></div> </td></tr></table>
linux

MySQL

db - example of a left join on a concat

1
2
3
4
SELECT t.tid AS tid, ua.alias
FROM taxonomy_term_data t
LEFT JOIN url_alias ua ON ua.source LIKE CONCAT('taxonomy/term/', t.tid )
WHERE t.vid =2
https://snipt.net/embed/3b612d8bdca43fa04cb8aaefef3f7f29/
/raw/3b612d8bdca43fa04cb8aaefef3f7f29/
3b612d8bdca43fa04cb8aaefef3f7f29
mysql
MySQL
4
2019-06-24T23:01:43
True
False
False
/api/public/snipt/88471/
db-example-of-a-left-join-on-a-concat
<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><span class="k">SELECT</span> <span class="n">t</span><span class="p">.</span><span class="n">tid</span> <span class="k">AS</span> <span class="n">tid</span><span class="p">,</span> <span class="n">ua</span><span class="p">.</span><span class="n">alias</span> </span><span id="L-2"><a name="L-2"></a><span class="k">FROM</span> <span class="n">taxonomy_term_data</span> <span class="n">t</span> </span><span id="L-3"><a name="L-3"></a><span class="k">LEFT</span> <span class="k">JOIN</span> <span class="n">url_alias</span> <span class="n">ua</span> <span class="k">ON</span> <span class="n">ua</span><span class="p">.</span><span class="n">source</span> <span class="k">LIKE</span> <span class="nf">CONCAT</span><span class="p">(</span><span class="s1">&#39;taxonomy/term/&#39;</span><span class="p">,</span> <span class="n">t</span><span class="p">.</span><span class="n">tid</span> <span class="p">)</span> </span><span id="L-4"><a name="L-4"></a><span class="k">WHERE</span> <span class="n">t</span><span class="p">.</span><span class="n">vid</span> <span class="o">=</span><span class="mi">2</span> </span></pre></div> </td></tr></table>
db, mysql

Bash

No email on cron - add to end of script in crontab -e

>/dev/null 2>&1
https://snipt.net/embed/b94effa88130d0d083e388d31b8381ca/
/raw/b94effa88130d0d083e388d31b8381ca/
b94effa88130d0d083e388d31b8381ca
bash
Bash
2
2019-06-25T08:10:04
True
False
False
Oct 18, 2013 at 06:15 AM
/api/public/snipt/88470/
no-email-on-cron-add-to-end-of-script-in-crontab-e
<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>&gt;/dev/null 2&gt;<span class="p">&amp;</span>1 </span></pre></div> </td></tr></table>
cron, linux