Skip to content

Instantly share code, notes, and snippets.

@tadruj
Last active October 3, 2015 05:48
Show Gist options
  • Save tadruj/2402835 to your computer and use it in GitHub Desktop.
Save tadruj/2402835 to your computer and use it in GitHub Desktop.
Meteor pair-programming App
This app is used for pair programming JavaScript. I have the console open on Chrome so when I click Run or do the CMD+ENTER, the script that is inside textarea executes.
BUG:
If I have 2 windows open I can type on W1 and see the changes published on W2, but when I start to type on W2, the changes won't get dispatched to W1.
#code {
width: 1000px;
height: 400px;
font-family: "Courier";
font-size: 20px;
}
<head>
<title>jSinTi Sandbox2</title>
</head>
<body>
<h1>jS<sub>in</sub>Ti Sandbox</h1>
{{> sandbox}}
</body>
<template name="sandbox">
<div id="sandbox" class="sandbox">
<textarea id="code">{{code}}</textarea>
<div>
<input id="run" type="button" value="Run" /> ⌘⏎
</div>
</div>
</template>
Code = new Meteor.Collection('code');
if (Meteor.is_client) {
Meteor.subscribe('code');
Template.sandbox.code = function () {
kode = Code.findOne();
return kode !== undefined ? kode.code_text : '';
};
Template.sandbox.events = {
'keydown #code' : function (e) {
if(e.keyCode == 13 && e.metaKey) {
eval($("#code").val());
e.preventDefault();
e.stopPropagation();
return false;
}
},
'keyup #code' : function () {
Code.remove({});
Code.insert({ code_text: $("#code").val() });
},
'click #run' : function () {
eval($("#code").val());
}
};
}
if (Meteor.is_server) {
Meteor.publish('code');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment