Skip to content

Instantly share code, notes, and snippets.

View morningtoast's full-sized avatar

Brian Vaughn morningtoast

View GitHub Profile
@morningtoast
morningtoast / js-ajax
Created August 23, 2013 18:42
Vanilla ajax
function ajax(url, callback) {
var xmlhttp;
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { callback(xmlhttp.responseText); }
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
@morningtoast
morningtoast / timezone-php
Created August 28, 2013 19:06
Time zone conversion
<?php
// http://forrst.com/posts/PHP_Timezone_Conversion_Including_Daylight_Savi-9ah
date_default_timezone_set("America/New_York");
function timec($event, $eventtz, $usertz){
//convert event time to gmt
$etz = new DateTime(date('Y-m-d'), new DateTimeZone($eventtz));
$etzo = $etz->getOffset();
$gmt = strtotime($event) - $etzo;
@morningtoast
morningtoast / php-timezone-dropdown
Last active December 21, 2015 21:39 — forked from tamaspap/gist:6281449
Time zone list for PHP
<select name="timezone">
<option value="America/New_York">(-05:00) US/Canada Eastern Time</option>
<option value="America/Chicago">(-06:00) US/Canada Central Time</option>
<option value="America/Denver">(-07:00) US/Canada Mountain Time</option>
<option value="America/Los_Angeles">(-08:00) US/Canada Pacific Time</option>
<option value="">-----</option>
<option value="Pacific/Wake">(-12:00) International Date Line West</option>
<option value="Pacific/Apia">(-11:00) Midway Island</option>
<option value="Pacific/Apia">(-11:00) Samoa</option>
<option value="Pacific/Honolulu">(-10:00) Hawaii</option>
@morningtoast
morningtoast / url-bookmarklet
Created September 5, 2013 15:18
Bookmarklet that passes title and URL
javascript:(function() { window.open('http://localhost/lazy/uri.php?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title),'bookmarklet','width=200,height=200'); });
@morningtoast
morningtoast / typeahead
Created December 9, 2013 18:15
Search typeahead. jQuery-based that uses inline template for output (not included)
var typeahead = {
timer: false,
start: function(input) {
_debug(".typeahead keyup");
// Unset any started timers from previous keyup
if (typeahead.timer != undefined) {
clearTimeout(typeahead.timer);
}
@morningtoast
morningtoast / gist:8680405
Created January 29, 2014 01:56
Styled inputs with glyphs
// Works well on most current popular browsers. (Web fonts shakey on fringe browsers)
.styled-input {
input[type=radio] {
display: none;
&:checked + label:before {
@include icon($icon-radio-checked);
color: #000;
}
@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;