Intro
Since the base code have been written years ago and back then I lacked the foresight to predict how the program would perform, I made quite few mistake and kept creating and deleting labels to show the pings delay. This caused the program to eat more and more of the computers memory and after leaving it open for few days I realized it took a gigabyte of RAM, not it's time to fix this problem by recycling the same labels over and over.
Stripping the code
First i had to strip the program from most of it's old code and the logging functionality to have the minimal amount of the code to work with that's basically the main loop.
Fixing responsibility problem
Those whom are familiar with AutoIt know that: sleep()
makes the program freeze and not response to the user input, to fix this problem I added a simple counter to run the ping code every fifty cycle of the main loop, this also gives me the option to add the function to adjust the delay between pings later on.
if $delays > 50 then
pingit()
$delays = 0
EndIf
sleep(10)
$delays += 1
Ping as a function
In the first version everything was happening in the main loop, by moving the ping into its own function the code would become simpler and I can pass variable to it easier.
Func pingit()
$var = ping($Ping)
if $var == 0 Then
GUICtrlSetData ($p1, "Out")
GUICtrlSetColor($p1, 0xff0000)
ElseIf $var < 50 Then
GUICtrlSetData ($p1, $var)
GUICtrlSetColor($p1, 0x0055ff)
ElseIf $var < 100 Then
GUICtrlSetData ($p1, $var)
GUICtrlSetColor($p1, 0x8800ff)
ElseIf $var < 150 Then
GUICtrlSetData ($p1, $var)
GUICtrlSetColor($p1, 0x8800ff)
ElseIf $var < 200 Then
GUICtrlSetData ($p1, $var)
GUICtrlSetColor($p1, 0xff0000)
EndIf
EndFunc
At the moment it's only updating the same label over and over, adding the rest of the labels and make the ping, loop through them to show a brief history of the speed would be the next step,
I'm planing to add the option to let the user input their threshold for colors based on the usual speed of their internet, for me: my ping doesn't go lower than 150ms but I'm sure the rest of the world have faster Internets.
Prof of work
You can see the changes in this commit
Conclusion
Now the foundation is correct I can keep adding more and more functions to make it a program beyond a simple delay monitor for your ping, since it would be open while online, mostly gaming, maybe I add some function to assist you in your game, type things, break up with your girlfriend/boyfriend or kill your cat... maybe not the last one though.
Posted on Utopian.io - Rewarding Open Source Contributors
Your contribution cannot be approved yet. See the Utopian Rules. This is not your first post about the project. You are require to provide the links to the PRs or commits as a proof of your work. Please edit your contribution to reapply for approval.
You may edit your post here, as shown below:
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Even though I was reminding myself constantly, got distracted by discord and forgot the most important part, ^_^
added the link
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @kiaazad I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
This is nice one keep it up
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Does this monstrosity of code deserve a upvote? Why do you use a Elsif in this manner? Use a switch statement if you even know what that is. And a 12% upvote from utopian?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit