Skip to content

Instantly share code, notes, and snippets.

View Eworm's full-sized avatar
💭
Happy

Wout Mager Eworm

💭
Happy
View GitHub Profile
@stefthoen
stefthoen / functions.php
Last active February 12, 2016 21:33
WordPress function to create picturefill HTML.
function get_responsive_image($id, $src, $alt = "") {
$large = wp_get_attachment_image_src( $id, 'large' );
$medium = wp_get_attachment_image_src( $id, 'medium' );
$small = wp_get_attachment_image_src( $id, 'thumbnail' );
$output = '<div class="img-responsive">';
$output.= ' <div data-picture data-alt="' . $alt . '">';
$output.= ' <div data-src="' . $small[0] . '"></div>';
$output.= ' <div data-src="' . $medium[0] . '" data-media="(min-width: 786px)"></div>';
$output.= ' <div data-src="' . $large[0] . '" data-media="(min-width: 920px)"></div>';
@ngryman
ngryman / snippet.js
Last active February 14, 2019 23:55 — forked from necolas/snippet.js
/*
* 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(d, u) {
var s = d.scripts[0],
i = u.length, g;
@davidjb
davidjb / acceleration-demo.html
Last active June 7, 2019 22:16
Web API demos for acceleration, compass (non-standard), directions, geolocation and more.
<!DOCTYPE html>
<html>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<body>
<script type="text/javascript" charset="utf-8">
var counter = 0;
var timeout;
window.addEventListener('devicemotion', function(event) {
var accel = event.acceleration;
@benlumley
benlumley / migrateorders.php
Created December 5, 2013 22:57
Script to migrate woocommerce orders from one wordpress database into another, along with associated data.
<?php
// Copies woocommerce orders and users over from source to target.
// I use this on my local machine - loading both db's up there side by side
// could easily adjust the connect strings to connect elsewhere if needed.
// will change order ids
// My use case for this is when I've got a staging/test version of a site with new posts/products/pages etc, that needs
// to go live without the loss of any orders placed on the site site since we copied it to the staging site.
@bacoords
bacoords / grab_vimeo_thumbnail.php
Last active January 24, 2024 09:40
Grab a thumbnail of a private (but embeddable) Vimeo video
<?php
/**
* Grab the url of a publicly embeddable video hosted on vimeo
* @param str $video_url The "embed" url of a video
* @return str The url of the thumbnail, or false if there's an error
*/
function grab_vimeo_thumbnail($vimeo_url){
if( !$vimeo_url ) return false;
$data = json_decode( file_get_contents( 'http://vimeo.com/api/oembed.json?url=' . $vimeo_url ) );
@tjlytle
tjlytle / imageColor.php
Created November 17, 2009 19:19
Class to find 'average' image color.
<?php
/**
* imageColor
*
* Shows three methods to find the 'average' image color.
*
* Each function expects a gd image object.
*
* imageColor::averageResize($image) resizing to 1px, and checking the color.
* imageColor::averageBorder($image) find the average color of all border pixels.
@cfaria
cfaria / migrateorders.php
Last active February 12, 2024 16:45 — forked from maddisondesigns/migrateorders.php
Migrate WooCommerce Orders
<?php
//increase max execution time of this script to 150 min:
ini_set('max_execution_time', 9000);
//increase Allowed Memory Size of this script:
ini_set('memory_limit','960M');
// Copies woocommerce orders and users over from source to target.
// I use this on my local machine - loading both db's up there side by side
// could easily adjust the connect strings to connect elsewhere if needed.
@mishterk
mishterk / LocalValetDriver.php
Last active March 1, 2024 22:00
A local Valet driver for proxying images to a remote host
<?php
/**
* Class LocalValetDriver
*
* This class demonstrates how we might go about proxying any missing local images to a remote host. i.e; the production
* site. This has been created with WordPress in mind but could be adjusted to work with any other system.
*/
class LocalValetDriver extends WordPressValetDriver {
@hdragomir
hdragomir / sm-annotated.html
Last active March 5, 2024 08:57
The deferred font loading logic for Smashing Magazine. http://www.smashingmagazine.com/
<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);
@mjackson
mjackson / color-conversion-algorithms.js
Last active April 14, 2024 08:46
RGB, HSV, and HSL color conversion algorithms in JavaScript
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSL representation