Skip to content

Instantly share code, notes, and snippets.

@oslego
oslego / cssToDOM.js
Last active August 29, 2015 13:57
Converts a CSS property name to its DOM form. Removes dashes and upperacases the char following the dash.
/*
Takes a CSS property name string and returns its DOM notation.
@example: shape-inside -> shapeInside
@example: -webkit-shape-inside -> webkitShapeInside
@param {String} str CSS property name, possibly hyphenated.
@return {String}
*/
function getDOMCSSProperty(str){
@oslego
oslego / ajax-jsonp-promise.js
Last active August 29, 2015 14:02
Cycle through data request strategies (ajax, jsonp) within a Promise.
function get(url){
return new Promise(function(resolve, reject){
// request strategies: ajax, jsonp
var types = ['json', 'jsonp'];
function call(){
// try data type strategies one-by-one; mutates the array
var type = types.shift();
@oslego
oslego / chrome.runtime.js
Created July 6, 2014 16:43
Mock impl of chrome.runtime for static development
/*
Mock-implementation of chrome.runtime messaging API
*/
var Messager = (function (){
var _listeners = [];
return {
onMessage: {
addListener: function(cb){
_listeners.push(cb);
<script type="text/javascript">
(function () {
"use strict";
// once cached, the css file is stored on the client forever unless
// the URL below is changed. Any change will invalidate the cache
var css_href = './index_files/web-fonts.css';
// a simple event handler wrapper
function on(el, ev, callback) {
if (el.addEventListener) {
el.addEventListener(ev, callback, false);
@oslego
oslego / events-wrapper.js
Created July 14, 2015 12:02
DOM events wrapper with auto-unbind from @toddmotto
// addEventListener wrapper
// returns function for auto-unbinding
function on(elem, type, fn) {
elem.addEventListener(type, fn, false);
return function () {
off(elem, type, fn);
};
}
// removeEventListener wrapper
@oslego
oslego / browserUtil.js
Created July 17, 2009 07:57
Detect browser CSS capabilities by looking for DOM property references
/**
* @author Razvan Caliman, razvan.caliman@gmail.com
*/
/**
* wrapper for browser sniffing / capabilities check methods
*/
var browser = {};
/**
@oslego
oslego / Simple CSS Liquid Grid
Created July 30, 2009 15:02
A simple CSS layout grid that suits liquid layouts
.grid_container{
position:relative;
width:100%;
}
.grid_half{
width:50%;
float:left;
}
function loadScript(url, callback){
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState){ //IE
script.onreadystatechange = function(){
if (script.readyState == "loaded" ||
script.readyState == "complete"){
script.onreadystatechange = null;
mysqldump -h localhost -u username -ppassword dbname1 dbname2 --compress --default-character-set=utf8 | gzip -c --best > `date +%Y_%m_%d_dbname.sql.gz`
@oslego
oslego / Apache gzip
Created November 19, 2009 14:07
Apache gzip filter
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/javascript text/javascript text/css application/x-javascript