snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#27319

CSS

CSS box model fix

1
2
3
4
5
6
7
Fix for the crazy CSS 2 box model

-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box;    /* Firefox, other Gecko */
box-sizing: border-box;         /* Opera/IE 8+ */

Not supported in IE6 and IE7
https://snipt.net/embed/17b46dff5a4db622c1205e97bb0d3869/
https://snipt.net/raw/17b46dff5a4db622c1205e97bb0d3869/
17b46dff5a4db622c1205e97bb0d3869
css
CSS
7
2014-04-24T12:13:59
True
False
/api/public/snipt/27319/
css-box-model-fix
<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 id="L-1"><a name="L-1"></a><span class="nt">Fix</span> <span class="nt">for</span> <span class="nt">the</span> <span class="nt">crazy</span> <span class="nt">CSS</span> <span class="nt">2</span> <span class="nt">box</span> <span class="nt">model</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="nt">-webkit-box-sizing</span><span class="o">:</span> <span class="nt">border-box</span><span class="o">;</span> <span class="c">/* Safari/Chrome, other WebKit */</span> </span><span id="L-4"><a name="L-4"></a><span class="nt">-moz-box-sizing</span><span class="o">:</span> <span class="nt">border-box</span><span class="o">;</span> <span class="c">/* Firefox, other Gecko */</span> </span><span id="L-5"><a name="L-5"></a><span class="nt">box-sizing</span><span class="o">:</span> <span class="nt">border-box</span><span class="o">;</span> <span class="c">/* Opera/IE 8+ */</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="nt">Not</span> <span class="nt">supported</span> <span class="nt">in</span> <span class="nt">IE6</span> <span class="nt">and</span> <span class="nt">IE7</span> </span></pre></div> </td></tr></table>
box, css, model
#26816

HTML

Html CSS tag

<link href="xxxx.css" rel="stylesheet" type="text/css" /> 
https://snipt.net/embed/3d3a607fd6f80a213b482251e6345305/
https://snipt.net/raw/3d3a607fd6f80a213b482251e6345305/
3d3a607fd6f80a213b482251e6345305
html
HTML
1
2014-03-27T04:54:53
True
False
/api/public/snipt/26816/
html-css-tag
<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="nt">&lt;link</span> <span class="na">href=</span><span class="s">&quot;xxxx.css&quot;</span> <span class="na">rel=</span><span class="s">&quot;stylesheet&quot;</span> <span class="na">type=</span><span class="s">&quot;text/css&quot;</span> <span class="nt">/&gt;</span> </span></pre></div> </td></tr></table>
html
#26239

JavaScript

jQuery, check if element is visible

//jQuery, check if element is visible
$(element).is(":visible") 
https://snipt.net/embed/cbb0263a6ec88662e1410d0766bb693c/
https://snipt.net/raw/cbb0263a6ec88662e1410d0766bb693c/
cbb0263a6ec88662e1410d0766bb693c
js
JavaScript
2
2014-04-24T17:15:44
True
False
/api/public/snipt/26239/
jquery-check-if-element-is-visible
<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">//jQuery, check if element is visible</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">$</span><span class="p">(</span><span class="nx">element</span><span class="p">).</span><span class="nx">is</span><span class="p">(</span><span class="s2">&quot;:visible&quot;</span><span class="p">)</span> </span></pre></div> </td></tr></table>
jquery, visible
#25898

JavaScript

Log function for JS

1
2
3
function log(msg){
    if (window.console && console.log) console.log(msg);
}
https://snipt.net/embed/4c64ddd90c7993ea9307e57fb4e606b8/
https://snipt.net/raw/4c64ddd90c7993ea9307e57fb4e606b8/
4c64ddd90c7993ea9307e57fb4e606b8
js
JavaScript
3
2014-04-24T02:20:48
True
False
/api/public/snipt/25898/
log-function-for-js
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kd">function</span> <span class="nx">log</span><span class="p">(</span><span class="nx">msg</span><span class="p">){</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">if</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">console</span> <span class="o">&amp;&amp;</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">)</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">msg</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
log
#25874

Ruby

Add column migration

1
2
3
4
5
6
7
def self.up
    add_column :table_name, :field_name, :string
  end
 
  def self.down
    remove_column :table_name, :field_name
  end
https://snipt.net/embed/4339ae7eee6c52f644a4207a5c903073/
https://snipt.net/raw/4339ae7eee6c52f644a4207a5c903073/
4339ae7eee6c52f644a4207a5c903073
rb
Ruby
7
2014-04-16T15:51:38
True
False
/api/public/snipt/25874/
add-column-migration
<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 id="L-1"><a name="L-1"></a><span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">up</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">add_column</span> <span class="ss">:table_name</span><span class="p">,</span> <span class="ss">:field_name</span><span class="p">,</span> <span class="ss">:string</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">end</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> <span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">down</span> </span><span id="L-6"><a name="L-6"></a> <span class="n">remove_column</span> <span class="ss">:table_name</span><span class="p">,</span> <span class="ss">:field_name</span> </span><span id="L-7"><a name="L-7"></a> <span class="k">end</span> </span></pre></div> </td></tr></table>
add, column, migration, rails, ruby