Skip to content

Instantly share code, notes, and snippets.

View dylanhthomas's full-sized avatar

Dylan Thomas dylanhthomas

View GitHub Profile
@dylanhthomas
dylanhthomas / jquery.scrolldirection.js
Created June 7, 2017 14:54 — forked from marcojetson/jquery.scrolldirection.js
jQuery - Adds scroll direction to scroll event
(function ($) {
"use strict";
var wnd = $(window),
lastScrollTop = wnd.scrollTop(),
lastScrollLeft = wnd.scrollLeft();
wnd.on("scroll", function (event) {
var scrollTop = wnd.scrollTop(),
scrollLeft = wnd.scrollLeft(),
@dylanhthomas
dylanhthomas / unsized-images.css
Created June 18, 2013 16:48
CSS - Spot unsized images during development.
// Add this to stylesheet to find all unsized images
// Via 37signals http://37signals.com/svn/posts/2979-css-tip-spot-unsized-images-during-development
img:not([width]):not([height]) {
border: 2px solid red !important;
}
@dylanhthomas
dylanhthomas / ipad-conditional-viewport.php
Created June 18, 2013 16:46
iPad Conditional Viewport - Serve different viewports to different clients based on user-agent. With php this is a trivial affair, as long as you know the user-agents that your targeting.
<?php
//Probably an iPad
if(stristr($_SERVER['HTTP_USER_AGENT'], 'iPad')) {
echo '<meta name="viewport" content="width=980;user-scalable=yes;" />';
}
else{
echo '<meta name="viewport" content="width=1150;user-scalable=yes;" />';
}
@dylanhthomas
dylanhthomas / delete-dstore.sh
Created June 18, 2013 16:42
Shell - Recursively Delete All .DS_Store Files
find . -name *.DS_Store -type f -exec rm {} \;
@dylanhthomas
dylanhthomas / change-extension.sh
Created June 18, 2013 16:40
You can adapt this for any filename find/replace, but I find it most useful for changing a directory of .html files to .php files.
for file in *.html ; do mv $file `echo $file | sed 's/\(.*\.\)html/\1php/'` ; done
@dylanhthomas
dylanhthomas / underscore.sh
Created June 18, 2013 16:38
Shell - Replace Spaces with Underscores in All Filenames
#!/bin/bash
ls | while read -r FILE
do
mv -v "$FILE" `echo $FILE | tr ' ' '_' `
done
@dylanhthomas
dylanhthomas / drop-extension.htaccess
Last active December 18, 2015 15:49
htaccess - remove file extensions from URL. Replace .php with whatever extension you want to remove:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
@dylanhthomas
dylanhthomas / excel-remove-trailing-slash.txt
Created June 18, 2013 16:36
Remove the Trailing slash from a cell in Excel. This is especially handy when dealing with lots of urls. Replace "A1" with your cell.
=IF(RIGHT(A1,(LEN(A1)-(LEN(A1)-1)))="/",LEFT(A1,(LEN(A1)-1)),A1)
@dylanhthomas
dylanhthomas / iphone5.css
Created June 18, 2013 16:34
iPhone 5 specific mediaquery
@media only screen and (device-aspect-ratio: 40/71)
Replace all instances of old_string with new_string recursively within the current directory and its sub-directories:
grep -rl old_string * | xargs sed -i '' 's/old_string/new_string/g'