[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 21
File: monad diagram.png (26 KB, 334x358) Image search: [Google]
monad diagram.png
26 KB, 334x358
What are you working on, /g/?

(I apologise for not using an anime image.)

Previous Thread: >>55169989
>>
>>55173239
First for D
>>
>>55173239
what's a monad?
>>
>>55173252
Anything described by that diagram
>>
>>55173239
How do I into monads?
>>
>>55173239
>Being this careless

4chan.g->current_dpt->next = NULL;


/dpt/s form a linked list. Please be careful when changing the current node! You don't want people trying to get undefined behaviour when trying to access the next (inexistant) thread.
>>
>>55173270
>/dpt/s form a linked list
False, the chain has been broken, bisected and interleaved many times.
>>
What's a good resource that will help me reach the next level? Been studying Python, working through some textbooks, codewars.

Some website or general resource that will bring me ascendance...

Still at the basics, but grasping em'. Very motivated and I enjoy practicing.
Share suggestions and advice.

Some online community I could be a part of and contribute to is especially something I'm interested in.
>>
>>55173239
>not using an anime image
I hope animefags will boycott this thread. We could finally have some quality here.
>>
File: 1443389327375.jpg (29 KB, 450x351) Image search: [Google]
1443389327375.jpg
29 KB, 450x351
Students/those who aren't working yet, have you made any money from programming?
>>
>>55173297
Yes. By teaching younger students programming.
>>
File: Programming Shelves.png (952 KB, 2100x1400) Image search: [Google]
Programming Shelves.png
952 KB, 2100x1400
>>55173283
>next level
>from Python
Visual Basic?

>>55173287
Stop trying to derail the thread
>>
>>55173297
No
>>
>>55173280
The legitimate /dpt/s form a linked list. The mods work in the background thread linking all the broken links.
>>
>>55173312
>not asking the unicorn to summon you a shelf
Haskell wins again.
>>
>>55173312
Caught red handed. You non-animefags are smart after all.
>>
>>55173329
The mods are the garbage collectors who free any illegitimate thread (any thread that is not linked by another node)
>>
>>55173342
That's only one of their functions, and, truth be told, it's not fair to ignore the janitor daemons who invoke the mods.
>>
>>55173312
Lol, by next level I mean keeping the shelf hanging.
>>
Working on a screen saver/locker in Rust, because I'm bored and I don't really like xscreensaver.

Trying to figure out a better way to implement the locker/saver process separation that xscreensaver does without resorting back to passing a Drawable XID to the process.

I'm most likely going to end up using GLX_EXT_import_context or an OpenGL ES alternative if I can find one.
>>
File: alphatest_simple.webm (36 KB, 640x480) Image search: [Google]
alphatest_simple.webm
36 KB, 640x480
I am trying to do some simple stuff in OpenCV but it's not working out.
Essentially I want to create a video where a circle is "moving" on a parabola. So far so good, that works. The circle should have a trail of <bufflength> circles, that works as well.
What doesn't work is, I want the trail in alphatest_alpha.mpeg to fade using alpha blending. The OpenCV doc says to give the alpha value as the fourth element of the color tuple, but as you can see all the circles are completely opaque despite having different alpha values. What is going on?


import cv2
import numpy as np

# how many frames should the trail be long (at most)?
bufflength = 20

# properties of output video files
fourcc = cv2.cv.CV_FOURCC('M','P','E','G')
outfile_repo = '/home/blockus/dev/notebooks/alphatest/'
outfile_name = 'alphatest'
outfile_mime = '.mpeg'
outvid_fps = 25
outvid_size = (640, 480)
outvid_simple = cv2.VideoWriter(outfile_repo + outfile_name + '_simple' + outfile_mime, fourcc, outvid_fps, outvid_size)
outvid_alpha = cv2.VideoWriter(outfile_repo + outfile_name + '_alpha' + outfile_mime, fourcc, outvid_fps, outvid_size)

# define marker positions
markerpos = []
for x in range(81):
markerpos.append((x + 320, int(np.floor(x * x / 10))))


(1/2)
>>
>>55173388
(2/2)

for ptidx in range(len(markerpos)):
# read previous point coords into array
framepoints = []
buffidx = 0
while ptidx - buffidx >= 0 and buffidx < bufflength:
framepoints.append(markerpos[ptidx - buffidx]) # listed in chronologically reverse order (left = most recent)
buffidx = buffidx + 1

# create blank images
img_simple = np.zeros((outvid_size[1], outvid_size[0], 3))
img_alpha = np.zeros((outvid_size[1], outvid_size[0], 3))

# draw points into images
for drawptidx in range(len(framepoints)):
cv2.circle(img_simple, framepoints[drawptidx], 5, (0, 0, 255), -1)
cv2.circle(img_alpha, framepoints[drawptidx], 5, (0, 0, 255, drawptidx * 25), -1)

# turn img_alpha into 3-channel image by merging alpha channel

# convert data type and write to video
img_simple = img_simple.astype('u1')
outvid_simple.write(img_simple)
img_alpha = img_alpha.astype('u1')
outvid_alpha.write(img_alpha)
>>
>>55173254
In case you're looking for an answer here, I answered to you in the old thread:
>>55173398
>>
>>55173414
I replied in the old thread as well, but we can carry on in this one if you'd rather.
>>
>C released in 1972
>OS still provides the build system
thanks dennis
>>
>>55173472
What is wrong with that?
>>
>>55173479
not portable
>>
>>55173489
Howso?
>>
>>55173469
I didn't see this message of yours in time and replied there again (>>55173544), but that's the last time I post in the old thread.
>>
>>55173568
Even so, on average you would have to send more data per message. Perhaps less than a bit less, but less nonetheless.
>>
>>55173642
>Perhaps less than a bit less, but less nonetheless.
Fuck, I meant
"Perhaps more by less than a bit, but more nonetheless."
>>
Anyone know of a tool for generating documentation for Java Hibernate webservices? Not javadocs, I mean something that I can configure to list out the services, their parameters, and the list of their possible responses.
>>
>>55173283
K&R C programming. Alternatively SICP.
>>
>>55173239
So I've been using make on some smaller projects, and it's been working fine, but would any of you recommend a different system?
>>
>>55173848
shit advice, he wants to move forward not backwards
>>
>>55173564
I just got around to reading your post now

>>55173544
>>55173568
But I thought that even when the size of the message doesn't matter, compressing it before encrypting it could still subject it to exploits like CRIME

Anyway, after thinking for a bit longer, I see no way of compression + encryption being both useless and secure, so I think I'll abandon the idea and just use padding + encryption. Thanks for all the help.
>>
>>55173968
Checkout tup and its rationale. Make lets you be wrong and miss a dependency, thus not rebuilding enough and causing bugs. It is also slow on big enough stuff. Tup is better, and language-specific kludges are taking ideas from it rn.
>>
>>55174241
>useless
useful*
>>
>>55173283
bump
>>
What should I write? What kind of projects should I start?

If you happen to run across these problematic questions or someone in your family needs a trauma kit please visit:

www.senka.com

~Together against the elements.
>>
>>55174616
~
>>
>>55174244
Syntax already looks a lot cleaner than Make, I like it
>>
File: 1460202104435.gif (287 KB, 696x504) Image search: [Google]
1460202104435.gif
287 KB, 696x504
Did anyone here write a login display or how do they call it for any Linux based operating systems? Did you just rewrite some of the code or did you write fron scratch?


Can I make a simple gui app that passes the username and password to the actual manager while it is not showing in the backround just my app?
>>
>>55174682
>excel
literally one of the most useless applications made
>>
>>55174682
>using a display manager
lol why
>>
File: euphoric tip.jpg (42 KB, 479x720) Image search: [Google]
euphoric tip.jpg
42 KB, 479x720
>>55174712
>>
>>55174723
Everyyyyyybuuuddyyyy huuuuurts
>>
>>55174726
>le euporia meme
Nothing in the office suit has any use at all.
>>
>>55174755
> office
> Basement
Pick one
>>
>>55174766
If I seriously had to choose I would pick basement.
>>
Okay guys, in C++ what is better, a static class, a namespace or a singleton?
>>
>>55174712
You are edgy.
>>
>>55174814
No
>>
>>55174805
Depends
>>
File: burypinkgirl.png (1 MB, 5000x4859) Image search: [Google]
burypinkgirl.png
1 MB, 5000x4859
this is nice thread.
post fizzbuzz please.
>>
>>55174814
>winfag calling people edgy
>>
>>55173252
A monoid in the category of endofunctors
>>
>>55173297
Do I work if I'm not officially employed?
>>
>>55173239

Can someone redpill me on IP addresses?

I want to build something simillar to Shodan's web crawler, which I assume just brute forces IPs to find non-website servers
>>
Making a requests bot in python to brute force a password, but I'm not patient enough...
Is there a way to make it more efficient? Currently what I am doing is:
req=requests.post(url,  data={"username":username,"password":str(pssw)})
if check(req):
return pssw
#check() checks title through lxml.html and xpath to see if it's the same with a failed attempt

loops through pssw for an 8 digits code. It's slow and I am wondering if there's a better way.
Downloading the whole page seems bad to me, let alone how noobish checking the title for confirmation seems to me, but since even if it's the wrong password it returns repsonse 200, I can't think of any other way. Suggestions?
PS:Dunno if I have to say that due to 4chan's rules, but it's nothing illegal as far as I know for this site.
>>
>>55174978
You work if you derive an income from your labour.
>>
>>55175055
pregenerate the combinations in chunks
use multiproces/aiohttp
>>
File: fucking-font.webm (320 KB, 1138x640) Image search: [Google]
fucking-font.webm
320 KB, 1138x640
>>55174845
repost
>>
>>55175055
>brute forcing across the Internet
Consider suicide senpai.

Otherwise send hundred or thousands of requests at a time as many as you network can support.
>>
>>55175299
C stands for cemetry cause no one just old fags use it. The nowadays devs only use that outdated shite cause they are too lazy to develope new more efficient systems and they are just maintaining the old world's misery.
>>
>>55175338
>C stands for cemetry

Holy shit! C users on suicide watch!
>>
Do you developed a program (small or big) that you use everyday? If yes what does it do?

Searching for ideas. I don't have any problems besides autism to fix.
>>
>>55175381
More like One Slow Gay Trap Prick #gotem
>>
>>55175338
> C stands for cemetry
Well done
>>
>>55175338
This.
>>
>>55175338
Upvoted :^>
>>
>>55175381
C stands for not Cludadwy
>>
>can't get out of bed

Help
>>
>>55175338
This
>>
>>55175338
Actually, C stands for Cuckoldry.
>>
>>55175475
C stands for chemotherapy

C USERS ON SUICIDE WATCH 24/7
>>
Do you guys suffer from occasional back pain?

Often I don't watch myself at work and I work straight for 5-6 hours and my back goes kind of numb. I wouldn't call it pain but it is uncomfortable.

Also I have developed scoliosis during my childhood but is does not affect me at all just the knowledge taunts me that I have it.
>>
>>55175338
Wow you're right, guess I'm a #JavaDrinker now, really makes you think
>>
>>55175542
I used to sit bent over on my chair which caused back pain. Now I sit properly and the pain has gone.
>>
>>55175627
>sitting properly on a chair
>ever
>>
Stupid question.

I have 2 sets of 48 million 16-bit integers that I need to perform an operation on.

The operation is:
set1[n] = (set1[n] & 0xFFF0) | (set2[n] >> 12)


Would it make sense to somehow use OpenCL to do this faster, or is it not possible? I understand if you wanted to sum up 48 million numbers, then you'd just have to read the one answer and that's it. But here, I have to perform 48 million assignments, and that means moving a lot of data around. Anyone know?
>>
>>55173239
Anyone have a link to the instructor's manual for CLRS 3rd edition?
>>
>>55173297
Yes, through gsoc
>>
>>55176068
How much?
>>
What the hell is wrong with glibc? Apparently the developers don't have plans of implementing threads.h because it's "optional".
>>
>>55175828
I'm no expert, but the problem looks IO bound, and OpenCL shouldn't help with that.
>>
>>55176234
proof?
by the way, musl supports it and there are many wrappers on top of pthreads.
>>
>>55176234
>clang
Lol retard
>>
>>55176262
According to the comments here: http://stackoverflow.com/questions/8859394/c11-thread-h-in-gcc
>>
>>55176234
>>55176307
That's interesting
I found this if you want to give it a gander
https://github.com/jtsiomb/c11threads
>>
>>55176327
There is one more based on pthreads and two more based on winthreads.

>>55176307
When I asked for proof I meant the
>Apparently the developers don't have plans of implementing threads.h because it's "optional".
>>
>>55176340
>There is one more based on pthreads and two more based on winthreads.
Yeah, but how can you say no to a neckbeard like this?
https://github.com/jtsiomb
>>
>>55176354
I really like that guy actually, he is a fsf member with a fsf mail address and he even made a kernel for a GNU/Linux magazine http://nuclear.mutantstargoat.com/articles/kerneldev/index.en.html
>>
>SDL2
What's the best way to move a bunch of pixels to the screen. I have a tiny 160x144 4-color 'screen' in my code and want to upscale it to a 1600x1440 window efficiently, preferably without a bunch of platform-specific code that depends on the exact format of the framebuffer.
>>
>>55176389
That magazine actually looks pretty interesting, damn shame I stopped learning Greek a while ago.
>>
>>55176234
>What is POSIX threads
>>
>>55176506
>What is portability
>>
>>55176644
>What are those double dubs
>>
>>55176644
>portability
More systems support pthreads actually.
>>
>>55176678
>most
n o t p o r t a b l e
>>
>>55173239
[CODE]
//================
// Nyu-Hook
//---------------------
// Description : This is a project that i'm going to try to write completely from scratch!
// I'm going to work to comment every bit of this as well as i can for better understanding.
//
// Credits :
// n3x [ Coder ]
// Nanocat [ GetVFunc ]
// UC [ Info on a few things ]
//
//---------------------
#include "Nyu.h"

//================
cEngineClient * pEngineClient;
cBaseClientDll * pBaseClientDll;
cClientEntityList * pClientEntityList;
CreateMove oCreateMove;
cClientMode ** pClientMode;
cVMTManager * CreateMoveHook;
cMisc * pMisc;

//================
extern cClientEntityList * pClientEntityList;
extern cEngineClient * pEngineClient;
extern cBaseClientDll * pBaseClientDll;
extern CreateMove oCreateMove;
extern cClientMode ** pClientMode;
extern cVMTManager * CreateMoveHook;
extern cMisc * pMisc;

//================
// CreateMove Function
bool __stdcall hkCreateMove( float SampleTime , CUserCmd * pCmd ) {

CreateMoveHook->Function< CreateMove >( 24 )( pClientMode , SampleTime , pCmd ); // Call the original CreateMove inside of our function, this fixes a lot to do with player freezing.

cBaseEntity * pLocal = ( cBaseEntity * )pClientEntityList->GetClientEntity( pEngineClient->GetLocalPlayer( ) ); // Create a pointer to our Local Player.

if ( pCmd->CommandNumber == 0 || !pEngineClient->IsInGame( ) ) // If the commandnumber is 0, return false.
return false;

pMisc->AutoHop( pCmd , pLocal );

return false;

}
[/CODE]

First person to guess what this is gets a prize
>>
>>55176696
>>55176678
>>55176644
>>55176234
>>55176506

For fucks sake, just use pthreads. Those platforms that DON'T support pthreads are either Windows or an embedded system.
>>
Holy shit why is making a video game such a strenous thing?! Sometimes it makes me want to just go into a comfy IT or database job like everyone else. You have to code, then do some bullshit graphic and menu placements, then you have to add game mechanics then test that the game is fun even though there's no factual context for that.

>make program to query a database and know its function is meant to index results
>make program to give "fun" to consumer, except what the fuck is fun

Then you have to have bells and whistles so they wont get bored. And then I have to program this and hope it doesn't fail.

tl;dr I'm trying to be motivated to finish the last 50% of my commercial project. But Im coding everything myself and havent had any motivation in two weeks. Get me out of this slump, dpt.
>>
>>55176709
Looks like a game hack of some sort
> cBaseClientDll
> GetVFunc
> all dose hooks
> __stdcall

from just the name of the functions, it looks like you're making a bot for some kinda RTS, but that's a total guess.
>>
>>55176422
SDL_Renderer lets you set scaling so you can draw to a 20x20 framebuffer and display it in a 200x200 window or whatever size you want.

https://wiki.libsdl.org/SDL_RenderSetLogicalSize
https://wiki.libsdl.org/SDL_RenderSetScale
https://wiki.libsdl.org/SDL_SetHint (can set how it scales and at what quality)
>>
>>55176757
Cheat for cs go :)
>>
>>55176726

