Skip to content

Instantly share code, notes, and snippets.

View danro's full-sized avatar
👀

Dan Rogers danro

👀
View GitHub Profile
@danro
danro / easing.scss
Created August 16, 2012 21:43
SCSS easing equations
// Cubic
$easeInCubic: cubic-bezier(0.550, 0.055, 0.675, 0.190);
$easeOutCubic: cubic-bezier(0.215, 0.610, 0.355, 1.000);
$easeInOutCubic: cubic-bezier(0.645, 0.045, 0.355, 1.000);
// Circ
$easeInCirc: cubic-bezier(0.600, 0.040, 0.980, 0.335);
$easeOutCirc: cubic-bezier(0.075, 0.820, 0.165, 1.000);
$easeInOutCirc: cubic-bezier(0.785, 0.135, 0.150, 0.860);
@danro
danro / webflow-resize.js
Created November 12, 2013 18:59
Webflow.js resize example
var Webflow = Webflow || [];
Webflow.push(function () {
// Find example element
var $element = $('.resize-demo');
var $parent = $element.parent();
// Listen for optimized resize event
Webflow.resize.on(function () {
@danro
danro / 1-mixin.scss
Created September 9, 2012 19:40
SCSS hover-active mixin
@mixin hover-active {
&:hover {
.no-touch & {
@content;
}
}
&:active {
.touch & {
@content;
}
@danro
danro / twitter-text.js
Created October 14, 2011 17:35
Parse links & usernames in twitter text.
// parses the text in a tweet and adds links to users, hash tags and urls
parseTweet: function (text) {
// parse urls
text = text.replace(/[A-Za-z]+:\/\/[A-Za-z0-9_-]+\.[A-Za-z0-9_:%&~\?\/.=-]+/g, function(url) {
return url.link(url)
})
// parse usernames
text = text.replace(/[@]+[A-Za-z0-9_-]+/g, function(u) {
var username = u.replace("@","")
return u.link("http://twitter.com/"+username)
@danro
danro / twitter-date.js
Created October 18, 2011 20:02
Twitter date string regex replace, IE8 fix
var s = "Fri Apr 09 12:53:54 +0000 2010";
var date = new Date(s.replace(/^\w+ (\w+) (\d+) ([\d:]+) \+0000 (\d+)$/, "$1 $2 $4 $3 UTC"));
// Cross-browser, time-zone-aware parsing via JavaScript:
// Tested on IE, Firefox, Safari, Chrome and Opera.
@danro
danro / starter.sh
Created September 12, 2013 07:00
nodejs forever crontab reboot script
#!/bin/sh
if [ $(ps aux | grep $USER | grep node | grep -v grep | wc -l | tr -s "\n") -eq 0 ]
then
export PATH=/usr/local/bin:$PATH
export NODE_ENV=production
cd /path/to/app && forever --spinSleepTime 10000 start server.js >> forever.log 2>&1
fi
@danro
danro / webflow-snippet.js
Last active August 17, 2022 19:29
Webflow.js front-end JS wrapper
var Webflow = Webflow || [];
Webflow.push(function () {
// DOMready has fired
// May now use jQuery and Webflow api
});
@danro
danro / remove-video.js
Created June 6, 2013 23:33
Remove HTML5 video and clear src attribute to prevent leaks.
// remove audio + video + stop all the downloadin’
// assumes $video and $audio are jQuery selectors for <video> and <audio> tags.
var removeMedia = function () {
_.each([$video, $audio], function ($media) {
if (!$media.length) return;
$media[0].pause();
$media[0].src = '';
$media.children('source').prop('src', '');
$media.remove().length = 0;
});
@danro
danro / iphone-media-queries.css
Created October 25, 2012 02:06
iphone media queries
/* iPhone 3 portrait */
@media (device-height: 480px) and (-webkit-max-device-pixel-ratio: 1) and (orientation:portrait) {
}
/* iPhone 3 landscape */
@media (device-height: 480px) and (-webkit-max-device-pixel-ratio: 1) and (orientation:landscape) {
}
/* iPhone 4 retina portrait */
@media (device-height: 480px) and (-webkit-min-device-pixel-ratio: 2) and (orientation:portrait) {
@danro
danro / href.js
Created February 25, 2013 20:23
neat href tricks
// example window url: http://test.dev/stuff
var query = 'poop=butts&farts=smellz';
var parser = document.createElement('a'); // create anonymous 'a' tag
parser.href = window.location.href;
parser.search = query;
console.log(parser.href);
// ^ should output: http://test.dev/stuff?poop=butts&farts=smellz