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

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 322
Thread images: 25

File: 1473888365840.jpg (61KB, 491x604px) Image search: [Google]
1473888365840.jpg
61KB, 491x604px
What are you working on, /g/?

Old thread: >>58846135
>>
>>58851338
"The most powerful programming language is Lisp. If you don't know Lisp (or its variant, Scheme), you don't know what it means for a programming language to be powerful and elegant. Once you learn Lisp, you will see what is lacking in most other languages." -Richard Stallman
>>
File: 1483883433855.gif (408KB, 400x264px) Image search: [Google]
1483883433855.gif
408KB, 400x264px
thanks for using an anime image!
>>
>>58851378
>posting /pol/tardisms
remove yourself
>>
>>58851387
>/pol/
yeah, you can fuck off to that left wing board for all I care. just don't pollute this thread with your garbage.
>>
File: 1266976046836.jpg (72KB, 480x640px) Image search: [Google]
1266976046836.jpg
72KB, 480x640px
>>
>>58851422
>just don't pollute this thread with your garbage
>said the /pol/tard
>>
>turboautists still arguing
Another day, another /dpt/.
>>
File: 1485889318615.jpg (33KB, 590x452px) Image search: [Google]
1485889318615.jpg
33KB, 590x452px
>>58851524
I don't fucking care who are you, anti-leftist or pro-leftist, these are political terms which have no place outside of their containment boards.
Here's a link for you:
>>>/pol/
>>
>>58851506

