Skip to content

Instantly share code, notes, and snippets.

View kurtschlatzer's full-sized avatar

Kurt Schlatzer kurtschlatzer

View GitHub Profile
@codepo8
codepo8 / localstorage.js
Created August 25, 2010 14:44
Store the state of a rendered form the easy way
<script>
// test for localStorage support
if(('localStorage' in window) && window['localStorage'] !== null){
var f = document.getElementById('mainform');
// test with PHP if the form was sent (the submit button has the name "sent")
<?php if(isset($_POST['sent']))){?>
// get the HTML of the form and cache it in the property "state"
localStorage.setItem('state',f.innerHTML);
@wookiehangover
wookiehangover / index.html
Created April 10, 2011 06:28
jquery mobile basic index
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>
</head>
<body>
@necolas
necolas / snippet.js
Created June 14, 2011 20:36
Optimised async loading of cross-domain scripts
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
@cuppster
cuppster / node-express-cors-middleware.js
Created April 9, 2012 16:02
express.js middleware to support CORS pre-flight requests
app.use(express.methodOverride());
// ## CORS middleware
//
// see: http://stackoverflow.com/questions/7067966/how-to-allow-cors-in-express-nodejs
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
@speier
speier / cssincimages
Created May 4, 2012 14:04
Replace CSS images with inline base64 data
var fs = require('fs');
var path = require('path');
function cssIncImages(cssFile) {
var imgRegex = /url\s?\(['"]?(.*?)(?=['"]?\))/gi;
var css = fs.readFileSync(cssFile, 'utf-8');
while (match = imgRegex.exec(css)) {
var imgPath = path.join(path.dirname(cssFile), match[1]);
try {
var img = fs.readFileSync(imgPath, 'base64');
@andrerom
andrerom / responsive_images.htm
Created May 15, 2012 23:22
Responsive image html support proposal
<p>The proposed (but human unreadable) WHATWG syntax:<p>
<pre>
<img src="[email protected]" alt=""
set="[email protected] 600w 200h 1x,
[email protected] 600w 200h 2x,
face-icon.png 200w 200h">
</pre>
<p>The propposed RICG syntax (that WHATWG rejects):</p>
@WillsonSmith
WillsonSmith / Swipe.js
Created July 3, 2012 17:19
Swipe Events (on end touch)
(function(){ //Self executing, anonymous function
//Leave out above if including in already existing script
function Swipe(){
var firstX, lastX;
function swipeRight(){
@DevinWalker
DevinWalker / woocommerce-optimize-scripts.php
Last active November 14, 2024 09:20
Only load WooCommerce scripts on shop pages and checkout + cart
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
@lukehedger
lukehedger / ffmpeg-compress-mp4
Last active November 15, 2024 21:28
Compress mp4 using FFMPEG
$ ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 output.mp4