Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Java

.htaccess redirect domain with www to the one without www

1
2
3
4
5
6
# Redirect all users to access the site WITHOUT the 'www.' prefix
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteCond %{HTTP_HOST} !\.([a-z-]+\.[a-z]{2,6})$ [NC]
  RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
  
// Source: http://drupal.org/node/499104#comment-3655776
https://snipt.net/embed/43b30ec7a548bb3d4e286e1ced814f0f/
https://snipt.net/raw/43b30ec7a548bb3d4e286e1ced814f0f/
43b30ec7a548bb3d4e286e1ced814f0f
java
Java
6
2016-11-25T12:29:16
True
False
False
/api/public/snipt/55124/
htaccess-redirect-domain-with-www-to-the-one-without-www
<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="err">#</span> <span class="n">Redirect</span> <span class="n">all</span> <span class="n">users</span> <span class="n">to</span> <span class="n">access</span> <span class="n">the</span> <span class="n">site</span> <span class="n">WITHOUT</span> <span class="n">the</span> <span class="err">&#39;</span><span class="n">www</span><span class="o">.</span><span class="err">&#39;</span> <span class="n">prefix</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">RewriteCond</span> <span class="o">%{</span><span class="n">HTTP_HOST</span><span class="o">}</span> <span class="o">^</span><span class="n">www</span><span class="err">\</span><span class="o">.(.+)</span><span class="n">$</span> <span class="o">[</span><span class="n">NC</span><span class="o">]</span> </span><span id="L-3"><a name="L-3"></a> <span class="n">RewriteCond</span> <span class="o">%{</span><span class="n">HTTP_HOST</span><span class="o">}</span> <span class="o">!</span><span class="err">\</span><span class="o">.([</span><span class="n">a</span><span class="o">-</span><span class="n">z</span><span class="o">-]+</span><span class="err">\</span><span class="o">.[</span><span class="n">a</span><span class="o">-</span><span class="n">z</span><span class="o">]{</span><span class="mi">2</span><span class="o">,</span><span class="mi">6</span><span class="o">})</span><span class="n">$</span> <span class="o">[</span><span class="n">NC</span><span class="o">]</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">RewriteRule</span> <span class="o">^</span> <span class="n">http</span><span class="o">:</span><span class="c1">//%1%{REQUEST_URI} [L,R=301]</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="c1">// Source: http://drupal.org/node/499104#comment-3655776</span> </span></pre></div> </td></tr></table>
config, htaccess, server

PHP

Joomla global configuration object

1
2
3
4
// get object
$config =& JFactory::getConfig();
// only way JDump works (otherwise it shows just methods of JRegistry, at least in J1.6+)
dump($config->toArray());
https://snipt.net/embed/153bd3e245649c85b31c52753eb52d3c/
https://snipt.net/raw/153bd3e245649c85b31c52753eb52d3c/
153bd3e245649c85b31c52753eb52d3c
php
PHP
4
2016-12-05T00:29:27
True
False
False
/api/public/snipt/43057/
joomla-global-configuration-object
<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="x">// get object</span> </span><span id="L-2"><a name="L-2"></a><span class="x">$config =&amp; JFactory::getConfig();</span> </span><span id="L-3"><a name="L-3"></a><span class="x">// only way JDump works (otherwise it shows just methods of JRegistry, at least in J1.6+)</span> </span><span id="L-4"><a name="L-4"></a><span class="x">dump($config-&gt;toArray());</span> </span></pre></div> </td></tr></table>
config, configuration, joomla

Ruby

Get current environment database configuration.

1
2
3
4
Rails.configuration.database_configuration[Rails.env]


=> {"encoding"=>"unicode", "username"=>"postgres", "adapter"=>"postgresql", "port"=>5432, "host"=>"localhost", "password"=>"postgres", "database"=>"mydb", "pool"=>5}
https://snipt.net/embed/1cc7c0a5f6940605863a6e551117f669/
https://snipt.net/raw/1cc7c0a5f6940605863a6e551117f669/
1cc7c0a5f6940605863a6e551117f669
rb
Ruby
4
2016-12-07T03:00:48
True
False
False
/api/public/snipt/28360/
get-current-environment-database-configuration
<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="no">Rails</span><span class="o">.</span><span class="n">configuration</span><span class="o">.</span><span class="n">database_configuration</span><span class="o">[</span><span class="no">Rails</span><span class="o">.</span><span class="n">env</span><span class="o">]</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="o">=&gt;</span> <span class="p">{</span><span class="s2">&quot;encoding&quot;</span><span class="o">=&gt;</span><span class="s2">&quot;unicode&quot;</span><span class="p">,</span> <span class="s2">&quot;username&quot;</span><span class="o">=&gt;</span><span class="s2">&quot;postgres&quot;</span><span class="p">,</span> <span class="s2">&quot;adapter&quot;</span><span class="o">=&gt;</span><span class="s2">&quot;postgresql&quot;</span><span class="p">,</span> <span class="s2">&quot;port&quot;</span><span class="o">=&gt;</span><span class="mi">5432</span><span class="p">,</span> <span class="s2">&quot;host&quot;</span><span class="o">=&gt;</span><span class="s2">&quot;localhost&quot;</span><span class="p">,</span> <span class="s2">&quot;password&quot;</span><span class="o">=&gt;</span><span class="s2">&quot;postgres&quot;</span><span class="p">,</span> <span class="s2">&quot;database&quot;</span><span class="o">=&gt;</span><span class="s2">&quot;mydb&quot;</span><span class="p">,</span> <span class="s2">&quot;pool&quot;</span><span class="o">=&gt;</span><span class="mi">5</span><span class="p">}</span> </span></pre></div> </td></tr></table>
config, db, ruby
Copyrighted, illegal, or inappropriate content? Email [email protected].