Skip to content

Instantly share code, notes, and snippets.

View philfreo's full-sized avatar

Phil Freo philfreo

View GitHub Profile
@philfreo
philfreo / keybase.md
Created May 21, 2015 18:18
keybase.md

Keybase proof

I hereby claim:

  • I am philfreo on github.
  • I am philfreo (https://keybase.io/philfreo) on keybase.
  • I have a public key whose fingerprint is 1F81 B578 6E87 8A29 B28B 4578 2DCA C2F7 8DAA 538B

To claim this, I am signing this object:

@philfreo
philfreo / body-drag-listener.js
Last active August 17, 2016 18:29
Keep track of when a file is currently dragged over a web page
// Keep track of when a file is dragged onto the page.
// Adding a 'filedragging' class to <body> when one is.
(function() {
// Since dragenter & dragleave get fired for children elements, need some workaround
// to tell when file is started & stopped being dragged onto page.
// Ideas extracted from https://github.com/bensmithett/dragster
var klass = 'filedragging',
first = false,
second = false;
$(document).on({
@philfreo
philfreo / localstorage_safari_private_shim.js
Last active November 20, 2019 22:49
Don't let localStorage/sessionStorage setItem throw errors in Safari Private Browsing Mode
// Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem
// throw QuotaExceededError. We're going to detect this and just silently drop any calls to setItem
// to avoid the entire page breaking, without having to do a check at each usage of Storage.
if (typeof localStorage === 'object') {
try {
localStorage.setItem('localStorage', 1);
localStorage.removeItem('localStorage');
} catch (e) {
Storage.prototype._setItem = Storage.prototype.setItem;
Storage.prototype.setItem = function() {};
@philfreo
philfreo / gist:fc068094f6e26d6995e2
Last active December 10, 2015 18:34
Backbone.js patch to prevent duplicate POSTs
// Queue of Backbone.Model save()s so that we don't issue multiple POSTs while waiting for
// the first one to come back. The first save() will always POST and the second will always PUT now.
// https://github.com/documentcloud/backbone/issues/345
// http://stackoverflow.com/a/6122530/137067
// https://gist.github.com/1037984
Backbone.Model.prototype._save = Backbone.Model.prototype.save;
Backbone.Model.prototype.save = function(attrs, options) {
// Queue up consecutive requests if the model is new and the initial
// POST request hasn't finished yet (xhr.readyState === 4 if the
// "request finished and response is ready").
@philfreo
philfreo / _README.md
Last active February 3, 2022 20:46
How to do conditional statements in Close.io template tags
@philfreo
philfreo / gist:cbab6aad493a6a3c21e8
Last active August 29, 2015 14:08
SMTP & IMAP details for popular email services

IMAP

Gmail/Google Apps:

Host: imap.gmail.com
Port: 993
Username: youremail@gmail.com or youremail@yourdomain.com (Google Apps)
Password: Your email password
SSL: Yes
@philfreo
philfreo / fauxSelect.js
Last active April 6, 2018 16:30
Give a <select> element a different look, but still retain all OS benefits of using a real <select> (full screen height options list, keyboard navigation, etc.)
// Make faux dropdowns show their new value, when it's changed.
$(document.body).on('change', '.faux-select-wrapper select', function(e) {
var select = $(e.target);
$.fn.fauxSelect.refresh(select);
});
$.fn.fauxSelect = function(method) {
var select = this;
// if fauxSelect is being called again on an already-handled element, then just update the
// visible text