Categories

Perl Regular Expressions reference

m//   Searches a string for a pattern match
m//g   Matches globally (finds all occurrences)
m//i   Performs case-insensitive pattern matching
m//x   Uses extended regular expressions
[gix]   Modifiers for the search operator
\   Used to escape characters
.   Matches any single character except new line (except when the /s modifier is being used)
^   Matches at the beginning of a string (or line if /m modifier is being used)
$   Matches at the end of a string (or line if /m modifier is being used)
*   Matches the preceding element zero or more times
+   Matches the preceding element one or more times
?   Matches the preceding element zero or one times
{ }   Denotes a range of occurrences for the element preceding it
[ ]   Creates a character class. Matches any character within the brackets
( )   Used to group regular expressions
| Matches expression either preceding or following it
\.^$*+?{}[]()| Metacharacters
\a   System alarm
\n   New line
\r   Carriage return
\t   Horizontal tab
\f   Form feed
\e   ESC character
\a \n \r \t \f \e   Escape sequences
\d   A digit; equivalent to [0-9]
\D   A non-digit; equivalent to [^0-9]
\w   An alphanumerical word character; equivalent to [a-zA-Z_0-9]
\W   A non-word character; equivalent to [^a-zA-Z_0-9]
\s   A whitespace character; equivalent to [\t\n\r\f ]
\S   A non-whitespace character; equivalent to [^\t\n\r\f ]
\b   Matches at word boundary (between \w and \W)
\B   Matches except at word boundary
\A   Matches at the beginning of a string
\Z   Matches at the end of a string
\z   Matches at the end of a string only
\G   Matches where previous m//g left off
\b \B \A \Z \z \G   Assertions
s///   Performes substitution
s///e   Evaluates the right side as an expression
s///g   Replaces globally (replaces all occurrences)
s///i   Performs case-insensitive pattern matching
s///x   Uses extended regular expressions
[egix]   Modifiers for the substitution operator
FacebookTwitterGoogle+TumblrPinterestStumbleUponRedditLinkedInWhatsAppBlogger PostWordPressBaiduDeliciousDiggFarkKindle ItPlurkPrintFriendlyShare

PHP Array Function Definitions

array_change_key_case  Changes all keys in an array
array_chunk  Split an array into chunks
array_combine  Creates an array by using one array for keys and another for its values
array_count_values  Counts all the values of an array
array_diff_assoc  Computes the difference of arrays with additional index check
array_diff_key  Computes the difference of arrays using keys for comparison
array_diff_uassoc  Computes the difference of arrays with additional index check which is performed by a user supplied callback function
array_diff_ukey  Computes the difference of arrays using a callback function on the keys for comparison
array_diff  Computes the difference of arrays
array_fill_keys  Fill an array with values, specifying keys
array_fill  Fill an array with values
array_filter  Filters elements of an array using a callback function
array_flip  Exchanges all keys with their associated values in an array
array_intersect_assoc  Computes the intersection of arrays with additional index check
array_intersect_key  Computes the intersection of arrays using keys for comparison
array_intersect_uassoc  Computes the intersection of arrays with additional index check, compares indexes by a callback function
array_intersect_ukey  Computes the intersection of arrays using a callback function on the keys for comparison
array_intersect  Computes the intersection of arrays
array_key_exists  Checks if the given key or index exists in the array
array_keys  Return all the keys or a subset of the keys of an array
array_map  Applies the callback to the elements of the given arrays
array_merge_recursive  Merge two or more arrays recursively
array_merge  Merge one or more arrays
array_multisort  Sort multiple or multi-dimensional arrays
array_pad  Pad array to the specified length with a value
array_pop  Pop the element off the end of array
array_product  Calculate the product of values in an array
array_push  Push one or more elements onto the end of array
array_rand  Pick one or more random entries out of an array
array_reduce  Iteratively reduce the array to a single value using a callback function
array_replace_recursive  Replaces elements from passed arrays into the first array recursively
array_replace  Replaces elements from passed arrays into the first array
array_reverse  Return an array with elements in reverse order
array_search  Searches the array for a given value and returns the corresponding key if successful
array_shift  Shift an element off the beginning of array
array_slice  Extract a slice of the array
array_splice  Remove a portion of the array and replace it with something else
array_sum  Calculate the sum of values in an array
array_udiff_assoc  Computes the difference of arrays with additional index check, compares data by a callback function
array_udiff_uassoc  Computes the difference of arrays with additional index check, compares data and indexes by a callback function
array_udiff  Computes the difference of arrays by using a callback function for data comparison
array_uintersect_assoc  Computes the intersection of arrays with additional index check, compares data by a callback function
array_uintersect_uassoc  Computes the intersection of arrays with additional index check, compares data and indexes by a callback functions
array_uintersect  Computes the intersection of arrays, compares data by a callback function
array_unique  Removes duplicate values from an array
array_unshift  Prepend one or more elements to the beginning of an array
array_values  Return all the values of an array
array_walk_recursive  Apply a user function recursively to every member of an array
array_walk  Apply a user function to every member of an array
array  Create an array
arsort  Sort an array in reverse order and maintain index association
asort  Sort an array and maintain index association
compact  Create array containing variables and their values
count  Count all elements in an array, or something in an object
current  Return the current element in an array
each  Return the current key and value pair from an array and advance the array cursor
end  Set the internal pointer of an array to its last element
extract  Import variables into the current symbol table from an array
in_array  Checks if a value exists in an array
key  Fetch a key from an array
krsort  Sort an array by key in reverse order
ksort  Sort an array by key
list  Assign variables as if they were an array
natcasesort  Sort an array using a case insensitive “natural order” algorithm
natsort  Sort an array using a “natural order” algorithm
next  Advance the internal array pointer of an array
pos  Alias of current
prev  Rewind the internal array pointer
range  Create an array containing a range of elements
reset  Set the internal pointer of an array to its first element
rsort  Sort an array in reverse order
shuffle  Shuffle an array
sizeof  Alias of count
sort  Sort an array
uasort  Sort an array with a user-defined comparison function and maintain index association
uksort  Sort an array by keys using a user-defined comparison function
usort  Sort an array by values using a user-defined comparison function
FacebookTwitterGoogle+TumblrPinterestStumbleUponRedditLinkedInWhatsAppBlogger PostWordPressBaiduDeliciousDiggFarkKindle ItPlurkPrintFriendlyShare

PHP Date Codes

d   The day of the month (from 01 to 31)
D   A textual representation of a day (three letters)
j   The day of the month without leading zeros (1 to 31)
l (lowercase ‘L’)   A full textual representation of a day
N   The ISO-8601 numeric representation of a day (1 for Monday, 7 for Sunday)
S   The English ordinal suffix for the day of the month (2 characters st, nd, rd or th. Works well with j)
w   A numeric representation of the day (0 for Sunday, 6 for Saturday)
z   The day of the year (from 0 through 365)
W   The ISO-8601 week number of year (weeks starting on Monday)
F   A full textual representation of a month (January through December)
m   A numeric representation of a month (from 01 to 12)
M   A short textual representation of a month (three letters)
n   A numeric representation of a month, without leading zeros (1 to 12)
t   The number of days in the given month
L   Whether it’s a leap year (1 if it is a leap year, 0 otherwise)
o   The ISO-8601 year number
Y   A four digit representation of a year
y   A two digit representation of a year
a   Lowercase am or pm
A   Uppercase AM or PM
B   Swatch Internet time (000 to 999)
g   12-hour format of an hour (1 to 12)
G   24-hour format of an hour (0 to 23)
h   12-hour format of an hour (01 to 12)
H   24-hour format of an hour (00 to 23)
i   Minutes with leading zeros (00 to 59)
s   Seconds, with leading zeros (00 to 59)
u   Microseconds (added in PHP 5.2.2)
e   The timezone identifier (Examples: UTC, GMT, Atlantic/Azores)
I (capital i)   Whether the date is in daylights savings time (1 if Daylight Savings Time, 0 otherwise)
O   Difference to Greenwich time (GMT) in hours (Example: +0100)
P   Difference to Greenwich time (GMT) in hours:minutes (added in PHP 5.1.3)
T   Timezone abbreviations (Examples: EST, MDT)
Z   Timezone offset in seconds. The offset for timezones west of UTC is negative (-43200 to 50400)
c   The ISO-8601 date (e.g. 2013-05-05T16:34:42+00:00)
r   The RFC 2822 formatted date (e.g. Fri, 12 Apr 2013 12:01:05 +0200)
U   The seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
FacebookTwitterGoogle+TumblrPinterestStumbleUponRedditLinkedInWhatsAppBlogger PostWordPressBaiduDeliciousDiggFarkKindle ItPlurkPrintFriendlyShare

Python Escape Sequences

