Samul's Training and Nutrition Log

@Voxel did you see my post in the flame free confession thread? I’ll be working on some software for my university!

One of the requirements we informally discussed already is they’ll need a platform that runs JS programs submitted by students as solution to presented exercises against some test-case inputs and checks if they’re correct by comparing the given output to a set of expected outputs.

I’d like to be able to do this in django as I already wrote quite a bit of code for other functionalities needed by the platform I’m developing (multiple choice questions, score history, …), so I started looking around and stumbled across this GitHub - PiotrDabkowski/Js2Py: JavaScript to Python Translator & JavaScript interpreter written in 100% pure Python🚀 Try it online:

It’s very interesting and looks like a well done library. It’s extremely recent too. Only issue is there is no docs yet. The eval_js function does exactly what you’d think, and there’s also convert_js which very neatly takes in a js file and outputs an equivalent python file. Only issue I’ve seen is eval_js can apparently only print the output of the evaluation to the console, rather than allowing for it to be saved to a variable. I would like to be able to capture the output of the evaluation so I can either compare it to a stored expected output or run it through a comparing function. I’m sure I’ll find a way to accomplish this; I already opened an issue on github to ask about this.

— EDIT: after thinking this through some more, a better solution would most likely be to have a separate node.js server handle this. I’ll look into a possible implementation.

Meanwhile, you might (or might not) have seen that I put up a personal website to display my projects. I put the link to it on my profile. Something I worked on a bit lately is polishing a card game I had coded a few months ago, which I think I even showed you on github. I am in the process of publishing it to heroku (I got it to work which is no mean feat, considering it uses django-channels and it was the first time I worked in a production environment, but there’s some issue going on with static file serving).

Anyway, there’s a demo video of me playing it with two other people on this page, if you wanna take a quick look and tell me what you think. The page is in Italian, but you don’t need to read it, just watch the video
https://samul-1.github.io/dubitowebsite/

I’d love to hear feedback from somebody looking at it externally who also knows what it takes to build things with code!

For sure, like after the first lockdown, you will rebound, better than ever! Keep faith. Use the motivation from this recent great news to motivate you!

Maybe try to find friends to do some street workout or whatever. I feel you, it’s really hard training in a fucking cold park under the rain. I advice going on wodwell or something, pick up some bodyweight WODs and do them. It motivates me way more than just doing 4 x 30 push-ups or something

1 Like

This is very dissimilar to stuff that I’ve built so I can’t really say much. To paint a picture, not to suggest I’m on his level in my domain, but it’d be like asking John Meadows what his thoughts are on a parkour training plan. I’m more backend, enterprise, infrastructure.

Did you do the landing page using Django as well or bootstrap some Github pre-made stuff?

1 Like

the landing page is just a pre-made bootstrap template. I wasn’t going to “waste” hours making a webpage knowing well in advance that my nonexistent graphical taste means it still wouldn’t have looked good. I did make the fading animations though (using animate.css that is) and picked the colors and background image. if I didn’t screw that up, as far as look of the page goes, that’s a win.

I understand the kind game I made may be far away from your field of experience, I was asking more from a “what does the product look like” perspective, just like you’d ask for user feedback but in this case you’re more than a user because you also know code. If that makes sense

Aha, I’ll have a look again tomorrow then!

If people are submitting JS it is going to include ES6 and more recent, ES10 was released in 2019. The library you linked to doesn’t support ES6, that pretty much makes it a non-starter, imo. I’ve never done anything like this so I don’t have much more to add but I wouldn’t try and do JS in python. Have you looked at websites that already do things like this? If I understand what you are shooting for https://www.codewars.com/ does something similar, might be able to take ideas from it.

1 Like

I managed to make something work today. I just straight up used node.js.

I created the following node script

const {VM} = require('vm2')
const safevm = new VM({
    timeout: 1000,
})

user_program = process.argv[2]

