snipt

Ctrl+h for KB shortcuts

Text only

Snippet - Simple Form

 - claim_reason_collection = ClaimReason.all.map { |cr| [cr.to_s, cr.id, { data: { ids: cr.accounting_ids } }] }
 = f.input :claim_reason_static_id, collection: claim_reason_collection
https://snipt.net/embed/c5a242b6c6258936864f4451911a78ef/
https://snipt.net/raw/c5a242b6c6258936864f4451911a78ef/
c5a242b6c6258936864f4451911a78ef
text
Text only
2
2016-09-21T10:34:55
True
False
False
/api/public/snipt/144778/
simple-form-409e7fa9
<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> - claim_reason_collection = ClaimReason.all.map { |cr| [cr.to_s, cr.id, { data: { ids: cr.accounting_ids } }] } </span><span id="L-2"><a name="L-2"></a> = f.input :claim_reason_static_id, collection: claim_reason_collection </span></pre></div> </td></tr></table>
haml, snippet

Text only

Snippet : Rspec - stubbing

Object.stub_chain(:config_hash, :find) { { week: 12, day: 13} }
Object.stub(:all_by_agent) { Agent.where(id: ids) }
https://snipt.net/embed/6ff81b4f7d10bd8dc76af6ff15bc21b5/
https://snipt.net/raw/6ff81b4f7d10bd8dc76af6ff15bc21b5/
6ff81b4f7d10bd8dc76af6ff15bc21b5
text
Text only
2
2016-10-01T07:23:08
True
False
False
Jan 14, 2016 at 07:58 AM
/api/public/snipt/143549/
snippet-rspec-stubbing
<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>Object.stub_chain(:config_hash, :find) { { week: 12, day: 13} } </span><span id="L-2"><a name="L-2"></a>Object.stub(:all_by_agent) { Agent.where(id: ids) } </span></pre></div> </td></tr></table>
rspec, snippet

Text only

Execute PHP CLI background mode

1
2
3
exec('/usr/bin/php  '.__PATH__.'/CLI/run-background.php '.$var1.' > /dev/null &',$output);
// $output is the variable return for command "exec"
// $var1 send variables in the string path- get array data with vars in run-background.php usign $argv
https://snipt.net/embed/55609c21d588a357b9caf876ccc39a0a/
https://snipt.net/raw/55609c21d588a357b9caf876ccc39a0a/
55609c21d588a357b9caf876ccc39a0a
text
Text only
3
2016-09-29T21:55:31
True
False
False
Jan 29, 2013 at 03:12 PM
/api/public/snipt/54745/
execute-php-cli-background-mode
<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>exec(&#39;/usr/bin/php &#39;.__PATH__.&#39;/CLI/run-background.php &#39;.$var1.&#39; &gt; /dev/null &amp;&#39;,$output); </span><span id="L-2"><a name="L-2"></a>// $output is the variable return for command &quot;exec&quot; </span><span id="L-3"><a name="L-3"></a>// $var1 send variables in the string path- get array data with vars in run-background.php usign $argv </span></pre></div> </td></tr></table>
"php cli", background, snippet

JavaScript

Trim string to length

1
2
3
4
5
function trimLength(str, length) {
	str = $.trim(str); // jQuery required
	str = str.slice(0, length);
	return str;
}
https://snipt.net/embed/b282ce90eccedb80413e42bfea8f0572/
https://snipt.net/raw/b282ce90eccedb80413e42bfea8f0572/
b282ce90eccedb80413e42bfea8f0572
js
JavaScript
5
2016-10-01T11:47:50
True
False
False
/api/public/snipt/23868/
trim-string-to-length
<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 id="L-1"><a name="L-1"></a><span class="kd">function</span> <span class="nx">trimLength</span><span class="p">(</span><span class="nx">str</span><span class="p">,</span> <span class="nx">length</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">str</span> <span class="o">=</span> <span class="nx">$</span><span class="p">.</span><span class="nx">trim</span><span class="p">(</span><span class="nx">str</span><span class="p">);</span> <span class="c1">// jQuery required</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">str</span> <span class="o">=</span> <span class="nx">str</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">length</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">return</span> <span class="nx">str</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
cut, function, helper, javascript, length, shorten, snippet, string, trim
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.