/dpt/ - Daily Programming Thread

old thread: What are you working on, Jow Forums?

Attached: astolfo the lad2.jpg (682x928, 600K)

Other urls found in this thread:

strawpoll.me/16604780
stackoverflow.com/questions/27568254/how-to-extract-1-screenshot-for-a-video-with-ffmpeg-at-a-given-time
youtube.com/watch?v=wbRx18VZlYA
javascript30.com/
twitter.com/SFWRedditImages

How do I make this better?
def prime_factors(n):
factors = []
if n == 1: return factors
if is_prime(n): return [n]
found_last_factor = False
while not found_last_factor:
for f in range(2, int(n**0.5+1)):
if n % f == 0:
while n % f == 0:
factors.append(f)
n /= f
if n == 1 or is_prime(n):
if n != 1: factors.append(int(n))
found_last_factor = True
break
return factors

>if you don't need them, don't use them?
but now we're deviating from the original point, which is the whole using/not using OO in the first place. I could use C++ that way if I wanted to, if I ever felt like I needed C++ constructs in my projects

Where do I freelance? Upwork rejected my application despite me having a programming diploma.

Attached: they_glow_in_the_dark.jpg (474x400, 37K)

nice repeating digits user-OP

Attached: 128x128.png (128x128, 2K)

>Upwork rejected my application
how the fuck does this happen?

Just sent out a couple job applications, hoping for the best.

Also, currently learning Scheme:

