Skip to content

Instantly share code, notes, and snippets.

@crystalw
crystalw / redirect to non www
Created September 2, 2012 04:20
.htaccess preferred domain redirect
# 301 direct to preferred domain
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^yourdomain.com$ [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
# End 301 direct
@crystalw
crystalw / html5_doctype.html.haml
Last active December 19, 2015 01:28
HTML5 HAML Doc Type Declaration
!!! 5
%html
%head
%title= "My Website"
%meta{ :charset => "utf-8" }
%meta{ :content => "", :name => "description" }
%meta{ :content => "", :name => "author" }
%link{ :href => "/feed", :rel => "alternate", :title => "Atom", :type => "application/atom+xml" }
%link{ :href => "/css/screen.css", :media => "screen", :rel => "stylesheet" }
%body
@crystalw
crystalw / outcome.html
Last active December 19, 2015 03:19
Check an element's class to determine the outcome of an event and push the occurrence to Google Analytics. Useful for tracking successful form submits on Ajax or other form types with static urls. Google Event Tracking Guide: https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
<div class="outcome" class="successful">
<p>Thanks, your message has been sent!</p>
</div>
<script>
$(document).ready(function() {
if ($( '#outcome' ).hasClass( "successful" )) {
_gaq.push(['_trackEvent', 'Category', 'Action', 'opt_label']);
}
});
DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL
@crystalw
crystalw / Regex Phone Validation
Created February 5, 2014 15:06
A few regex examples for validating common phone number formats
<?php
//regex for 7 or 10 digit number, delimiters are spaces, dashes, or periods:
^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]‌​)\s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-‌​9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})$
//same regex as above, but for 10 digit number only
^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]‌​)\s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)([2-9]1[02-9]‌​|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})$
//this regex will not allow the preceeding 1 at the beginning of the phone number
^(?:(?:(\s*\(?([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*)|([2-9]1[02-9]|[2‌​-9][02-8]1|[2-9][02-8][02-9]))\)?\s*(?:[.-]\s*)?)([2-9]1[02-9]|[2-9][02-9]1|[2-9]‌​[02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})$
// iframes
var $iframes = $( document.querySelectorAll( '.widget iframe' ) );
function iframeSizing() {
var $this = $( this ),
width = $this.width(),
height = $this.height(),
containerWidth = $this.parent().width(),
heightRatio = height / width,
newHeight = heightRatio * containerWidth;
@crystalw
crystalw / .bash_profile
Created April 6, 2016 20:38
bash aliases
#opens chrome with CORS disabled
alias chromex='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-web-security'
#removes merged local branches (except for master)
alias gitprune='git branch --merged | grep -v "\*" | grep -v master | xargs -n 1 git branch -d'
#switches to ui project
alias backend="cd ${PWD/ui/backend}"
#switches to backend project
@crystalw
crystalw / SassMeister-input.scss
Created April 14, 2016 07:52 — forked from davidkpiano/SassMeister-input.scss
Generated by SassMeister.com.
// ----
// Sass (v3.4.12)
// Compass (v1.0.3)
// ----
$scotch-color-key: 'base' !default;
$scotch-colors: (
'primary': (
'base': #8e3329,
@crystalw
crystalw / pseudo-elements.md
Created April 15, 2016 21:41 — forked from p3t3r67x0/pseudo_elements.md
A CSS pseudo-element is used to style specified parts of an element. In some cases you can style native HTML controls with vendor specific pseudo-elements. Here you will find an list of cross browser specific pseudo-element selectors.

Styling native elements

Native HTML controls are a challenge to style. You can style any element in the web platform that uses Shadow DOM with a pseudo element ::pseudo-element or the /deep/ path selector.

video::webkit-media-controls-timeline {
  background-color: lime;
}

video /deep/ input[type=range] {