Skip to content

Instantly share code, notes, and snippets.

@oslego
oslego / cssToDOM.js
Last active Aug 29, 2015
Converts a CSS property name to its DOM form. Removes dashes and upperacases the char following the dash.
View cssToDOM.js
/*
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 Aug 29, 2015
Cycle through data request strategies (ajax, jsonp) within a Promise.
View ajax-jsonp-promise.js
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 Jul 6, 2014
Mock impl of chrome.runtime for static development
View chrome.runtime.js
/*
Mock-implementation of chrome.runtime messaging API
*/
var Messager = (function (){
var _listeners = [];
return {
onMessage: {
addListener: function(cb){
_listeners.push(cb);
View sm-annotated.html
<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 Jul 14, 2015
DOM events wrapper with auto-unbind from @toddmotto
View events-wrapper.js
// 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 Jul 17, 2009
Detect browser CSS capabilities by looking for DOM property references
View browserUtil.js
/**
* @author Razvan Caliman, razvan.caliman@gmail.com
*/
/**
* wrapper for browser sniffing / capabilities check methods
*/
var browser = {};
/**
@oslego
oslego / Simple CSS Liquid Grid
Created Jul 30, 2009
A simple CSS layout grid that suits liquid layouts
View Simple CSS Liquid Grid
.grid_container{
position:relative;
width:100%;
}
.grid_half{
width:50%;
float:left;
}
View N Zakas's JavaScript lazy loader
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;
View mysql_database_backup
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 Nov 19, 2009
Apache gzip filter
View Apache gzip
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/javascript text/javascript text/css application/x-javascript
You can’t perform that action at this time.