(define make-list-of-one
(lambda (item)
(cons item '())))

(define make-list-of-two
(lambda (item1 item2)
(cons item1 (make-list-of-one item2))))

(define regroup
(lambda (ls) ;;; input = list of four elements
(make-list-of-two (first-half ls) (second-half ls))))

(define first-half
(lambda (ls)
(make-list-of-two (car ls) (cadr ls))))

(define second-half
(lambda (ls)
(make-list-of-two (caddr ls) (cadddr ls))))

I haven't used Java in about a year and I need to get good at it again for a project that's starting in a week. What's a good book to refresh me on Java?

Shitting on Streets 4th edition

add fucking enters and space between new lines. just the indenting makes it a pain to read. I have no clue what language you are using(probaly python or something) but this is hard to read. why are you using keywords like not, or, in you might as well do ! || < thats way more clear.

def prime_factors(n):

factors = []

if n == 1: return factors
if is_prime(n): return [n]

found_last_factor = False

while not found_last_factor:

for f in range(2, int(n**0.5+1)):

if n % f == 0:

while n % f == 0:
factors.append(f)
n /= f

if n == 1 or is_prime(n):
if n != 1: factors.append(int(n))
found_last_factor = True
break

return factors

to me this is way more easy to read. i cant help you with what you are doing cause i dont no what you mean with prime factors exactly (do you mean numbers like 1, 3, 7, 13, 17, etc).

>symbols clearer than words
>doesn't know what prime factors is
>thinks 1 is a prime factor
these are the idiots criticizing languages

kill yourself this is so fucking disgusting jesus christ

Attached: yamero.jpg (302x326, 7K)

>>symbols clearer than words
yes

ok, what symbol would be better than using return, break, while, for?

in the context of the first answer, obviously.

In the context of the first example, I could maybe with not being easier to read as !, but or is about as easy to read either way, and you're 'in' as < is absolutely not clear and not even valid in most languages that offer the 2

Thanks for adding a bunch of white space to my code user. I appreciate it.

Is there any difference between
const ClassName & objectName
vs
ClassName & const objectName
in the use of constant reference parameters? I had one of my instructors tell me it's incorrect, but all the examples I've seen reading out of my textbooks and cursory googling show that you can do this.

JavaScript rocks!

Attached: js-rocks.png (1000x494, 369K)

unironically this

Yes.
const ClassName &objectName; and ClassName const &objectName; have the same meaning. The referred-to object is const.
ClassName &const objectName; means the reference is const, not the referred-to object.
But since references can't be mutated anyway, it doesn't mean anything. It's mainly just there for consistency, since you can make pointers const the same way.
ClassName *const objectName; means the pointer is const, not the pointed-to object.

I want to like JS but I can't handle the cancerous number of frameworks and tools that people make for it. Its confusing as fuck and I don't want to deal with it.

arent const refs forbidden by the standard?

Then don't. We have to use several JS libs at work for convenience, but my webassembly-based website itself uses raw JS, not even jQuery where it would make sense. The code is so much sexier than what I'm used to at work

Hmm, it seems you're right. Mea culpa.

Yeah, is a moron. X const& is legal, X&const is not.

That was pseudocode, per se. Once I figure out how to write the interpreter, the global tree and functions that act on the global tree will be available as lisp symbols/commands. I have no idea how to write the interpreter atm, but it'll be a learning experience.
Probably anyways.

I'm getting the feeling the company I've been working with is slowly going under. Project management got really bad this year and after the last product launch nobody really seems to be around half the time to sort problems out, of which there are many since it was basically rushed out the door.

I don't know whether I should just find a replacement quickly or just take a break from it all for a few weeks.

Attached: 1355136992305.jpg (768x900, 92K)

I'm currently getting back into C++ and working on some meta heuristics stuff. I've got an environment class containing vectors of objects that represent the constraints and a class representing possible solutions that is basicly a vector of different objects with the assigned values and references to the objects containing the constraints.
at the moment I'm using shared_ptrs to the objects with the constraints in the environment and in the solutions and shit works, but considering the concept of ownership it doesn't feel right. the environment will live during the whole run of the program, so I don't need reference counting.
I think the environment class owns the constraints objects, so it should be unique_ptrs there. what to use in the solutions? regular references? weak_ptr? raw pointers?

You just use raw references or raw pointers, that's right.

i dont know great english so excuse me if i got something wrong. but for me characters like || && ! are easier to spot and get then writing or and not. as they fall away agains other characters.

are you using vectors of objects or pointers for the constraints?
what I'd do is keep a vector of objects, and store raw pointers in the solutions that you will fill with the addresses of the objects
let the vector take care of memory management

def prime_factors(n):
factors = []
p = 3

while not n & 1:
factors.append(2)
n >>= 1

if is_prime(n):
factors.append(n)
return factors

while not n == 1:
d, m = divmod(n, p)

if m:
p += 2
else:
n = d
factors.append(p)

if is_prime(n):
factors.append(n)
break

return factors

But I don't see the point of is_prime.

well in my opinion this will save you a headache if you ever read this back.

What's the story behind this image.

could you tell me why?

my dick

I started out with vectors of objects, but somehow I fucked that up. either resizing one vector also affected other vectors or I actually made a copy somewhere and didn't realize. changed to vector of pointers because of that.
thanks for your input

Started my first job last week and in the next few days I'll be given a sit down with a long time engineer (+15 years) in the firm I'm working at.
Any advice for what type of questions I should ask him about the existing code to help me be able to work on it? The code occupies a large engine with fairly deeply nested data structures
I'm thinking I'll be asking him what design patterns specifically are employed and what would be the top level access procedures of datastructures if I were to be adding or bug fixing part of the system.
I suppose I could also ask which parts of the code base will be fairly solid and not need any changes or attention and which parts will be based to study in detail.

But that's really all the depth I could think of in questions. I really can't think of anything else I could ask him to tell me about even though he knows the whole thing in and out

>cause i dont no what you mean with prime factors exactly
The absolute state of Jow Forums

good luck in your job hunt.

or just stfu and listen to what the guy has to say

ask him what girly socks are best for programming

Lisp is the most powerful programming language.

Trust me I'd be happy to do that.
I just don't want to be sitting there blank faced with him not having a clue what I want to know

Their response said something along the lines of "We already have too many freelancers with a similar skillset.".

an actual engineer of 15 years will most likely not understand any of that abstract shit and just think you are dumb millennial

ask if there exists any documentation or specifications and where to find it. also which people to best ask about which parts of the system in case you need something.

this

text editor poll continues
strawpoll.me/16604780

>VS Code 2nd place
mah fellow negroids

I have a request. I don't mind paying, assuming it's 50 bucks or less.

I've got a folder with screenshots, and there's a timestamp in the filename (HH:MM:SS.MS). I still have the original video, and I'm wondering if it's possible to make a script to automatically re-capture those screenshots with mpv and place the new screenshots in another folder or whatever. Just fyi, I'm on Windows.

Is this feasible?

Attached: 1536259261550.jpg (1920x1080, 1.71M)

Right so use grounded language.
Let's say I'm working with customer data. I see already where in the system its stored. What Id ask is where is the appropriate place to access and what's the proper process of altering it.

I have access to documentation but its mostly really bad and the company has no interior API listed which sucks. I can ask him anyway because there could be a lot of stuff I'm missing in it

Why not just copy the original screenshots to a new folder

auto hot key nigga

you could probably do this yourself.
pass the time into mpv using the --start switch.
since it's a screenshot, --frames=1.
extracting the time from the filename won't be hard as long as it's consistent.

stackoverflow.com/questions/27568254/how-to-extract-1-screenshot-for-a-video-with-ffmpeg-at-a-given-time

I know but I don't want to use ffmpeg, because I want the screenshots to be taken with my settings on mpv.

I want to replace my low quality screenshots with better screenshots, because I got a new monitor, and there are artifacts etc on the old screenshots because the default settings on mpv aren't good.

I'm actually a brainlet

How? I don't think auto hotkey can read the timer on mpv and take a screenshot at the exact same frame

honestly a pretty good set of Qs

If he's working on anything in particular I'd ask about that -- diving deep into how it works (ask followups) to get a good example-driven understanding of how someone interacts with the codebase. people love talking about what they work on directly, which is good for the networking opportunity you should also see this encounter as

what is a project i can do as a beginner python programmer taking intro to programming at uni?

I think I can do that, give me some time

Write a script to get me a girlfriend

write a script to transform my girlfriend into a 2D waifu

neural network

Attached: 1525869252115.png (1920x1080, 549K)

Oh nice, here's a screenshot of a folder with old screenshots. The filenames are a bit different because Window's filesystem can't use ":" in the filename. I've also noticed that mpv uses the programming language Lua for scripts, but I don't think Lua would work with this idea, or would it? I still have the original video, so the timestamp should lead to the exact frame in the screenshot... unless something unknown could interfere with it.

00_01_16.910
HH:MM:SS.milliseconds

Attached: 1533764398778.jpg (1072x839, 245K)

What’s a not-too-complicated but not-trivially-easy program I can make as an exercise to learn C++ multithreading?

Attached: A0461BB9-EE46-470E-918A-C882829E13D5.jpg (281x500, 122K)

chip 8 emulator

Determine a numbers prime facorization, using threads to speed it up.

Finding the shortest circuit of nodes in a network

a game where you bet on which thread will win the data race

Does Google's AI actually learn anything from this or is it just wasting my time?

Attached: dumb ai.png (400x580, 270K)

Yes

all three

Attached: 1532896925124.png (524x479, 365K)

youtube.com/watch?v=wbRx18VZlYA

at 22 minutes starts the good part

What are some fun JavaScript project that ROCK!?

Attached: 1539456738562.jpg (750x750, 72K)

BUMP

javascript30.com/

It probably got some useful labelled data in the first month but by now its probably just generating trash data.

GUYS I DID IT, I FINALLY MADE A FIZZBUZZ IN ASSEMBLY.

Imagine a language where multithreading is just considered a quirk of the hardware. You just write the things to do and the compiler makes it run in parallel, and IO is automatically async.

In Java, how do I separate the transparency and the RGB out of a 32-bit ARGB value?

>Java has colours in its standard library
wut

probably a phoneshit

>tfw too dumb to learn programming
Damn

Good.

nigger u dumb as FUCK! haha LOOK AT THIS NIGGER AND LAUGH!!

Attached: 6c7.jpg (480x472, 28K)

int argbValue = 0xff0000ff;
int alphaValue = argbValue >> 24; // shift off rgb bits
int rgbValue = rgb & 0xffffff; // bitmask of rightmost 24 bits

Has anyone ever programmed on a "Make and Touch" computer? What is the sensation like?

Cool boi

Http://makemusiconline.net:8080 It's supposed to be a website where people can collaboratively make music and be happy

Attached: 20180929_105553.jpg (4032x3024, 3.49M)

Currently I am working on some dope lofi hip hop beats based on Frere jacques

What are some good libraries for detecting toxic masculinity and trumptard/incel-bigotry?

paste from here
>

Does anyone can explain per line this short of code do?

int main(int argc, char**argv)
{
char payload[120]={0};
int offset = 104;

memset(payload,0x90,sizeof(payload));
memcpy(payload+30,shellcode,strlen(shellcode));
*(long*)&payload[offset-4]=0x41414141;
*(long*)&payload[offset]=0xdeadbeef;

One user already answer, eventhough it isn't complete answer. meanwhile the thread has been archived. I'll ask again here.

some of my another question on previous user answer.

> // memset overwites a spot of in memory
> // here the spot where the 'payload' char array is saved
> // gets overwritten with '0x90', the NOP code
> memset(payload,0x90,sizeof(payload));

so, the payload will be overwritten with the "NOP" 120 byte? is that correct?

> // shellcode isn't defined so this doesn't do anything
> memcpy(payload+30,shellcode,strlen(shellcode));

actually it's defined, but I delete it.

Then again,
>memcpy(payload+30) what this actually do?

copy the "NOP" 120 byte + 30 byte? is that correct?


thank you.

Keep in mind that I don't actually have any idea what the API looks like so that might not be correct. I'm assuming it's a 32-bit int with alpha, red, green, and blue each taking up 8 bits, in that order from left to right.

In any case, you should learn bitwise operators.

Is Elixir + Phoenix as gosu as they say or is it just a meme?

Attached: aerodynamics.png (1434x930, 1.88M)

mixed bag
t. learning them both right now

how do I cheat on my hackerrank test, if I pass it I get a phone interview

Attached: 1536615443208.jpg (1280x1509, 761K)

>cheat on hackerrank
>get interview
>bomb
>get blacklisted as a brainlet
gee what a great idea