There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

aliyss , in Variable Declaration
@aliyss@programming.dev avatar

Just type faster than the LSP needs to check. I don’t see an issue.

pewgar_seemsimandroid , in Open Source VS Company

the power of forking

Jako301 , in Open Source VS Company

You haven’t worked in any customer support position, and it shows. The amount of slurs hurled at them is far greater than anything found in a few github comments.

savvywolf ,
@savvywolf@pawb.social avatar

Yeah, I read this meme and it was like… Have you met gamers?

The amount of patches that apparently ruin the game or Devs refusing to fix “simple” bugs is astounding.

setsneedtofeed , (edited )
@setsneedtofeed@lemmy.world avatar

Also complaints that lack specificity must be aggravatingly common. I once complained on an open board about a bug in Wasteland 3 and a dev reading comments actually PM’d me asking for details. I provided details as best I could, including screenshots- the very next patch included a fix for my niche issue. But I imagine most bug reports being “GAME BROKEn! SUX! Fix NOW character creation BROKENN!”

Daxtron2 ,

Yeah that’s pretty average for most bug reports. You’re lucky if they even mention the issue, people like you who actually submit details are the only reason we can fix bugs lol.

sqw , in Aaargh....my eyes......my eyes......
@sqw@lemmy.sdf.org avatar

rage bait

bjoern_tantau , in Touch a file in Linux
@bjoern_tantau@swg-empire.de avatar

Does anyone actually use touch for its intended purpose? Must be up there with cat.

BestBouclettes ,

The intended use of touch is to update the timestamp right?

bjoern_tantau ,
@bjoern_tantau@swg-empire.de avatar

Yeah. It could just as well have issued a file not found error when you try to touch a nonexistent file. And we would be none the wiser about what we’re missing in the world.

BestBouclettes ,

If you touch -c it should work I guess

4am ,

“Do one thing and do it very well” is the UNIX philosophy after all; if you’re 99% likely to just create that missing file after you get a file not found error, why should touch waste your time?

0x0 ,

Because now touch does two things.

Without touch, we could “just” use the shell to create files.


<span style="color:#323232;">: > foo.txt
</span>
deegeese ,

Touch does one thing from a “contract” perspective:

Ensure the timestamp of <file> is <now>

dan ,
@dan@upvote.au avatar

Systemd also does one thing from a contract perspective: run your system

emptiestplace ,

Oh no.

