Onion Information
Recreational Programming - nanochan
oc/ - Original Content - Share your own art, code, and music
Onion Details
Page Clicks: 0
First Seen: 03/11/2024
Last Indexed: 10/22/2024
Onion Content
/oc/ - Original Content Share your own art, code, and music [Make a Post] Recreational Programming Nanonymous 2020-06-12 09:04:58 No. 119 (L) [D] [U] [F] [S] [L] [A] [C] File: 1d5bbece89b71a75fca2a999df7342a87f1a94cedf3faa90de89e353d656cb37.png ( dl ) (168.50 KiB) Recreational programming is the programming you do in your free time for fun. When you want to share your code make sure to include information on what it is, how to compile it, and how to use it. iviewer Nanonymous 2020-06-12 09:16:11 No. 121 [D] [U] [F] >>130 >>301 >>303 File: 0918527e2757b3ea70e9ae77c49782335d824e11dcdd62952555330894e30671.txt ( dl ) () I made a simple PNG image viewer. It is 250 lines and is hardware accelerated. When displaying an image it will not scale the image. This means that if your window is bigger than the image than there will be a black border. If it is smaller it will not show the whole image. In order to compile this you will need to rename the attached file to main.c and make sure you have the libraries: libpng, libglfw, and libGL. You can compile it with gcc -O3 -lpng -lGL -lglfw main.c -o iviewer You can use iviewer as so: iviewer ... You can use view as many files as you want as long as they are all PNG files. When the image viewer is open you can go to the next image by hitting space bar and you can exit the application by hitting escape. Nanonymous 2020-06-12 11:52:02 No. 130 [D] >>121 is there a way to move around a picture or zoom in or zoom out? msort Nanonymous 2020-06-18:52:37 No. 276 [D] [U] [F] >>302 File: 2a5d156639a0543cd7f7c12afcda9188378379941264eef7df2f71cc965829db.txt ( dl ) () Motivation/what is it for I often download larger collections of music even though i dont necessarily like all of it. Cue in a few years later, i have over 300GB of music taking up space on my drive while only liking less than a quarter of it. So i need some kind of way to sort out the good ones while getting rid of the meh ones. Solution Make my own playlist manager that has ability to delete files from the drive. Make it such that i can bind its operations to systemwide shortcuts so that i can cast a judgement with a single keypress How to use this/what it does - edit the list of supported extensions at the beginning (so that you dont try to play a jpg file or something) - You choose a folder with songtracks to sort by putting the path relative to your home directory into a file at ~/.config/msort (that bit could arguably use some work, though i dont actually find myself changing the directories that often so whatever) about in this manner: "/Music/" - execute "msort -n" to play the first or the next file - execute "msort -r" to delete the file last added to the queue from the currently selected folder and play the next one. Running it without having added anything first may have unintended consequences Each directory you run it on, it creates an .msort file in that it keeps all the passed files in so that you can resume the session later. The audio player being used to actually play the song is audacious because of how well i can control it from the command line. It shouldnt however be that hard to edit the queueing action at the end of the code to suit whatever player you want. Files that have ' in them are not supported. Couldnt make it work. Also its in python because bash is too hard. The files are completely out of order, though files from shared subdirectories should stick together i am very much aware that its shit, but it works. Criticism is appreciated Nanonymous 2020-06-23 02:17:50 No. 301 [D] >>121 Nice fren; I can appreciate a fellow Cfag Nanonymous 2020-06-23 03:34:07 No. 302 [D] >>276 >Criticism is appreciated Nitpicks: Why use readlines() on line 15 instead of readline()? The msort file is suppose to be one line, right? Line 16 can be compacted into line 15 - Instead of calling file.close() you can use the "with" keyword, like so: file = open(os.environ['HOME'] + "/.config/msort") with file: folder = file.readline()[: 1] Personally I like calling close() more. Lines 6 and 22 could print to stderr using print's "file" keyword argument. Nanonymous 2020-06-23 04:05:15 No. 303 [D] >>305 >>121 Nice. Few criticisms: Except for your usage summary on line 208, replace fprintf(stderr, ...) with warn(3) or err(3) . You have a double/triple/etc-free on line 227 if files > 1. Big no-no. Pretty sure it's a typo and you meant to put it outside the for loop. Lines 216-218 is another memory error and should be deleted. If load_images returns 1 then malloc would not have been called or failed for image->data. Nanonymous 2020-06-23 04:33:51 No. 305 [D] >>307 >>303 >Lines 216-218 is another memory error and should be deleted. If load_images returns 1 then malloc would not have been called or failed for image->data. But it would have succeeded for all of the previous images. Nanonymous 2020-06-23 05:13:11 No. 307 [D] >>305 You're right. Didn't see j=i-1 Nanonymous 2020-12-01 21:24:23 No. 1007 [D] [U] [F] >>1010 >>1011 File: f8902b060f56cbf6b523c49bf0c2b49267142cda18bb89ae9c986c0bd4d6ddd9.txt ( dl ) () A little file encrypt/decrypt script I wrote a while ago, inspired by Rclone's crypt remote. Code is kinda shit, but it does its job. It can also read a file from stdin and output everything to stdout. ./crypt --help (It requires PyNaCl installed.) Feedback is very welcome. Nanonymous 2020-12-02 11:22:00 No. 1010 [D] >>1007 Looks good. An optional thing you could add to improve it would be to add some padding, so that you do not leak the unecrypted file's size in full. Nanonymous 2020-12-02 18:16:05 No. 1011 [D] >>1019 >>1007 Could you walk me through your salt thinking? Nanonymous 2020-12-02 23:31:31 No. 1019 [D] >>1011 You can supply an optional salt with the flag -s. A salt is needed for the key derivation function (scrypt), so if the user doesn't input one the default will be used. Nanonymous 2020-12-06 02:06:41 No. 1023 [D] [U] [F] >>1024 File: cb29cffba25863fea8f5d53b8044c43be7142ad605bb9f6c462576c285bc2349.txt ( dl ) () i am the c nubi spamming the /g/ qtddot. i made a replace function and its already in use in my c static website generator. critique appreciated :D Nanonymous 2020-12-06 03:21:32 No. 1024 [D] >>1023 I'm going to start off with correction problems. Remember to use sanitizers. AddressSanitizer found an issue in get_instances where you are reading past the end of the string buffer. The problem is that you always assume that s_ptr has enough room to store what's in ss_pptr. For example if the string was "a" and you substring was "abcd" it would read "a" from the string and then read 3 more characters beyond the end of the string. AddressSanitizer also catches the exact same mistake in replace. There is also a logic problem. The version of looping through your string in get_instances does not increment s_ptr by the length of the substring when a match is found. This means that if your string is "aaa" and your substring is "aa" get_instances would return 2 instead of 1. In regards to the code itself. You should use strlen from the standard library instead of until_null. For the implementation of until_null a more simple way to do that is to use. > while (string[length++]); For read ability, you could also move the increment to inside of the while loop's body. I would recommend using indexes instead of just incrementing pointers through your whole program. You are adding unnecessary complexity by mutating the pointers. Since you pretty much duplicate your substring check in both get_instances and replace I would recommend pulling that out into a function starts_with. This function will need the string, the prefix you are searching for and the lengths of both of the strings. When printing out the new string in your main method, you forgot to add a new line at the end of format string. Nanonymous 2020-12-17 14:34:31 No. 1118 [D] [U] [F] File: 5c1258f5b80610fcebbd0a5b9df9cb8f10e4da2df1a4073954f55d2107f813c0.txt ( dl ) () nanochan thread archiver made in perl it was original made to be ntd.py replacement feedback is appreciated [Catalog] [Overboard] [Update] [Reply] 6 files, 15 replies