Skip to content

Instantly share code, notes, and snippets.

@magistrula
Last active March 28, 2019 02:53
Show Gist options
  • Save magistrula/5e6cf89c7808df46743793c52206aeb6 to your computer and use it in GitHub Desktop.
Save magistrula/5e6cf89c7808df46743793c52206aeb6 to your computer and use it in GitHub Desktop.
Eng Example
import Ember from 'ember';
const { $ } = Ember;
export default Ember.Controller.extend({
valueToEncode: null,
encodedValue: '- - - - - ',
valueToDecode: null,
decodedValue: '- - - - -',
actions: {
encode() {
const word = this.get('valueToEncode');
const t = word.replace(/\w/g, function(c) {
const i = 'abcdefghijklmnopqrstuvwxyz'.indexOf(c);
return 'abcdefghijklmnopqrstuvwxyz'[(i + 4) % 26];
});
this.set('encodedValue', t);
},
decode() {
const word = this.get('valueToDecode');
const t = word.replace(/\w/g, function(c) {
const i = 'abcdefghijklmnopqrstuvwxyz'.indexOf(c);
return 'abcdefghijklmnopqrstuvwxyz'[(i % 26) - 4];
});
this.set('decodedValue', t);
}
}
});
body {
text-align: center;
}
div {
font-size: 60px;
}
button {
font-size: 24px;
}
{{input
value=valueToEncode
enter=(action "encode")
}}
<button {{action "encode"}}>Encode</button>
<div>{{encodedValue}}</div>
<hr>
{{input
value=valueToDecode
enter=(action "decode")
}}
<button {{action "decode"}}>Decode</button>
<div>{{decodedValue}}</div>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment