Skip to content

Instantly share code, notes, and snippets.

View mikermcneil's full-sized avatar
🧑‍🚀

Mike McNeil mikermcneil

🧑‍🚀
View GitHub Profile
@mikermcneil
mikermcneil / icscfs.12.11.02.html
Created November 2, 2012 13:48
ie conditional stylesheet example for sebastian
<!DOCTYPE html>
<html>
<head>
<!-- http://css-tricks.com/how-to-create-an-ie-only-stylesheet/ -->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="/stylesheets/ie7.css" /> <![endif]-->
@mikermcneil
mikermcneil / get-jquery.js
Created November 6, 2012 04:02
Get jQuery on a page that doesn't have it
// Example usage:
getjQuery(function (e) {
// jQuery loaded successfully!
});
// Get jQuery on a page that doesn't have it,
// perhaps in order to engage in some laid-back hacking
function getjQuery(callback) {
loadScript("https://stripe.com/javascripts/jquery.js",callback);
}
@mikermcneil
mikermcneil / quick-veil.js
Created November 6, 2012 04:10
Cover the current page in a semi-transparent, black veil
// ************************************
// To use this code, run drawVeil(opacity,callback)
// ************************************
function drawVeil(opacity,cb) {
// Use 0.5 by default
opacity = opacity || 0.5;
// If jQuery doesn't exist, get it
@mikermcneil
mikermcneil / remote-loaded-drawVeil.js
Created November 6, 2012 10:29
Bookmarklet to toggle transparent black veil over current interface
// *Usage*
// Include the following as a bookmark:
// javascript: var gistSrc = "https://raw.github.com/gist/4022488/d8b31cf4fb663ce2b1afee89f3bd6bf72479c10c/quick-veil.js";console.log("Toggling veil, please wait...");function loadScript(src, optionalCallback) { var s = document.createElement("script"); s.type = "text/javascript"; s.src = src; var context = document.getElementsByTagName('script')[0]; context.parentNode.insertBefore(s, context); s.async = true; s.addEventListener('load', optionalCallback);}if(typeof veil_liev !== "undefined" && veil_liev) { jQuery("#veil-liev").stop().fadeTo(250, 0, function() { console.log("Veil lifted."); veil_liev = false; jQuery("#veil-liev").remove(); });} else { function afterLoadScript() { drawVeil(0.65, function(v) { veil = v; console.log("Veil dropped."); veil_liev = true; }); } if(typeof veil_liev !== "undefined") { afterLoadScript(); } else { loadScript(gistSrc, afterLoadScript); }}
// Source:
var gistSrc = "https://raw.github.com/gist/4022488/d8b31cf
@mikermcneil
mikermcneil / simple-async-script-loader.js
Created November 6, 2012 10:46
Tiny script to load a remote piece of javascript
// The goal of this script is a dependency-free method of grabbing a remote chunk of javascript (i.e. jQuery)
// loadScript
function loadScript(src,optionalCallback) { var s = document.createElement("script"); s.type = "text/javascript"; s.src = src; var context = document.getElementsByTagName('script')[0]; context.parentNode.insertBefore(s, context); s.async=true; s.addEventListener('load',optionalCallback); }
// Example usage
loadScript("https://some.url",function(e){
console.log("Script loaded successfully!");
});
@mikermcneil
mikermcneil / grab-jquery-bookmarklet.js
Created November 6, 2012 11:11
Bookmarklet to grab jQuery on a site that doesn't have it
function loadScript(src,optionalCallback) { var s = document.createElement("script"); s.type = "text/javascript"; s.src = src; var context = document.getElementsByTagName('script')[0]; context.parentNode.insertBefore(s, context); s.async=true; s.addEventListener('load',optionalCallback); } function getjQuery(callback){loadScript("https://stripe.com/javascripts/jquery.js",callback);} getjQuery(function (e) { console.log("\n\n","jQuery loaded successfully!"); });
@mikermcneil
mikermcneil / localstorage-adapter.js
Created November 19, 2012 04:57
Agnostic storage adapter for HTML localStorage + Chrome sync storage
var Storage;
// If this is running as a chrome extension, use chrome sync storage
if (chrome && chrome.storage && chrome.storage.sync) {
Storage = {
get: function (key,cb) {
chrome.storage.sync.get(key,function(result) {
cb(null,result && result[key]);
});
},
@mikermcneil
mikermcneil / anchor.js
Created November 20, 2012 09:37
Parameter validator for Express
/**
* Return fn which enforces required request params
* (Req parameter validation should be lenient, and marshal rowdy values)
*/
exports.required = function(validationRules, cb) {
return function(req, res, next) {
// Keep track of list of validation errors
var errors = [];
@mikermcneil
mikermcneil / sails-example-adapter.js
Created November 21, 2012 08:51
An example of what the new Sails adapter specification looks like
// An example sails adapter
module.exports = {
////////////////////////////////////////////////////////////////////////////////
//
// Sails uses migrate() to synchronize the underlying data model with your app's schema.
// If any changes are detected in your models, migrate() is called when starting the server.
//
// Handle associations/references logic here (i.e. belongsTo,has, hasMany)
//
@mikermcneil
mikermcneil / Sublime-from-command-line.sh
Last active October 13, 2015 08:18
How to use Sublime Text 2 from the command line (OS X)
# Add an alias to your .profile directly access the sublime binary
echo >> ~/.profile
echo 'alias sublime="/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl"' >> ~/.profile
# Make sublime your default text editor
echo >> ~/.profile
echo 'export EDITOR="subl -w"' >> ~/.profile
# Refresh your bash .profile
source ~/.profile