/dpt/ daily programming thread

What are you working on, Sup Forums?
old thread

Other urls found in this thread:

youtube.com/watch?v=G1fFCnjThCQ
{}:{}'.format(IP,port)})
llvm.org/docs/CommandGuide/llc.html
news.ycombinator.com/classic
doc.crates.io/guide.html
twitter.com/NSFWRedditGif

First for Hitler

youtube.com/watch?v=G1fFCnjThCQ

Second for decentralized TV

Third for bunnies

Reading a book about preparing for an interview.
I really miss my belier bunny, she was the more affectionate pet I ever had. ;_;

Oh no user, I'm very sorry ;_;

>she was the more affectionate pet I ever had

Did you have sex with it?

;_; she was that same color btw
furfags bls go

What is the most efficient way to check if a proxy is alive using python?
This is what I use to check:
s = requests.Session()
req = s.get("example.com",timeout=15.0,
proxies={'http': '{}:{}'.format(IP,port)})
if "Example Domain" in req.text:
works.append(IP+":"+str(port))
else:
questions.append(IP+":"+str(port))
I am trying to scan IP ranges for them, here are the ports I check:
[80,800,3128,8080,8888,6588,3124,1080]

Suggestions? Doing anything wrong? Socks proxies going to get fucked the way I do it, right?

just imagine how much better things would be if everything was coded in assembly.

Not much better because people suck at assembly?

>people suck at assembly
exactly.
less shitty stuff.
quality of code & programs improve.

stuff = 'CONNECT : GET https:// HTTP/1.1\r\n'.encode('utf-8')
27 a, b = 0, 1
28 l = []
29 while b

Does anybody see a problem with this code for making a WAV file? It looks fine, but SDL_mixer keeps saying "Error reading from datastream".
std::vector retval;
tv_audio_wave(&retval, "RIFF");
tv_audio_wave(&retval, (uint32_t)frame->get_data().size());
tv_audio_wave(&retval, "WAVE");
tv_audio_wave(&retval, "fmt ");
tv_audio_wave(&retval, (uint32_t)16); // length of data section
tv_audio_wave(&retval, (uint16_t)1); // uncompressed PCM
tv_audio_wave(&retval, (uint16_t)1); // channel count
tv_audio_wave(&retval, (uint32_t)frame->get_sampling_freq());
tv_audio_wave(&retval, (uint32_t)frame->get_sampling_freq()*1*frame->get_bit_depth()/8);
tv_audio_wave(&retval, (uint16_t)(1*frame->get_bit_depth()/8)); // block aligh
tv_audio_wave(&retval, (uint16_t)frame->get_bit_depth());
tv_audio_wave(&retval, "data");
std::vector frame_data =
frame->get_data();
tv_audio_wave(&retval, (uint32_t)frame_data.size());
retval.insert(
retval.end(),
frame_data.begin(),
frame_data.end());
return retval;


I'll go over it again

tv_audio_wave is defined here
static void tv_audio_wave(std::vector *retval, const char *data){
retval->insert(retval->end(), data, data+strlen(data));
}

static void tv_audio_wave(std::vector *retval, uint32_t data){
// reverse byte order, but little endian bits
std::vector data_tmp(&data, &data+sizeof(data));
retval->insert(retval->end(), data_tmp.begin(), data_tmp.end());
}

static void tv_audio_wave(std::vector *retval, uint16_t data){
std::vector data_tmp(&data, &data+sizeof(data));
retval->insert(retval->end(), data_tmp.begin(), data_tmp.end());
}


I know it is pretty ugly and redundant, but i'm going to clean that up soon

It's written in C++.

Someone convince me to write my compiler

You know what, you're right.

actually I don't think that'd necessarily be better.

but just imagine if all programs were magically made as performant as possible. less wasted cpu cycles. less wasted energy. maybe we wouldn't need as much GHz and RAM anymore.

Why would you turn PCM into WAV to load with SDL_mixer when you can send PCM directly to SDL_audio?

Write it, faggot.

Is there a way to code directly in LLVM bytecode?

anyone know why on my proxy server i can get the response from the browser but then when i close the socket, get the data, and try to connect to the website through a newly opened socket i get an error.

pic is related

the first string is the binary response, then i strip the url which is in this case water.usgs.gov:443

as you can see the code in the thing but it won't connect?

SDL_Mixer code was already layed down, and it code is structured to import WAV files already. Might change that later though.

Hell, I would be surprised if there wasn't a way to use PCM directly with SDL_mixer.

llvm.org/docs/CommandGuide/llc.html

I can't seem to find a way to do that. You can write directly to Mix_Chunk, but using WAV formatting looks more convenient

>using WAV formatting looks more convenient
Clearly not, though.

*looked
I hope I can make it work

I can't believe Rust still doesn't fucking have HKTs.

LLVM IR is the future.
@.str = private constant [13 x i8] c"Hello World!\00", align 1 ;