/dpt/ attracts /pol/ and /x/ hilariously enough the act of programming has beneficial concepts for both of them. Legitimately on some level a lot of the mysticism from /x/ translates directly into mathematical and logical algorithms that can be used to solve problems. As for /pol/ guess what our computers with the current trend of advancement will shortly (History wise) be biological.
>>
>>58851592
>muh mental illness is a culture
>>
>>58851629
>mental illness 4lyf!
>>
How can tracing garbage collection be faster than reference counting? Isn't the difference that with a tracing garbage collection you pay a big computational price "P" once, whereas with reference counting you pay "P" over time?
>>
>>58851662
>I'm by definition mentally ill tho
>>
>>58851707
>"what kind of" pretending
cmon lad...
>>
Fuck you I will learn and use C++.
>>
>>58851721
>le confuseled about quotes meme
animoooooooooooooooooooo
>>
Jesus fucking Christ, can we just delete this thread and start again?
>>
>>58851748
>DELET DIS
>>
>>58851763
I don't know what that means, but I'm not getting involved in this madness.
>>
>>58851770
>who the hell are you quoting?
the mentally ill apparently
>>
File: Screenshot_2017-02-08_16-17-38.png (74KB, 673x669px) Image search: [Google]
Screenshot_2017-02-08_16-17-38.png
74KB, 673x669px
>>58851338
A simple language-agnostic syntax highlighter for an imageboard.
>>
>>58851782
who is "mentally ill"? does he need our support?
>>
>>58851776
>I'm this new
>>
>>58851793
Who art thou quoting?
>>
>>58851792
>who is "mentally ill"?
the one I'm quoting, pay attention, dumb fuck
>>
>>58851793
I've been here since before /dpt/s started, but if it's not from /g/, I don't know the meme.
>>
>>58851803
me? what the fuck?
>>
>>58851807
>if it's not from /g/, I don't know the meme
all memes start on reddit and 9gag tho, there are no /g/ memes
>>
>>58851827
That'll be why I don't know them, then.
>>
File: vga but not vga.png (196KB, 960x1053px) Image search: [Google]
vga but not vga.png
196KB, 960x1053px
>>58851338
I need some ideas for where to put my registers for my RGA video device, and what they should do.
>>
>>58851884
what are you making exactly
>>
>>58851912
A VM for an architecture I came up with. The CPU is somewhat done(as in it's functional), and now I'm working on peripherals.
>>
>>58851919
What's your instruction set like?
>>
>>58851928
It's like if MIPS, x86, and PPC had a horrible child.
>>
>>58851938
Awesome. Post some of it.
>>
>>58851919
i imagined something along those lines
just be yourself and get registers as you need them, maybe write on a piece of paper what you need
>>
Anyone experience with multithreading in C++?
I made a thread pool and built my own parallel for loop on top of it. Takes loop parameters and a lambda as an argument.

The thing is. It keeps deadlocking. Most often happens when I'm running it with 1 thread (i.e. the pool has 1 thread that it runs the loop on, which is a different thread than the main thread). I have no idea why it's doing this. My suspicion is that it may have something to do with the lambda (or functor object rather) that could possibly be outdated in a thread's local stack, but I am far from sure about that.

It's slightly faster (for my needs) than Microsoft's concurrency::parallel_for from the PPL and since I need maximum performance and I like portability I'd rather fix this than resort to that.

Anybody wanna take a look?
http://pastebin.com/RJtqRKSm
>>
>>58851947
the assembly looks like
mov r2,255
mov r0,8
push8 r0
pop8 r1
st byte,r1,r2

which would store 8 into address 255
the actual machine code would be:
15 41 00 00 00 FF 15 01 00 00 00 08 36 00 34 20 0D 08

woah human assembling
>>
>>58851719
You don't learn C++, you endure it.
No one in their right mind would teach themselves C++ without being forced to use it.
>>
File: 1308510680.33837935.jpg (473KB, 1000x750px) Image search: [Google]
1308510680.33837935.jpg
473KB, 1000x750px
>>58852013
>tfw being a programmer 50 years ago literally meant to be a human assembler
>>
>>58852051
It was a time when men were men and computers were toasters.
>>
Has anybody a recommendation for a graphics library for c?
>>
>>58852079
SDL
>>
Rolling my own NFA regex implementation.
>>
>>58852079
Lisp with cl-sdl2
>>
>>58852061
In the Art of Computer Programming books Knuth talks about his summer's spent writing compilers in the 1960s for vastly different architectures since there existed no standards at the time so he would frequently write the same compiler in 6 different assembly languages at the same time. That's why he laughs when people complain about MIX (now MMIX) being in the book as 'yet another language to learn' because he had to be able to learn a new language in a couple of days in order to pay the bills back then.
>>
>>58851338
python retard here, lets say I have
#!/usr/bin/python3
def start():
global one
one = 1
second()

def second():
global one
one = 1+1
third()

def third():
print(one)

start()


instead of doing global each time can I sort of send one from start to second then to third? is that better or is global each time fine?
>>
>>58852262
its because language nowadays have so much more features than just functions and loops
>>
>>58852290
assumig you forgot 'global one' in third(), otherwise that shouldn't work at all I think
def start():
second(1)
def second(n)
third(2)
def third(n)
print(n)
start()

would accomplish the same (as would print(2))
>>
>>58852337
>assumig you forgot 'global one' in third(),
no it prints two, your way works though, thanks
>>
>>58852290
Having is little global state as possible is a good thing, so someone along the chain of calls you make doesn't suddenly mutate that state with garbage.
>>
>>58852357
oh yeah forgot how globals worked there for a second
>>
>>58852079
Haskell
>>
>>58852451
it's a shame there's no support for haskell and QT
>>
>>58852458
There are a few QT libraries for Haskell.
>>
>>58852458
other than FFI bindings i mean
>>
How do I duplicate and double an array in C#?
By that I mean, how do I write each n from array1 to n and n+1 in array2?
>>
>>58852473
Well that's because it would be slow as fuck.
>>
>>58852295
They all compile to the same assembly/machine code though
>>
File: 1484177458718.png (514KB, 810x698px) Image search: [Google]
1484177458718.png
514KB, 810x698px
>>58852458
But Haskell is QT!
>>
>>58852500
You're right anon

You -> Me -> Love ()
>>
>>58852482
int[] shit = new int [] {1, 2, 3};
int[] feces = new int [shit.Length * 2]

for (int i = 0; i < shit.Length; i++) {
feces[i] = shit[i];
feces[i+1] = shit[i];
}
>>
>>58852525
Don't you have to increment by 2 then?
>>
>>58852482
Look through these lecture notes:
http://www.cs.cmu.edu/~15122/schedule.shtml

Specifically this lecture under 'Aliasing Arrays' shows you a few methods how to copy safely http://www.cs.cmu.edu/~15122/handouts/03-arrays.pdf which you can translate into C#
>>
>>58852633
Yep. Disregard.
>>
>>58852525
Use 2*n and 2*n+1 instead.
>>
>>58852654
>>58852525
Also, wouldn't you get an out of range exception? shit[6] = nonexistent.
>>
>>58852691
Well in that example, the length would be 3, so the for loop just goes from 0 to 2.
>>
I have a question about powershell and WSL.

When trying to get stdout from a bash call I instead get errors.
$text = bash -c "echo success"
$text
E r r o r : 0 x 8 0 0 7 0 0 5 7

What I'm doing right now is write to a file on the Linux side and then read the file in again on the windows side, afterwards deleting the file.
This is quite annoying.
Anyone here that managed to work with text output from WSL commands?
>>
>>58852764
After some more googling I found this issue to be a problem with WSL on the current Windows 10 stable version. The latest insider builds do have working shell redirection.

Guess I can wait a few months.
>>
File: Screenshot_2017-02-08_18-04-16.png (36KB, 1131x248px) Image search: [Google]
Screenshot_2017-02-08_18-04-16.png
36KB, 1131x248px
Syntax now highlights live. There is something magical about watching code appear as it's typed.
>>
>>58852861
Does it report syntax errors like newline braces?
>>
>>58852764
GNU*
>>
>>58852875
>literal trash
ftfy
>>
>>58852873
Hell no. It doesn't even detect language. Just some lightweight highlighting akin to the code tags on /g/.
>>
>>58852903
what about languages where none of those are keywords and // isn't a comment?
>>
>>58852908
You've put your finger on it. Like he says, it's just lightweight and language-agnositc.
>>
>>58852908
It accepts // and # style comments at the moment, and has a list of 165 keywords and 15 operators commonly used across languages. Of course there will be false positives and missing highlights, but I would rather use < 300 lines of optimised code, than a huge JS library for reparsing possibly many times per second. The highlighting is just a nice addition.
>>
>>58853002
what about -- comments and {- comments -}
>>
>>58852861
Is that you, Lat?
>>
>>58853026
Those would cause false positives with most other languages, so it can't be helped. There is only so much you can do, without huge language definition files and automatic language detection.
>>
>>58853085
Hello, slut.
>>
>>58853086
Why not use language detection then? Bad at statistics?
>>
>>58853096
Overhead.
>>
>>58851338
I kinda need to program a microcontroller in the next two to three months. In the last 5 months I managed to get buttons, an LCD screen an LED working and I programmed a simple 4 button menu.

In 3 months I need to work with motors and it needs to drive on wheels and know its position in a room based on the steps that the stepper motors made.

How fucked am I?
>>
>>58853124
Just use an Arduino, you'll have it done in a week.
>>
>>58853124
You could do all of that in a day.
>>
>>58853124
If it's taking you that long, you need to ask for extra instruction.

What microcontroller are you using?
>>
How do I check between arrays if there's any elements matching on any position in C#?
>>
>>58853149
Can't do that sadly.
>>58853151
Okay.
>>58853223
They're shit at giving instructions/refuse to actually help. I'm using an ATmega 324A
>>
>>58853306
ATmega's nearly as straightforward. There are plenty of cut-and-paste code snippets for servo motor control on Google that you can start from.
>>
Can someone give me some code review:
https://sstewartgallus.com/git?p=linted.git;a=blob;f=src/ada-core/src/linted-wait_lists.adb;h=7dda6c96c645b2c4d5cc8eab96321b929f7833ee;hb=737f037c8fdeca0c4f46740141909430cc43c1a6
>>
>>58853331
Not a servo motor, a normal stepper motor so I'll have to count the steps and get the information on the position in the software.
>>
>>58853354
My bad. Regardless, there's plenty of example code on Google.

Try and get a motor working today and go from there.
>>
>>58853395
Thanks man.
>>
A language where operators can be defined (not overloaded, though, except through e.g. type classes) and precedence is a partial order. In order to assert that an operator has precedence over another or how it binds when used with itself (e.g. a + (b + c) vs. (a + b) + c), you need to prove certain properties.

For instance, in order to say that * binds tighter than +, you also need to prove that * distributes over +. Operators that look symmetrical must be associative if you want to use them without brackets, and operators that look asymmetrical must not be associative if you want to use them without brackets (e.g. a + b + c vs. A -> B -> C).
>>
>have app that will primarily be used by kids
>want parents to get updates of the kids progress in the app
>someone suggested an email to the parents
>as far as i know, this would require a database and server which my app currently doesnt need

anyone know of anything of the top of their heads that might work for this?

my app doesnt require making accounts at all so it would add a big level of grossness if i had to add a email prompt and database to hold the emails. is there such an API that would let me get around this?
>>
>>58851338
I need some ideas for a clean and easily configurable way to restrict possible values of an enum attribute, depending on its current value and some other condition, e.g. if the current value is A it can only be changed to B or C, or if the current value is C and some other attribute is equal 6, it can be changed to any predefined value. I was thinking about using a nested map with possible transitions, defined in xml, but this seems ugly.
>>
>>58853443
10/10 would program in unironically
>>
Any lisp fags here.
I suppose I use quicklisp to get a graphics library for CL?
Also is CFFI the preferred way to do FFI?
>>
>>58853513
cl-sdl2 for graphics in CL.

What implementation of CL are you using?
>>
>>58853273
Please respond. I can only do if the current element matches between arrays on the same position, but that's not what I want.
>>
>>58853513
What >>58853533 said. CFFI is commonly used, though I saw cl-autowrap on quickdocs.org which may simplify the work to make bindings.
>>
>>58853554
Nested for loops or create map of both arrays and then loop over them.
>>
Doing some address slicing in Python. Say I have two addresses:

123 Hasklel Lane
334-360 Pooinloo Drive

The "123" part of the first address will have an end resting place in one column of an excel spreadsheet. In the next row, the "334" part of the second will end up in a preceding column of that same spreadsheet, and the "334-336" part will live in the same column as where "123" is, just the next row under.

Is it better to have one function that does the slicing and placing for both columns, or to split it up between two functions and have each one deal with a specific column?
>>
>>58853584
This is what I got so far.
for (int i = 0; i<5;i++)
{
for (int j = 0; j < 10; j++)
{
first[i, j] = r.Next(1, 100);
second[i, j] = r.Next(1, 100);
if (first[i, j].Equals(second[i,j]))
matches++;
}
}


They are both 5x10, but with my method I only compare elements of same positions. How do I fix this?
>>
>Vulkan registry file for generating bindings contains literal C code that you have to parse anyway to use for another language
>it's XML if that wasn't bad enough already
>>
Any thoughts on this approach to basic tokenization?
//Rule functions. Return 0 if the rule matches so far and we want more chars. 
//Return -1 if the rule doesn't match. Return N if the rule was matched except for the last N-1 characters.

int rule_integer(char *chr, int *state) {
if(isdigit(*chr)) {*state=1; return 0;}
if(*chr=='.' || isalpha(*chr)) return -1;
return (*state) ? 2 : -1;
}

int rule_float(char *chr, int *state) {
if(isdigit(*chr)) {
if(*state==0 || *state==2) (*state)++;
return 0;
}

if(*state==1 && *chr=='.') {
*state=2; return 0;
}
return *state==3 ? 2 : -1;
}

int rule_string(char *chr, int *state) {
if(*chr=='\"') {
(*state)++;
if(*state==2) return 1;
else return 0;
} else {
return *state ? 0 : -1;
}
}

int rule_space(char *chr, int *state) {
return isspace(*chr)?1:-1;
}

int rule_identifier(char *chr, int *state) {
if(isalpha(*chr)) {*state=1; return 0;} else return (*state)?2:-1;
}

int _tmain(int argc, _TCHAR* argv[])
{
vector<Rule> rules;

rules.push_back(MakeRule("==", NULL, "isequal"));
rules.push_back(MakeRule(NULL, &rule_integer, "integer"));
rules.push_back(MakeRule(NULL, &rule_float, "float"));
rules.push_back(MakeRule(NULL, &rule_string, "string"));
rules.push_back(MakeRule(NULL, &rule_space, "*space"));
rules.push_back(MakeRule(NULL, &rule_identifier, "identifier"));

// Omitted for brevity: getting user input

ApplyRules(line, "[]{}()-+/*.<>=", rules, &tokens);
PrintTokens(rules, tokens);

return 0;
}


Example output:
> if(3.2==32) {print("Egad==5");}
identifier | if
(
float | 3.2
isequal | ==
integer | 32
)
{
identifier | print
(
string | "Egad==5"
)
}

>


My goal was to write a fairly small, simple, and flexible system. I realize that the proper way to write it would probably be with a full-blown regular expression approach, but that's overkill in many cases.)
>>
>>58853273
Make a set out of each then check for intersection.
>>
Working on a project where users enter stuff into a database on a little pad, then, when in cell signal, it sends the data to a main database in the cloud.

What would be the best way to do the database transfer?
>>
File: angry_pepe.jpg (65KB, 900x900px) Image search: [Google]
angry_pepe.jpg
65KB, 900x900px
>give code to boss
>He replies with "it doesn't compile. pls see me"
>Go to him and he shows me his monitor
>code actually just compiled fine. He just has compiler warnings.
>point that out to him
>him: "fix it"
>>
>>58853841
>warnings
>compiled fine
>>
>>58853841
-w
>>
I am planning to program a little board game in C. I'd like to read a tab-separated text file containing two columns of data:
ID    Name
1 Egypt
...
9 Tanger
10 Cairo
11 Addis Abeba
...


Basically an integer from 1 to 32 and a text string.

I'd like to read the lines into an array of struct objects. I defined the struct like this:
struct City {
short int id_num; /* ID number 1..32767 */
char name[30]; /* city name, max 29 chars */
};


Currently I'm trying to read in the csv file character by character with
fgetc()
called in a while loop. I can read individual characters and filter out the newlines and tab chars just fine. Does /g/ have some advice on how I should proceed to separate the fields and store them into an array of City structs?
>>
>>58853799
Pick library of choice corresponding to your database.
>>
>>58853876
scanf
>>
>>58853876
fscanf
>>
>can't reassign an array in C with brackets

Why is this still not implemented?
>>
double ***coor = new double**[ndim];
for( int i=0; i<nfe; ++i)
{
coor[i] = new double*[natm];
for( int j=0; j<natm; ++j)
{
coor[i][j]=new double[nfe];
delete coor[i][j];
}
delete coor[i];
}
delete coor;


All I'm trying to do is allocate and then delete a 3d array. This segfaults on the last delete command. Any idea why?
>>
>>58853841
>warnings
Go fix it.
>>
>>58851606
>>58851647
>>58851706
>>58851716
>>58851742
>>58851782
what did I lose?
>>
>>58853954
https://archive.rebeccablacktech.com/g/thread/58851338
>>
>>58853885
Using mysql.
It will mostly be js, but optionally, I can have something backend to do it.
>>
File: 1485900658587.jpg (211KB, 1280x720px) Image search: [Google]
1485900658587.jpg
211KB, 1280x720px
How much do you care about aesthetics
>>
>>58853984
As long as it's not material and glossy, it's fine.
>>
>>58853954
Two idiots were carrying over an argument from the last thread.
Around about 50 posts into this thread I went through and reported 34 of them.
>>
>>58853929
    double ***coor = new double**[ndim];
natm=input.getNatm();
nfe=option.getn_fe();
for( int i=0; i<nfe; ++i)
{
coor[i] = new double*[natm];
for( int j=0; j<natm; ++j)
{
coor[i][j]=new double[nfe];
delete[] coor[i][j];
cout<<"deleted i="<<i<<" j= "<<j<<endl;
}
delete[] coor[i];
cout<<"deleted i= "<<i<<endl;
}
delete coor;
cout<<"finished deleting"<<endl;


Formatting got a little fucked up. It deletes everything until the final delete coor command.

Another thing note is that is only segfaults for nfe greater than 3.
>>
>>58853984
As long as it doesn't get in my way.
>>
File: 1372198960900.jpg (28KB, 247x246px) Image search: [Google]
1372198960900.jpg
28KB, 247x246px
>>58853841
>warnings
>fine
What a pleb
>>
>>58853348
In wait, why use unchecked access when you can just send the aliased record?
>>
>>58853983
There's a node mysql lib if you want to do everything in JS.
>>
>>58853725
I know the logic, I don't know the syntax, C# is new to me.
>>
>>58854066
https://msdn.microsoft.com/en-us/library/bb359438%28v=vs.110%29.aspx
>>
>>58853533
>>58853568
Thanks. I'll go install quicklisp and hopefully get this stuff working.
>>
First result on Google: https://msdn.microsoft.com/en-us/library/bb359438.aspx
>>
>>58853458
>>want parents to get updates of the kids progress in the app
>Wants no database to actually track the progress
This is somewhat tricks, but good on you for not wanting the app to have unnecessary internet connection I suppose.

Have you thought of an parent version for the app, that the parents install on their device and then 'connect' to their child's device using NFC? They'd have to enter an email, which is saved on the child's device using NFC. They then get emails about the progress.

There's no real way I can think of that would allow you to display the data inside the parent app, since you don't want to use a database and I don't think there is (and should be) a way to let two devices communicate freely.

Then again, I'm mainly a developer for desktop applications and the most app-like software I have written is an app for bar-code scanners. Have taken a look at some app development but not at a level where I could tell you that there's a better way.
>>
File: 1486396299203.jpg (124KB, 882x731px) Image search: [Google]
1486396299203.jpg
124KB, 882x731px
>>58851338
I'm making a
>>
>>58853458
>>58854101
>They then get emails about the progress.
Just for clarification, what I meant by this is, that the child's device sends those emails directly.
>>
>>58854113
>I'm making a
A-anon? you okay there?
>>
>>58854118
I think most major email providers are paranoid about strange domains, so your email would get classified as spam unless you used another big name provider.
>>
File: FUG.png (6KB, 328x107px) Image search: [Google]
FUG.png
6KB, 328x107px
Are these extra? Or is there a version I should select for windows 10 dev?
>>
>>58854147
He was making a lazy shitpost.
>>
File: b49.gif (1MB, 680x680px) Image search: [Google]
b49.gif
1MB, 680x680px
>>58854147
ATISHOO
>>
>>58854066
>>58853273
Holy shit, anon.

var muhFirstArray = new int[] { 1, 2, 3, 6, 69, 1337 };
var muhSecondArray = new int[] { 69, 1337 };

var matches = muhFirstArray.Intersect(muhSecondArray);
>>
>>58854079
But I need to do it with arrays, pretty sure you can't apply that to them?
>>
>>58854158
You are probably not going to be working on an Universal App so you can leave all unchecked.
>>
>>58854158
Get the Tools and latest SDK (14393)
>>
>>58854228
see >>58854214
>>
In an IT lab watching someone attempt to use HTML tags in a Java print statement
>>
>>58854231
>>58854235
Alright thanks for the advice. I went for the not installing it. I mainly wanted to check out Monogame(3rd party) and DirectX dev so its probably better to leave those things unchecked.
>>
>>58854277
Maybe they're writing server-side code in Java. Seems perfectly reasonable. Or it could even be a program to generate static HTML pages according to some template or fancy scheme.
>>
>>58854295
Oh, yeah, absolutely. I thought when you said "Windows 10 dev" you mean actually making UWP applications.

Lucky for us all, the new installer in 2017 makes it very clear what you're working with and has way less bloat.
>>
>>58854214
No, they need to be arrays, you can't define them as vars.
>>
>>58854322
The first two ARE arrays, and the last can be easily converted:
int[] muhFirstArray = new int[] { 1, 2, 3, 6, 69, 1337 };
int[] muhSecondArray = new int[] { 69, 1337 };

int[] matches = muhFirstArray.Intersect(muhSecondArray).ToArray();
>>
>>58854342
Thanks for writing part of my homework assignment! I'm sure my professor will be pleased with this work!
>>
>>58854366
Obvious false flag, however I'm completely aware that I'm helping an anon with their homework.
>>
>>58854366
No problem, bud.
>>
>ASP.Net

Am I the only one that reads this as Aspie.Net?
>>
>>58854385
I think of the snake whenever I see that.
>>
>>58854342
This literally doesn't work. They are 2D arrays.
>>
>>58854392
Seconded, makes me think "asps' nest".
>>
>>58854401
Why didn't you say that in the first place?

Show me what your array declarations look like with some sample data.
>>
File: triggered.jpg (75KB, 1893x1063px) Image search: [Google]
triggered.jpg
75KB, 1893x1063px
>>58854385
>aspie.net
>>
File: 1481753609956.jpg (34KB, 600x337px) Image search: [Google]
1481753609956.jpg
34KB, 600x337px
>>58854366
>there are people here programming just because it's their homework
I thought everyone here just enjoyed programming as much as me
>>
>>58854410
see
>>58853623

Thought you saw the code already.
>>
>>58854310
Doubt it since I know they're working on an assignment for a beginner Java course
>>
>>58854431
Writing a program to generate an HTML file according to some simple user input would be a fun and easy beginner assignment.
>>
Question to all wage cucks out there.
Have you ever talked about functional programming during an interview?
>>
>>58854526
Have you ever met a beginner? Maybe 25% of them would be bright enough to do that, the other 75% would shit themselves.
>>
>>58854556
Nope.
>>
>>58854427
Just flatten the values into a collection with their index and then compare.
>>
>>58854560
project harder

if you honestly believe that, you're the hopeless one
>>
>>58854556
Nope, only had like 2 interviews. One was about C#/Java, the other one embedded programming.
>>
So when people ask what I do for work I say freelance programmer rather than saying I currently can't work due to mental illness (schizophrenia) - how much do freelance programmers make on average an hour and a month? and how many hours a day do you work?
>>
>>58854597
Not that guy, but I've helped many beginners in programming, and while they were pretty much all smart, I seriously doubt they would be able to do something like that.

It takes a different mindset, and it needs practice.
>>
>>58854597
Been programming for two years.

I'm shitting myself thinking about how complex this would be.
>>
>>58854655
Do you not know anything about recursion?
>>
>>58854663
>using recursion for that
Pajeet, I...
>>
>>58854680
X/HTML is a tree, obviously you would use fucking recursion.
>>
>>58854680
Pajeets can't into recursion, Anon. They can barely into iteration.
>>
>>58854687
Recursion can and should always be translated into a solution that utilizes iteration instead.
>>
>>58854597
Nigger, I've actually worked with beginners, it's unbelievable how many have trouble with simple things. I've seen so many people who try to learn the concept of functions and loops but it just flies high over their head, these are the people that end up dropping out and they're all in beginner classes.
>>
File: 1477810493150.jpg (192KB, 600x632px) Image search: [Google]
1477810493150.jpg
192KB, 600x632px
>>58854526
I'm writing a program to replace text in html with text from a spreadsheet which creates a new html.
>>58854560
I was told c# was easy to learn.
I'm a beginner and I threw myself into the deepend (it might not be so deep for you, but I can't swim).
>>58854647
I know web languages, and the logic behind them makes me understand c#.
>>
>>58854694
Recursion is an easy-to-understand crutch for poor programmers. It shouldn't be used, regardless of whether your language/compiler supports tail-call optimization.
>>
>>58854695
This is true; it's why God gave us TCO.
>>
>>58854695
Manually trampolining a recursive algorithm to make it execute iteratively (i.e. use the heap instead of the stack) is still using a recursive algorithm.
>>
>>58854613
>the other one embedded programming.
could you talk about that a bit? where did you apply, what would the job entail, what prerequisites did you need?
asking because I'm thinking about getting into embedded myself
>>
>>58854710
Lmao if you think a beginner is gonna understand recursion, I've got a bridge to sell you.
>>
>>58854710
>Recursion is an easy-to-understand crutch for poor programmers
But Pajeets can't into recursion, Anon. They can barely into iteration.
>>
>>58854722
Or is it?