:(

dukk ,

Does it do it well, though?

stebo02 ,
@stebo02@lemmy.dbzer0.com avatar

with this logic, any command that moves, copies or opens a file should just create a new file if it doesn’t exist

and now you’re just creating new files without realising just because of a typo

Kusimulkku ,

But this directly goes against that philosophy, since now instead of changing timestamps it’s also creating files

kautau , (edited )

You can pass -c to not create a file, but it does go against the philosophy that it creates them by default instead of that being an option

EDIT: Looking closer into the code, it would appear to maybe be an efficiency thing based on underlying system calls

Without that check, touch just opens a file for writing, with no other filesystem check, and closes it

With that check, touch first checks if the file exists, and then if so opens the file for writing

magic_lobster_party ,

I sometimes use cat to concatenate files. For example, add a header to a csv file without manually copy and paste it. It’s rare, but at least more frequent than using touch.

wewbull ,

<span style="color:#323232;">$ cat file1 > output_file
</span><span style="color:#323232;">$ cat file2 >> output_file
</span><span style="color:#323232;">$ cat file3 >> output_file
</span>

I’m sorry!

dan ,
@dan@upvote.au avatar

That’s its intended purpose - combining files together (the opposite of split). See the first line of the man page: man7.org/linux/man-pages/man1/cat.1.html

funkajunk ,
@funkajunk@lemm.ee avatar

TIL it’s actually for changing timestamps.

www.man7.org/linux/man-pages/man1/touch.1.html

TheBat ,
@TheBat@lemmy.world avatar

Wtf. All these years I thought ‘touch’ was reference to Michelangelo’s Creation of Adam.

funkajunk ,
@funkajunk@lemm.ee avatar

That’s beautiful, bro 🥲

gandalf_der_12te ,

touché

orphiebaby ,

That’s not how you use “touché”. Pet peeve of mine.

BitsOfBeard ,
@BitsOfBeard@programming.dev avatar

Touché!

RustyShackleford ,
@RustyShackleford@programming.dev avatar

🇪​🇳​ 🇬​🇦​🇷​🇩​🇪​

or…

ʳᶦᵖᵒˢᵗᵉ…?

ik5pvx ,

Yes, when you are for example checking if the permissions in the directory are correct, or if you want to check if your nfs export is working. It’s one of those commands that once you know it exists, you WILL find a way to use it.

bjoern_tantau ,
@bjoern_tantau@swg-empire.de avatar

Well, those aren’t really the intended use either.

tubaruco ,

what is cat’s use if not seeing whats inside a file?

Navigate ,

It is short for concatenate, which is to join things together. You can give it multiple inputs and it will output each one directly following the previous. It so happens to also work with just one input.

kautau ,

That’s why we have bat now

github.com/sharkdp/bat

0x0 ,

To bonbatenate files?

kautau ,

Exactly

DrWeevilJammer ,
@DrWeevilJammer@lemmy.ml avatar

Bat bat bo-at

Bonbaten-fana fo-fat

Fee-fi-fo-fat

Bat!

Hamartiogonic ,
@Hamartiogonic@sopuli.xyz avatar

Cat with wings? Isn’t a bat more like a rat with wings?

Mad_Punda ,

TIL

I never realized. Thanks!

ulterno ,
@ulterno@lemmy.kde.social avatar

It is to use along with split. e.g.

  1. You take a single large file, say 16GB
  2. Use split to break it into multiple files of 4GB
  3. Now you can transfer it to a FAT32 Removable Flash Drive and transfer it to whatever other computer that doesn’t have Ethernet.
  4. Here, you can use cat to combine all files into the original file. (preferably accompanied by a checksum)
Tangent5280 ,

Doesnt computers do this automatically if you try to copy over a file larger than its per file size limit?

Octopus1348 ,
@Octopus1348@lemy.lol avatar

No. It just gives an error that it’s too big.

sqw ,
@sqw@lemmy.sdf.org avatar

i use both frequently but im also a pretty dumb user

marcos ,

When you updated a Django server, you were supposed to touch the settings.py file so the server would know to reload your code. (I haven’t used any for a long time, so I don’t know if it’s still the procedure.)

There are many small things that use it.

alexdeathway ,
@alexdeathway@programming.dev avatar

it now has a hot reload, How long ago were you using Django?

noproblemmy ,

cat

Ahhhhh, fuck. I’m quite noob with linux. I got into some rabbit hole trying to read the docs. I found 2 man pages, one is cat(1) and the other cat(1p). Apparently the 1p is for POSIX.

If someone could help me understand… As far as I could understand I would normally be concerned with (1), but what would I need to be doing to be affected by (1p)?

survivalmachine , (edited )

The POSIX standard is more portable. If you are writing scripts for your system, you can use the full features in the main man pages. If you are writing code that you want to run on other Linux systems, maybe with reduced feature sets like a tiny embedded computer or alternates to gnu tools like alpine linux, or even other unixes like the BSDs, you will have a better time if you limit yourself to POSIX-compatible features and options – any POSIX-compatible Unix-like implementation should be able to run POSIX-compliant code.

This is also why many shell scripts will call #!/bin/sh instead of #!/bin/bash – sh is more likely to be available on tinier systems than bash.

If you are just writing scripts and commands for your own purposes, or you know they will only be used on full-feature distributions, it’s often simpler and more comfortable to use all of the advanced features available on your system.

Phoenix3875 ,

If you execute a binary without specifying the path to it, it will be searched from the $PATH environment variable, which is a list of places to look for the binary. From left to right, the first found one is returned.

You can use which cat to see what it resolves to and whereis cat to get all possible results.

If you intentionally wants to use a different binary with the same name, you can either directly use its path, or prepend its path to $PATH.

zurchpet ,
@zurchpet@lemmy.ml avatar

We use it to trigger service restarts.


<span style="color:#323232;">touch tmp/service-restart.txt
</span>

Using monit to detect the timestamp change and do the actual restart command.

dan ,
@dan@upvote.au avatar

This is an interesting idea to allow non-root users to restart a service. It looks like this is doable with systemd too. superuser.com/a/1531261

zurchpet ,
@zurchpet@lemmy.ml avatar

Indeed. Replacing monit with systemd for this job is still on our todo list.

Speculater ,
@Speculater@lemmy.world avatar

Cat is actually super useful.

Crow ,

I mean, timestamps aren’t really all that useful. Really just if you do some stuff with makefiles but even then it’s a stretch. I did once use cat for it’s intended purpose tho, for a report. We split up the individual chapters into their own files so we have an easier time with git stuff, made a script that had an array with the files in the order we wanted, gave it to cat and piped that into pandoc

NotSteve_ ,

I used it recently to update the creation date of a bunch of notes. Just wanted them to display in the correct order in Obsidian. Besides that though, always just used it for file creation lol

Anticorp ,

I use it all the time, especially in ssh on a server.

qaz ,

Yes, Nextcloud can’t sync files with a timestamp of 0

NaiveBayesian ,

Yup, stupid zip files and their directories from 1970

starman2112 ,
@starman2112@sh.itjust.works avatar

I don’t know anything about Linux but I do love touching cats

YoorWeb ,

You would love Linux cli.

Trainguyrom ,

Touch is super useful for commands that interact with a file but don’t create the file by default. For example, yesterday I needed to copy a file to a remote machine accessible over ssh so I used scp (often known as “secure copy”) but needed to touch the file in order to create it before scp would copy into it

emptiestplace ,

Sorry, what?

makingStuffForFun ,
@makingStuffForFun@lemmy.ml avatar

I use it regularly

mox ,

Creating an empty file is one of its intended purposes. Unix commands were designed as multi-purpose primitives, so they could be reused and composed to handle many different tasks. The touch command is no exception.

www.youtube.com/watch?v=tc4ROCJYbm0&t=287s

Hupf , in Aaargh....my eyes......my eyes......
mectag ,

It’s an unwritten rule that there‘s always a fitting xkcd post

Vigilante , in Open Source VS Company

Yeah those entitled shits are ruining it for everybody .

pivot_root ,

“Add support for XYZ.”

No please, no thank you, just a follow-up of “is it done yet?” three days later.

kernelle ,

Eta when?

testeronious , in Aaargh....my eyes......my eyes......

Cleanest code by Unclest Bob

hardkorebob , in Aaargh....my eyes......my eyes......
MicrowavedTea ,

I’d ask what I’m looking at here but feel I might regret it

hardkorebob , (edited )

In Oct’23 a basic Text widget with Subprocess to run shell commands allowed me to take my command line fu into a different arena because Tkinter gave me special tricks. This tool (shell functions) allows me to type up GUI apps or any Python script with less effort, for my fingers and brain.

wc newide; ksh newide | wc

513 1671 11018 newide in pnk

604 1987 29867 newide in python

The blocks of color are capital letters colored using tkinter methods (tag_add & tag_configure) with a bg and fg of the same color to make it look like a lego block, it’s all ASCII. On the right, an idle clicker game/toy made with pnk.lang, also just ASCII/UTF-8. The IDE you see in the pic also was coded using functional shell language I call pnk.lang and the original first iteration of this specification is in the legacy folder in the repo below. Just me learning how to code faster in Python but in shell but in neither at this point.

github.com/dislux-hapfyl/pynksh

www.reddit.com/r/pnk/

Don’t be put off by Ksh because Bash can also interpret it, since it’s just shell functions that print Python code. But I have plans to use an Xbox controller so I can move away from building with the keyboard at piecemeal rates. I will do this by abstracting away identifiers and all data we use as engineers into “dictionaries” to then transform it into a spatial system. I already done this first step! Using a basic grid with a maximum of 10 rows x 3 cols, indexing row[0-9] col[0-2], as you see there on the left side, and by using a letter I then categorize the functions of pnk(shell+python) so I can have 30 x 26[a-z] available slots; a00 b11 k22 and so on…by making it a visual shortcut that reduces cognitive load and typing for me.

Take a closer look at my repo without dismissing it too quickly. It could seem unnecessary but maybe someone else can see what I have made as useful and how we gonna take it to higher levels of abstraction and create a new realm for making computer applications in an abstract game/IDE of art and code. Perhaps it’s that creator effect that happens when you make something for the first time that makes me see its future utility and appeal. All this was made incrementally using my own software I built from scratch. I do have a great vision and would love to speak to anyone who is interested. I also demonstrate the utility of this small tool on youtube[link in repo]. Thanks.

MicrowavedTea ,

Ok I don’t completely get the use case but that’s…impressive. Thanks for the detailed explanation and good luck moving it forward

hardkorebob ,

Thanks a lot! ;) … maybe also see my reply above.