define i32 @main() ssp {
entry:
%retval = alloca i32
%0 = alloca i32
%"alloca point" = bitcast i32 0 to i32
%1 = call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %0, align 4
%2 = load i32* %0, align 4
store i32 %2, i32* %retval, align 4
br label %return
return:
%retval1 = load i32* %retval
ret i32 %retval1
}

declare i32 @puts(i8*)

The problem is in frame_data, not in the loader itself.

I take that back, calling QuickLoad_RAW works, but the RWops and LoadWAV didn't, weird

Got it to work, but it sounds terrible.

how can i disable auto saving in visual studio?

Youre the reason 90% of other programming languages are shit

Nice, rite?
import requests
useragent = {'User-Agent': "Mozilla/5.0 (Linux; U; Android 4.0.3; de-ch; HTC Sensation Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/5334.30."}

google = requests.get("google.com/search?q="ICACTaskforce.org" filetype:pdf&num=100&biw=1920&bih=978&filter=0", headers=useragent)
##print(google.text)
lol = str(google.text).split("href=\"")
lol = [x.split("\" onmousedown=\"") for x in lol]
for x in lol:
if len(x) == 2:
## print(x[0])
if "pdf" in x[0] and "google.com" not in x[0]:
print(x[0])
response = requests.get(x[0])
with open(str(x[0].split("/")[-1]).split("?")[0], 'wb') as f:
f.write(response.content)

So, I'm reading a book on C Programming, got to typedef, and I found out this.