What are you developing?
>>
File: 1444878444415.jpg (126 KB, 1095x662) Image search: [Google]
1444878444415.jpg
126 KB, 1095x662
Okay /dpt/, let's play "find the Rajeet":

>c++
>You are making a simple LinkedList class
>You have defined a copy constructor
>Your copy constructor throws while allocating memory for a pointer

How do you handle the exception?

>9/10 people who get this wrong also poo on a designated street and/or beach.
>>
>>55176772
An educational language game.
>>
File: homo.png (590 KB, 775x547) Image search: [Google]
homo.png
590 KB, 775x547
>>55176780
homo
>>
>>55176776
std::terminate()
>>
>>55176696
More than c11 threads lol
>>
>>55176776
re-throw that shit and it ain't your problem anymore
>>
>>55176716
Windows supports pthreads.
>>
>>55176776
>How do you handle the exception?
first I make sure there wasn't somehow an infinite loop
then I allow the thing to crash
then I make sure my ram isn't failing
then I check to make sure my ssd isn't completely full
>>
>>55176855

I stand corrected.

Then there's even less reason to use C11 threads.
>>
I have some lousy course in Operating systems. During the lab classes we learned about system calls, reading file stats, reading dir entries, forks, execs, pthreads etc...
We had a small passage and an example concerning the select function. I only used it for pipe communication between a parent and a child process, and then I don't have to guess which file descriptor is ready for usage.
But what would be a realistic use for that function when there are arbitrary many file descriptors to watch in some pretty short timespans?
>>
>Trying to do safe and intuitive interactive IO in a platform-agnostic manner in C

