Skip to content

Instantly share code, notes, and snippets.

View krabello's full-sized avatar

Kevin Rabello krabello

  • Stetson University
  • DeLand, Florida
View GitHub Profile
@krabello
krabello / gist:10ba1b2c7a9336a5eb56
Created June 26, 2015 13:19
CSS Media Queries Template
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen
and (min-width : 321px) {
@krabello
krabello / head-template.txt
Last active August 29, 2015 14:27
HTML Head Template
<!-- Behavioral Meta Data -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<!-- Core Meta Data -->
<meta name="author" content="">
<meta name="description" content="">
<meta name="keywords" content="">
<!-- Open Graph Meta Data -->
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
// Static Server + watching scss/html files
gulp.task('serve', ['sass'], function() {
browserSync.init({
@krabello
krabello / debounce.js
Created October 12, 2015 13:41
debounce function to keep code efficient
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
@krabello
krabello / poll.js
Created October 12, 2015 13:43
Poll function if the event doesn't exist, you need to check for desired state at intervals
function poll(fn, callback, errback, timeout, interval) {
var endTime = Number(new Date()) + (timeout || 2000);
interval = interval || 100;
(function p() {
// If the condition is met, we're done!
if(fn()) {
callback();
}
// If the condition isn't met but the timeout hasn't elapsed, go again
@krabello
krabello / once.js
Created October 12, 2015 13:44
Once for times when you prefer a given functionality only happen once, similar to the way you'd use an onload event.
function once(fn, context) {
var result;
return function() {
if(fn) {
result = fn.apply(context || this, arguments);
fn = null;
}
return result;
@krabello
krabello / getAbsoluteUrl.js
Created October 12, 2015 13:50
Getting an absolute URL from a variable string isn't as easy as you think. There's the URL constructor but it can act up if you don't provide the required arguments (which sometimes you can't).
var getAbsoluteUrl = (function() {
var a;
return function(url) {
if(!a) a = document.createElement('a');
a.href = url;
return a.href;
};
})();
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $url, $matches);
@krabello
krabello / gist:60b6bf53cc7ac2642e5a
Created February 29, 2016 01:04
Wordpress CRUD class
<?php
/**
* Abstract class which has helper functions to get data from the database
*/
abstract class Base_Custom_Data
{
/**
* The current table name
*
* @var boolean
import time
class StopWatch:
def __init__(self, func=time.perf_counter):
self.elapsed = 0.0
self._start = None
self._func = func
self.maxTime = 10000000