/dpt/ Daily Programming Thread

This is /dpt/, the best subreddit of Jow Forums

In this thread:
r/programming
r/compsci
r/ReverseEngineering
r/softwaredevelopment

/!\ ** Read this before asking questions ** /!\

mattgemmell.com/what-have-you-tried/
catb.org/~esr/faqs/smart-questions.html


What are you working on?

Attached: dptf.png (779x465, 345K)

Other urls found in this thread:

youtube.com/watch?v=v1COuU2vU_w
eel.is/c draft/basic.lval#11.8
elixir.bootlin.com/linux/v4.16.7/source/drivers/input/evdev.c#L537
elixir.bootlin.com/linux/latest/source/Documentation/input/uinput.rst#L34
en.cppreference.com/w/cpp/string/byte/memcpy
lessonsofhn.com/
developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html
geekfeminism.org/about/code-of-conduct/
youtube.com/watch?v=s087Ca9JnYw
twitter.com/NSFWRedditVideo

Asking again:

Is there a Linux equivalent of "injecting" unicode characters as keyboard input, like Windows's SendInput? I want to write a program to auto-type some text without having to manually press and release individual keys with a keyboard device through uinput (which also doesn't really allow non-ascii characters).

Attached: 1498761058644.jpg (314x267, 24K)

Lisp is the most powerful programming language.

Q: Do these functions contain UB?

template
auto to_bytes(const T &t)
{
static_assert(std::is_trivial_v);
std::array s;
auto p = reinterpret_cast(&t);
for (auto &e : s) {
e = *p++;
}
return s;
}

template
auto from_bytes(const std::array &s)
{
static_assert(std::is_trivial_v);
T t;
auto p = reinterpret_cast(&t);
for (auto &e : s) {
*p++ = e;
}
return t;
}

unconditional branch?

rewrite this code in Java then i'll tell ya.
seriously reading such a piece of code in 2018 is nothing more than masochism

you can send input events by writing to /dev/input/... files

#include

