Skip to content

Instantly share code, notes, and snippets.

View bpierre's full-sized avatar
✌️

Pierre Bertet bpierre

✌️
View GitHub Profile
@bpierre
bpierre / parseurl.js
Created September 5, 2012 23:40
ParseURL
/*
ParseURL by James Padolsey: http://james.padolsey.com/javascript/parsing-urls-with-the-dom/
*/
// This function creates a new anchor element and uses location
// properties (inherent) to get the desired URL data. Some String
// operations are used (to normalize results across browsers).
function parseURL(url) {
var a = document.createElement('a');
@bpierre
bpierre / index.html
Created August 23, 2012 13:37
Mini Slider: zero dependencies, IE8+.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mini slider</title>
<link rel="stylesheet" href="mini-slider.css">
</head>
<body>
<div id="slider">
<!-- The previous button is inserted here -->
@bpierre
bpierre / gist:2603011
Created May 5, 2012 14:45
hasOwnProperty style
var obj = {
foo: 1,
bar: 2
};
Object.prototype.oops = function(){};
// Meh.
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
@bpierre
bpierre / documentup-bookmarklet.js
Created May 1, 2012 16:01
Switch between documentup.com and github.com
// javascript:(function(){var%20w%20=%20window,h%20=%20w.location.host,p%20=%20w.location.pathname,r%20=%20p.match(/^(\/[^\/]+\/[^\/]+)/),gh%20=%20%27github.com%27,du%20=%20%27documentup.com%27;if%20(r%20&&%20h%20==%20gh)%20{w.location%20=%20%27http://%27%20+%20du%20+%20r[1];}%20else%20if%20(r%20&&%20h%20==%20du)%20{w.location%20=%20%27https://%27%20+%20gh%20+%20r[1];}})();
(function(){
var w = window,
h = w.location.host,
p = w.location.pathname,
r = p.match(/^(\/[^\/]+\/[^\/]+)/),
gh = 'github.com',
du = 'documentup.com';
if (r && h == gh) {
@bpierre
bpierre / mini-lightbox.js
Created November 6, 2011 00:08
A mini lightbox (jQuery)
/* A small script to display lightboxes. No IE6 support. */
/*global jQuery: false*/
(function($, window){
"use strict";
$.miniLightbox = {};
var EVENT_NS = 'minilightbox';
var DEFAULT_SETTINGS = {
'class': '',
@bpierre
bpierre / Makefile
Created November 5, 2011 03:18 — forked from abackstrom/Makefile
CSS and JavaScript Minification/Compression Makefile
#
# css/js minification/compression makefile
#
#
# JS_TARGETS -- js files to minify/gzip
# CSS_TARGETS -- css files to minify/gzip
# CLEANUP -- additional files to delete during "make clean"
#
@bpierre
bpierre / _init-routes.js
Created October 15, 2011 01:04
A simple routing function for jQuery history
// Use it with jQuery history: http://tkyk.github.com/jquery-history-plugin/
// Hashes should begin with #!/ (see hash.slice(2) below)
(function($) {
$.history.initRoutes = function (routes) {
$(function() {
$.history.init(function(hash) {
hash = hash.slice(2);
var routeFound = false;
for (var rpath in routes) {
if (routes.hasOwnProperty(rpath)) {
@bpierre
bpierre / video_url_to_id.php
Created August 23, 2011 11:52
Parse video providers
<?php
// From Robbie Player: https://forrst.com/posts/Grab_Youtube_or_Vimeo_Info_with_PHP-0el#comment-150356
function video_url_to_id($url, $provider) {
$video_id = FALSE;
$url = parse_url($url);
switch ($provider) {
case 'youtube':
Error.prepareStackTrace = function(error, structuredStackTrace) {
console.log('ok.');
};
// Simple test, ok
try {
console.log('simple test\u2026');
i_dont_exist();
} catch(e) {
var access_stack = e.stack;
@bpierre
bpierre / edit_css.js
Created January 13, 2011 14:11
To fix the "disappearing background images and @font-face" bug in the "edit CSS" feature of the Web Developer Toolbar Firefox Addon. See instructions below.
var webdeveloper_editCSSIntervalId = null;
var webdeveloper_editCSSOldStyleText = new Array();
var webdeveloper_editCSSSelectedTab = 0;
var webdeveloper_editCSSUpdateFrequency = 500;
// Applies the CSS
function webdeveloper_applyCSS()
{
var contentDocument = webdeveloper_getContentDocument();
var headElement = webdeveloper_getDocumentHeadElement(contentDocument);