michaelfox + gist   34

Keymando keyboard shortcuts — Gist
Dan Rogers (@danro)
12/2/11 3:42 PM
If you use multiple text-editors on the mac (ie. TextMate + Xcode), @keymando is a fantastic key remap tool. My config: gist.github.com/1424734
textmate  xcode  config  dotfiles  keymando  gist  github 
january 2012 by michaelfox
Git aliases — Gist
[alias]
edit-unmerged = "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; $EDITOR `f`"
add-unmerged = "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; git add `f`"

lc = log ORIG_HEAD.. --stat --no-merges
smash = merge --no-commit --log
eat = branch -M
prune-all = !git remote | xargs -n 1 git remote prune
whois = "!sh -c 'git log -i --pretty="format:%an <%ae>" --author="$1" | sort -u' -"
whatis = show -s --pretty='tformat:%h (%s, %ad)' --date=short
this = !git init && ( [[ -n $(ls) ]] || touch .gitignore ) && git add . && git commit -m "initial commit"

sp = ![[ -z $(git status --porcelain -uno) ]] && git pull || git stash && git pull && git stash pop
spp = ![[ -z $(git status --porcelain -uno) ]] && git pull || git stash && git pull && git push && git stash pop
pp = !git pull && git push
ppu = !git pp && git submodule sync && git submodule update --init

ls = "!git status -suno"
ls-modified = "!git status --porcelain -uno | awk 'match($1, /M/) {print $2}'"
ls-added = "!git status --porcelain -uno | awk 'match($1, /A/) {print $2}'"
ls-deleted = "!git status --porcelain -uno | awk 'match($1, /D/) {print $2}'"
ls-renamed = "!git status --porcelain -uno | awk 'match($1, /R/) {print $2}'"
ls-copied = "!git status --porcelain -uno | awk 'match($1, /C/) {print $2}'"
ls-updated = "!git status --porcelain -uno | awk 'match($1, /U/) {print $2}'"
ls-staged = "!git status --porcelain -uno | grep -P '^[MA]' | awk '{ print $2 }'"
ls-untracked = "!git status --porcelain -uall | awk '$1 == "??" {print $2}'"

sup = !git submodule sync && git submodule update --init

# install t first: http://github.com/sjl/t
todo = !python ~/lib/t/t.py --task-dir "$(git rev-parse --show-toplevel)" --list TODO
bug = !python ~/lib/t/t.py --task-dir "$(git rev-parse --show-toplevel)" --list BUGS

alias = "!sh -c '[ $# = 2 ] && git config --global alias."$1" "$2" && exit 0 || [ $# = 1 ] && [ $1 = "--list" ] && git config --list | grep "alias\." | sed "s/^alias\.\([^=]*\)=\(.*\).*/\1@@@@=>@@@@\2/" | sort | column -ts "@@@@" && exit 0 || echo "usage: git alias <new alias> <original command>\n git alias --list" >&2 && exit 1' -"
ignore = "!sh -c '([ $# = 2 ] && ([ "$1" = "--local" ] && echo "$2" >> "./$(git rev-parse --show-cdup)/.git/info/exclude" || ([ "$2" = "--local" ] && echo "$1" >> "./$(git rev-parse --show-cdup)/.git/info/exclude"))) || ([ $# = 1 ] && (([ "$1" == "--list" ] && git ls-files -i --exclude-standard) || (([ ! -e .gitignore ] && touch .gitignore || echo "$(cat .gitignore)" > .gitignore) && echo "$1" >> .gitignore))) || echo "usage: git ignore <file>\n git ignore --local <file>\n git ignore --list" >&2 && exit 1' -"

lol = log --graph --decorate --pretty=oneline --abbrev-commit
lola = log --graph --decorate --pretty=oneline --abbrev-commit --all

cs = !git ls-staged | grep ".php" | xargs phpcs

peeps = !git log --pretty=format:%aN | sort | uniq -c | sort -rn
graph = log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
git  dotfiles  config  gist  github-user:bobthecow 
october 2011 by michaelfox
rsync Project now.tmCommand itspriddle's gist: 107286 — Gist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>

if [ "$SSH_KEY" != "" ] &amp;&amp; [ "$SSH_HOST" != "" ] &amp;&amp; [ "$SSH_USER" != "" ] &amp;&amp; [ "$SSH_REMOTE_PATH" != "" ]; then

if [ "$RSYNC_OPTIONS" != "" ]; then
  OPTS="$RSYNC_OPTIONS"
fi

if [ "$RSYNC_EXCLUDE_FROM" != "" ]; then
  if [ -f "$RSYNC_EXCLUDE_FROM" ]; then
    OPTS="$OPTS --exclude-from=$RSYNC_EXCLUDE_FROM"
  elif [ -f "$TM_PROJECT_DIRECTORY/$RSYNC_EXCLUDE_FROM" ]; then
    OPTS="$OPTS --exclude-from=$TM_PROJECT_DIRECTORY/$RSYNC_EXCLUDE_FROM"
  fi
fi

OUT=`rsync -e "ssh -i $SSH_KEY" -auv $OPTS "$TM_PROJECT_DIRECTORY"/ "$SSH_USER@$SSH_HOST:$SSH_REMOTE_PATH"`
echo -e "$OUT"
</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
<string>^@r</string>
<key>name</key>
<string>rsync Project now</string>
<key>output</key>
<string>showAsTooltip</string>
<key>uuid</key>
<string>3CB55098-1709-444B-A3BE-E72680134CF0</string>
</dict>
</plist>
gist  textmate  rsync  command 
april 2011 by michaelfox
AppleScript for Pasting To Gist
tell application "Safari"
activate
open location "http://gist.github.com"
end tell
delay 1
tell application "System Events"
tell process "Safari"
keystroke "v" using {command down}
end tell
end tell
applescript  gist  apple  osx  mac  safari 
february 2011 by michaelfox
gist: 747637 - TinyMCE jQuery UI Inline Popups- GitHub
/**
* @filename : editor_plugin.js
* @description : jQuery UI Inline Popups plugin to replace the default inlinepopups
* @developer : badsyntax (Richard Willis)
* @contact : http://badsyntax.co
* @moreinfo : http://is.gd/j1FuI
*/