int main(){
std::string getuserinput;
std::cout

No seriously? Gonna try that.

Probably either:
1. There is a way around the keyboard input, or
2. Run a vm
Not too experienced here, just spit ballin

undefined behavior
youtube.com/watch?v=v1COuU2vU_w

i don't ever use using namespace std; because putting std:: before all standard library functions makes me feel like a hacker

Haha, yeah, same.
It's just a perk for me though, I don't use namespace STD because it's generally a bad practice.
But I love the perk of feeling like an epic hacker.

How could I check for a certain condition to run in Java using ints? Say I want to check if a number is divisible by either 400, or divisible by 4 BUT NOT 100? I know I can't use the $$ || signs as they are for booleans, but I'm not sure what to write out. If I do something, say
(if year / 4 || year / 400)
that shit won't fly, but how can I word it so it DOES fly?

Accessing a stored value through a char or unsigned char pointer is an exception to the strict aliasing rule. Thus your functions do not contain UB. The other way around is problematic.

However, use memcpy instead of copying individual bytes.

That is generally considered shit indeed. You aren't saving that to disk or sending down the tubes are you? Why aren't you using a proper serializer?

For reference:
eel.is/c draft/basic.lval#11.8

i am looking at the kernel code, evdev file has the write procedure implemented

elixir.bootlin.com/linux/v4.16.7/source/drivers/input/evdev.c#L537

the procedure calls input_inject_event to inject an invent into the event queue.

using the command xinput, you can see which file is bound to which device

then write an event to the corresponding file (eg: /dev/input/event10)

the event data structure

struct input_event {
#if (__BITS_PER_LONG != 32 || !defined(__USE_TIME_BITS64)) && !defined(__KERNEL)
struct timeval time;
#define input_event_sec time.tv_sec
#define input_event_usec time.tv_usec
#else
__kernel_ulong_t __sec;
__kernel_ulong_t __usec;
#define input_event_sec __sec
#define input_event_usec __usec
#endif
__u16 type;
__u16 code;
__s32 value;
};

xd

xd


niggurz xd


i are haxor

elixir.bootlin.com/linux/latest/source/Documentation/input/uinput.rst#L34

yeah, makes for smaller code as well:

template
auto to_bytes(const T &t)
{
static_assert(std::is_trivial_v);
std::array s;
std::memcpy(s.data(), &t, sizeof(T));
return s;
}

template
auto from_bytes(const std::array &s)
{
static_assert(std::is_trivial_v);
T t;
std::memcpy(&t, s.data(), sizeof(T));
return t;
}


I just wasn't sure if memcpy would interpret the data as unsigned char, but it seems it does:
en.cppreference.com/w/cpp/string/byte/memcpy

memcpy is a c function. it interprets the data as void*.

use 2 functions - one to check if it's divisible by 4, the other for the 400 one

if(checkIf4() || checkIf400() )

memcpy is explicitly the standard-sanctioned way to avoid strict aliasing issues and thus UB issues. From your link:
>Where strict aliasing prohibits examining the same memory as values of two different types, std::memcpy may be used to convert the values.

lessonsofhn.com/

"
My latest hobby is to search lessons shared by Hacker News users in their comments. You'll be amazed how many hidden gems are there if you just search by keywords like "a lesson I learned...".
"

Is hackernews the greatest programming community?

>std::cout

So write the functions, and in those functions have them return true or false depending on if they're divisible or not. If they return true, then use them to write the initial method I wanted to use?

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?


value = 3
found = False
prime_list = [1, 2]
while not found:
print(prime_list)
for val in prime_list:
if value % val == 0:
value += 2
break
prime_list.append(value)

else:
print(prime_list)
prime_list.append(value)
value += 2
finresult = len(prime_list)
if finresult == 10001:
found = True

print(prime_list[-1])
raw_input()
how much of a retard am I? I cant figure out why
my code doesn't execute as intended. It gets stuck in an infinite loop and just prints prime list "[1, 2]" infinitely.

>absolutely straight to an email list
no thanks. stop trying to "hustle" like a silicon valley fag.

value = 3
found = False
prime_list = [1, 2]
while not found:
print(prime_list)
for val in prime_list:
if value % val == 0:
value += 2
break
prime_list.append(value)

else:
print(prime_list)
prime_list.append(value)
value += 2
finresult = len(prime_list)
if finresult == 10001:
found = True

print(prime_list[-1])

forgive me not putting it in code blocks, im pretty tired and I have a headache.

Attached: 1471388428452.png (1263x675, 191K)

value = 3
found = False
prime_list = [1, 2]
while not found:
print(prime_list)
for val in prime_list:
if value % val == 0:
value += 2
break
prime_list.append(value)

else:
print(prime_list)
prime_list.append(value)
value += 2
finresult = len(prime_list)
if finresult == 10001:
found = True

print(prime_list[-1])
raw_input()

and now I'm forgetting to preserve whitespace by copying the actual code I wrote instead of copying my post above.
Gonna go hide in shame.

Attached: 1459001882819.gif (270x263, 3.91M)

>hackernews
That reminds me, I still haven't read last week's n-gate.

anybody know some good resources for learning Ada? I'm bored and it seems interesting enough to mess around with for a bit.

t. haskeller

if by "greatest" you mean, most cucked echo chamber full of onions, then yes, it is.

Otherwise, even r/programming has a wider variety of content and viewpoints than that cargo culty sjw pajeet shithole.

Why the fuck do people add CoCs to their projects?

IS it possible to use a list compreshension instead of a normal for loop?

PyQt5
combo = QComboBox(self)

lst = [
"ASD","GHJ","DFG","XDC","HHH","OPH"
]

for i in lst:
combo.addItem(i)

Are there any good books or websites that provide a decent introduction to desktop Objective-C development for people who already know C?
Everything I've found is boring the fuck out of me.

nvm fixed
i used
combo.addItems(lst)

because those people don't have cocks.

Why are you learning Objective-C?

You didn't include string, this will not compile.

Look where you placed break
it never reaches .append

I'm looking into building some native chat clients for OS X 10.4 since the web clients are pretty unbearable even on nicer G5s. It seems like it can be done, but I don't have much experience developing graphical applications and figured it was a good excuse to get some introduction to it.

IF I LAY HERE
IF I JUST LAY HERE
WOULD YOU LIE WITH ME
AND JUST FORGET THE WORLD?
#include

auto
main() -> int
{
std::string buffer;
std::cout
buffer,
buffer == "Okay" ? "Good, glad you understand."
: "I am a simple script and I understand one phrase, "
"please try again.")

Attached: 1519337863831.gif (340x340, 148K)

>not std::endl
dropped

You fucking moron, compile it right now.
I used "std::string" instead of "#include".
It will compile. I just did, faggot.

You can also redirect input from a file.
command < input.txt
where the file has all the inputs

What's the point of this reformatting.
It worked just as well the way I had it.
Some with the gay supremacy.

Terminals flush on '\n' regardless

FORGET WHAT WE'RE TOLD
BEFORE WE GET TOO OLD
SHOW ME A GARDEN
THAT'S BURSTING INTO LIFE

>being this much of a supremacist
Get up.
Grab your stuff.
Get out.

std::forgot to #include an std::akari

Attached: 1518949762366.jpg (467x531, 48K)

>Terminals flush on '\n'
mine doesn't

Attached: index.jpg (195x259, 8K)

Nice!
What does it hack user? XD

the brian of de closest niggur XD
into the craynium

Some are leftists. I avoid all "with CoC" projects.

It's the rise of community-based programming. Rather than having open source projects that anyone can contribute to and around which communities can arise, you've got the establishment of communities as part of the project itself.

Like Jow Forums?

This is really bad user.
1: 1 isn't prime
2: Unnecessary and unreachable append after break
3: value % 1 always equals 0
4: The else statement is evaluated whenever value % val != 0 for ANY val in primes_list, not when value % val != 0 for all.

Looks like std::cin's `>>` isn't overloaded for std::optional yet. C++17 btfo

Attached: DeepinScreenshot_select-area_20180507093910.png (613x770, 87K)

undecidable

>yet
do it yourself

Does anyone have the pastebin w the custom css to block all of Hiroshimoots tracking and ad bullshit? Phone was just bricked and I had it saved there

Project Euler #15 was tricky, I had to research algorithms to try and struggled for a bit. But the implementation isn't complicated at the end.
Anyone else finished it?

let paths=function(dimension){
let arr=new Array(dimension);
for(i=0;i

Yeah, I have a bunch of them done in J
PE_15 =: dyad define NB. Number of paths through an x by y grid
x ! x + y
)

(Calculates (x+y) Choose x)

If you already know C, you could probably get away with reading an existing project and just checking out the spec to learn about syntax and types.
developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html

Can anyone help me with some basic ass math
I'm rendering a 2D scene in OpenGL and I have a variable named zoom, and I scale the whole scene by its value (1.0 is no zoom, 2.0 is 200% zoom, 0.5 is 50%)
To control the zoom I did something like

zoom_speed = 0.001
if (zoom in key is being pressed) {
zoom += zoom_speed
}
if (zoom out key is being pressed) {
zoom -= zoom_speed
}

This works, but the problem is, the closer I am, the faster it zooms, and the farther away, the slower
How do I make the "zooming speed" uniform

tfw the ThinkPad in that pic has been retired years ago

stale meme

That's just plugging in the formula, where's the fun in that?

Is my quad fucked up? I'm pretty sure the colors are supposed to be a smooth gradient from one vertex to the other but mine sometimes looks like pic related when I turn up the color vals for just one vertex. Maybe it's because I'm using GL_TRIANGLE_STRIP instead of GL_QUAD? But when I use GL_QUAD it doesn't work. Wat do?
Also fuuzetsu is cute.

Attached: Window.png (640x480, 26K)

Does the lunix kernel offer a way to share memory between two running programs?

>How do I use a serach engine?

Is that not a smooth gradient?

COC's are specifically implemented in an open source as an inquisition against the values it was founded on, writing software. Most COCs should be summarized as "don't be a dick" but for some reason OSP love to reach out the most fringe leftist groups available when writing them.

Its not about inclusion or making people feel they can contribute its about control.

related:
geekfeminism.org/about/code-of-conduct/
youtube.com/watch?v=s087Ca9JnYw

is agile good or bad

>Physical contact and simulated physical contact (eg, textual descriptions like “*hug*” or “*backrub*”) without consent or after a request to stop.

Attached: 1523386156678.jpg (250x245, 17K)

The fun is in figuring the formula out

It's good in concept but not really relevant when discussing reality. It's literally just the new generation of managers putting lipstick on the word "deadlines". Are deadlines good? Probably. Will they make a meaningful impact? Probably not.

It's done when it's done, telling me I have to give an estimate of when it will be done on Monday and expecting me to have it done by Firday doesn't make a difference. It will either be done or not. When something is finished doesn't usually rely on 1 person.

memes. Go back to work, saro.

>Showing results for How do I use a search engine?

Is there a way to send unicode character input though? I already know about uinput and creating a keyboard device and sending key events, but that seems to be only for sending keystrokes (like I can press and release KEY_COMMA to type a ,).

For example on Windows with SendInput, I can create an input event with the value of the unicode character ▲and that will be typed in any focused text box in (almost) any application.
I feel like this concept won't be possible on the kernel level, it'd probably only make sense in the window system, so I guess I'll continue looking at X11 stuff.

Attached: 7897.png (581x530, 337K)

I don't see how anyone can support open source software when over half of the world (china, india) has no problem with stealing and selling other people's work. Am I being an idiot?

>C++
Probably

I'm working on a VN for kissing robots

I'm thinking it might be easiest to just manipulate the copy/paste buffer for this rather than doing it "the right way".

Three of the vertices blend well ((-1,-1), (1,-1) and (1,1)) but the last vertex seems to dominate its adjacent vertices, it is magenta for about 80% of the way and then abruptly changes.

I don't see the logic behind refusing to support a FOSS developer because someone else is infringing on their copyright.

Selling GPL software isn't copyright infringement. The GPL allows it. If original authors don't want people making money off their software they shouldn't have open sourced it in the first place.

I don't think it's a problem with the mesh. If it was you would have a hard seam or part of it wouldn't be drawn, it's probably the shader. It might not even be 'wrong', but just a result of however you're doing the color interpolation.

Is this stack good to learn for someone with little programming knowledge?

Attached: unknown (1).png (846x335, 77K)

There is absolutely no excuse to use auto unless you are working on a codebase 40k lines+

>stealing and selling
Quite a bit different than just "selling".

How do you steal something that's freely and legally available to copy?

>litle programming knowledge
ASP MVC and flask are easy for brainlets.

use Java and look to the java.awt.Robot class
you can also use it on other operating systems.
you can thank me later.

Spent HOURS cytonizing a wrapper around a library on windows 10 in fucking cygwin clone instead of mingw with fucking dll dependencies and of course it's not working when imported in a py file and ran thru bundled python. Just kill me.

inb4
>python
>windows

>java
>awt
>Robot
>class
Pajeet I...

By "stealing" I assume user meant copyright infringement, since you can't really "steal" a program, only copy it. A common misuse of the word. That is, if the aforementioned poos and chinks are not releasing the source of the derivative software under the GPL, which would not shock me.

If they were, like you said, it would be fine.

I'm trying to write the assembly that my compiler generates for a simple print instruction. My thought process is to have a label in the .bss section and just write the ASCII values to its memory location and subsequent addresses depending how big the string is with a subroutine.

1.- Is this a good idea
2.- I was thinking of just reserving one byte, but then I thought that if I do that I may be messing with occupied memory addresses
2.1.- Is my assumption correct?
2.1.1.- Do I just need to reserve more memory in that case?

is it true?

Attached: gnuc.png (1920x95, 23K)