Skip to content

Instantly share code, notes, and snippets.

View morningtoast's full-sized avatar

Brian Vaughn morningtoast

View GitHub Profile
@morningtoast
morningtoast / gist:8721307
Last active August 29, 2015 13:55
imageshack api curl
<pre>
<?
class ImageShack {
function auth($username, $password) {
$this->debug("Logging in");
$response = $this->doCurl("post", "https://api.imageshack.us/v1/user/login", array(
"user" => $username,
"password" => $password
@morningtoast
morningtoast / gist:9400516
Created March 6, 2014 21:55
YouTube URL replacer
function ytEmbed($str) {
$pattern = '/https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/ytscreeningroom\?v=|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]{11})[?=&+%\w-]*/i';
$found = preg_match_all($pattern, $str, $matches);
if ($found > 0) {
foreach ($matches[0] as $k => $replaceThis) {
$ytid = $matches[1][$k];
$replaceWith = '<div class="media"><div class="video-container"><iframe title="YouTube video" class="youtube-player" height="315" width="560" type="text/html" src="http://www.youtube.com/embed/'.$ytid.'" frameborder="0"></iframe></div></div>';
$str = str_replace($replaceThis, $replaceWith, $str);
}
@morningtoast
morningtoast / bbcodetohtml
Last active August 29, 2015 13:57
phpBB convert bbcode to html
<?php
$bbcode = file_get_contents("bbcode.txt");
function bbcodeToHtml($str, $convertBreaks=true) {
$replace = array(
// bold
array(
@morningtoast
morningtoast / css-mini-arrow
Created April 23, 2014 15:22
CSS mini arrow
<style>
.arrowme:after {
position: absolute;
display: inline-block;
content: '';
margin-left: 10px;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
border-left: 6px solid #000;
margin-top: 9px;
@morningtoast
morningtoast / sass-pxtoem
Created May 13, 2014 14:30
SASS: PX to EM function
// SASS
@function pxtoem($pixels, $context: 16) {
@return #{$pixels/$context}em
}
// USE
.element {
max-width: pxtoem(780);
}
@morningtoast
morningtoast / viewsource
Created May 16, 2014 13:53
View source JS
// Get HTML from an element, then escape it and drop it into another element (pre)
function viewsource(sel) {
var source = document.getElementById(sel).innerHTML;
source = source.replace(/[<>]/g, function(m) { return {'<':'&lt;','>':'&gt;'}[m]});
source = source.replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a href="$1">$1</a>');
document.getElementById("source").innerHTML = source;
}
@morningtoast
morningtoast / tile-sliderx
Created May 16, 2014 17:10
Tile slider. Fixed-width tiles for off-canvas tile effect.
jQuery(function($){
function debug(str) {
if (settings.debug) { console.log(str); }
}
var settings = {
debug: true
}
var root = {
@morningtoast
morningtoast / plugin-template-new
Last active August 29, 2015 14:01
Updated jQuery plugin template
/*
My Plugin
The description/summary of the plugin
5/21/14 ~BV
Syntax:
$(selector).myPlugin(options)
Usage:
/*
Content Toggler
Show/hides content as specified in the target elements by data attribute
5/21/14 ~BV
The target elements must have the attribute "toggler" with a value
that is the selector of the content you want to show/hide when
the trigger is clicked.
Markup example:
@morningtoast
morningtoast / modaloverlay
Last active August 29, 2015 14:02
Modal overlay background
<div class="overlay" tabindex="-1"></div>
.overlay {
@include opacity (70, .70); // enabled
z-index:998; // enabled
z-index: -1;
position: fixed;
left: 0;
top: 0;
width: 100%;