Skip to content

Instantly share code, notes, and snippets.

View alexmcpherson's full-sized avatar

Alex McPherson alexmcpherson

  • Colorado
View GitHub Profile
@alexmcpherson
alexmcpherson / scrape.js
Created September 17, 2012 00:52
Casper.js vimrc scraper
var casper = require("casper").create();
var url = "https://github.com/search?langOverride=VimL&language=&q=vimrc&repo=&type=Repositories&start_value=" + casper.cli.get(0);
var repoLinks = [];
var fileLinks = [];
function getRepoLinks() {
var links = [];
$("div.results .result h2 a").each(function(i,el){
links.push(el.href);
});
@alexmcpherson
alexmcpherson / gist:97a4160c08a5e06a0acb
Last active February 13, 2016 10:23
Google.com <enter> interview question

This was my very first take with no research on what happens when you press in Chrome with Google.com in the address bar:

  • press enter on keyboard
    • some switch gets connected
    • hardware encodes signal for key to go over USB
    • sends signal over USB
  • computer gets enter signal
    • driver gets signal from keyboard
    • signal translated into an OS-level event probably was pressed
  • OS knows what program has focus, dispatches event to that program
@alexmcpherson
alexmcpherson / circle.yml
Created July 28, 2015 23:12
CircleCI consuming private node modules
dependencies:
pre:
- |
npm login <<!
$NPM_USERNAME
$NPM_PASSWORD
$NPM_EMAIL!
@alexmcpherson
alexmcpherson / pre-compilation.js
Last active December 31, 2015 21:39
Minifier error?
_update: function() {
//Kill old style
if (helpers.isDefAndNotNull(this.active)) { // <-- properly guarded here
this.active.el.removeClass('selected');
this.active.active = false;
}
// Grab the new state
this.active = this.states[this.currentIdx];
this.active.active = true;
@alexmcpherson
alexmcpherson / build.bat
Created September 3, 2013 16:33
Grunt! Use Grunt!
@echo off
copy src\intro.js /B + src\core.js /B + src\tooltip.js /B temp1.js /B
copy src\models\*.js /B temp2.js /B
copy temp1.js /B + temp2.js /B + src\outro.js /B nv.d3.js /B
del temp1.js
del temp2.js
require "money"
class Decorator < BasicObject
undef_method :==
def initialize(component)
@component = component
end
def method_missing(name, *args, &block)
@alexmcpherson
alexmcpherson / upload.coffee
Created March 13, 2013 17:20
Image Preview on upload
handleFileUpload: (e) ->
file = e.target.files[0]
reader = new FileReader();
reader.onload = (e) =>
@image = new Image()
@image.onload = @renderImage
@image.src = e.target.result
reader.readAsDataURL(file)
@alexmcpherson
alexmcpherson / MyView.js
Last active December 10, 2015 14:08
More granular view updating:
var MyView = Backbone.View.extend({
initialize: function() {
this.render();
//Two different update calls here, neither using .render()
this.model.on('change:first', this.updateFirst, this);
this.model.on('change:last', this.updateLast, this);
},
render: function() {
//Puts el on page, called ONLY once, by init
},
@alexmcpherson
alexmcpherson / MyView.js
Last active December 10, 2015 14:08
Another separation of concerns that's possible:
var MyView = Backbone.View.extend({
initialize: function() {
this.render();
this.model.on('change', this.update, this);
},
render: function() {
//Puts el on page, called ONLY once, by init
},
update: function() {
this.$el.html( /* Some template */ )
@alexmcpherson
alexmcpherson / index.html
Created January 3, 2013 00:42
Page content after a few renders:
<div id="content">
<div>Person Name: Alex</div>
<div>Person Name: AlexPerson Name: Ale</div>
<div>Person Name: AlexPerson Name: AlePerson Name: Al</div>
</div>