kralk ,

I’m somehow more confused

hardkorebob , (edited )

I write python in shell. Literally. I made a shell function file (pnk.lang) that prints correct python code. The capital letters in the shell function’s name, my Tkinter IDE turns into color as you see above. So I let the color (capital letter) abstract away indentation for my brain. The second letter is for category of python code according to me. Again using color to allow me to think. I dont like Python syntax. I looks ugly to me. So I made this tool to make coding colorful, succint and fun for me. It reduces my eye strain among many other personal benefits.

S=self

E=echo

#Z=“” #0

Y=" " #3

X=“$Y$Y " #7

W=”$Y$X "

V=“$Y$W "

U=”$Y$V "

YDfd() {


<span style="color:#323232;">typeset z="$1"
</span><span style="color:#323232;">
</span><span style="color:#323232;">    typeset nn="$2"
</span><span style="color:#323232;">
</span><span style="color:#323232;">typeset cc="$3" 
</span><span style="color:#323232;">
</span><span style="color:#323232;">if [[ $z == z ]]; 
</span><span style="color:#323232;">
</span><span style="color:#323232;">then
</span><span style="color:#323232;">
</span><span style="color:#323232;">	$E "$Y def $nn(${S}$cc):"
</span><span style="color:#323232;">
</span><span style="color:#323232;">else
</span><span style="color:#323232;">
</span><span style="color:#323232;">	$E "$Y def $nn($cc):"
</span><span style="color:#323232;">
</span><span style="color:#323232;">fi
</span>

}