function_name = process.argv[2].split(/^function (.*)\(/)[1]
parameters = process.argv[3].split("\n")

// turn a parameter array into a string like '(param_1, param_2, ..., param_n)'
let parameter_string = '('
for(parameter of parameters) {
    parameter_string += parameter + ','
}
parameter_string = parameter_string.slice(0, -1) + ')'
// add 'function_name(params)' to the program to actually call the function defined in the input text
user_program += '\n' + function_name + parameter_string
try {
    console.log(safevm.run(user_program))
} catch(error) {
    return "ERROR"
}

which takes in a program containing a single js function and a list of parameters, and calls the function with those parameters, outputting the return value

Then with django I get all the test cases associated with the exercise and test it against them. I made it work already.

To call the script from django, you just instantiate a subprocess. The node syntax would look something like node evalUserProgram.js programstring paramlist.

Next on the list will be to make the checking more flexible. What if the output is an object? I will make it so the teacher can supply a custom function that will be used for evaluating the correctness of the solution.

1 Like

Couple things I’d consider would be to check out Javascript’s eval function which evaluates a string as code.

e.g.

const userFunctionEval = eval('timesThree = (input) => input * 3')

userFunctionEval(5) => 15

Secondarily, and likely more importantly I’d make sure I knew how to sandbox the code you are going to run. It is potentially very dangerous to run other’s code.

Yeah, I know about eval. Matter of fact I actually used it in the past in a project. I made a javascript assembly interpreter :slight_smile:
https://samul-1.github.io/asm/

Unfortunately, eval is deprecated because it’s very unsafe and doesn’t do any sandboxing of the code it is supplied. In my interpreter, I only used it because it wouldn’t actually get called with user-provided code (think of it as a private method if we’re speaking oop).

Absolutely. The library I’m using seems to be notoriously safe, and they claim to be immune to all known attacks. A sandbox is created and kept completely separate from the actual environment. What’s more, the code times out after 1 second (I chose that number because I thought it was sensible for my needs, but it can be any number) so it’s not susceptible to endless loops and the like. It’s also executed in a separate thread per my understanding.

I think I’m actually going by the safest possible solution.

Here’s a test drive of the thing:

the exercise text just prompts the user to create a function that returns the maximum between two numbers.

It was very satisfying to see it work, even though it’s just the beginning.

Also, here’s a quick video I took the other day which showcases some of the other features I implemented in this elearning platform

this exposes some performance issues too with LaTeX formulas’ rendering which I’m working on

Glad to see I still look half decent in fitting room selfies :joy:

5 Likes

image

3 Likes

Just concluded my winter exam session.

These last two weeks have been filled with study. Study study study. 6-8 hours a day.

On Friday, I had my Operations Research spoken exam and I got 30 cum laude. I was happy with it, but it didn’t last too long because shortly after they published the results of the Statistics test, and I got a 20. Very bad.

Turns out I lost a ton of points due to naive mistakes. Computation errors and the like. I was very upset. Buried myself in the books for the weekend. Today I had the spoken part of the statistics exam, going in with a 22 as the average of my two written tests (I remind you the highest grade is 30 here, with 30 cum laude corresponding to an absolutely outstanding exam).

I was an idiot with both written tests and robbed myself a lot of points due to petty mistakes. The teacher was looking at my tests and said, “well yeah, you messed up in more than one spot, that’s unfortunate… I don’t even know which question to start with because you didn’t really get anything completely wrong, just a handful of mistakes here and there.”

But I was there to change his mind. I put autopilot on and let my preparation do the work. I aced every. Single. Question.

Went in with a 22… Got out with 29 as my final grade. To give an estimate of what that means, I’ll just say that on average, the spoken part gets the grade from the written part up by 1-2 points. This was a +7.

I am as happy as I can be. This time I really turned the tables and it was all, everything due to sheer hard work.

Before leaving the call with the teacher, I told him, “just wanted to let you know that I came here very angry. Mad at myself for screwing up the written part, and wanting to show that this is me. Not the one you saw in those two tests.”

Now I’m up to par with my exams and I have one month and a half completely free to work on other stuff. Yay!!

3 Likes

Nice work dude! Stats sucks, I was not a fan of that class.

1 Like

Happy new year to the t-nation crew!

I wanted to do a short write-up of this year, just like I did last year.
There have been several changes in my life this year, mostly school related. I have learned a lot of new skills that’ll be useful in my quest to becoming a very, very proficient computer scientist.

The first thing I want to talk about is the concept of getting something good out of a bad situation, especially when you have lots of spare time.
With the first lockdown, a lot of my peers let go, and would spend their days eating and playing videogames. Not gonna judge that: it is indeed a way to cope.

However, this is what I told myself, “You’re going to be locked in for possibly months, and you’ll have all of those days absolutely free to do whatever you want. You MUST come out of this having accomplished something with all that spare time. That way, these won’t be wasted months.” I thought, the outside situation has the power to force us to stay inside, but it does not have to power to dictate what we do, while we’re inside.

So every day, I would spend hours on end studying for my upcoming exams, and training at night with the little equipment I had. My grades went up a lot, taking me to a near perfect average, and that was thanks to all the work I was able to put in with no distractions.

Training-wise, this year is worth of no mention. I did find out about Meadows’ programs, and that’s a big up. But, overall, I only got to train for about 7 months this year. As soon as gyms re-open, I’m ready to attack my training.

One last thought I wanted to share is something that disturbed me a little bit. This Christmas, in Italy, was spend for most people away from their loved ones. Severe restrictions were in place during Christmas day and New Year’s Eve, to prevent people from moving around and spreading the virus, so a result a lot of us were alone on those days.

I did have lunch with my mother and spent rest of Christmas with my gf, so I can’t complain. But that’s the point. I never complained about any of this, becuase the more I thought about it, the more I realized how lots of people have less, less, less than I do and their lives went from bad to even worse during this period.

In preparation to new year’s, my dad bought a lot of groceries and I found my fridge full and completely stuffed. As I looked at all the stuff, I felt a strong sense of sadness rushing through me. I have done nothing in order to have all of this! Yet there are so many people who, still having done nothing, have none of this. I don’t wanna say I felt guilty because it’s not the right word, but you get the idea.

A promise I made to myself is: the day I have money, a job, a stable and independent situation as an adult, is the day I will help those in need, according to my possibilities. There is no amount of money that’ll ever make me happy if I know I am not doing anything to help those whose only sin was being unlucky when coming to this world.

5 Likes

@Voxel just wanted to share this with you

I’ve been working very hard on polishing that card-game I showed you on here some time ago, and it’s finally ready for production! I’m very excited to launch it, and that’ll happen over the next couple of days.

If you’re curious or anything, you might wanna check out:
http://playdubito.com/

I’m very excited to put online my first complete project :slight_smile:

1 Like

Good job lad. I believe there’s an internationalisation module for Django called “i18n”. You might want to explore that.

Never be afraid of starting a project to try just one thing. So, rather than adding the feature to Dubito straight away you’d create a new project from scratch and only wire up i18n and get it to work. Think of it like a ROM regression, or making a movement easier. Focus on the one thing first, that way you’ll always have a template pristine implementation to refer to that’s simple and easy to grasp even when out of practice.

You might also want to check out the courses on testdrivenio. They have a project there with Django Channels. Now that you’ve used it yourself you can go back and get some best practices ideas.

1 Like

You read my mind! I have been thinking about that and it’s definitely on my to-do list of things to learn.

Thank you, will definitely check it out. I’ve become very passionate about Channels. It lets you create really cool stuff. I think my obsession with websockets has to do with my childhood :joy: when I was first learning about coding, I was fascinated with a chat app (which, in retrospective, was simply Ajax based and nothing fancy) and always wanted to make one, so being able to do this cool real-time stuff is just too good for me haha.

Have you tried running a game on Dubito? You can do that against yourself pretty easily with an incognito tab. I was curious about your opinion of the game interface. But maybe I already linked a video of that? Can’t quite recall right now.

So we got the news that gyms won’t have a chance to open again until March 5th in Italy.

I’m not going to comment on that because I’m so sick of the clowns that run my country that I don’t have any more words to say. As a reference, please note that ALL other businesses are open and have been for quite some time, but gyms and pools. Barber shops, restaurants, bars, beauty centers, malls…

Whatever.

So I was training at home (ten sets of chins followed by 4 non-stop rounds of curls going back and forth between arms, adding forced reps at the end) and I noticed that, for not having been able to train at a gym for nearly three months, I still like the way I look with a pump! It was a nice surprise, so I took a video to share with you guys.

I’m not going to say that I look good, but I definitely look better than I would have expected after this much forced time off, training sub-optimally and, honestly, eating sub-optimally as well.

I must say that, while I haven’t stepped foot in a gym in ages, I never really went more than 5 days in a row without some training at any time during this, training on average 3 times a week. I guess consistency is still key even when not giving top effort. Hopefully I keep looking like this until March, but damn I thought I’d have disappeared by now!

8 Likes

Oh no!

At least you don’t have a narcissistic idiot leading the clowns

I think this is more economic than anything. The aforementioned institutions are far more dangerous, but generate a lot more tax revenue

1 Like

Yeah yeah I feel you mate it’s all the same in my country… So annoying.

And yeah you look good! You thought you were going to disappear into nothingness so easily hehe? Home BW work is still better than anything and goes a good way into keeping muscle and all!

1 Like