Skip to content

Instantly share code, notes, and snippets.

@aswebdev
aswebdev / h1 paragraph selector
Created October 1, 2014 07:34
h1 paragraph selector
// Selecting all p that are next siblings of h1:
h1 + p { ... }
// Selecting all h1 that are *previous* siblings of p:
h1:has(+ p)
@aswebdev
aswebdev / EmailWithAttachment.php
Last active August 29, 2015 14:03
Send Email with an Attachment in PHP
//define the receiver of the email
$to = 'youraddress@example.com';
//define the subject of the email
$subject = 'Test email with attachment';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//add boundary string and mime type specification
@aswebdev
aswebdev / installing perl modules
Created June 17, 2014 02:18
Installing Perl Modules
# Use cpan and the module name to install the module
cpan NET::SFTP
@aswebdev
aswebdev / australian-states-select.html
Created June 12, 2014 04:00
HTML Select - List of Australian States
<select name="state">
<option value="ACT">Australian Capital Territory</option>
<option value="NSW">New South Wales</option>
<option value="NT ">Northern Territory</option>
<option value="QLD">Queensland</option>
<option value="SA ">South Australia</option>
<option value="TAS">Tasmania</option>
<option value="VIC">Victoria</option>
<option value="WA ">Western Australia</option>
</select>
@aswebdev
aswebdev / Sudoers Access
Created June 9, 2014 01:27
Enable Apache sudoers Access for User
visudo
# Add the line
nobody ALL=(ALL)NOPASSWD:/usr/bin/perl
# replace nobody with whatever your apache user is.
@aswebdev
aswebdev / Map a JavaScript Array
Last active August 29, 2015 14:00
Looping a JavaScript array as per a PHP array_map
var set1 = [2, 4, 6, 8, 10];
var set2 = [2, 4, 5, 8, 10];
console.log(set1.every(function (a) {
return a % 2 === 0;
})); // true
console.log(set2.every(function (a) {
return a % 2 === 0;
})); // false
$countries = array(
'AD' => 'Andorra',
'AE' => 'United Arab Emirates',
'AF' => 'Afghanistan',
'AG' => 'Antigua &amp; Barbuda',
'AI' => 'Anguilla',
'AL' => 'Albania',
'AM' => 'Armenia',
'AN' => 'Netherlands Antilles',
'AO' => 'Angola',
<!doctype html>
<html>
<head>
<!-- Run in full-screen mode. -->
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- Make the status bar black with white text. -->
<meta name="apple-mobile-web-app-status-bar-style" content="black">
@aswebdev
aswebdev / Filename Append
Last active August 29, 2015 13:56
Append an append string to a filename
// Append to a filename
function appendToFilename($file,$append) {
return preg_replace('/(\.[^.]+)$/', sprintf('%s$1', $append), $file);
}
@aswebdev
aswebdev / PHP Create HTML Email
Last active December 28, 2015 18:09
Function for creating HTML emails in PHP
function createEmail($to,$from,$subject,$content,$cc=false,$bcc=false) {
$headers = "From:$from\r\n";
$headers .= "CC:".$bcc."\r\n";
$headers .= "BCC:".$bcc."\r\n";
$headers .= "MIME-Version: 1.0\r\n";