(function() {

var DOM = tinymce.DOM,
Element = tinymce.dom.Element,
Event = tinymce.dom.Event,
each = tinymce.each,
is = tinymce.is;

// Create the editor plugin
tinymce.create('tinymce.plugins.jQueryInlinePopups', {

init : function(ed, url) {

// Replace window manager
ed.onBeforeRenderUI.add(function() {

ed.windowManager = new tinymce.InlineWindowManager(ed);
});
},

getInfo : function() {
return {
longname : 'jQueryInlinePopups',
author : 'Richard Willis',
authorurl : 'http://badsyntax.count',
infourl : '',
version : '0.1a'
};
}
});

// Create the window manager
tinymce.create('tinymce.InlineWindowManager:tinymce.WindowManager', {

InlineWindowManager : function(ed) {

var t = this;

t.parent(ed);
t.zIndex = 300000;
t.count = 0;
t.windows = {};
},

open : function(f, p) {

f = f || {};
p = p || {};

// Run native windows
if (!f.inline)
return t.parent(f, p);

var
config = {
title: f.title || '',
width: f.width + 1,
height: f.height + 25,
modal: true,
resizable: false,
draggable: true,
dialogClass: 'ui-dialog-tinymce'
},
t = this,
id = DOM.uniqueId(),
dialog = $('<div />')
.attr('id', 'dialog-' + id)
.hide()
.appendTo('body'),
w = {
id : id,
features : f,
element: dialog
};

if (f.title)
dialog.attr('title', f.title);

if (f.content){

if (f.type == 'confirm'){

function buttonAction(e){

if (/mceClose/.test(e.target.className)) {

t.close(null, id);

} else if (/mceOk/.test(e.target.className) || /mceCancel/.test(e.target.className)) {

f.button_func(/mceOk/.test(e.target.className));
}

Event.cancel(e);

return false;
}

config.buttons = [
{
text: "Ok",
click: buttonAction,
class: 'mceOk'
},
{
text: "Cancel",
click: buttonAction,
class: 'mceCancel'
}
];
}

var content = $('<div />')
.addClass('ui-dialog-tinymce-content')
.html(f.content);

dialog.html(content);
}
else
{

var iframe = $('<iframe />', {
id: id + '_ifr',
frameborder: 0
})
.css({
width: f.width,
height: f.height
})
.appendTo(dialog)
.attr( 'src', f.url || f.file );

w.iframeElement = iframe[0];
}

p.mce_inline = true;
p.mce_window_id = id;
p.mce_auto_focus = f.auto_focus;

this.features = f;
this.params = p;
this.onOpen.dispatch(this, f, p);

dialog.dialog(config);

// Add window
t.windows[id] = w;

t.count++;

return w;
},

_findId : function(w) {

var t = this;

if (typeof(w) == 'string')
return w;

each(t.windows, function(wo) {
var ifr = DOM.get(wo.id + '_ifr');

if (ifr && w == ifr.contentWindow) {
w = wo.id;
return false;
}
});

return w;
},

resizeBy : function(dw, dh, id) {

return;
},

focus : function(id) {

return;
},

close : function(win, id) {

var t = this, w, d = DOM.doc, ix = 0, fw, id;

id = t._findId(id || win);

// Probably not inline
if (!t.windows[id]) {
t.parent(win);
return;
}

t.count--;

if (w = t.windows[id]) {

t.onClose.dispatch(t);

Event.clear(id);
Event.clear(id + '_ifr');

DOM.setAttrib(id + '_ifr', 'src', 'javascript:""'); // Prevent leak

w.element.dialog('destroy').remove();

delete t.windows[id];
}
},

setTitle : function(w, ti) {

var e;

w = this._findId(w);

if (e = DOM.get('ui-dialog-title-dialog-' + w))
e.innerHTML = DOM.encode(ti);
},

alert : function(txt, cb, s) {
var t = this, w;

w = t.open({
title : 'Error',
type : 'alert',
button_func : function(s) {
if (cb)
cb.call(s || t, s);

t.close(null, w.id);
},
content : DOM.encode(t.editor.getLang(txt, txt)),
inline : 1,
width : 400,
height : 130
});
},

confirm : function(txt, cb, s) {
var t = this, w;

w = t.open({
title: 'Please confirm',
type : 'confirm',
button_func : function(s) {
if (cb)
cb.call(s || t, s);

t.close(null, w.id);
},
content : DOM.encode(t.editor.getLang(txt, txt)),
inline : 1,
width : 400,
height : 130
});
}
});

// Register plugin
tinymce.PluginManager.add('jqueryinlinepopups', tinymce.plugins.jQueryInlinePopups);
})();
gist  tinymce  javascript  richtexteditor  editor  jquery  jqueryui  popups 
january 2011 by michaelfox
gist: 606737 - GitHub
function resizeImage($file,$scale="",$width="",$height="")
{
// If they wish to scale the image.
if (isset($scale))
{
// Create our image object from the image.
$fullImage = imagecreatefromjpeg($file);
// Get the image size, used in calculations later.
$fullSize = getimagesize($file);
// If there is NOT a thumbnail for this image, make one.
if (!file_exists("tn_".$file))
{
// Create our thumbnail size, so we can resize to this, and save it.
$tnImage = imagecreatetruecolor($fullSize[0]/$scale, $fullSize[1]/$scale);
// Resize the image.
imagecopyresampled($tnImage,$fullImage,0,0,0,0,$fullSize[0]/$scale,$fullSize[1]/$scale,$fullSize[0],$fullSize[1]);
// Create a new image thumbnail.
imagejpeg($tnImage, "tn_".$file);
// Clean Up.
imagedestroy($fullImage);
imagedestroy($tnImage);
// Return our new image.
return "tn_".$file;
}
// If there is a thumbnail file, lets just load it.
else
return "tn_".$file;
}
// If they want to force whatever size they want.
elseif (isset($width) && isset($height))
{
return "tn_".$file;
}
else
{
return false;
}
}
gist-606737  gist  images  gd  php  resize  scale 
november 2010 by michaelfox
gist: 379244 - GitHub
// simple jquery tinymce lazyload
// - using $.getScript alone will not work
// - it's important to set the tinymce basepath, and set the domLoaded attribute

window.tinyMCEPreInit = {
base: '/js/tiny_mce/',
suffix : '',
query : ''
};
$(function(){
$.getScript('/js/tiny_mce/tiny_mce.js', function(){
tinymce.dom.Event.domLoaded = true;
tinyMCE.init({
mode: 'textareas',
theme: 'advanced'
});
});
});
gist-379244  gist  javascript  jquery  tinymce  lazyload  async 
october 2010 by michaelfox
gist: 601260 - GitHub
// This is the conclusion to my tests of determining the best way to cache images.
// I used apache access logs to determine when an image was actually requested from the web server.


// The following code, although not that elegant, works fine in IE6, IE7, IE8, FF3, Safari, Chrome, Opera

var _cacheImages = [];

function cacheImages(images){

$.each(images, function(index, val){

var image = new Image()
image.src = val;

_cacheImages.push( image );
});
};

// The following will NOT work in IE6:
function cacheImages(images){

$.each(images, function(index, val){

var image = new Image()
image.src = val;
});
};

// Also the following will NOT work in IE6 (sorry!)
function cacheImages(images){

$.each(images, function(index, val){

new Image().src = val;
});
};

// It seems you need to save a reference to the image object in order for IE6 to send a request to retrieve it
gist-601260  gist  javascript  cache  caching  performance  optimization  test  research 
october 2010 by michaelfox
gist: 603087 - GitHub
(function(window, document, undefined){

// !incomplete

var comments = [];

function hideComments(content){

var c = -1;

return content
.replace(/(\/\/.*?)\n/g, '__c{$1}') // find '// comment' and replace with placeholder
.replace(/\n/g,'\uffff') // replace new lines chars so we can match over multi lines
.replace(/(\/\*.*?\*\/)/g, '__c{$1}') // find '/* comment */' and replace with placeholder
.replace(/__c\{(.*?)\}/g, function(x, y){ // find placeholder comment and store comment content

comments[++c] = y;

return '__c{' + c + ';}';
})
.replace(/\uffff/g,'\n'); // replace newline placeholder with actual newline
}

function restoreComments(content){

return content
.replace(/__c\{([0-9]+);\}/g, function(x, y){ // find placeholder comments and replace with comment content

return '\n' + comments[y].replace(/\uffff/g,'\n') + '\n';
});
}

function cleanWhitespace(content){

return content

.replace(/\s/g, ' ') // convert all whitespace to normal space char
.replace(/ {2,}/g, ' ') // convert multiple consecutive space chars to one space char
.replace(/([:;]) /g, '$1') // remove space after semi-colons
.replace(/ ([:;])/g, '$1') // remove space before semi-colons
.replace(/\s+([\{\}])/g, '$1') // remove space before braces
.replace(/([\{\}])\s+/g, '$1') // remove space after braces
.replace(/\}/g, '}\n') // add newline after brace
.replace(/([^;])\}/g, '$1;}') // add semicolon before brace
;
}

document.getElementById('clean').onclick = function(){

var content = document.getElementById('content').value;

content = hideComments(content);

content = cleanWhitespace(content);

content = restoreComments(content);

document.getElementById('content').value = content;
};


})(window, document);
gist-603087  gist  formatting  text  regex  javascript 
october 2010 by michaelfox
gist: 400118 - GitHub
// fixing The Mysterious Firefox setTimeout "Lateness" argument™
// by paul irish

// detail: http://benalman.com/news/2009/07/the-mysterious-firefox-settime/


// "feature" test
void setTimeout(function(){
if (arguments.length==1){ // bad mozilla!, bad!

// now, we fix
(function(){
var old = window.setTimeout;
window.setTimeout = function(func,delay){

var args = Array.prototype.slice.call(arguments,2,arguments.length);

return old.call(window,function(){
func.apply(window,Array.prototype.slice.call(args));
},delay);
}
})();
}
},0)


// Does it work?

// because the feature test is asynchronous, this will probably fail
// if immediately executed afterwards.
// if you sniffed for firefox/gecko instead of feature testing, this
// would be synchronous and this test would immediately pass

setTimeout(function(){
console.log('is setTimeout normalized now?',arguments.length==3);
},4,'true',false,5)
gist-400118  gist  javascript  settimeout 
october 2010 by michaelfox
gist: 581815 - GitHub
// feature test for position fixed.

Modernizr.addTest('positionfixed', function () {
var test = document.createElement('div'),
control = test.cloneNode(false),
fake = false,
root = document.body || (function () {
fake = true;
return document.documentElement.appendChild(document.createElement('body'));
}());

var oldCssText = root.style.cssText;
root.style.cssText = 'padding:0;margin:0';
test.style.cssText = 'position:fixed;top:42px';
root.appendChild(test);
root.appendChild(control);

var ret = test.offsetTop !== control.offsetTop;

root.removeChild(test);
root.removeChild(control);
root.style.cssText = oldCssText;

if (fake) {
document.documentElement.removeChild(root);
}

return ret;
});
gist-581815  gist  javascript  modernizr  featuretest  test  css  positionfixed 
october 2010 by michaelfox
gist: 603681 - html5 and friends - a bigass bulleted list of features- GitHub
A bigass bulleted list of features.

I commonly need to get a big list of all the stuff people think of when they think new and shiny these days. This list is for that.

I take a very inclusionist approach to it. 1
gist-603681  gist  html5  reference  features  javascript  flash  browser 
october 2010 by michaelfox
gist: 626834 - userscript: Drop the UTM params from a URL when the page loads- GitHub
// ==UserScript==
// @name UTM param stripper
// @author Paul Irish
// @namespace http://github.com/paulirish
// @description Drop the UTM params from a URL when the page loads.
// @extra Cuz you know they're all ugly n shit.
// @include http://*
// ==/UserScript==


// save this as utmstrip.user.js and drag it into Chrome or Firebug (with greasemonkey)


if (/^\?utm_/.test(location.search) && window.history.replaceState){
window.history.replaceState({},'', location.href.replace(/\?utm_.*/,''));
}



