snipt

Ctrl+h for KB shortcuts

Bash

Drupal 6 update file path

1
2
3
4
5
6
7
8
/**
 * Move files from sites/default/files to /files folder (Drupal 6).
 */
function mymodule_update_6002() {
 $ret = array();
 $ret[] = update_sql("UPDATE {files} SET filepath = REPLACE(filepath, 'sites/default/files', 'files') WHERE filepath LIKE 'sites/default/files%%'");
 return $ret;
}
https://snipt.net/embed/2a2d027243b1741ca65214cc9b717105/
/raw/2a2d027243b1741ca65214cc9b717105/
2a2d027243b1741ca65214cc9b717105
bash
Bash
8
2019-06-24T07:58:08
True
False
False
/api/public/snipt/28559/
drupal-6-update-file-path
<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><span id="L-2"><a name="L-2"></a> * Move files from sites/default/files to /files folder <span class="o">(</span>Drupal 6<span class="o">)</span>. </span><span id="L-3"><a name="L-3"></a> */ </span><span id="L-4"><a name="L-4"></a><span class="k">function</span> mymodule_update_6002<span class="o">()</span> <span class="o">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="nv">$ret</span> <span class="o">=</span> array<span class="o">()</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a> <span class="nv">$ret</span><span class="o">[]</span> <span class="o">=</span> update_sql<span class="o">(</span><span class="s2">&quot;UPDATE {files} SET filepath = REPLACE(filepath, &#39;sites/default/files&#39;, &#39;files&#39;) WHERE filepath LIKE &#39;sites/default/files%%&#39;&quot;</span><span class="o">)</span><span class="p">;</span> </span><span id="L-7"><a name="L-7"></a> <span class="k">return</span> <span class="nv">$ret</span><span class="p">;</span> </span><span id="L-8"><a name="L-8"></a><span class="o">}</span> </span></pre></div> </td></tr></table>
development, drupal, mysql, php

Bash

sed search replace on mac

1
2
3
4
5
# Sed is available on Mac OS X, but the -i option requires an 
# extension, even if its non-existent. Try specifying an empty
# string before the regular expression:

sed -i '' 's/foo/foo_bar/g' *.module
https://snipt.net/embed/0dd09cdb85f7f8abde430b47c6db7bc6/
/raw/0dd09cdb85f7f8abde430b47c6db7bc6/
0dd09cdb85f7f8abde430b47c6db7bc6
bash
Bash
5
2019-06-24T11:18:22
True
False
False
/api/public/snipt/25304/
sed-search-replace-on-mac
<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="c1"># Sed is available on Mac OS X, but the -i option requires an </span> </span><span id="L-2"><a name="L-2"></a><span class="c1"># extension, even if its non-existent. Try specifying an empty</span> </span><span id="L-3"><a name="L-3"></a><span class="c1"># string before the regular expression:</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>sed -i <span class="s1">&#39;&#39;</span> <span class="s1">&#39;s/foo/foo_bar/g&#39;</span> *.module </span></pre></div> </td></tr></table>
bash, cleanup, development, sed

Bash

git recursive rm

# git remove missing files from current directory and sub-directories
git ls-files -d -z | xargs -0 git update-index --remove
https://snipt.net/embed/01abbc928530c71013299263866b6996/
/raw/01abbc928530c71013299263866b6996/
01abbc928530c71013299263866b6996
bash
Bash
2
2019-06-24T07:58:22
True
False
False
/api/public/snipt/25070/
git-recursive-rm
<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="c1"># git remove missing files from current directory and sub-directories</span> </span><span id="L-2"><a name="L-2"></a>git ls-files -d -z <span class="p">|</span> xargs -0 git update-index --remove </span></pre></div> </td></tr></table>
development, git

Bash

Install Drupal with Drush

1
2
3
4
5
6
7
# Install Drupal with drush.  This assumes you've already setup the 
# database and know where to put the drupal-7.0 folder once its downloaded
# so that your webserver (eg apache) knows how to serve the site.

drush dl drupal

drush site-install standard --account-name=admin --account-pass=[useruser_pass] --db-url=mysql://[db_user]:[db_pass]@localhost/[db_name]
https://snipt.net/embed/6c585616265259646213502166c21aae/
/raw/6c585616265259646213502166c21aae/
6c585616265259646213502166c21aae
bash
Bash
8
2019-06-24T07:58:28
True
False
False
/api/public/snipt/24240/
install-drupal-with-drush
<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><span class="c1"># Install Drupal with drush. This assumes you&#39;ve already setup the </span> </span><span id="L-2"><a name="L-2"></a><span class="c1"># database and know where to put the drupal-7.0 folder once its downloaded</span> </span><span id="L-3"><a name="L-3"></a><span class="c1"># so that your webserver (eg apache) knows how to serve the site.</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>drush dl drupal </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a>drush site-install standard --account-name<span class="o">=</span>admin --account-pass<span class="o">=[</span>useruser_pass<span class="o">]</span> --db-url<span class="o">=</span>mysql://<span class="o">[</span>db_user<span class="o">]</span>:<span class="o">[</span>db_pass<span class="o">]</span>@localhost/<span class="o">[</span>db_name<span class="o">]</span> </span></pre></div> </td></tr></table>
bash, drupal, drush

Bash

Install homebrew cli

# install homebrew using ruby.
ruby -e "$(curl -fsS http://gist.github.com/raw/323731/install_homebrew.rb)"
https://snipt.net/embed/0affb0543ae7c8e70c2510749afe289c/
/raw/0affb0543ae7c8e70c2510749afe289c/
0affb0543ae7c8e70c2510749afe289c
bash
Bash
2
2019-06-24T07:58:33
True
False
False
/api/public/snipt/23522/
install-homebrew-cli
<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="c1"># install homebrew using ruby.</span> </span><span id="L-2"><a name="L-2"></a>ruby -e <span class="s2">&quot;</span><span class="k">$(</span>curl -fsS http://gist.github.com/raw/323731/install_homebrew.rb<span class="k">)</span><span class="s2">&quot;</span> </span></pre></div> </td></tr></table>
"mac os x", bash, ruby

Bash

rsync over ssh

rsync -vaz --rsh="ssh -l username" ~/folder targetHost:~/
https://snipt.net/embed/2d1e2ddebe807544419c35b462eba3e5/
/raw/2d1e2ddebe807544419c35b462eba3e5/
2d1e2ddebe807544419c35b462eba3e5
bash
Bash
1
2019-06-24T07:58:40
True
False
False
/api/public/snipt/22401/
rsync-over-ssh-1
<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>rsync -vaz --rsh<span class="o">=</span><span class="s2">&quot;ssh -l username&quot;</span> ~/folder targetHost:~/ </span></pre></div> </td></tr></table>
ssh, syncing

Bash

Mac OS X Recursive file unlock

chflags -R nouchg *
https://snipt.net/embed/0366743c11deeffc3a8822eedfd5f8e0/
/raw/0366743c11deeffc3a8822eedfd5f8e0/
0366743c11deeffc3a8822eedfd5f8e0
bash
Bash
1
2019-06-24T07:58:51
True
False
False
/api/public/snipt/20832/
mac-os-x-recursive-file-unlock
<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>chflags -R nouchg * </span></pre></div> </td></tr></table>
"mac os x", bash

Bash

resume incomplete download with curl or wget

1
2
3
4
5
6
7
# with curl

cat download-incomplete.zip | curl -C - http://example.com/download.zip > download-resume.zip

# or with wget

wget -c http://example.com/download.zip -O download-incomplete.zip
https://snipt.net/embed/d214e08f5e00e9b4040f65005edf7aa3/
/raw/d214e08f5e00e9b4040f65005edf7aa3/
d214e08f5e00e9b4040f65005edf7aa3
bash
Bash
7
2019-06-25T13:24:47
True
False
False
/api/public/snipt/18368/
resume-incomplete-download-with-curl-or-wget
<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><span class="c1"># with curl</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>cat download-incomplete.zip <span class="p">|</span> curl -C - http://example.com/download.zip &gt; download-resume.zip </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="c1"># or with wget</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a>wget -c http://example.com/download.zip -O download-incomplete.zip </span></pre></div> </td></tr></table>
bash

ApacheConf

Htaccess Private Files (svn, cvs, sql, etc)

1
2
3
4
# Drupal's way of denying access to delicate server files
<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
  Order allow,deny
</FilesMatch>
https://snipt.net/embed/5ce63763c77b5a0c9c89919d8f9720ef/
/raw/5ce63763c77b5a0c9c89919d8f9720ef/
5ce63763c77b5a0c9c89919d8f9720ef
apacheconf
ApacheConf
4
2019-06-25T03:36:45
True
False
False
/api/public/snipt/17855/
htaccess-private-files-svn-cvs-sql-etc
<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="c"># Drupal&#39;s way of denying access to delicate server files</span> </span><span id="L-2"><a name="L-2"></a><span class="nt">&lt;FilesMatch</span> <span class="s">&quot;\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$&quot;</span><span class="nt">&gt;</span> </span><span id="L-3"><a name="L-3"></a> <span class="nb">Order</span> allow,deny </span><span id="L-4"><a name="L-4"></a><span class="nt">&lt;/FilesMatch&gt;</span> </span></pre></div> </td></tr></table>
apache, htaccess, svn