Skip to content

Instantly share code, notes, and snippets.

View dan-diaz's full-sized avatar
🚀

Dan Diaz dan-diaz

🚀
View GitHub Profile

Keybase proof

I hereby claim:

  • I am dan-diaz on github.
  • I am danieldiaz (https://keybase.io/danieldiaz) on keybase.
  • I have a public key ASBFvC7wDpS0yAOg2SgT5rKblEG8v1qJVdL73_jd4gEc7Ao

To claim this, I am signing this object:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div id="schoolLunch"></div>
<script src="generated/js/bundle.js"></script>
</body>
</html>
@dan-diaz
dan-diaz / gist:2cc9564cdf22563a6310
Created September 12, 2014 17:56
Default Settings Pattern
var defaultSettings = {
x:0.5,
y:true,
}
var settings = defaultSettings;
function exampleFunction(userSettings) {
//extend settings object
for (var key in userSettings) {
if (userSettings.hasOwnProperty(key) && userSettings[key] !== undefined) {
@dan-diaz
dan-diaz / gist:a264274251f1557116c0
Created August 21, 2014 18:01
draw canvas hexagon
var dxCanvas = document.getElementById('dxCanvas');
var ctx = dxCanvas.getContext('2d');
function drawHex(size,x,y) {
ctx.beginPath();
ctx.moveTo(x,y);
var x2 = Math.sqrt((size*size) - ((size/2)*(size/2)))+x,
y2 = y-(size/2),
x3 = (Math.sqrt((size*size) - ((size/2)*(size/2)))*2)+x,
y3 = y,
@dan-diaz
dan-diaz / gist:2852d84e9f1f25b3ce71
Created July 15, 2014 20:30
Custom AJAX object that doesn't require jQuery.
DD.ajax = function(settings) {
var ajax = new XMLHttpRequest();
// settings
var method = settings.method || 'GET';
var url = settings.url || null;
var async = settings.async || true;
ajax.open(method, url, async);
ajax.send();
@dan-diaz
dan-diaz / form.js
Created April 14, 2014 18:27
AJAX Form w/ PHP response
$('#main-form').submit(function(e) {
e.preventDefault();
var name = $('#main-form #name-input').val();
var email = $('#main-form #email-input').val();
var formData = {};
var alertElement = $('#main-form .alert');
alertElement.removeClass('alert-success alert-danger');
@dan-diaz
dan-diaz / throttler
Created March 21, 2014 19:49
event throttler, to prevent rapid firing of potentially heavy functions.
var throttler = function(func) {
var throttle;
window.addEventListener('resize',function(){
clearTimeout(throttle);
throttle = setTimeout(func, 200);
});
}
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
@dan-diaz
dan-diaz / gist:8894374
Last active August 29, 2015 13:56
gmail attachment automation
var autoDrive = {};
autoDrive.settings = {
label: 'Band',
folder: 'Music'
};
//collect attachments by labelName from unread messages within the inbox
//Example: autoDrive.collectAttachments('Band', 'Music');
autoDrive.collectAttachments = function(label, folder){