Holy shit, this is an entirely new dimension of suffering and pain
>>
im a front end web dev but might be working on some java projects in android studio. From what i can see it uses XML? How tough is java for android development?
>>
>>55176776
>>c++
Found the Rajeet!

>>You are making a simple LinkedList class
Another Rajeet!

>Your copy constructor
3rd Rajeet! It's like we are back to India.
>>
>>55176817
>>55176870
Paresh and Pajeet are here already!

>>55176835
Yes you rethrow, but what if your copy constructor has successfully allocated memory for some elements, but not all. You will now have a leak.
>>
>>55174903

A monoid object in the category of endofunctors.
>>
>>55176776
Catch the exception and throw it back
>>
>>55176908
>but what if your copy constructor has successfully allocated memory for some elements, but not all. You will now have a leak.
uh, no
only if you are literally pajeet
>>
>>55176908
use unique_ptrs.
>>
>>55176905
>Haskellfag detected
This is a simple question, but I understand why you, as a meme programmer, are unable to answer it.
>>
>>55176908
> You will now have a leak.
Boehm-Demers-Weiser always have the answer to the Indian question!
>>
>>55176883
Actually, excuse me, but that post wasn't enough bitching

This is literally the most daunting and seemingly impossible task I have ever had the horrible idea to undertake. Please, if you're considering using C for the above, do NOT do it
>>
>>55176934
I actually use C.
>>
>>55176905