YDdefe() {


<span style="color:#323232;">typeset fn="$1"
</span><span style="color:#323232;">
</span><span style="color:#323232;">YDfd z $fn ,e=None
</span>

}

YDdefe addNew

XIcv $ap Pnk

XFpk $ap 1 both

XFfc zz pw.add $ap

turns into


<span style="color:#323232;">def addNew(self,e=None):
</span><span style="color:#323232;">    self.appinstance = Pnk(self,)
</span><span style="color:#323232;">    self.appinstance.pack(expand=1,fill="both",padx=2,pady=2,)
</span><span style="color:#323232;">    self.pw.add(self.appinstance)
</span>
tourist , in Aaargh....my eyes......my eyes......
@tourist@lemmy.world avatar

lgtm

merged

xmunk ,

I’m assigning all my PRs to you, buddy, your performance metrics will be over 9000!

RatBin , in Aaargh....my eyes......my eyes......

Why not leave comments

bAZtARd ,

Why leave comments?

wise_pancake , in You can certainly change it. But should you?

Some people hate that C is dangerous, but personally I like its can-do attitude.

“Hey C, can I write over the main function at runtime?”

Sure, if you want to, just disable memory protection and memcpy whatever you want there! I trust you.

It’s a great attitude for a computer to have.

mox ,

This is sometimes practical, too. For example, hooking and extending functions in compiled code that will never be updated by the original author, while preserving the original executable/library files.

huginn ,

You can do that in memory safe languages too. Kotlin extension functions, for example.

RonSijm , (edited )
@RonSijm@programming.dev avatar

Extension functions are not the same at all. Extension functions are syntactic sugar. For example if you have an extension function like


<span style="color:#323232;">public static class ObjectExtension
</span><span style="color:#323232;">{
</span><span style="color:#323232;">    public static void DoSomething(this object input) { }
</span><span style="color:#323232;">}
</span>

