Skip to content

Commit

Permalink
Base64 Permalinks in IDE (Closes #45)
Browse files Browse the repository at this point in the history
  • Loading branch information
phase committed Nov 20, 2015
1 parent 39e4e76 commit 16baae7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
12 changes: 7 additions & 5 deletions ide.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def index():
#Run code
code = request.form['code']
input = request.form['input'].replace('\r\n', '\n')
if input is None: input = ""
print('Got code:', code, 'input:', input)
print('Running O code...')
p = Popen(['./oide', '-e', code], stdout=PIPE, stderr=PIPE, stdin=PIPE, universal_newlines=True)
Expand All @@ -45,14 +46,15 @@ def index():
return render_template('primary.html')

@app.route('/link/')
@app.route('/link/<link>')
def link(link='code="Error in linking code"o&input='):
@app.route('/link/<code>/')
@app.route('/link/<code>/<input>')
def link(code="IkVycm9yJTIwbGlua2luZyUyMGNvZGUibw==", input=""):
url_for('static', filename='logo.ico')
print('Link:', link)
return render_template('link.html', link=link)
print('Link:', code, input)
return render_template('link.html', code=code, input=input)

if __name__ == '__main__':
print('Compiling O...')
compileO()
print('Starting server...')
app.run(debug='-d' in sys.argv[1:])
app.run(port=80, debug='-d' in sys.argv[1:])
18 changes: 2 additions & 16 deletions static/o.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,27 +140,13 @@ function updateUtils() {
updateUtils();

$(document).ready(function() {
$('#code').on('keydown', function() {

This comment has been minimized.

Copy link
@phase

phase Nov 21, 2015

Author Owner

@kirbyfan64 Does this now work on Android?

This comment has been minimized.

Copy link
@refi64

refi64 Nov 22, 2015

Collaborator

@phase Yup!

var code = $("#code").val();
var key = event.keyCode || event.charCode;
var c = String.fromCharCode(event.which);
var pos = $("#code").getCursorPosition()-1;
if( key == 8 || key == 46 ){ //delete text
console.log("Delete: " + c + " " + pos + " :: " + event.which);
if(c == "(" && code.charAt(pos+1) == ")") code.replaceAt(pos+1, "");
if(c == "{" && code.charAt(pos+1) == "}") code.replaceAt(pos+1, "");
} else {
//if()
}
$("#code").val(code);
});
$("#permalink").click(function() {
/*var code = $.param({
code : $('#code').val().replace(" ", "%20"),
input : $('#input').val()
});*/
var code = "code=" + $('#code').val().replace(/ /g, "%20")
+ "&input=" + $('#input').val().replace(/ /g, "%20");
// var code = "code=" + window.btoa($('#code').val().replace(/ /g, "%20")) + "&input=" + window.btoa($('#input').val().replace(/ /g, "%20"));
var code = window.btoa($('#code').val().replace(/ /g, "%20")) + "/" + window.btoa($('#input').val().replace(/ /g, "%20"));
prompt("Permalink:", "http://" + window.location.hostname + "/link/" + code);
window.location.pathname = "/link/" + code;
});
Expand Down
5 changes: 2 additions & 3 deletions templates/link.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
<body>
<script>
$(document).ready(function() {
var s = $('<textarea/>').html(decodeURI(`{{ link }}`)).text();
var sCode = s.split("&")[0].split("=")[1];
var sInput = s.split("&")[1].split("=")[1];
var sCode = $('<textarea/>').html(decodeURI(window.atob(`{{ code }}`))).text();
var sInput = $('<textarea/>').html(decodeURI(window.atob(`{{ input }}`))).text();
var url = "http://" + window.location.hostname + "/";
$.redirect(url, {code: sCode, input: sInput});
});
Expand Down

0 comments on commit 16baae7

Please sign in to comment.