Skip to content

Instantly share code, notes, and snippets.

View amacdougall's full-sized avatar

Alan MacDougall amacdougall

View GitHub Profile
@amacdougall
amacdougall / gist:1078176
Created July 12, 2011 15:15
Mouse return focus detector
import com.alanmacdougall.underscore._;
// and then, after View is added to stage...
stage.addEventListener(Event.MOUSE_LEAVE, function handleMouseLeave(event:Event):void {
stage.removeEventListener(Event.MOUSE_LEAVE, handleMouseLeave);
stage.addEventListener(MouseEvent.MOUSE_OVER, function handleMouseReturn(event:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_LEAVE, handleMouseReturn);
// wait 500ms to let other handlers sort themselves out, I guess
_(function():void {
@amacdougall
amacdougall / gist:1078525
Created July 12, 2011 17:48
Self-cleaning anonymous function
sprite.addEventListener(Event.ENTER_FRAME, function handleFrame(event:Event):void {
sprite.addEventListener(Event.REMOVED_FROM_STAGE, function(event:Event):void {
sprite.removeEventListener(Event.ENTER_FRAME, handleFrame);
});
});
@amacdougall
amacdougall / gist:1152808
Created August 17, 2011 22:28
Model.as, setValue refactoring
/**
* Sets the value targeted by the key to the value. Only handles key formats
* that have been seen "in the wild," but adding new ones is a cinch. Known
* formats so far:
*
* event
* event.card
* event.card.fonts
* event.card.sides.0.assets.0.propertyName
* event.card.side(paper,front,0).assets
task :production_deploy do
xpaths = {
:debug => "//compiler/debug",
:debug_define => "//compiler/define[name='CONFIG::debug']"
}
# read config xml and set to production mode, storing old values
xml = Nokogiri::XML File.open("src/Main-config.xml")
debug_node = xml.at_xpath xpaths[:debug]
debug_define_node = xml.at_xpath xpaths[:debug_define_node]
@amacdougall
amacdougall / gist:1270302
Created October 7, 2011 13:40
Project Euler problem 3
# target = 13195
target = 600851475143
sub_target = target
current_factor = 2
prime_factors = []
while sub_target > current_factor:
while sub_target % current_factor > 0:
current_factor += 1
prime_factors.append(current_factor)
@amacdougall
amacdougall / gist:1345526
Created November 7, 2011 17:02
Human-friendly context strings
require 'test_helper'
class NewPaperTest < ActiveSupport::TestCase
context "setting design_theme along with family" do
# see Paperless::Content::Family -- setting design theme should also load
# the family from which the theme comes
setup do
@paper = create_new_paper
@paper.design_theme = {:design_theme => "Red", :family => "Flowers"}
@paper.save
@amacdougall
amacdougall / focus.vim
Created March 6, 2012 23:38
Simple vim script for a single centered text column.
" Name: focus.vim
" Author: Alan MacDougall <smoke@alanmacdougall.com>
" License: Public Domain
"
" Focus on a single column of text, showing it in a distraction-free format.
" Save this as ~/.vim/scripts/focus.vim (or whatever you please), and invoke
" it with :source <filename>. Of course, you could certainly hook that up to a
" :command, or a macro, or a Vimscript function...
" collapse current splits and divide screen in three
@amacdougall
amacdougall / AirFileStreamTest.as
Created March 13, 2012 15:09
Quick and dirty AIR filestream test
package {
// imports
import flash.display.*;
import flash.events.*;
import flash.filesystem.*;
import flash.text.TextField;
/**
* Quick and dirty AIR file stream test.
*/
@amacdougall
amacdougall / .git-completion.bash
Created July 11, 2012 15:05
Change .git-completion.bash to ignore remotes
#!bash
#
# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
@amacdougall
amacdougall / gist:3123594
Created July 16, 2012 16:22
Collection filtering idea
var collection = new DataCollection(apiURL);
collection.pageSize = 20;
collection.filters = {
recommended: function(element) {
return element.isRecommended;
},
favorite: function(element) {