// also..
// this is just as useful on your own site.. in case you have feedburner tracking or whatever.
gist-626834  gist  userscripts  javascript 
october 2010 by michaelfox
gist: 261269 - GitHub
// When the next click or keypress happens, anywhere on the screen, hide the
// element. 'clickable' makes the element and its contents clickable without
// hiding. The 'onHide' callback runs when the hide fires, and has a chance
// to cancel it.
autohide : function(options) {
var me = this;
options = _.extend({clickable : null, onHide : null}, options || {});
me._autoignore = true;
setTimeout(function(){ delete me._autoignore; }, 0);

if (!me._autohider) {
me.forceHide = function(e) {
if (!e && options.onHide) options.onHide();
me.hide();
$(document).unbind('click', me._autohider);
$(document).unbind('keypress', me._autohider);
me._autohider = null;
me.forceHide = null;
};
me._autohider = function(e) {
if (me._autoignore) return;
if (options.clickable && (me[0] == e.target || _.include($(e.target).parents(), me[0]))) return;
if (options.onHide && !options.onHide(e)) return;
me.forceHide(e);
};
$(document).bind('click', this._autohider);
$(document).bind('keypress', this._autohider);
}
}
gist-261269  gist  javascript  hide  jquery 
october 2010 by michaelfox
gist: 270742 - GitHub Attempt to make a drop-and-forget bunch of scripts that mimick some missing html5 goodies automatically
var ProvideHtml5 = {
autofocus : function() {
if (!Modernizr.autofocus)
$('input[autofocus=""]').focus();
},
colorpicker : function() {
if (!Modernizr.inputtypes.color)
$('input[type=color]').ColorPicker({
onSubmit: function(hsb, hex, rgb, el) {
$(el).val(hex);
$(el).ColorPickerHide();
},
onBeforeShow: function () {
$(this).ColorPickerSetColor(this.value);
},
onChange: function (hsb, hex, rgb, el) {
$('input[type=color]').val('#'+hex);
}
}).bind('keyup', function(){
$(this).ColorPickerSetColor(this.value);
});
},
datepicker : function() {
var datetypes = 'date month week time datetime datetime-local'.split(/ /)
$(datetypes).each(function(i, type) {
if (!Modernizr.inputtypes[type])
$('input[type='+type+']').datepicker()
})
},
forcenumber : function() {
if (!Modernizr.inputtypes.number)
$('input[type=number]').forcenumber();
},
placeholder : function() {
if (!Modernizr.input.placeholder)
$('input[placeholder]').placeholder();
},

all : function() {
for (f in this)
if (f != 'all')
this[f]()
}
};

$.fn.placeholder = function() {
return $(this)
.each(function(){
$(this).data('default', $(this).attr('placeholder'));
})
.focus(function(){
($(this).val()===$(this).data('default')) && $(this).val('');
})
.blur(function(){
($(this).val()==='') && $(this).val($(this).data('default'));
}).blur();
}


$.fn.forcenumber = function() {
return $(this).unbind().keyup(function(e) {

var val = $(this).val(),
num = parseFloat(val),
min = parseFloat($(this).attr('min')),
max = parseFloat($(this).attr('max'));

if ( ! val.match(/^(\d|-)?(\d|,)*\.?\d*$/) )
return $(this).val(val.match(/((\d|-)?(\d|,)*\.?\d*)/)[0])

if (min && num < min)
return $(this).val(min)

if (max && num > max)
return $(this).val(max)

});
}
javascript  modernizr  html5  jquery  shim  placeholder  autofocus  date  color  number  gist-270742  gist 
october 2010 by michaelfox

related tags

ajax  apple  applescript  async  autofocus  bash  browser  bundle  cache  caching  chrome  class  cli  code  codeigniter  color  command  config  css  css3  date  defaults  dotfiles  download  editor  environment  etc  evernote  exports  extension  extensions  features  featuretest  firefox  flash  formatting  function  functions  gd  gist  gist-243409  gist-257736  gist-261269  gist-270742  gist-379244  gist-400118  gist-460360  gist-581815  gist-601260  gist-603087  gist-603681  gist-606737  gist-626834  git  github  github-user:bobthecow  googleanalytics  grammar  greasemonkey  hacks  headers  hide  history  html5  http  image  images  inspiration  javascript  jquery  jqueryui  keymando  language  lazyload  library  loader  mac  markdown  models  modernizr  module  multisite  my.cnf  mysql  MY_Loader  number  ondomready  opensource  optimization  osx  performance  php  placeholder  popups  positionfixed  preload  projects  reddit  reference  regex  replacestate  research  resize  richtexteditor  rsync  safari  scale  script  service  settimeout  settings  setup  shell  shim  source  system  test  text  textmate  tinymce  url  userscripts  utilities  via:cowboy  via:rodneyrehm  window  wordpress  wysiwyg  xcode 

Copy this bookmark:



description:


tags: