Skip to content

Instantly share code, notes, and snippets.

@ganey
ganey / secret santa
Created December 11, 2014 14:36
Fisher Yates JS Secret Santa
var a = "joe tom dave mike mark sue lauren".split(" "), b = 0, c = a, d, e, f, g = c.length;
for (d = 0;d < g;d++) {
f = ~~(Math.random() * (d + 1)), e = c[d], c[d] = c[f], c[f] = e;
}
for (a = c;b < a.length;) {
console.log(a[b] + " => " + (b + 1 < a.length ? a[b + 1] : a[0])), b++;
}
;
@ganey
ganey / cpanel_mysql_move_to_new_mount_point
Last active August 29, 2015 14:12
cPanel mysql move to new mount point
#thanks to http://forums.cpanel.net/f354/how-move-mysql-data-directory-110481.html#post861642 and
#http://forums.cpanel.net/f354/how-move-mysql-data-directory-110481-p2.html#post1055762
#1. fallback dump
mysqldump --opt --all-databases | gzip > /home/alldatabases.sql.gz
#2. create new mount point
mkdir /var/lib/mysqltmp
#3. Configure /etc/fstab so that the new partition is mounted when the server boots (adjust values as necessary)
<?php
/*
This is a fork of https://gist.github.com/frzsombor/ddd0e11f93885060ef35
Thanks frzsombor!
|--------------------------------------------------------------------------
| Checking the Sentry Auth for CKFinder CheckAuthentication
|--------------------------------------------------------------------------
| Put in the CKFinder config.php within the CheckAuthentication() function.
|
@ganey
ganey / Domain Regex
Created April 14, 2015 10:45
Domain Regex
Works in the laravel regex as part of an array.
Covers with http,https and none.
requires a 2 letter domain extension.
/^((http|https)\:\/\/|)[\w+\.]+[\w]+$/
@ganey
ganey / osx_smb1
Created July 10, 2015 09:34
Mac OSX use SMB1
sudo echo "[default]" >> ~/Library/Preferences/nsmb.conf;
echo "smb_neg=smb1_only" >> ~/Library/Preferences/nsmb.conf
@ganey
ganey / full-height.css
Last active May 16, 2016 16:53
CSS Full height
/* Author: http://www.minimit.com/articles/solutions-tutorials/bootstrap-3-responsive-columns-of-same-height, stored here for easy reference */
/* USAGE
<div class="row">
<div class="row-height">
<div class="col-xs-2 col-xs-height col-xs-middle">
<div class="inside"></div>
</div>
<div class="col-xs-4 col-lg-5 col-xs-height col-xs-middle">
<div class="inside"></div>
</div>
@ganey
ganey / upload_image_example.php
Last active November 10, 2015 14:24
Google Api Client PHP Image Upload
<?php
//Based on composer require google/api-client:^1.1
$filename = $_FILES['file']['name'];
$type = $_FILES['file']['type'];
$tmp_name = $_FILES['file']['tmp_name'];
$newurl = '/media/' . $filename;
@ganey
ganey / oneactivemodal.js
Created April 7, 2016 08:13
jQuery 1 active modal
// Not my code
// Code from here: http://www.minimit.com/articles/solutions-tutorials/bootstrap-3-open-only-one-modal-at-time
// Storing here for reference
var modalUniqueClass = ".modal";
$('.modal').on('show.bs.modal', function(e) {
var $element = $(this);
var $uniques = $(modalUniqueClass + ':visible').not($(this));
if ($uniques.length) {
$uniques.modal('hide');
@ganey
ganey / domainValidation.php
Last active May 20, 2016 10:56
Domain / url regex
<?php
// tested here: https://regex101.com/r/iC1uQ4/1
// as laravel validation rule: 'regex:/^((http|https)\:\/\/|)([\w]+\.)+\w+($|[\w\/\.]+$|[\w\/\.]+\?[\w\=\&\.]+$)/'
$re = "/^((http|https)\:\/\/|)([\w|\-]+\.)+\w+($|[\w\-\/\.]+$|[\w\/\.]+\?[\w\=\&\.]+$)/";
$str = "www.example.com/metropolitanlondon";
preg_match($re, $str, $matches);
/*
@ganey
ganey / .htaccess
Last active December 20, 2016 15:25
Compression for htaccess
## Add correct content-type for fonts
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-ttf .ttf
AddType application/x-font-opentype .otf
AddType application/x-font-woff .woff
AddType image/svg+xml .svg
## Fix other types
AddType text/javascript .js
AddType text/css .css