Skip to content

Instantly share code, notes, and snippets.

View dryan's full-sized avatar
Black Lives Matter

Dan Ryan dryan

Black Lives Matter
View GitHub Profile
#element {
-webkit-transform: scale(0.75), rotateY(0deg), translate(0, 20px);
}
#element:hover {
-webkit-transform-scale: 1.0;
-webkit-transform-translate: 0, 0;
}
#element.flipped {
function getElementTransitionDuration(elem, property) {
// this currently only supports Webkit browsers, but should be easy enough to apply to others as they begin to support CSS transitions
var td = elem ? window.getComputedStyle(elem)['-webkit-transition-duration'].split(', ') : [],
tp = elem ? window.getComputedStyle(elem)['-webkit-transition-property'].split(', ') : [],
durations = {},
longest = 0,
i = td.length;
while( --i ) {
var dur = parseFloat(td[i], 10);
if(i < tp.length) {
function getElementScale(elem) {
var transform = /matrix\([^\)]+\)/.exec(window.getComputedStyle(elem)['-webkit-transform']),
scale = {'x': 1, 'y': 1};
if( transform ) {
transform = transform[0].replace('matrix(', '').replace(')', '').split(', ');
scale.x = parseFloat(transform[0]);
scale.y = parseFloat(transform[3]);
}
return scale;
}
@dryan
dryan / gravatar.py
Created July 29, 2010 20:27
Django templatetag for getting gravatars
from django import template
from django.conf import settings
import urllib, hashlib
register = template.Library()
class GravatarUrlNode(template.Node):
def __init__(self, email):
self.email = template.Variable(email)
AWS_ACCESS_KEY_ID = 'your_key_goes_here'
AWS_SECRET_ACCESS_KEY = 'your_secret_key_goes_here'
AWS_STORAGE_BUCKET_NAME = 'your_bucket_name_goes_here'
@dryan
dryan / check_site.py
Created July 1, 2010 18:16
check_sites shell script to monitor a list of websites and send notices when they are down.
#!/usr/bin/env python
sites = [
'google.com',
]
USE_BOXCAR = True
USE_GROWL = True
BOXCAR_EMAIL = ''
BOXCAR_API_KEY = ''
@dryan
dryan / gist:453321
Created June 25, 2010 19:27
media query conditional CSS for iPhone 4
/* normal clients -- desktops */
#header a.logo {
padding-left: 210px;
background: url('/images/logo-200x200.png') no-repeat 0 50%; /* this is our original graphic at say 200x200px */
}
/* older iPhones, Android, Palm, etc. assuming that their screen is 480px long on the longest side */
@dryan
dryan / nav2select.js
Created May 24, 2010 16:59
convert nav links to <select>
var nav = document.getElementById('nav'),
links = nav.getElementsByTagName('a'),
select = document.createElement('select'),
option = document.createElement('option');
for (var i = 0; i < links.length; i++){
var link = links[i],
_option = option.cloneNode(false);
_option.value = link.href; // Set the option's value to the original link
_option.innerHTML = link.innerHTML; // Set the option's text to the original text
@dryan
dryan / tweet-urlizer.js
Created March 17, 2010 18:07
JavaScript for converting @replies, #hashtags, and URLs to links
// JavaScript for converting @replies, #hashtags, and URLs to links. If you have jQuery on the page, it will also look for yfrog images and photos and embed them as well.
// put this at the top of your file
var isMobile = (navigator.userAgent.toLowerCase().match('mobile') && navigator.userAgent.toLowerCase().match('webkit'));
// run this on each tweet
if( typeof jQuery == 'object' && tweet.text.indexOf('http://yfrog.') > -1 ) {
var yfrogurl_start = tweet.text.search(/http:\/\/yfrog\.com\/([A-Z0-9]+)/i);
var yfrogurl_end = tweet.text.substr(yfrogurl_start + 17).search(/(\s|$)/);
if( yfrogurl_start == -1 ) {
@dryan
dryan / remove_www_middleware.py
Created January 30, 2010 22:54
Django middleware for removing www.
class RemoveWWW(object):
def process_request( self, request ):
try:
if request.META['HTTP_HOST'].lower().find('www.') == 0:
from django.http import HttpResponsePermanentRedirect
return HttpResponsePermanentRedirect( request.build_absolute_uri().replace('//www.', ‘/') )
except:
pass
return None