You can call that function on an object by doing object.DoSomething() - Yes. But underneath it’s the same as doing ObjectExtension.DoSomething(object)

That function does not actually become part of the object, and you can’t use it to override existing functions

A closer example of how to do something similar in a memory safe language would be - in C# - using something like Castle DynamicProxy - where through a lot of black magic - you can create a DynamicProxy and fool the CLR into thinking it’s talking to an object, while it’s actually talking to a DynamicProxy instead. And so then you can actually intercept invocations to existing methods and overrule them

Generally overruling existing functions at runtime is not that easy

huginn ,

Ah my bad, misunderstood the use case.

I thought you were talking about keeping an unmaintained library intact but building onto it.

I thought C was a really dangerous way to use that syntactic sugar pattern. Actual manipulation of the bytecode to maintain and extend a compiled binary is wild

mox ,

Actual manipulation of the bytecode to maintain and extend a compiled binary is wild

Just wait until you learn about machine code. :)

huginn ,

I do have a degree in this. I am aware.

This is sometimes practical, too. For example, hooking and extending functions in compiled code that will never be updated by the original author, while preserving the original executable/library files.

Your original comment made it seem more like extensions - extend and preserve. That’s the misunderstanding.

When I said it’s wild to manipulate bytecode I means “wow that’s a terrifying practice, I would hate to check that PR”

mox , (edited )

Fair enough. What threw me is that you said “bytecode”, which is generally not used when referring to hardware machine instructions. My original comment is about patching the in-memory image of a running program or library, replacing machine instructions in order to intercept certain calls and extend their behavior.

I thought my phrase “compiled code” would convey this, but I guess nowadays bytecode-compiled languages are so common that some people assume that instead.

huginn ,

Yeah and part of this is that the domain I’ve been working in for years now is very far from machine code, and I’m probably overly lax with my language here.

The result of being in very corporate app dev - I’m usually talking in much higher level abstractions. My bad on conflating bytecode and machine code

mox ,

Ah, corporate work. I hope they’re treating you well.

huginn ,

Different strokes - some would find what I’m doing hell. I personally love it.

The 260k/yr salary may help alleviate the pain.

wise_pancake ,

That actually sounds pretty cool

Sometimes what I’d like to be able to do is treat part of an app as a core and the rest like user provided scripts, but written and evaluated in the host language and not running an embedded scripting language like lua with all the extra burden.

E.g. you have an image editor and you want the user to be able to write native functions to process the image. Or you have a game engine and you want to inject new game code from the user without the engine being a compiler or the game logic being bundled scripts.

RonSijm ,
@RonSijm@programming.dev avatar

You’d probably use a different approach for that. Like you’d make your program dynamically load all the .dlls in a “plugins” folder -

Then you’d provide some plugin interface for the users to create plugins, for example:


<span style="color:#323232;">public interface IImageEditorPlugin
</span><span style="color:#323232;">{
</span><span style="color:#323232;">    public void BeforeImageEdit(int[,] imageData);
</span><span style="color:#323232;">    public void AfterImageEdit(int[,] imageData);
</span><span style="color:#323232;">}
</span>

And then you can load plugin classes from all the dlls with dependency injection, and execute them though something like this:


<span style="color:#323232;">public class ImageEditor(IEnumerable<IImageEditorPlugin> plugins)
</span><span style="color:#323232;">{
</span><span style="color:#323232;">    public void EditImage(int[,] imageData)
</span><span style="color:#323232;">    {
</span><span style="color:#323232;">        foreach (var imageEditorPlugin in plugins)
</span><span style="color:#323232;">        {
</span><span style="color:#323232;">            imageEditorPlugin.BeforeImageEdit(imageData);
</span><span style="color:#323232;">            // Do internal image edit function
</span><span style="color:#323232;">            imageEditorPlugin.AfterImageEdit(imageData);
</span><span style="color:#323232;">        }
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">}
</span>

This is a very simple example obviously, normally you’d send more meta-data to the plugins, or have multiple different interfaces depending on the kinda plugin it is, or have some methods to ask plugins when they’re suitable to be used. But this way a user can provide compiled versions of their plugins (in the same language as the core application) - instead of having to provide something like lua scripts

SubArcticTundra ,
@SubArcticTundra@lemmy.ml avatar

Agreed. It’s a very adult approach. C hands you a running chainsaw and whatever happens after that is your responsibility. It is also your responsibility to decide when it’s not the right time to use C.

mindbleach ,

C is dangerous like your uncle who drinks and smokes. Y’wanna make a weedwhacker-powered skateboard? Bitchin’! Nail that fucker on there good, she’ll be right. Get a bunch of C folks together and they’ll avoid all the stupid easy ways to kill somebody, in service to building something properly dangerous. They’ll raise the stakes from “accident” to “disaster.” Whether or not it works, it’s gonna blow people away.

C++ is dangerous like a quiet librarian who knows exactly which forbidden tomes you’re looking for. He and his… associates… will gladly share all the dark magic you know how to ask about. They’ll assure you, oh no no no, the power cosmic would never pull someone inside-out, without sufficient warning. They don’t question why a loving god would allow the powers you crave. They will show you which runes to carve, and then, they will hand you the knife.

5C5C5C ,

You have a talent for metaphor.

AVincentInSpace , (edited )

Rust is like a paranoid overprotective guardian. A “mom friend”, of sorts. Always the designated driver of the group, keeps you from staying up too late, stops you from eating things that might be choking hazards without proper precaution, and so on and so forth. You’ll never meet a person more concerned with your health and safety – until, that is, you say the magic word “unsafe”. Suddenly the alter ego that their hypnotist implanted gets activated, and their entire demeanor changes on a dime. BMX biking? Bungee jumping? Inline assembly? Sounds like a great idea! Let’s go, man! Rules are for NERDS! Then the minute the unsafe block ends, they’re back to normal, fully cognizant of the adventure they just went on and thinking absolutely nothing of it. “Whitewater rafting with you guys was really fun, especially the part where Jason jumped into the water and I went after him! I’d best go get the first aid kit, though – that scrape he got when he did that looks like it might get infected. I know he said it didn’t hurt, but better safe than sorry!”

They kinda scare you when they’re like that, if you’re honest.

mindbleach ,

I tried thinking of one for Rust, and ‘the mom friend with a safeword’ is alarmingly accurate.

The secret basement is never locked. It’s fine to go down there, alone. You’ll only be scarred on the inside.

It’s when you go down together that all bets are off.

derpgon ,

I loved C/C++ in university, finally the damn piece of rock we forced into thinking was doing exactly what I told him to do, no more and no less.

solarvector , in Open Source VS Company

Yes, but also have you seen some game development forums? Oof. Some people just need their gaming chair hooked up to a sun facing launchpad.

myxi , in Variable Declaration
@myxi@feddit.nl avatar

I turn off LSPs during my train of thoughts. I don’t want all red and yellow underline bullshit to disrupt my thoughts. Like, calm the fuck down. I WILL write the correct code eventually; just give me some fucking time.

Well, I use Neovim, so turning off the LSPs or restarting them is sufficiently simple.

When I work on a new project, or on a new feature, I temporarily turn off the LSP, and rely on the compiler to figure out where the code errors. Plain white text gives me the freedom to write whatever the fuck I want without any disruption. Of course, I eventually turn on the LSP again to fix the little issues.

baseless_discourse , (edited )

Many languages allow type hole like _ to indicate to the compiler/lsp that this is an expression you will fill in later.

So that lsp don’t put a squiggle on the entire program, only the type hole

myxi ,
@myxi@feddit.nl avatar

I also leave out little syntax errors and only only focus on the rough idea during my train of thoughts. And the variables, aren’t really supposed to be implied as private or unused – I do eventually meaningfully use them. If I have to prefix all my variables with a underscore to avoid the LSP, I might instead just disable the LSP. When I eventually turn the LSP back on, it tells me the actually unused variables and imports that I can now get rid of.

Because of the LSP, I used to write maybe three hundred lines of code per hour, but now I probably average at least five hundred or more.

jimmy90 , in Variable Declaration

#![allow(warnings)]

:)

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines