Skip to content

Instantly share code, notes, and snippets.

@cladley
cladley / setup_django.py
Created July 3, 2013 19:23
Script to setup a django project and create any app that have been passed in. Creates the templates,static/js,static/img, static/css in the root and each app. Also edits the settings.py file and adds a few default properties that I always use.
import os
import sys
import subprocess
class FileHeadRule:
def __init__(self):
self.once = False
def condition(self,line):
.box{
width: 100px;
height: 100px;
float: left;
margin: 10px;
border: 1px solid black;
}
/* Only one item */
var latestKnownScrollY = 0,
ticking = false;
function onScroll(){
latestKnownScrollY = window.scrollY;
requestTick();
}
@cladley
cladley / endevents.js
Last active September 15, 2015 10:40
transition end , animation end event names
function whichAnimationEndEvent(){
var el = document.createElement('fakeelement');
var animationsEvents = {
'WebkitAnimation' : 'webkitAnimationEnd',
'OAnimation' : 'oAnimationEnd',
'msAnimation' : 'MSAnimationEnd',
'animation' : 'animationend'
};
for(var t in animationsEvents){
function SocialShare(el) {
this.POPUP_WIDTH = 550;
this.POPUP_HEIGHT = 420;
this.$element = $(el);
this.$element.on('click', this.onClick.bind(this));
}
SocialShare.prototype = {
var attach = require('attach.js');
var utils = require('./helpers/utils');
var constants = require('./helpers/const');
/**
* Create a new accordion object
* @param {HTMLElement} el
*/
function Accordion(el) {
var docElem = window.document.documentElement;
function getViewportH() {
var client = docElem['clientHeight'],
inner = window['innerHeight'];
if( client < inner )
return inner;
else
return client;
@cladley
cladley / Full screen background-image or image
Created June 10, 2016 12:49
snippet to create a full screen image on any viewport size
<div class="fullscreen" data-img-width="1500" data-img-height="900"> <---- because its a background image, we need the width and height
// whatever here. If it was a normal image tag, we could just get it off
</div> the image
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
.fullscreen {
width: 100%;
height: 100%;
background-image:url('http://someimage.jpg');
function timeoutfunc(fn,delay) {
var intv = setTimeout(function() {
intv = null;
fn(new Error("Timeout"));
}, delay);
return function() {
// timeout hasn't happened yet?
if(intv) {
clearTimeout(intv);
/**
* Timeout promise that can cancel a long running promise
* using Promise.race
*/
function timeoutPromise(delay) {
return new Promise(function(resolve, reject) {
setTimeout(function(){
reject("Timeout!");
}, delay);