#mlem's computing stuff
Explore tagged Tumblr posts
mlembug · 1 year ago
Text
Tumblr media
@canonkalluzeb It's an attempt in mirroring terminology of IRC, which does not necessarily makes sense in context of Discord, and Discord knows this perfectly well because they're both internally, and also among programmers who make Discord bots, called "guilds", not "servers".
Some background: when two computer applications on two separate computers have to communicate, one of them has to first set up the connection, and so the program which listens to connections is often called "server", and the program which attempts to connect is called "client", which is an analogy of how restaurants work.
And of course it's not like two arbitrary programs can understand each other, so when one needs to make two programs communicate with each other, one designs a "protocol", which is a description of the exact rules these two programs are supposed to interact on.
Back in The Old Days (90s to early 00s) the most common protocol for chat-like applications was called IRC (Internet Relay Chat), which does follow the "client-server architecture", where someone (could be anyone, but usually it was universities or ISPs) runs the IRC server application on their computers, and people who want to chat, run IRC client applications which connect to these servers.
(it is still possible to use IRC today, but a lot of people don't because the newer alternatives provide features which people are used to, like... file upload/storage, persistent chat history, or transport encryption)
On the most basic level, a person that uses an IRC client first makes it connect to an IRC server by typing an address to connect to, and then picks the channels to join there, of which each functions as an independent conversation, in that
your IRC client usually displays the chat messages grouped together by the channel
the clients which joined a channel can send a message to this channel, which server receives...
...and then sends it to every other client which joined such channel
the clients which did not join a channel do not receive messages that are sent to the channel
if your client did not receive a message (due to lost connection, or maybe you were not in the channel in the first place), you will not see this message ever again, as IRC has no mechanisms of providing you a message history, nor retransmission of earlier messages
it may be possible for a regular user to create a channel, depending on how the IRC server is configured
Now here's how Discord works:
you are not supposed to run a Discord server application. Discord (the company) made one, and it is running on their computers (the ones they manage at least), but you can't run it on your computer (for whatever reason you wanted to do so), because they won't give it to you in the first place
the only thing you are supposed to run, is the Discord client application, which they offer to you for free
since no one outside of Discord (the company) is supposed to run Discord servers, the fact you're connecting to them specifically is not supposed to be relevant to the end user
your Discord client maintains a connection to a Discord server, which sends real-time information on stuff like "there is an unread message on guild number 253958353" or "you got pinged in a direct message by user with number 34235936984" to the client
any user can create a "guild", of which the person who created it is marked as a "guild owner", which is highest possible rank and everyone else on the server can only be a granted permission to do a subset of actions a server owner can do.
a guild has a list of channels, a list of users joined it, and a list of roles
roles can be assigned to the user, and apply within a guild only
a role controls the list of possible actions a user can do in the context of the server
a channel functions as a chronologically-sorted list of messages, of which you can retrieve a part of it by clicking on it, and other parts - by scrolling
Now take this into account that what I've just called "Discord server" is usually not something the end user needs to worry about, so it's typically not mentioned at all, and "guild" is called "server" literally everywhere else outside of developer documentation, and you can see why this feels a bit confusing.
29 notes · View notes
mlembug · 2 years ago
Text
How to archive a Discord channel
I'm going to say this way ahead of time: this is going to be waaaaaaay more of an annoying process than it should be. Discord should allow exporting the channel history to server owners, without the need of doing all this. I won't blame you if you give up.
Get the DiscordChatExporter application to download the chat history
This program has two versions
one that has a graphical interface, but works on Windows only
one that has a command line interface, but works on Windows, Linux and macOS
This guide covers the first. The second one maybe next time, in another post. The second version also makes it easier to download every channel on the server.
Step 1: Go to here, and download the latest version in the zip file named DiscordChatExporter.zip
Tumblr media
Step 2: Unpack the zip file
Tumblr media
Step 3: Run DiscordChatExporter.exe
Tumblr media
Step 4: Dismiss the scary looking warning as this will show up for any program that which developer can't afford paying $629 a year.
Tumblr media
Step 5: Close the welcoming message and you'll see the application interface:
Tumblr media
Prepare an access token. Do not share it to anyone else - treat it the same way as you treat your password.
There are two ways to do it:
Approach 1: use your own access token, will work with any channel you're able to access, including Direct Messages, but it is a violation of Discord Terms of Service, and therefore your Discord account could get banned for it. Use at your own risk.
Follow the instructions here, which are fairly detailed step-by-step instructions for Chrome, Firefox, and also the desktop app. I'm gonna expand more on approach 2 as I had to figure it out myself, and the current instructions for approach 2 are not really adequate enough. If you go with approach 1, skip down the entire section below, until the "Paste the token in the Token textbox and click the arrow button" section.
Approach 2: create a bot account, invite it to your server, and use its access token. This process assumes you have enough privileges to invite bots to the server ("Manage Server" permission), and therefore, but is also 100% okay as far as Discord's Terms of Service are concerned. It is also generally safer, as accidental leaking of the token will not risk you losing your user account.
Step 1: Go to the Discord developer portal.
Step 2: Create a new application by clicking the "New Application" button
Tumblr media
Step 3: Name it however you want, I personally named it "mlemgrab". Agree to the scary sounding long ass terms of service.
Tumblr media
Step 4: Go to the Bot section, scroll down to the "Privileged Gateway Intents"
Tumblr media
Step 5: Enable the "Message Content Intent". We don't have to worry about the "if your bot is in more than 100 servers" part because our bot will never be in this many servers.
Step 6: Save changes by pressing the green button "Save Changes"
Tumblr media
Step 7: Go to "OAuth2" followed by "URL Generator"
Tumblr media
Step 8: Select the "bot" scope and then "Read Messages/View Channels" and "Read Message History" permissions
Tumblr media
Step 9: Copy the link at the bottom and visit it:
Tumblr media
Step 10: Press "Continue", and approve the required permissions by clicking Authorize. Once you do it, the bot account is on the server.
Tumblr media
Step 11: Go to "Bot" and click the "Reset Token" button to get the token that will allow you to act (in our case, getting all the messages) using the bot user. If you lose that token, you can click reset again to get a new one.
Tumblr media
Paste the token in the Token textbox and click the arrow button
Tumblr media
Select the server, and then the channel you want to archive
Tumblr media
Click the download button on the bottom right
Tumblr media
Select where you want to save it, and the format. HTML is good for easy browsing and preview in a web browser, JSON is good for further processing (let's say someone else later writes a program for importing the conversation elsewhere).
For archivization purposes I recommend saving in both HTML and JSON.
Click "More" for more options.
Tumblr media
By default the program will not download any message attachments nor avatars or emotes. If you want that, select "Download assets" option. Preferably while also selecting the "Reuse assets" option and selecting a single directory for assets if you want to archive multiple channels.
You can also select the specific time range and using the partition limit - split the archive into several files each containing N messages.
Press Export. Wait. The progress bar will move very slowly.
Tumblr media
Once it is done, you should be able to open the HTML file with your web browser.
Treat anything on Discord as media that will be lost
Do not use Discord to host your files. Do not rely on Discord to preserve your text. DO NOT RELY ON DISCORD FOR ANY KIND OF PRESERVATION OR HOSTING!!
It CAN be lost, it WILL be lost! You must consider Discord as a part of the Core Internet, controlled by one company that hosts the servers.
I thought it was impressive at first that it replaced IRC, but now I am horrified. If the company behind Discord went under today, how many friends would you lose?
How many relationships? How much writing?
You may think this won't happen, but I remember when AIM went down and along with it, entire novels worth of interaction with my oldest friend.
IT CAN HAPPEN TO YOU. IT WILL HAPPEN AGAIN. NO COMPANY IS INFALLIBLE.
Back up your files! Download anything you've saved to Discord NOW, before the API changes go into effect! And DO NOT RELY ON THEM FOR HOLDING IMPORTANT FILES!
52K notes · View notes
shadowdragonia · 5 years ago
Text
I care more about my pet than myself
Y’all I am 32 years old. My work hours at 4pm to midnight. I would just come home and catch up on stuff at night, stay up till about 6 or 7am, sleep till 3pm and go to work. That was my life, not the best schedule but I had nothing better to do so whatever.
Then I got my little baby bearded dragon, Mlem.
Mlem requires a good sleep schedule because Mlem is precious baby that needs healthy life.
I still get home at Midnight, so I check on Mlem when I get home, get some basic stuff done, then its light out at 2am at the latest. I’ll still stay up another hour maybe on the computer but when the room is dark its too tempting to go to bed. I set my alarm for noon now so I can get up and turn Mlems lamps on and get him all warmed up and ready for breakfast.
I am 32 years old and didn’t give a shit about my sleep related health patterns until I got a baby bearded dragon. I changed my life for Mlem. 
32 notes · View notes
mlembug · 2 years ago
Text
Relay operated power button
Tumblr media
What you need:
a 5V relay module
Raspberry Pi
a bunch of cables
Explanation:
A power button on a computer case lets electricity flow between two power pins upon it being pressed, which is when the motherboard detects the button is pressed and reacts accordingly.
Tumblr media
A relay is a specific kind of switch which lets electricity flow conditionally upon the flow of electricity in another circuit. The voltages involved both in motherboard power pins and on Raspberry Pi are generally low to not damage both, but we're taking extra precautions to electrically separate them both.
"5V relay module" here means that 5V is the voltage that is required for the relay module to work, while the controlling voltage can be lower. It being relay module it means it also has a flyback diode we'd otherwise have to provide ourselves.
Tumblr media
Raspberry Pi's GPIO pins are programmable and can be controlled through Python code, and operate on 3.3V. Raspberry Pi also provides 5V output, but this one is not controllable.
By
connecting a power button to rPi GPIO pins
connecting the 5V voltage output pin from rPi to the relay module's Vcc input pin
connecting the ground pin from rPi to the relay module's groud pin
connecting programmable GPIO pins as the relay module's input pin
connecting the relay module's outputs (the normally open one and the ground) to the motherboard power pins
running some code on rPi
We can extend the power button functionality so Raspberry Pi can turn on and off our computer, while also still keeping the power button working.
Which is what I use to remotely turn on my computer on, by SSHing to rPi and running a script to turn the PC on while I'm away from home.
Why not Wake-On-LAN?
Wake-On-LAN has restrictions which makes it not as reliable as it could be, for example:
The ability to wake from a hybrid shutdown state (S4) (aka Fast Startup) or a soft powered-off state (S5) is unsupported in Windows 8 and above
The code and explanation for it in Part 2, when I get to writing it.
17 notes · View notes
mlembug · 2 years ago
Text
I checked out that post about restarting and what OP writes is one thing (his rationale is nonsense and also incredibly vague, so even in circumstances when it could apply you don't know when and therefore you fall into cargo culting), but somehow the replies are even worse.
Tumblr media Tumblr media
This person doesn't know what registry is. Rule of thumb: if someone talks about "registry" in terms of computer optimization you can safely ignore them altogether.
Also the whole section about "RAM buffers" is also buzzword nonsense. There's one thing that could potentially be called a "RAM buffer" and it's I/O cache (yes, the link talks about Linux but every modern OS does this because it's common sense to do it), except I/O cache being used is a good thing, and in fact your OS will attempt to fill it as soon as you restart. Unused RAM is wasted RAM. If your applications are not using RAM entirely, OS will use it for I/O cache. If you start using more RAM with your applications, OS will hand it over from the RAM used for I/O cache.
EDIT: I also missed out on "deleted files are not marked as rewritable until after restart". Holy shit this such massive bullshit of incredible proportions. To elaborate: deletion is what marks disk space as "rewritable" in the first place.
Restarts in general are done in response to a problem that could potentially be solved in different ways (but it's not always feasible to do so), but thinking that the problems arise from not restarting is cargo cult mentality. OP of the post talked about OS restarts which are needed even more rarely.
11 notes · View notes
mlembug · 2 years ago
Text
Random Numbers 101
(actually "pseudo-random number generators" but we'll get to that later)
Attempting to write for a general audience which is why I'm attempting to use simple explanations and focus on explanations rather than code.
How do they work
Step 1: prepare a bunch of bits (a seed), and from these bits, create the initial state of the generator
Step 2: modify current state
Step 3: given current state, produce a number from it
Example 1: MINSTD
Step 1: The state is a single 32-bit unsigned integral number variable. We don't know how to create a seed yet, so let's pick a number 23455264 as a seed.
state = 23455264
Step 2: Calculate the new state using the equation
(a*state + c) % m
MINSTD in particular uses a = 48271, c = 0, m = 2147483647
state = (48271 * state) % 2147483647
Step 3: use the new state directly as the output number
output = newstate output = 485166575
Done: this generator provides numbers in range from 0 to 2147483647 (exclusive, so it will generate every non-negative smaller than 2147483647). Want another number? Go through steps 2-3 again.
Example 2: Doom (1993) pseudo-random number generator
Step 1: prepare an array of 256 (hopefully) random numbers. The array is not part of the current state, as it is not modified during step 2.
rndtable = [ 0, 8, 109, 220, 222, 241, 149, 107, 75, 248, 254, 140, 16, 66, # the full table is too long, here is it if you're curious 120, 163, 236, 249 ]
Also prepare an integral number variable. This is the state of the generator.
state = 0
Step 2: Increase the number by 1. If the number goes beyond what is an acceptable range of indexing the array, set it to the index of the first element.
state = (state + 1) % 256
Step 3: use the state to index the array.
output = rndtable[state] output = 8
Done: this generator provides numbers in range from 0 to 255 (inclusive)
Tricks and Traps
Generating a number from range 0 to N*N (exclusive) when your generator only provides numbers from range 0 to N (exclusive)
Generate two numbers using your generator
high = gen() # let's say N = 10 low = gen()
Multiply one of the numbers by N and add the second number
x = high * N + low
Because "N" (10) is bigger than any possible value of "low" (0, 1, 2, ..., 9), no two different generations of "high" and "low" will result in same "x". The lowest possible value of x is 0 for high = 0 and low = 0, and highest is 99 for high = 9 and low = 9.
Generating a number from range 0 to H (exclusive) using a generator that provides numbers from range 0 to N (exclusive), and H is less than N
Let's say N = 10 and H = 4.
Step 1: find the biggest possible integral number divisible by H which is smaller than N. Let's call that number S.
Here S = 8 as 2*H = 8, but 3*H = 12, which is already bigger than 10.
Step 2: generate a number. If the number is not smaller than S, throw it away and generate another one until the generator will get you a number smaller than S
while True: x = gen() if x < S: break
Step 3: Put the generated number into one of H buckets by using the modulo operation. Let this will be the resulting number.
b = x % H
Generated number: 0 1 2 3 4 5 6 7 8 9 Resulting bucket: 0 1 2 3 0 1 2 3 0 1
As you can see, if we were to not apply the step 2, before doing step 3, values 0 and 1 would be 50% more likely to be generated than values 2 and 3. Good thing we discarded 8s and 9s before doing that.
Pseudorandomness
We're calling these numbers pseudorandom because we used a fairly simple step-by-step procedure to generate them, but also it is fairly difficult to say what would true randomness be.
Tumblr media
We will never know if the devil creature will say something else than nine.
The two examples listed above were very simple pseudo-random number generators (PRNGs), but we have PRNGs which are good enough to generate numbers which must be unpredictable enough to secure your connection to your online bank. We call these cryptographically secure pseudo-random number generators. Explaining on how to use them will come in another post.
Picking a seed
We deliberately avoided explaining how to pick a seed for step 1 in both of these examples. Doom (1993) always picks 0 at the start of the level, but we have to keep in mind that using the same seed will result in the same sequence, which is why if we want to have different sequences, we will have to pick different seeds.
Two most common ways are using the current time, which is extremely predictable (everyone knows the current time), but good enough for quite a lot of programs. The alternative is using a better generator to seed our generator.
Picking a specific seed
The flip side of the fact that using the same seed results in the same sequence is that we can deliberately pick a seed to create the same sequence every time.
If you have ever played Minecraft or Factorio and saved a specific world seed to share with your friends, you know what I'm talking about.
Because Doom (1993) always uses the same seed and also has two separate generator states, one specifically for game logic and other for everything else, it can record your playthrough by recording your inputs and then replay it by simulating a player that rather than taking inputs from your keyboard or mouse, it takes input from the replay file.
8 notes · View notes
mlembug · 2 years ago
Note
yes please write more about programming! i love your blog and translation work, i didn't know you were a programmer. obviously don't stress yourself out in addition to your job but im sure people would appreciate it. embarassing saying this kind of thing off-anon lol
Thanks for showing interest, I'll try posting what I think people may find interesting, from a sort of generalized perspective first, and then maybe in the detail later on. I'll probably start first with stuff that is already done or has sat on my mind for a while, just needs pouring into words first.
I already used "#programming" and "#technology" but the first one feels too narrow and the second one could be too wide, so I guess the new tag is in order, for now that will be named "#mlem's computing stuff" as a provisional name until I come up with something better.
2 notes · View notes
mlembug · 2 years ago
Note
Yes, human-generated comments can be misleading.
But also: comments' general purpose is to add info to the code that cannot be deduced from reading code.
Stuff like "I chose algorithm X because on our tests it gave improvements on datasets smaller than Y elements and we're guaranteed to have no more than that."
This adds the information of "why do we do it" to reading the code directly and learning "what do we do".
So letting ChatGPT read your code in order to produce comments is missing the point, and the idea is likely the result of a company policy of introducing warnings on non-commented code combined with making warnings fail the build.
I just watched a video where someone is using ChatGPT to generate comments on their code. Even as a layman I feel like I should be screaming at him, but on a scale from 1 to apocalypse, how bad is this?
Machine-generated comments could not possibly be more useless, nonsensical or maliciously misleading than most of the human-generated comments I've seen.
1K notes · View notes
schpeelah · 2 years ago
Photo
Shout out to the time a major Polish linguist started a project to come up with actual Polish terminology for computer stuff instead of merely adapting English terms to Polish pronounciation/ortography conventions and his term for "click the mouse" was
Mlem the hamster
Tumblr media
152K notes · View notes
mlembug · 2 years ago
Text
I'm planning to write a small article on floating-point numbers as part of my "mlem's computing stuff" tag, hang on tight.
Have a silly meme in the meantime, don't treat it too seriously.
Tumblr media
3K notes · View notes