It's literally the same reason one would use assert() in C. When shit goes awry in one of the absolute basics of your code and there's no clean way out, just abort the program entirely.
>>
File: Rajeet.jpg (448 KB, 1280x720) Image search: [Google]
Rajeet.jpg
448 KB, 1280x720
>>55176933
>>
>>55176883
>>55176936
What is the problem? FILE seems fine for what it does.

>>55176953
NO! Only Pajeets use assert for allocation failures.

>just abort the program entirely.
Again, only Pajeets.
>>
>>55175828
OpenCL is probably not worth it, but using simd on the cpu definitetly is, can probably gain somewhere between 8-16x speedup.
>>
>>55176970
By interactive I meant reading from stdin and writing to stdout. It might seem deceptively easy to do if you don't care about safety and portability, but the moment you try to make it robust, C just shits itself completely
>>
>>55176970
>NO! Only Pajeets use assert for allocation failures.

>I prefer to have my program segfault, crash and burn horribly instead of a clean exit

Pajeet detected
>>
>>55176944
>I actually use C.
Oh, well that would explain why you don't know what to do when handling exceptions. Enjoy your curry Kareem.
>>
>>55176963
unique_ptrs will free it automatically for you.
>>
>>55177008
Whom are you quoting? I don't remember saying anything like that my indian friend!
(I use a simple and nice if)

>>55177001
Works fine for me. What is the exact problem?
>>
>>55177032
>Works fine for me. What is the exact problem?
I don't mean to be rude, but if you have to ask then it's clear you've never tried to do it.
>>
>>55177054
I will never be able to help you get over your problem if you don't explain it anon.
>>
>>55177031
You are using raw pointers Vyasa. Get with the hypothetical and stop relying on hand-holding.
>>
>>55176883
>>55176936
>>55177054

I am not him, but can you describe the problem?
>>
GUYS CAN YOU PLEASE HELP ME!!! IT NO WORK I GOOD PROGRAMMER BUT NO WORK :(((!!!

int main( ) {

std:::::::cout <<<< "Hello, India!"""" ::

}
>>
File: outsourceman.jpg (114 KB, 640x640) Image search: [Google]
outsourceman.jpg
114 KB, 640x640
>>55176776

I dont write C++, or any language using exceptions, but I guess you'd just put all your allocated pointers on an auxillary stack and just delete everything on the stack if an allocation fails. Then I'd throw an exception

I dunno, I never really write cpp
>>
>>55177073
>raw owning pointers
no thanks.
>>
>>55177105
You need more :::::::::::
>>
>>55177105
%:include<stdio.h>
int main(void)
<%
printf("%s%c\n", "benis", 1["??=!"]);
return 0;
%>

Works for me
>>
>>55173283
Did you finish codeacademy.com's python tutorial?

If not, go ahead and do it. Make sure to write down what you learn on some form either evernote or onenote or straight up old school notebook(would not recommend since you can't search your notebook).

After you are done with codeacademy(or more likely, if you get stuck) do this
https://www.udacity.com/course/intro-to-computer-science--cs101


If so, I would recommend doing some web development and learning Django. That will force you to start learning javascript/html/css and all the server stuff.

Remember to use git/github so you can have a porfolio of your work(shitty work is better than no work at all).
Here is a course made by google on git/github.
https://www.udacity.com/course/how-to-use-git-and-github--ud775
>>
>>55177165
Oh, sorry! I meant to say
%:include<stdio.h>
int main(void)
<%
printf("%s%c??/n", "benis", 1["??=!"]);
return 0;
%>
>>
>>55177115
Correct! Congratulations, you are one of the few actual programmers ITT!
>>
>>55177105
int main() {
::std::cout << "hello india\n";
}
>>
>>55177069
>>55177076
There's too many problems to describe, but if you want an exercise that'll show you the problems with C here's a challenge:
Write a platform-agnostic (only standard C libraries. it's ok to use POSIX libs if you really have to) command line program to read a single line of text from users. Text over an arbitrary number N should be cut-off. The text must be echoed back to the user, who must confirm that the text is what they want to submit.
Aditionally, make the program capture at least one signal and use it to display a context menu to the user (imagine a REPL's error prompt).
The program must be 100% resistant to malicious/incorrect input.

Good luck anons.
>>
>>55177105
i think i fixed it


int main{ } (

__asm
__ecx*
_______IDK ASM I MAKE BAD JOKE

sexuallytransmitteddisease::::outC <<>> ""HEYY!!!! IM GAY""" ;;::::

)

>>
>pajeet-posting

This is what happens when you don't put anime in the OP.
>>
>>55177207
Oh, it's the shitposter again.
Don't bother replying to him.
>>
>>55177220
>55177220
There's too many problems to describe, but if you want an exercise that'll show you the problems with C here's a challenge:
Write a platform-agnostic (only standard C libraries. it's ok to use POSIX libs if you really have to) command line program to read a single line of text from users. Text over an arbitrary number N should be cut-off. The text must be echoed back to the user, who must confirm that the text is what they want to submit.
Aditionally, make the program capture at least one signal and use it to display a context menu to the user (imagine a REPL's error prompt).
The program must be 100% resistant to malicious/incorrect input.

Good luck anons.
>>
>>55177210
how do you put your code into that post like that?
>>
>>55177232
Oh, it's the shitposter again.
Don't bother replying to him.
>>
>>55177245
code tags, "
" "
" have you ever used a forum b4?
>>
>>55177220
>Shitposter

No, it's the "I'm not going to reply to the idiots who've clearly never tried to do what I'm describing and spend all day writing fizzbuzz in python" poster.
I'm not here to entertain your pedantic ego-masturbating desires.
>>
>>55177232
There's too many problems to describe, but if you want an exercise that'll show you the problems with C here's a challenge:
Write a platform-agnostic (only standard C libraries. it's ok to use POSIX libs if you really have to) command line program to read a single line of text from users. Text over an arbitrary number N should be cut-off. The text must be echoed back to the user, who must confirm that the text is what they want to submit.
Aditionally, make the program capture at least one signal and use it to display a context menu to the user (imagine a REPL's error prompt).
The program must be 100% resistant to malicious/incorrect input.

Good luck anons.
>>
>>55177245
you need a 4chan gold accoun
t
>>
>>55177232
>>55177271
I don't understand why you're doing this.
>>
>>55177251
not in years

"print("Hello world!")"
>>
>>55177207

>what if fgets()
>doesn't know how to print out a string
>doesn't know how to use even basic conditions
>goes on to pretend that signals are somehow relevant to simple input
>doesn't define the input parameters and what can be considered "malicious input"

gr8 b8 m8
>>
>>55177195

why, because I dont write cpp?
>>
>>55177286
Because he is a shitposter
>>
>>55177207
fgets and fputs, what the fuck are you having problem with?
>>
>>55177298
trying again
<code>print("Hello world!")</code>
>>
File: tfw-memory-leaks.jpg (15 KB, 236x349) Image search: [Google]
tfw-memory-leaks.jpg
15 KB, 236x349
Is there a way I can make Valgrind report not where unreachable blocks were allocated but instead where they were no longer reachable?
>>
>>55177195
C++ > All other languages, it's a fact, bow down.
>>
>>55177322
No, because you correctly answered the hypothetical which was a test of exception safety.

What do you write though, anon?
>>
>>55177347

You're using the wrong tool. Use gdb to figure that out.
>>
>>55177337
print("Hello world!"
>>
>>55177347
If you can't tell by yourself, what makes you think an unfeeling, unknowing machine would know either?
>>
>>55177364
tard
>>
>>55177304
Why do I let myself get baited into replying to shitposters:

>what if fgets()
Where did I imply that? Do you really think I'd be bitching about C IO if I didn't know its most important function to get input?

>doesn't know how to print out a string
I did not imply this and I honestly don't know what it's even supposed to mean. Are you legitimately retarded?

>doesn't know how to use even basic conditions
Take what I said above and paste it here, with emphasis on the question I asked.

>goes on to pretend that signals are somehow relevant to simple input
I did no such thing. I asked you to write a program that, in addition to taking input from the user and verifying it, is capable of catching a signal and using it in a novel way.

>doesn't define the input parameters and what can be considered "malicious input"
What input parameters? I'm asking you to get a single line of text, your mouth-breathing cunt.
The only real point you've raised is that I haven't defined malicious input, which I'll rectify now: Input designed specifically to make your program behave in an unintended way.

In short, kill yourself, and I'm done talking about this because, once again, the retarded script kiddies on /dpt/ just want to talk about anime and drive away interesting posters.
>>
>>55177390
>Why do I let myself get baited into replying to shitposters:

It's not a shitpost. I legitimately don't understand what the problem is. All the basic I/O functions are there in C and entirely portable. All the relevant platforms also have support for POSIX signals.

>Input designed specifically to make your program behave in an unintended way.

Without a specific problem to solve such a definition is worthless, and it's what I was complaining about.

I cannot determine what is malicious input without knowing what the expected input looks like, and believe it or not, pulling that out of my ass is hard.

I will agree that string parsing in C can be an absolute pain to do though, if that's what your problem is. The functions that C provides are somewhat lackluster.
>>
>>55177390
Thanks for the spergout m8, you sure helped drive up the quality you're looking for in this thread
>>
>>55177355
That was true once, but nowadays, rust exists.
>>
File: shifting.png (39 KB, 515x733) Image search: [Google]
shifting.png
39 KB, 515x733
>>
>>55173252
A lax 2-functor from the terminal bicategory to the underlying bicategory.

>>55173260
http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html
>>
>>55177510
C is a shit language

Why does anyone use it in 2016?
>>
>>55176183
2B
>>
>>55177356

Stuff like scala, haskell, C, python and hardware description languages. I don't really like the way exceptions are used to handle problems, I prefer stuff like maybe/either monads etc
>>
>>55177510
Found the Pajeet.
>>
>>55177532
I think it's a beautiful, concise language.
int main(void)
{
int r = 1;
while (r)
{
r <<= 1;
printf("%d\n", r);
}
}
>>
>>55177564
int main(void)
{
int r = 1;
while (r)
{
printf("%d\n", r);
r <<= 1;
}
return 0;
}

ftfy
>>
>>55177564
>>55177583
ftfy
#include <stdio.h>
int main(void)
{
unsigned int r = 1;
while (r)
{
printf("%u\n", r);
r <<= 1;
}
}
>>
>>55177564
c is concise only when you have nothing to write.
>>
>>55177532
For my systems class. I personally never use it for anything outside of it.
>>
>>55177598
ftfy
#include <stdio.h>

int main(void) {
unsigned int r = 1;
while (r) {
printf("%u\n", r);
r <<= 1;
}
return 0;
}
>>
>>55177532
It's shit, but it's also the only sane language out there.
>>
>>55177629
ftfy
#include <stdio.h>

int
main (void)
{
unsigned int r = 1;
while (r)
{
printf ("%u\n", r);
r <<= 1;
}
return 0;
}
>>
File: comfy.png (167 KB, 376x328) Image search: [Google]
comfy.png
167 KB, 376x328
DAILY PROGRAMMING CHALLENGE

Print an integer's binary representation on your machine.
>>
>>55177655
ftfy
#include <stdio.h>

int
main (void)
{ unsigned
int
r =
1 - 0;
while (!!!!!!r) {

printf ( "%"
"u" "\n",
r);
r <<= 1; }

return 0
;


}
>>
>>55177564
How can r ever become zero?
>>
File: SomeoneShouldStopThis.jpg (78 KB, 405x723) Image search: [Google]
SomeoneShouldStopThis.jpg
78 KB, 405x723
>>55177701
>>
>>55177713
Once you shifted away all the bits, there's nothing left and it's suddenly zero.
>>
>>55177701
fixd
#include <stdio.h>

int main () {
unsigned int r = 1;
while (r) printf ("%u\n", r<<=1, r>>1);
}
>>
>>55177658
void
printbin (unsigned int d, unsigned int high)
{

for (; high; high >>= 1)
if (high & d)
putchar ('1');
else
putchar ('0');
}



>>55177701
This is not a fix
>>
>>55177731
That's undefined behavior.
>>
>>55177749
Find me a single system where this wouldn't work correctly.
>>
>>55177749
No it is not.
>>
>>55177756
A C compiler is allowef to optimize it to an infinite loop.
>>55177759
Signed integer overflow is undefined behavior.
>>
File: d.png (7 KB, 145x124) Image search: [Google]
d.png
7 KB, 145x124
>>
>>55177789
You are correct, I thought you quoted one of the improved versions that were posted after.
>>
O's and X's in C++
Trying to make it really concise too and see if I can check for possible wins without making 8 different comparisons (1 for each solution)
>>
>>55177658
void binary(int num)
{
static const int size = sizeof(int) * 8 + 1;
char buf[size];
buf[size] = '\0'; /* null terminate */
int index = 0;
while (num)
{
buf[index++] = (num & 1) ? '1' : '0';
num >>= 1;
}
while (--index >= 0)
printf("%c", buf[index]);
}
>>
>>55177908
Undefined behaviour, not correct output for every input in every system and bad practices in multiple places.
>>
I have an architectural question for an application. Technologies used are python(Django), celery, redis.

It started as a web application, and still is, but now I am scraping files off various API's and processing them into my own system. One of the pages on my site is a page that displays files I've scraped in a gallery.

I have a periodic task using celery which kickstarts the whole process, and starts a celery task for each http url to get.

Now I'm wondering if this scraper shouldn't be it's own module capable of running on any machine. It would scrape the necessary files, keep them in memory, and do a HTTP post to my web page with the scraped data and metadata.

Does this sound retarded? The reason I'm asking is because celery is a distributed task queue. Whenever I pass data to a new task, it goes to a different process, and it doesn't do transfer of raw bytes / binaries. Everything is by default, pickled (serialized) into some format like json or the python pickle. That's how the message queue works.
>>
>>55177926
Aside from returning nothing on 0 and not using CHAR_BIT, what is the issue?
>>
    fn render(&mut self, screen: &[u8; bus::SCREEN_SIZE_BYTES]) ->Result<(), String> {
try!(self.texture.update(None, screen, bus::SCREEN_SIZE_BYTES/bus::SCREEN_HEIGHT).map_err(|e| format!("{:?}", e)));
self.renderer.copy(&self.texture, None, None);
self.renderer.present();
Ok(())
}

Why is this rendering loop so erratic in performance? One frame takes 5ms, the next one takes 20.
>>
>>55178029
int instead of size_t for index
buf[size] = '\0'; <-- causes UB
>>
>>55178078
Why would I use an ull if I know the index can never be that long?
>>
>>55177908
>static
You don't want static here.
>buf[size]
That indexes 1 past the end of the array.
>num >>= 1
Shift operations (and some bitwise operations) are implementation defined on signed integers.
>>
>>55178104
who said anything about unsigned long long? (is this what you mean by ull?)

>Why would I use an ull if I know the index can never be that long?
You don't know that, size should be a size_t as well.
>>
>>55178146
>static
yes i do
>buf[size]
notice how I added + 1 to the size
>>
>>55173239
import random

victory = False
attempts = 1
prompt = "\n\t>: "

print "Please select range."
ri = int(raw_input(prompt))
re = int(raw_input(prompt))

num = random.randrange(ri, re)

while victory == False:
print "What is your guess?"
guess = int(raw_input(prompt))

if guess == num:
print "You Win!"
print "attempts: %d" % attempts
victory == True
elif guess > num:
print "Too High!"
attempts = attempts + 1
print "What is your guess?"
guess = int(raw_input(prompt))
elif guess < num:
print "Too Low!"
attempts = attempts + 1
print "What is your guess?"
guess = int(raw_input(prompt))


This isn't working the way it should. Every other guess it doesn't tell you if it's too high or low. And even after going through every number within the range I couldn't win.
>>
>>55176709
A bhop cheat for CS:GO (suppose it could be CS:S too but probably not).
>>
>>55178187
>yes i do
Why? It adds a lifetime that is completely pointless for this situation.
>notice how I added + 1 to the size
That doesn't mean shit. You still allocated size bytes and index size bytes from the start.
If it was
char buf[size + 1];
, that would be different.
>>
>>55178237
>lifetime
It's not going to change during runtime, why would I want to recalculate it over and over?

Also, you seem to have no idea what you're talking about.
valgrind doesn't give me shit, and if I omitted the + 1, I would get "reading 0 bytes outside of" errors.
>>
>>55177658
Here's my attempt

#include <stdio.h>
#include <limits.h>

/**
* @brief prints the binary representation of an integer
* @note depends on underflow behavior
*/
void print_binary(int n)
{
size_t const size = sizeof n * CHAR_BIT;
unsigned long i = size;
putchar('0');
putchar('b');
while (i <= size) { /* Depends on underflow */
int c = ((n & (1<<i))>>i)+'0';
putchar(c);
--i;
}
}

int main() {
print_binary(5);
puts("");
print_binary(1339);
puts("");
}


It is guaranteed to run on any x86 or ARM machine.
>>
>>55178041
No idea, what library is that tho? glium?
>>
>>55178274
Holy shit, you are a fucking retard.
>>
>>55178274
>recalculate
The compiler would optimise it out with a constant. Now you've gone and allocated space for it.
>Also, you seem to have no idea what you're talking about.
YOU have no idea what you're talking about. Arrays of size n can only be indexed up to n-1.
Literally the next line after your declaration, you index it with n.
>valgrind doesn't give me shit, and if I omitted the + 1, I would get "reading 0 bytes outside of" errors.
Valgrind can't tell if you're incorrectly reading from the stack perfectly.
I'm not saying that you should remove the 1. You obviously need it for the null terminator, but you need to use size - 1 when you index it or something.
>>
>>55178314
sdl2
>>
>>55178274
>It's not going to change during runtime, why would I want to recalculate it over and over?
Assuming no optimization: A mul and add is faster than fetch from memory.
Assuming optimization: It's a constant, same code gen regardless (i.e optimized away completetly).

At worst it leads to slower code, at best it's equal except with extra syntax for no reason.
>>
>>55178357
ty
>>
So, I have a list [(IO Integer, String)], and what I want is to do convert it to [(Interger, String)], aka do the IO while keeping the structure
how do I do that?
>>
>>55178291
Somebody criticize my program pls
>>
>>55178432
Why wouldn't you just use a buffer instead?
>>
>>55178291
>
/* Depends on underflow */

What?

>unsigned long i = size;
Why not size_t?

>int c
You do not need the variable

>depends on underflow behavior
How so?
>>
>>55178474
Not him but it's retarded.
>>
>>55178485
>Why not size_t?
Needs to guarantee 1<<i has higher conversion rank than int (otherwise the right shift might be done on a negative value)
>>
>>55178474
>Why wouldn't you just use a buffer instead?
Why'd I need to store anything?

>>55178485
>Why not size_t?
Yeah, should've been size_t

>You do not need the variable
It looked like crap if I kept it inside:
putchar(((n & (1<<i))>>i)+'0');

I should have c const qualified though.

>What?
>How so?
i will never be greater than size if I only ever decrement it. If the architecture were to have unsigned integers stay at 0 when they're decremented by 1 from 0 the break condition of the loop would never be met.
In fact I believe it may be a valid choice for the compiler to assume it to be an infinite loop - not sure.

Revised version:
#include <stdio.h>
#include <limits.h>

/**
* @brief prints the binary representation of an integer
* @note depends on underflow behavior
*/
void print_binary(int n)
{
size_t const size = sizeof n * CHAR_BIT;
size_t i = size;
putchar('0');
putchar('b');
while (i <= size) { /* Depends on underflow */
int const c = ((n & (1<<i))>>i)+'0';
putchar(c);
--i;
}
}

int main() {
print_binary(5);
puts("");
print_binary(1339);
puts("");
}
>>
>>55178559
unsigned long does not guarantee that

>>55178563
>If the architecture were to have unsigned integers stay at 0
Not allowed by the standard.
>>
>>55178614
>unsigned long does not guarantee that
It does.
>>
>>55178621
Prove it
>>
>>55178559
Good point, though its actually wrong right now.

It should be something like this:

void print_binary(int n)
{
size_t const size = sizeof n * CHAR_BIT;
size_t i = size;
size_t const one = 1;
putchar('0');
putchar('b');
while (i <= size) { /* Depends on underflow */
int const c = ((n & (one<<i))>>i)+'0';
putchar(c);
--i;
}
}


>>55178614
>Not allowed by the standard.
Really? Cool then.
>>
>>55178563
>>Why wouldn't you just use a buffer instead?
>Why'd I need to store anything?
Because your multiple nested bitwise monstrocity is hard to read and even harder to debug.
>>
>>55177658
std::string convert(int dec, std::string acc = "")
{
if (dec == 0)
return acc;
else if (dec % 2 == 0)
acc = "0" + acc;
else
acc = "1" + acc;
return convert(dec / 2, acc);
}

int main()
{
std::cout << convert(666) << std::endl;
return 0;
}


>:^)
>>
>>55176776
>linked list

I just use one of std's many datatypes instead
>>
>>55178627
long has strictly greater rank than int (i.e never equal to, always greater). See 6.3.1

size_t could concievable be backed by a type smaller than int.
>>
>>55178678
convert(-832)
$ ./a.out
1101000000

Wha..
>>
>>55178563
Is there a good reason for not using a do-while loop for this?
>>
>>55178681
Can't write your own, Raj? This is not an exercise in gluing together someone else's code or using smart pointers. This is about testing your ability to think like a programmer. And you have failed miserably. Enjoy writing being a (((((coder))))), pleb.
>>
>>55178677
This is pretty basic.
You should read up on your bit hacks
https://graphics.stanford.edu/~seander/bithacks.html
>>
>>55178720
Why would you use do-while on this?
>>
>>55178736
I can write a linked list, but your post implies C++, so it would dumb to reinvent the wheel for it
>>
>>55177658
Here:

fn print_binary<I: std::fmt::Binary>(int: I) {
println!("{:b}", int);
}
>>
>>55178790
C++ does not have a useful standard linked list.
Only intrusive linked lists are worth using in the few cases where vectors are not.
>>
>>55178843
ctards everyone!
>>
>>55178870
Are you the Javafag who has the kneejerk reaction of calling everyone a ctard? You know they're talking about C++, right?
>>
What the hell is this and why does it print triforces?
void lkjadlkjsa(long long num)
{
long long i = 0;
while (i++ <= CHAR_BIT * sizeof(long long))
printf("%c", (num & i) ? ' ' : '*');
putchar('\n');
}

int main(void)
{
int i;
for (i = 0; i < 100000; i++)
lkjadlkjsa(i);
}
>>
File: Untitled.png (41 KB, 784x756) Image search: [Google]
Untitled.png
41 KB, 784x756
Wrote a program to generate 2 Powerball numbers using a 64-bit Mersenne Twister and output the result if the numbers match. It takes roughly 1 minute per winner.

I have an unhealthy obsession with lottery numbers.
Thread replies: 255
Thread images: 21

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.