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:47bd608180bbbe8ee83ca926c0d4b634
Created August 18, 2016 15:01
Symfony2 nginx virtual host
server {
listen 80;
# Server name being used (exact name, wildcards or regular expression)
server_name DOMAIN_NAME;
client_max_body_size 20M;
# Document root, make sure this points to your Symfony2 /web directory
root /var/www/html/DIRECTORY;
@krabello
krabello / drupalnginx.conf
Created May 12, 2016 13:41
Drupal 8 Nginx Configuration
server {
listen 80; # redundant in new nginx versions
server_name domain.com;
root /var/www/html/drupal;
access_log off;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
location ~ \..*/.*\.php$ {
return 403;
@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
@krabello
krabello / getYoutubeID.php
Created December 22, 2015 14:21
PHP Regex to get youtube video ID
/*
Matches:
youtube.com/v/vidid
youtube.com/vi/vidid
youtube.com/?v=vidid
youtube.com/?vi=vidid
youtube.com/watch?v=vidid
youtube.com/watch?vi=vidid
youtu.be/vidid
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $url, $matches);
@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;
};
})();
@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 / 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 / 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;