Recursion is just iteration written poorly.
>>
>>58854154
>I think most major email providers are paranoid about strange domains, so your email would get classified as spam unless you used another big name provider.
Well, I guess he has a domain registered and can use that as domain for the emails that are sent. Also his content shouldn't be too sketchy.

I've sent lots of emails using our company email address and they have never been flagged as spam.
>>
>>58854739
>>58854739
Actually, iteration is a specific case of recursion.
>>
>>58854739
Iteration is a poorly written recursion.
>>
>>58854767
iteration is well defined recursion
>>
>>58854774
Exactly, see: >>58854757
>>
>>58854774
Are you implying recursion can't be well-defined if it isn't iteration?
>>
when where you when you realize lisp is meme
compare
coje 0 _ = []
coje n (x:xs) = x : coje (n-1) xs

bota 0 xs = xs
bota n (_:xs) = bota (n-1) xs

ninit n = snd . foldr foo (n,[])
where foo x (0,xs) = (0,x:xs)
foo _ (a,xs) = (a-1,xs)

vs
(defun take (n xs)
(loop for i in xs
as k = n then (1- k)
until (= 0 k)
collect i))

(defun drop (n xs)
(loop repeat (+ n 1)
as ys = xs then (cdr ys)
finally (return ys)))

(defun tail-drop (n xs)
(flet ((foo (x acc)
(if (>= (decf n) 0)
acc (cons x acc))))
(reduce #'foo xs :initial-value ()
:from-end 'true)))

(defun init (xs)
(tail-drop 1 xs))
>>
>>58854790
Yeah, loop is gross.
>>
>>58854663
I do. I don't like using it though.

I also don't know HTML so that probably adds to the mystery of doing that type of project. I've made a windows command line interface library that I use for creating menu's and shit but that was easy compared to writing to a file with proper formatting and shit.

Most of my knowledge about programming comes from adapting what I know about video games and tabletop games as I don't have any former schooling in regards to programming (or post highschool education in general).

Its extremely easy to visualize a class that takes in commands, processes them and outputs HTML.

Writing an ambiguous algorithm to do the same makes me terrified. I'm not really comfortable with handling programflow thats dictated by recursion and other logic, I'd rather handle all program flow on the code level.
>>
>>58854787
well, iteration doesn't require a compiler hack in order to avoid stack overflow

recursion is just poorly designed iteration
>>
>>58854790

user error
>>
>>58853348
I would like to know >>58854032
>>
>>58854799
is there any lisp that allows me to be expressive?
>>
>>58854822
Pretty much all of them, as long as you avoid loop.
>>
>>58854805
Trampolining and iteration IS a hack to avoid stack overflow.
>>
>>58854828
why is loop so bad?
it's certainly better than imperative for / while loops
>>58854828
but I need one that is as expressive as haskell
>>
>>58854850
Um, loop IS imperative.
>>
>>58854805
>>58854829
TCO is one way of escaping the limitation that all function calls must allocate a new frame on the stack. It's not strictly necessary so why should it be forced?
>>
>>58854790
The Lisp is still more efficient, both in speed and size.
>>
>>58854818
go ahead, rewrite the list example
>>
>>58854850
I'd put LISP and Haskell on equal footing in terms of expressivity. LISP probably has the edge in general, but syntactic sugar and big libraries make Haskell terser in short examples.
>>
>>58854850
Don't listen to him, LOOP is perfectly fine.
>>
>>58854877
yeah, but is there a lisp where I can compose, partially apply, and pattern match easily without having to go out my way?
>>
>>58854900
Yeah, you can do all of those in LISP.
>>
>>58854908
>without having to go out my way
i hate having to create a new package and importing alexandria everytime
>>
>>58854900
Yep. Qi/Shen.
>>
seems racket is going the enterprise way
whatever, i'll still keep using it
>>
>>58854946
Then your complaint is about the size of the standard library, which is point number two here: >>58854885

They really are equally expressive; if anything, LISP is more so.
>>
>>58854900
Aren't composition and partially applied functions trivial in LISP? Like, even in Scheme?
>>
>anime

there's a special hell for people like you
>>
>>58854723
I doubt where is relevant, since I'm in Eastern Europe. It was actually straight out of uni and I didn't apply, they called me and offered me an interview the day after I graduated, the company has some sort of partnership with the school. I don't remember exactly what the job title was, but I was gong to do embedded programming for shit in the automotive industry. Since I was straight out of uni and they knew about it, the interview was mostly about what extra projects I had worked on. I was a part of a team which built robots for an international competition and they were most interested about what I did there, I was mainly a programmer but also worked on the electronics a bit.

Sadly the job they offered me was pretty much worse from every point of view compared to the C#/Java place despite embedded being much more fun, from pay, to working schedule and the location.
>>
>>58854992
why post this, you like (you)'s?
>>
>>58854992
is anime hell deeper than trap programmer hell?
>>
File: 1461869462105.png (932KB, 676x1110px) Image search: [Google]
1461869462105.png
932KB, 676x1110px
What's a good way to balance a binary tree? Right now I've thought up this process but I'm not sure if it's correct, all I've done is some tests on paper.

1) generate an ordered array of data from my unbalanced binary tree
2) input the array into a balance function that will return a binary tree node pointer
3) in this function I'll use the middle value of the array as the first data in the first node and end up with two arrays, so I'll assign the left node pointer to the same function balance(left_half_of_array) and the right node pointer to balance(right_half_of_array)

Is this the correct way to go about it?
>>
>>58855015
if traps had a rational mind they wouldn't be traps

they can't program for shit
>>
Does any of you know a tutorial where you I can find how to make the Julia fractal and zoom into it at the mouse coordinates? I can't seem to find a proper way to make it and too bad at math to figure it out on my own.
>>
>>58854988
Yes. For example:

(define (compose f g)
(lambda (x)
(f (g x))))


This sort of thing is comes out-of-the-box in Racket.
>>
I am too dumb to figure something out for myself, so I had to adapt source code made by someone else. it was posted in a programming forum. should I put a link to that post in my source code comments?
>>
did people forget about the metaobject protocol?
>>
>>58855036
really? what about partial application and currying
>>
>>58855024
https://en.wikipedia.org/wiki/AVL_tree
>>
>>58855069
https://docs.racket-lang.org/reference/procedures.html

The presence of these is nothing to do with expressiveness; any lambda calculus language will support them.

Where your complaint lies is actually with the 'extras', like libraries and syntactic sugar.
>>
>>58855024
binary trees are a meme and they degenerate into a straight linked list at least 50% of the time

just use a flat array

>>58855033
i don't know anon, i feel like I do my best when i have my morning coffee and wear pantyhose under my normal clothes
>>
>>58855096
To go further, here is 'compose' in pure LC:

COMPOSE = λfg. λx.f (g x)


Functions are curried by default in LC.
>>
>>58855069
1 ]=> (define (papply f . args) (lambda x (apply f (append args x))))
;Value: papply
1 ]=> (papply + 1 2 3)
;Value 15: #[compound-procedure 15]
1 ]=> ((papply + 1 2 3) 4 5)
;Value: 15

I'm not very knowledgeable in FP, but maybe something like this?
>>
>>58855098
Daily reminder to use hashmaps for everything.
>>
Currently working on YouTube videos for c# stuff. https://youtu.be/te-H1v-7Rto
>>
>>58855125
>not using plists
>>
>>58855098
>they degenerate into a straight linked list at least 50% of the time
Of course, that's why I want to balance it
>>
>>58855146
Nevaaarrrrr
>>
>>58855155
a flat array requires no balancing and has O(1) access time for any array member
>>
>>58855048
I would
>>
>>58855172
And O(n) search time, balanced binary trees have their purpose as well.
>>
>>58855098
>binary trees are a meme
lmao 4chan proabaly relies on b-trees for post indexing this site would crash without them
>>
>>58855189
O(n) and highly cache friendly search.
>>
>>58855199
I wrote a messageboard where all the post content is stored as a flat array of structs, there's no performance issue.
>>
>>58855222
and you probably had 3 users total
>>
>>58855204
Sure, but what is your point? That still doesn't mean balanced binary trees don't have their uses as well.
>>
>>58855199
That's pointless because you will rarely ever have gaps. All the posts are stored in a circular array, all the threads are arrays of indices into said array.
>>
>>58855259
So old posts could die while the threads they're part of are still ongoing? Seems dubious.
Also, do posts have a pointer to the thread they're part of so that you know they can be overwritten if the thread has died?
>>
>>58855304
No, you can resize a circular array just like a vector and the indices won't be invalidated.
>>
>>58854790
(define (take n xs)
(cond ((null? xs) '())
((<= n 0) '())
(#t (cons (car xs) (take (- n 1) (cdr xs))))))

(define (drop n xs)
(cond ((null? xs) '())
((<= n 0) xs)
(#t (drop (- n 1) (cdr xs)))))

(define (tail-drop n xs)
(reverse (drop n (reverse xs))))


I can't stand all this explicit recursion. We need some better libraries up in this bitch.
>>
>>58855259
so everything is lost when you reboot?
>>
>>58855304
>>58855325
And no, when the thread dies it sets a flag in its posts itself.

>>58855329
No, because you can serialize that. Indices, not pointers.
>>
Is this what a professional Python project actually looks like?
>>
>>58855325
I guess for some reason I thought the code would mindlessly overwrite the posts at the beginning of the circular array, because that's how I've often seen them used (e.g. for particle systems where the oldest entities can be overwritten when new particles spawn.)

So what is the logic for reuse of existing array slots vs. resizing of the array? Do you keep a free list? Or do you go over the whole array looking for now-empty entries?
>>
File: FunctionalCSharp.png (34KB, 1028x709px) Image search: [Google]
FunctionalCSharp.png
34KB, 1028x709px
In functional C#
>>
>>58855355
>nothing but imports
Yeah, pretty much.
>>
>>58855372
You overwrite dead posts (based on the flag) and reallocate when you encounter a live post.

Though, now that I think about it, this approach probably doesn't work well for really slow boards that don't cycle that often. So there you would use a sparse structure.
>>
>/dpt/ tries to write a server.jpg
loving every laugh
>>
Have you guys figured out data persistence yet?
>>
>>58855372
>>58855394
Or you could just use array storage for each thread. Since the vast majority of links are intra-thread it won't be an issue.
>>
>accidentally do sizeof(obj) instead of sizeof(struct obj)

FUCKING EVERY TIME
>>
>>58855447
isn't it the same thing?
if you were getting the size of the pointer, then I could see how it could lead to unwanted behavior
>>
>>58855447
typedefs nigger use em
>>
>C programmers need to typedef their structs
lul
>>
>>58851338
        private int GetHexCharValue(char c) {
switch (c) {
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
case 'A': return 10;
case 'B': return 11;
case 'C': return 12;
case 'D': return 13;
case 'E': return 14;
case 'F': return 15;
default : return -1;
}


why?
>>
>>58855482
i only do it when writing library code and it's to make the main context struct pointer stand out as an abstraction.
What's really bullshit is having to use opaque pointers to hide library internals from the rest of the program.
>>
>>58855465
If it's not typedefed then it's not the same

>>58855470
I don't want to name my shit _t because it's not recommended so I went with non typedefed structs. Lesson learned
>>
Where can I learn more about lock-free algorithms?
>>
File: 1352784783422.png (51KB, 479x591px) Image search: [Google]
1352784783422.png
51KB, 479x591px
>>58855543
>>
>>58855543
What about
private int GetHexCharValue(char c) {
if(c>='0' && c<='9') return (int)(c-'0');
if(c>='A' && c<='F') return 10+(int)(c-'A');
return -1;
}
>>
>>58855669
>Provide some numbers that exceed the number I'm thinking of.
The answer depends upon the value of the number you're thinking of.
>>
>>58855687
That'd be similar to what I'd do.
>>
Lets settle this,

Is (objname)_t typedef style acceptable in C, assuming it doesn't conflict with anything POSIX?
>>
>>58855687
how about just
const char hex_lut[UCHAR_MAX] = {
['0'] = 0, ['1'] = 1, ['2'] = 2, ['3'] = 3, ['4'] = 4, ['5'] = 5, ['6'] = 6, ['7'] = 7, ['8'] = 8, ['9'] = 9, ['A'] = 10, ['B'] = 11, ['C'] = 12, ['D'] = 13, ['E'] = 14, ['F'] = 15
};
>>
Anon learning ASM and C again from yesterday. I am trying to write a decryption function in C. If I had the following 3 operations how would I reverse it? I understand the xor will solve itself when processing the cipher text but I don't know what to do with the bitshifts or the &

tmp1 = a
tmp2 = a
tmp1 &= 0x20
tmp2 >>= 0x2
tmp1 ^= tmp2
>>
File: Untitled-3.png (87KB, 735x582px) Image search: [Google]
Untitled-3.png
87KB, 735x582px
>>58855543
>>
File: snap137.png (219KB, 1027x638px) Image search: [Google]
snap137.png
219KB, 1027x638px
Today I found a Denial of Service exploit in an image parsing library that works against 4chan!

It's forces the parser to allocate N times 96 bytes of memory, frees everything, and starts again, which not only consumes memory but maxes out a core for several seconds.

For every cycle of allocation/deallocation, the file only needs to grow by ~50 bytes, so a regular-sized image could keep a process busy for hours, if it doesn't get killed first.

I guess I should report it, I've never done that before.
>>
I'm working on some jsp filters. It's going well but Im not sure I actually understand how this is working lol
>>
>>58853623
Okay, I know this is a bit late, and you might not be here, but you got the right idea, thought you just need two more for loops there.

Don't listen to the others, they are overcomplicating things. Your code should look something like this (I edited your code).

for (int i = 0; i < 5; i++)
for (int j = 0; j < 10; j++)
first[i, j] = r.Next(1, 100);
second[i, j] = r.Next(1, 100);
for (int k = 0; k < 5; k++)
for (int l = 0; l < 10; l++)
if (first[i,j].Equals(second[k,l]))
matches++;
>>
>>58855790
a is the first 8 bytes of cipher text and this is just one segment of 50 lines of this crackme but the general pattern repeats itself.
>>
>>58855752
That's an interesting idea. Possibly the fastest way to implement it, if you were in a performance critical situation.
>>
>>58855809
Impressive if true.
How did you find out what image libraries 4chan uses?
How did you find the exploit?
>>
>>58855911
It's probably just whatever is the most popular PHP imagemagick binding library.
>>
>>58855790
well that sequence erases any information about the last two bits, so I'm not sure how well you could reverse it
>>
>>58855862
Follow up question, since I still need help.
How would you write out all the elements in the first array that are NOT in the second array?
>>
>>58855965
That's what I thought, but now I am wondering maybe I am framing this wrong and it only needs part of the ciphertext or something. It does another 2 shift right later on after a bunch more xors and shifts on tmp2 before adding tmp1 to the outstream.
>>
>>58855911
I wrote a long comment and then accidentally close the quick reply...

Long story short I was looking at the old 4chan source code leak to use an undocumented API for my GET tool, and I found the PHP code directly calls C binaries for PDF and JPG metadata parsing.

After some investigation, fuzzing, and spending last night working, it turns out there's an out-of-bounds read and several lack of input validation that can be turned into an exploit.
>>
>>58855965
Maybe that's supposed to be a wrapping shift?
>>
>>58851338
Oh this trap is cu...
>boobs
fuck
>>
>>58856080
I made a test on /p/ and 4chan mysteriously took 10 seconds to confirm my post, so it seems to be working.

Now I'm making a small tool to easily embed the exploit in pictures w/ configurable memory/CPU use, because I'm a horrible person.
>>
>>58856100
The asm for it is
shr     cl, 2

I want to avoid posting the full code here because I am technically doing this for school and I don't want it archived later.
>>
>>58856061
maybe post the whole thing if it's not too long?
>>
>>58856150
It's not a length thing, it's a I can't do that sort of thing. I am working on getting stuff published (undergrad working with grad students on a research paper about malware packers) and the last thing I need is code in a paper with my name on it being linked back to a 4chan thread when I am looking for work.
>>
in simple kid like terms can someone explain the difference between Vector, Set, Map, Tuple
>>
>>58851338
Fuck you for using an anime image
>>
>>58856238
http://stackoverflow.com/questions/972924/differences-between-vector-set-and-tuple#972938
>>
>>58856238
OOGA, STICK, ROCK ROCK, STICK ROCK
>>
>>58856238
A vector is a way by which a disease is able to penetrate the body. For instance, mosquitoes are a vector for malaria.

There are lots of ways to use "set", do you mean like a radio set, a box set, a train set, etc.?

A map is a sheet of paper that shows the geography of an area, points of interest, and maybe some navigational paths.

Not sure what a tuple is, is that even English?
>>
>>58856238
A vector is a list of elements of a specific type that is stored contiguously in memory (i.e. each element is next to each otheR)

A set is a list of elements in which duplicates do not occur (i.e. [1,2,3] is a set but [1,2,2,3] is not), and is normally represented as an ordered binary tree.

A tuple is a collection of elements of the types of which it is a tuple, e.g. (Int, Int) is two ints. It has a fixed size. A pair is an example of a tuple.

A map is a set of a (key, value) pairs, normally represented as an ordered binary tree sorted by the key. A common operation is looking up the value at a given key.
For example access the "name" field in [ "x" = 3, "y" = 6, "name" = 123 ] to give 123
>>
>>58856238
Set is like it is in math, has to be unique values. Data is unordered.
Map perform function on every item in a list.
tuple: ordered collection of different types. If you know what a hashmap is or a dictionary it is kind of like those.
>>
>>58856288
>Not sure what a tuple is, is that even English?
it's a fancy name for a struct that shitlang fags use
>>
>>58856284
Fuck, that's actually a really good answer.

>>58856288
http://en.cppreference.com/w/cpp/utility/tuple
https://www.tutorialspoint.com/python/python_tuples.htm
>>
>>58856311
>>58856319
Huh?
>>
>>58855447
sizeof varname instead
>>
>>58855687
>private
What is this macro thing?

>(int)
Why on earth? character literals are already int.

>
    if(c>='A' && c<='F') return 10+(int)(c-'A');

NOT portable
>>
>>58855746
No
>>
New thread:

>>58856389
>>58856389
>>58856389
>>
File: 1458881227218.png (304KB, 647x679px) Image search: [Google]
1458881227218.png
304KB, 647x679px
>>58856322
non-anime thread BTFO
>>
>>58856305

got it thanks

so a map is kind of like an object then? the key acts like a property?
>>
@58856439
lmao
do pajeet brainlet redditors literally think of everything as "objects"?
>>
>>58856544
Do you have an inferiority complex?
>>
>>58856569
it's more of a superiority "complex" but only i'm actually superior
>>
>>58856586
A delusion, then.
>>
>>58856594
only if you think reality is somehow a delusion. in which case you're the delusional one here.
>>
>>58856609
Of course, sweetie. Whatever helps you sleep at night.
>>
>>58856644
Fuck off, Rajesh. You sperged out for literal months wrapping your poo-in-loo "buu huuu animoooooooooo" statements in code blocks for every thread.
>>
>>58856717
Kek. I wasn't the guy you were insulting, I was just making fun of you.
>>
>>58856744
Holy shit mom I used a meme
>>
>>58856544
Good post, made me lol.
Thread posts: 322
Thread images: 25


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.