Skip to content

Instantly share code, notes, and snippets.

View wyattdanger's full-sized avatar

Stephen Bush wyattdanger

View GitHub Profile
// Keymaster.js https://github.com/madrobby/keymaster
(function(a){function h(a,b){var c=a.length;while(c--)if(a[c]===b)return c;return-1}function i(a){var b,g,i,j,k,m;g=(a.target||a.srcElement).tagName,b=a.keyCode;if(b==93||b==224)b=91;if(b in d){d[b]=!0;for(j in f)f[j]==b&&(l[j]=!0);return}if(g=="INPUT"||g=="SELECT"||g=="TEXTAREA")return;if(!(b in c))return;for(k=0;k<c[b].length;k++){i=c[b][k];if(i.scope==e||i.scope=="all"){m=i.mods.length>0;for(j in d)if(!d[j]&&h(i.mods,+j)>-1||d[j]&&h(i.mods,+j)==-1)m=!1;(i.mods.length==0&&!d[16]&&!d[18]&&!d[17]&&!d[91]||m)&&i.method(a,i)===!1&&(a.preventDefault?a.preventDefault():a.returnValue=!1,a.stopPropagation&&a.stopPropagation(),a.cancelBubble&&(a.cancelBubble=!0))}}}function j(a){var b=a.keyCode,c;if(b==93||b==224)b=91;if(b in d){d[b]=!1;for(c in f)f[c]==b&&(l[c]=!1)}}function k(){for(b in d)d[b]=!1;for(b in f)l[b]=!1}function l(a,b,d){var e,h,i,j;d===undefined&&(d=b,b="all"),a=a.replace(/\s/g,""),e=a.split(","),e[e.length-1]==""&&(e[e.length-2]+=",");for(i=0;i<e

Open Terminal.app and type ifconfig and then hit return. You should see something like this. I've highlighted the IP

ifconfig

Then visit that IP in your web browser. You should see the same thing that you see when you visit localhost

If your phone and computer are on the same wifi network, you should now be able to access your localhost from your phone.

@wyattdanger
wyattdanger / yaml_reader.rb
Created March 20, 2012 02:12
class that accepts a yaml file and dynamically creates getters/setters for each yaml key
class YAMLReader
def initialize yaml_file_path
YAML.load_file(yaml_file_path).each do |key, value|
self.class.instance_eval do
attr_accessor :"#{key}"
end
self.send "#{key}=", value
end
end
end
@wyattdanger
wyattdanger / whichquery.sass
Created March 31, 2012 15:08
Determine which media query breakpoint you're on
body::before
content: '< 480px'
@media only screen and (min-width: 480px)
body::before
content: '480px < 600px'
@media only screen and (min-width: 600px)
body::before
content: '600px < 768px'
@wyattdanger
wyattdanger / whichquery.css
Created March 31, 2012 15:12
Determine which media query breakpoint you're on
body::before {
content: "< 480px"; }
@media only screen and (min-width: 480px) {
body::before {
content: "480px < 600px"; } }
@media only screen and (min-width: 600px) {
body::before {
content: "600px < 768px"; } }
@media only screen and (min-width: 768px) {
@wyattdanger
wyattdanger / dad.md
Created April 9, 2012 03:52
dad post

Dad and I got to talk about programming for two weeks before he died.

I was 22, a senior in college completing a BFA in graphic design. Dad was 62, an older dad than most. When he started programming at Tennessee Tech back in the 60s, he wrote FORTRAN on punch cards. He was a wealth of knowledge.

I had just been introduced to code that semester, and it was already consuming my thoughts. It felt magical and powerful, in many ways a more fulfilling creative practice than visual design (but that's for another post).

When I came home for the holidays, Dad shared The Ten Commandments of Egoless Programming with me. He printed them and we discussed each point. It was one of the few programming related things we were able to discuss before he unexpectedly passed; perhaps that's why it sticks with me.

@wyattdanger
wyattdanger / simple-parser
Created April 23, 2012 00:50
simple parser in peg.js
start =
expression
expression =
_ a:atom
{ return a }
/ _ "(" a:expression b:expression* ")"
{ return [a].concat(b) }
@wyattdanger
wyattdanger / inheritance-demo.js
Created May 1, 2012 19:37
Contrasting prototypal inheritance in JavaScript with classical inheritance in Ruby. In this gist you'll find a JavaScript file and a Ruby file which try to do the same thing, the outputs of each file, and a diff of the two outputs.
var inspect = require('util').inspect, // To help with printing to console
log = console.log;
// Define class Foo
function Foo () {
this.a = [];
}
// Define class Bar which inherits from Foo
function Bar () {}
@wyattdanger
wyattdanger / further-example.diff
Created May 1, 2012 20:28
to give each instance of Bar it's own `a` property, rather than a shared `a` on the prototype
function Foo () {
this.a = [];
}
+function Bar () {
+ Foo.call(this);
+}
-function Bar () {}
Bar.prototype = new Foo();
function longestCommonPrefix ( arr ) {
var result = "";
var firstWord = arr[0];
for ( var i = 0; i < firstWord.length; i++ ) {
for ( var j = 0; j < arr.length; j++) {
if ( firstWord[i] === arr[j][i]) {
continue;
} else {
return result;