Why the fuck did Microsoft do this?
Like... I never really knew what those were, and I just edited them as I needed, but what the fuck? Why did they rename unsigned long to DWORD. It doesn't make sense
(also, since most of these are like... at most, like, the number 3 or 5 or something, why didn't they use short?)

I remember hearing that Windows was in the UTF-16 train, so double that word length would be 32, which might have been the min length of unsigned long at the time

So, it opens any non-google results from a Google search and saves them to a text file?

Sorry, I've kinda only used Python for a Discord Bot so far, so I may have missed something in there.
Mine currently returns the search result for an animelyrics page:
matches = re.findall(r'href=\"http:\/\/www.animelyrics.com\/[^\"]+\/[^\"]+\"',
str(urllib.request.urlopen("bing.com/search?q=anime lyrics " +
re.sub(r'[ ]', "+",
re.sub(r'[\$][\.](animeLyrics|al)', "", message.content)).strip()).read()))

count = 0
if len(matches) > 0:
for match in matches:
if not re.search(r'\.jis', match):
count += 1
match = re.sub(r'(href=\"|\")', '', match)
await client.send_message(message.channel,
match)
if count == 0:
await client.send_message(message.channel,
"I'm sorry! I couldn't find that song! :cry:")
else:
await client.send_message(message.channel,
"Those are all the matches I found (" + str(count) + ")")

Wanted to get it to return the lyrics, themselves, but different pages were formatted differently, so I wasn't sure how to go about it.

hmmm
But my question is why did they rename it? Just to fuck with people trying to edit their preferences for system functionality, so people don't actually know what it is?

It saves the PDFs but I guess it could be modified to do whatever you want with the links.

Ah, ok.

Yeah, that makes sense now.
I didn't really use Python for any kind of file handling yet.
Was thinking of making a help file and getting it to read that, b/c Discord only has a max of 2K characters per message, so it'll eventually exceed that.

little curious about the "split" function. Is that equivalent to PHP's explode function? Converts a string into an array on a delimiter?

They renamed it for the following reason.
Unsigned long is type defined by C and C++ standards.
It is defined as something along the lines of "whatever the fuck platform/compiler decides it to be".
Unsigned long can be 32 bits on some platforms and 16 bits on others.
Microsoft wanted a type that is strictly defined to be 32 bit unsigned integer.
On x86 Windows, DWORD is aliased to unsigned long. On some other platform where unsigned long is 16 bit, DWORD might be aliased to unsigned long long, or whatever else.
Hope this helps.

Hmmm, ok.
I guess that makes some sense.

Also, I never knew there was an "unsigned long long". Interesting

Just looked it up. Nvm.

Interesting.

>little curious about the "split" function. Is that equivalent to PHP's explode function? Converts a string into an array on a delimiter?
Yeah, I think so.
If you split "some;thing" it would return ["some","thing"]

Ok, cool. That could be helpful for my bot actually

I don't understand are you implying I should watch more anime?

It's still 32 bits on 64-bit Windows.

Please (you) me.

#include
#define FAGGOT "(You)"

int main(int argc, char** argv){
printf("Here's your %s\n", FAGGOT);
return 0;
}

T-thanks. Btw, why not a const string instead of that macro?.

That coulda worked, too.
I just figured it's more in your face to straight-up #define you to be a faggot.

Wow, rude.

GENTLEMEN!

Let us not sully this board with such foul language.

Precisely.

r u d e

>Not using string literal concatenation
#include
#define FAGGOT "(You)"

int main(void){
puts("Here's your "FAGGOT);
}

Input required

Hey /dpt/, book I'm reading says I can do this.
But, when I run it, it crashes when it tries to reassign the variable.
int main(int argc, char** argv){
union measure{
float cm;
int inch;
};

union measure you;
union measure paul;

paul.inch = 70;
printf("Paul is %d inches tall\n", paul);
printf("How tall are you in inches? ");
scanf("%d", you.inch);
you.cm = (CENT_PER_INCH * (float)you.inch);
paul.cm = (CENT_PER_INCH * (float)paul.inch);
//paul.cm = 2.00; //Tried to assign an immediate variable... didn't work either

printf("You are %.1f centimeters tall\n", you.cm);
printf("Paul is %.1f centimeters tall\n", paul.cm);
return 0;
}

Am I doing something wrong? Or was the book wrong in saying you can reassign unions?

>scanf("%d", you.inch);
You forgot your '&'.
scanf("%d", &you.inch);

Your example is a pretty pointless use of a union though.

oh fuck, I'm an idiot!
Thanks.
I didn't even see that.

Works now.

>Your example is a pretty pointless use of a union though.
It's just a thing my book was showing me.
I never even learned about unions in the classes I took; didn't even know it existed until this.

They have a better example, though, where there were 3 people, and each has a different hobby struct in the union, with different things like music, sports, or TV.

It's all just practice, though. I doubt they expect us to use the examples in real code, just showing us how it works.

>I never even learned about unions in the classes I took; didn't even know it existed until this.
Unions are a pretty niche thing, but they can sometimes be useful.
The two main uses for a union are probably tagged-unions (a value that can be one of multiple types at runtime) or type punning (interpreting a value as a different type directly, without conversion).
struct my_tagged_union {
int type;
union {
int i;
float f;
char *s;
}; // Note: Having no name here is a C11 feature
};
I would give a type-punning example, but I've yet to come up with a valid reason to use it that isn't hacky as fuck.

Hmm, interesting

How would you refer to that union, though, without a name?

As if it was a member of the parent struct.
struct my_tagged_union value;

value.i = 10;

oh that's pretty cool.

in Haskell you use tagged unions all of the time

I'm pretty sure they added that feature to specifically make tagged unions nicer to use.

Lots of languages used tagged unions all of the time. In C, it's just not as common.

That's because C programmers can't program

>should my library return some kind of meaningful error?
>naa, int

>should i use an enum?
>nope, #define is perfectly good

That's because C doesn't really have a continent way to "unbox" those errors.
It's really just a sign from when C was designed.

What does that have to do with anything?
C enums are weakly typed, so there isn't any actual practical difference.
I do prefer to use enums myself, though.

>continent
convenient*
I guess I picked the wrong correction.

I asked on SQT but got no answer:

What's the "classic" page on HN? IT doesn't always show on the navbar either news.ycombinator.com/classic

Which C-like should I learn

I understand imperative programming fairly well but I still haven't learned a 'proper' language (I can fluently code in Lua, JS, Py, Pascal and VB)

C

C

Rust.

Absolutely disgusting.

How do you compile a Rust project?

Why didn't they just use uint32_t?

I presume you would use the Rust compiler.

The important question is why you would compile a Rust project, truth to be told there are no useful projects written in Rust.

cargo build

Describes the very fundamental way computers operate

Some people say that you don't even deserve to call yourself a programmer if you don't understand how compilers work

didn't exist back then, but that doesn't make what they did any less retarded.

Someone's making an operating system

Someone's making an OS in any language

Be sure to congratulate them on another useless project written in Rust.

I presume you can bind practically anything to OGL these days and I want to write a like a backend engine in some low level language and then bind it through to LuaJit

What they should have done was make their own fixed width types (like Linux did), and call them by an appropriate name like, u32 or u64.

Anywhere I can read the process step by step specifically? Google is failing me

CHAR, WORD, DWORD and QWORD are for some given architecture known fixed sizes in computer science. The nomenclature predates both W32, Windows and Microsoft by a couple of decades.

It's exactly equivalent to naming them u8, u16 and u32.

First of all that can be done with a single line of curl.
Second why are you running the script as root
Third don't overcomplicate easy things.

doc.crates.io/guide.html

But far less descriptive.

Alright, thanks!

>CHAR, WORD, DWORD and QWORD
"word" is not synonymous with 16 bits. What they're done is tie it to x86 even more.

I have heard the term "word" refer both to 16 bits and 32 bits depending on architecture. On Intel, a word is 16 bits. On ARM and MIPS, a word is 32 bits. In using terms like WORD, you are tying the size of the type to a specific architecture. More descriptive would be to explicitly state the number of bits in the type. A name like u32 is simple. It's an unsigned 32-bit integer, no matter what platform it's on. There is no possibility for confusion when porting the OS to a different architecture.

>his name is ruby
>he only talks about low level stuff

>his
>he

>XD