\\   Backslash
\’   Single-quote (‘)
\”   Double-quote (“)
\a   ASCII bell (BEL)
\b   ASCII backspace (BS)
\f   ASCII formfeed (FF)
\n   ASCII linefeed (LF)
\N{name}   Character named name in the Unicode database (Unicode only)
\r ASCII   Carriage Return (CR)
\t ASCII   Horizontal Tab (TAB)
\uxxxx   Character with 16-bit hex value xxxx (Unicode only)
\Uxxxxxxxx   Character with 32-bit hex value xxxxxxxx (Unicode only)
\v   ASCII vertical tab (VT)
\ooo   Character with octal value ooo
\xhh   Character with hex value hh
FacebookTwitterGoogle+TumblrPinterestStumbleUponRedditLinkedInWhatsAppBlogger PostWordPressBaiduDeliciousDiggFarkKindle ItPlurkPrintFriendlyShare

Python keywords

False   Truth value; the result of comparison operations or logical operations.
None   A special constant that represents the absence of a value or a null value. It is an object of its own datatype, the NoneType. [We] cannot create multiple None objects but can assign it to variables.
True   Truth value; that result of comparison operations or logical operations.
and   Logical operator that will result into True only if both operands are True.
as   Used to create an alias (user-defined) while importing a module.
assert   Used for debugging purposes. Assert is followed by a condition. If the condition is true, nothing happens, but if the condition is false, AssertionError is raised.
break   Used inside for and while loops. Will end the smallest loop it is in and control flows to the statement immediately below the loop.
class   Used to define a new user-defined class; a collection or related attributes and methods that try to represent a real world situation. (This concept is central to OOP.)
continue   Used inside for and while loops. Causes to end the current iteration of the loop, but not the whole loop.
def   Used to define a user-defined function; a block of related statements, which together does some specific task.
del   Used to delete the reference to an object.
elif   Short for else if. Used for conditional branching or decision making.
else   Used for conditional branching or decision making. The block which is executed if the condition is false.
except   Used with exceptions; errors that suggests something went wrong during execution. The except block is executed if an exception is caught.
finally   Used with try…except block to close up resources or file streams. Ensures that the block is executed even if there is an unhandled exception.
for   Used for looping. (Generally used when the number of desired iterations is known.)
from   from…import is used to import specific attributes or functions into the current namespace.
global   Used to declare that a variable inside the function is global (outside the function). If [we] need to read the value of a global variable, it is not necessary to define it as global. But if [we] need to modify the value of a global variable inside a function, it must be declared with global.
if   Used for conditional branching or decision making. Used to test some condition and execute a block only if the condition is true.
import   Used to import modules into the current namespace.
in   Used to test if a sequence (list, tuple, string etc.) contains a value. Returns True if the value is present, else it returns False.
is   Used to test if two variables refer to the same object. Returns True if the objects are identical and False if not.
lambda   Used to create an anonymous inline function (function with no name) that does not contain a return statement. Consists of an expression that is evaluated and returned.
nonlocal   Used to declare that variable inside a nested function is not local, meaning it lies in the outer inclosing function. If [we] need to modify the value of a non-local variable inside a nested function, then we must declare it with nonlocal.
not   Used to invert the truth value.
or   Logical operator, will result into True if any of the operands is True.
pass   Null statement; nothing happens when it is executed. Used as a placeholder.
raise   Used to explicitly raise an exception.
return   Used inside a function to exit it and return a value. If no value is explicitly returned, None is returned.
try   Used with exceptions…
while   Used for looping. Statements inside a while loop continue to execute until the condition for the while loop evaluates False or a break statement is encountered.
with   Used to wrap the execution of a block of code within methods defined by the context manager; a class that implements __enter__ and __exit__ methods. Use of with statement ensures that the __exit__ method is called at the end of the nested block.
yield   Used inside a function. Returns a generator; an iterator the generates one item at a time.
FacebookTwitterGoogle+TumblrPinterestStumbleUponRedditLinkedInWhatsAppBlogger PostWordPressBaiduDeliciousDiggFarkKindle ItPlurkPrintFriendlyShare

Get time from an external website

If you visit the link, you will see the following as an example

Jun. 25, 18:34:54 UTC Universal Time
Jun. 25, 02:34:54 PM EDT Eastern Time
Jun. 25, 01:34:54 PM CDT Central Time
Jun. 25, 12:34:54 PM MDT Mountain Time
Jun. 25, 11:34:54 AM PDT Pacific Time
Jun. 25, 10:34:54 AM AKDT Alaska Time
Jun. 25, 08:34:54 AM HAST Hawaii-Aleutian Time

By changing the code you can change the time you want to show

import urllib2
for line in urllib2.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl'):
     if 'UTC' in line:      # look for Universal Time
         print line
FacebookTwitterGoogle+TumblrPinterestStumbleUponRedditLinkedInWhatsAppBlogger PostWordPressBaiduDeliciousDiggFarkKindle ItPlurkPrintFriendlyShare