snipt

Ctrl+h for KB shortcuts

PHP

PHP Current Year

<?php echo date("Y") ?>
https://snipt.net/embed/bc788462e5828cc9201e3e8fca82df6a/
/raw/bc788462e5828cc9201e3e8fca82df6a/
bc788462e5828cc9201e3e8fca82df6a
php
PHP
1
2019-07-20T10:22:13
True
False
False
/api/public/snipt/3755/
current-year
<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><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nb">date</span><span class="p">(</span><span class="s2">&quot;Y&quot;</span><span class="p">)</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"current year", date, php

Bash

commandline search server logs for activity in time frame

1
2
3
4
5
# following date/time is day/month/year:hour:min:sec
# as in 02/Feb/2009:23:59:59
# leave off more for a broader range like:
# 02/Feb/2009:0   ...here's mine:   [your structure may vary]
grep -rn "26/Sep/2008:01:" /usr/local/apache/domlogs/*
https://snipt.net/embed/e1d88fde101d30ce6e6fe8f747167b5c/
/raw/e1d88fde101d30ce6e6fe8f747167b5c/
e1d88fde101d30ce6e6fe8f747167b5c
bash
Bash
5
2019-08-15T15:39:18
True
False
False
/api/public/snipt/3179/
commandline-search-server-logs-for-activity-in-time-frame
<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"># following date/time is day/month/year:hour:min:sec</span> </span><span id="L-2"><a name="L-2"></a><span class="c1"># as in 02/Feb/2009:23:59:59</span> </span><span id="L-3"><a name="L-3"></a><span class="c1"># leave off more for a broader range like:</span> </span><span id="L-4"><a name="L-4"></a><span class="c1"># 02/Feb/2009:0 ...here&#39;s mine: [your structure may vary]</span> </span><span id="L-5"><a name="L-5"></a>grep -rn <span class="s2">&quot;26/Sep/2008:01:&quot;</span> /usr/local/apache/domlogs/* </span></pre></div> </td></tr></table>
commandline, date, grep, linux, logs, range, server, web, webserver

Bash

picture mover one-liner

/bin/ls -1 *.jpg | tar -cf - --files-from=- --transform 's#^\(\([^_][^_]*\)_\([^_][^_]*\)_\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9][0-9][0-9]\).*\)#\6/\4/\5/\1#'  | (cd Destdir/ ; tar -xf - )
https://snipt.net/embed/2f93764400ce9d5fa451526c7a02816e/
/raw/2f93764400ce9d5fa451526c7a02816e/
2f93764400ce9d5fa451526c7a02816e
bash
Bash
2
2019-08-13T20:27:53
True
False
False
/api/public/snipt/3055/
picture-mover-one-liner
<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>/bin/ls -1 *.jpg <span class="p">|</span> tar -cf - --files-from<span class="o">=</span>- --transform <span class="s1">&#39;s#^\(\([^_][^_]*\)_\([^_][^_]*\)_\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9][0-9][0-9]\).*\)#\6/\4/\5/\1#&#39;</span> <span class="p">|</span> <span class="o">(</span><span class="nb">cd</span> Destdir/ <span class="p">;</span> tar -xf - <span class="o">)</span> </span></pre></div> </td></tr></table>
bash, date, directories, files, move, sed, tar, transform

Bash

History Lesson

#!/bin/sh
grep -h "^$(date '+%m/%d')" /usr/share/calendar/calendar.{holiday,history,computer}|cut -f2
https://snipt.net/embed/aee16b74d87b8d943b2702a81254d0af/
/raw/aee16b74d87b8d943b2702a81254d0af/
aee16b74d87b8d943b2702a81254d0af
bash
Bash
2
2019-07-25T07:14:19
True
False
False
/api/public/snipt/3007/
history-lesson
<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="ch">#!/bin/sh</span> </span><span id="L-2"><a name="L-2"></a>grep -h <span class="s2">&quot;^</span><span class="k">$(</span>date <span class="s1">&#39;+%m/%d&#39;</span><span class="k">)</span><span class="s2">&quot;</span> /usr/share/calendar/calendar.<span class="o">{</span>holiday,history,computer<span class="o">}</span><span class="p">|</span>cut -f2 </span></pre></div> </td></tr></table>
bash, calendar, date, geektool

Python

Convert RFC 2822 time stamp (used in HTTP headers and web services) to a Django DateTimeField format

rfc_2822_time = time.strptime(2822_TIME_STRING, '%a, %d %b %Y %H:%M:%S +0000')
django_compat_time = time.strftime('%Y-%m-%d %H:%M:%S', rfc_2822_time)
https://snipt.net/embed/3b8b2406704676729276b1578de55a0f/
/raw/3b8b2406704676729276b1578de55a0f/
3b8b2406704676729276b1578de55a0f
python
Python
2
2019-08-01T13:06:52
True
False
False
/api/public/snipt/2619/
convert-rfc-2822-time-stamp-used-in-http-headers-and-web-services-to-a-django-datetimefield-format
<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="n">rfc_2822_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="mi">2822</span><span class="n">_TIME_STRING</span><span class="p">,</span> <span class="s1">&#39;%a, </span><span class="si">%d</span><span class="s1"> %b %Y %H:%M:%S +0000&#39;</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a><span class="n">django_compat_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y-%m-</span><span class="si">%d</span><span class="s1"> %H:%M:%S&#39;</span><span class="p">,</span> <span class="n">rfc_2822_time</span><span class="p">)</span> </span></pre></div> </td></tr></table>
date, datetime, django, python, time

Text only

Validate, with a regular expression, HTTP-date with the format rfc1123-date

(((Mon)|(Tue)|(Wed)|(Thu)|(Fri)|(Sat)|(Sun))[,] \s \d{2}\s (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \s \d{4} \s (0\d|1\d|2[0-3])
(\:)(0\d|1\d|2\d|3\d|4\d|5\d)(\:)(0\d|1\d|2\d|3\d|4\d|5\d) \s (GMT))
https://snipt.net/embed/4edc6f7b9fb7ca31a6ecc56f4cb7294b/
/raw/4edc6f7b9fb7ca31a6ecc56f4cb7294b/
4edc6f7b9fb7ca31a6ecc56f4cb7294b
text
Text only
2
2019-08-17T00:09:11
True
False
False
/api/public/snipt/2182/
validate-with-a-regular-expression-the-http-date-with-the-format-rfc1123-date
<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>(((Mon)|(Tue)|(Wed)|(Thu)|(Fri)|(Sat)|(Sun))[,] \s \d{2}\s (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \s \d{4} \s (0\d|1\d|2[0-3]) </span><span id="L-2"><a name="L-2"></a>(\:)(0\d|1\d|2\d|3\d|4\d|5\d)(\:)(0\d|1\d|2\d|3\d|4\d|5\d) \s (GMT)) </span></pre></div> </td></tr></table>
date, http-date, regular_expression, rfc1123-date