snipt

Ctrl+h for KB shortcuts

JavaScript

JS: Simple benchmark between two slices of code

1
2
3
4
5
6
var start = +new Date();

// Here the code I want to benchmark

var end = +new Date();
console.log((end - start) + " ms");
https://snipt.net/embed/81e89730ab287f6db2672c73aaf4f28b/
/raw/81e89730ab287f6db2672c73aaf4f28b/
81e89730ab287f6db2672c73aaf4f28b
js
JavaScript
6
2016-12-20T05:29:18
True
False
True
Dec 16, 2012 at 07:11 PM
/api/public/snipt/51925/
js-simple-benchmark-between-two-slices-of-code
<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="kd">var</span> <span class="nx">start</span> <span class="o">=</span> <span class="o">+</span><span class="k">new</span> <span class="nb">Date</span><span class="p">();</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c1">// Here the code I want to benchmark</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="kd">var</span> <span class="nx">end</span> <span class="o">=</span> <span class="o">+</span><span class="k">new</span> <span class="nb">Date</span><span class="p">();</span> </span><span id="L-6"><a name="L-6"></a><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">((</span><span class="nx">end</span> <span class="o">-</span> <span class="nx">start</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; ms&quot;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
benchmark, js

PHP

PHP: Get timestamp First day of the month (or last)

1
2
3
4
<?php

$tsFirstDayOfMonth = strtotime('first day of '.date('F Y'));
$tsLastDayOfMonth  = strtotime('last day of '.date('F Y'));
https://snipt.net/embed/fd5716b81a211fef6b91201bf874aa94/
/raw/fd5716b81a211fef6b91201bf874aa94/
fd5716b81a211fef6b91201bf874aa94
php
PHP
4
2016-12-28T21:12:39
True
False
True
Nov 19, 2012 at 10:38 AM
/api/public/snipt/50461/
php-get-timestamp-first-day-of-the-month-or-last
<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="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="nv">$tsFirstDayOfMonth</span> <span class="o">=</span> <span class="nb">strtotime</span><span class="p">(</span><span class="s1">&#39;first day of &#39;</span><span class="o">.</span><span class="nb">date</span><span class="p">(</span><span class="s1">&#39;F Y&#39;</span><span class="p">));</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$tsLastDayOfMonth</span> <span class="o">=</span> <span class="nb">strtotime</span><span class="p">(</span><span class="s1">&#39;last day of &#39;</span><span class="o">.</span><span class="nb">date</span><span class="p">(</span><span class="s1">&#39;F Y&#39;</span><span class="p">));</span> </span></pre></div> </td></tr></table>
date, php, timestamp

PHP

Symfony 1.x : Load helper in controller

1
2
3
4
5
6
<?php

public function executeMyAction(sfWebRequest $request) {
    $this->getContext()->getConfiguration()->loadHelpers(array('Url'));
    $this->getUser()->setFlash('notice', "Well done ! Follow this <a href=".url_for("homepage").">link</a>");
}
https://snipt.net/embed/5270bdbab797dafc8122d8a75dd329b0/
/raw/5270bdbab797dafc8122d8a75dd329b0/
5270bdbab797dafc8122d8a75dd329b0
php
PHP
6
2016-12-31T12:45:13
True
False
True
Oct 29, 2012 at 04:29 AM
/api/public/snipt/45744/
use-url_for-in-action-load-helper
<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="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="k">public</span> <span class="k">function</span> <span class="nf">executeMyAction</span><span class="p">(</span><span class="nx">sfWebRequest</span> <span class="nv">$request</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">getContext</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">getConfiguration</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">loadHelpers</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">&#39;Url&#39;</span><span class="p">));</span> </span><span id="L-5"><a name="L-5"></a> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">getUser</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">setFlash</span><span class="p">(</span><span class="s1">&#39;notice&#39;</span><span class="p">,</span> <span class="s2">&quot;Well done ! Follow this &lt;a href=&quot;</span><span class="o">.</span><span class="nx">url_for</span><span class="p">(</span><span class="s2">&quot;homepage&quot;</span><span class="p">)</span><span class="o">.</span><span class="s2">&quot;&gt;link&lt;/a&gt;&quot;</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
Helper, Symfony