/dpt/ - Daily Programming Thread

What are you working on, Sup Forums? Previous Thread:

Other urls found in this thread:

destroyallsoftware.com/talks/the-birth-and-death-of-javascript
tour.golang.org
clang-analyzer.llvm.org
stackoverflow.com/questions/15274696/importerror-in-importing-from-sklearn-cannot-import-name-check-build
twitter.com/AnonBabble

Does Sup Forums ever wish there were more men programming? These upper level classes have almost no guys. It's just another bland wave of girls with bags under their eyes. Pic related.

Anyone here good with embedded systems?

It's this shit 24/7. And there's someone talking about Bleach behind me during every lecture.

Reminder that all the best programmers dress up as handsome boys.

Sorry, I'm not a faggot so I only dress up as a cute girl.

unreadable code/10 but cute anime

good anime image.
yes

I would fail you if I was your TA

You're only hurting yourself.

You're a *** programmer.

int rows = 10;
//2lazy2change msb to ensure postive
for (int i = 0; i < rows; i++) {
int val = 1;
for (int j = 1; j < (rows - i); j++) {
cout

First data structures learning about linked lists. Nothing real crazy so far but just programs relating to that

Is it possible to get javascript running on bare metal? I want to make a kernel in it.

Don't let your professors meme you, basic data structures are easy as fuck if explained appropriately. My professor would rant about how hard it is to intimidate everyone all the time, just know recursion well for trees.

It is possible, but you'd have to either write a compiler or design new hardware. Also, ew.

In a few years
destroyallsoftware.com/talks/the-birth-and-death-of-javascript

Linked Lists
Unbalanced Binary Trees
Graphs
Hash Table

kek why would you make a kernal in javascript?

What's a good image compression library for C#?

How would that work?

You transcompile to C?

Python question.

funNumber = 50
FunList = [funNumber]

def funMethod():
global FunList, funNumber
FunList[0] += 1

Why can't I do this? It just creates two different values from when accessed in a list and accessed by it's name. Is it possible to have this variable be consistent when accessed from inside the list and directly from the name?

>but you'd have to either write a compiler
Isn't it bloated as fuck? I can't imagine that being very easy
>design new hardware
Too hard.
When did I say that I wanted to make a "kernal"?
I don't think that can be called running on bare metal.

attempting to decipher wordpress documentation so i can use the newly absorbed wp-rest api with its new syntax

Didn't you ask whether it's possible or not to create a kernel with JS?

...

A kernel? Yes. Not whatever you asked earlier.
I just asked if I can get JS running on bare metal

I'm trying to figure out Java lambda expressions. I'm slowly wrapping my head around them but I don't really understand when to use them or their limitations. Like, can I check if a string is a palindrome just by using lambda expressions in Java? Still trying to figure it out.

>their limitations
lmao
>Like, can I check if a string is a palindrome just by using lambda expressions in Java?
if they are anything like literal lambda expressions from lambda calculus, then yes.

Of fucking course not, you retard.

why? if it's this obvious then you should have no trouble coming up with an answer, right?

Why would you declare a variable is global inside a function if you have already declared it outside of the function?

Yes. What's up?

thanks?

Do LED display normally store all the stuff they need to display in the same memory location? Cause I am dealing with an LED with a documentation I can't read.

fp is the future

It's harder to make javascript a statically compiled language. It has dynamic typing, and a bunch of other features that make it difficult to make runtime guarantees of what the machine code will look like. Modern JS engines will compile sections of code and cache them to be run whenever, but depending on how the program is written, the JIT compiler will have to recompile your shit a bunch of times.

I think having a javascript engine that runs on baremetal could work, but to make it reasonably performant, you'd need to do something to keep yourself from writing code that gives the JIT problems.

Do you mean LED, like individual lights or LED like a screen of them? The most I had to do with LEDs was code review our LED code before I knew enough assembly to understand what I was looking at. I also had to deal with some bugs coming from where LEDs used to be on our boards. Usually it's just a matter of driving them high or low as far as I've seen. This was for the blinky lights on a network switch though, so your use case might be more complex.

In any case, docs and schematics will be your best friends. It's daunting at first, but since what you need to do depends on the parts you're using and the board configuration, that's basically the only way to go about doing it.

Rate my pascal's triangle implementation!

void pascals_triangle(int iters)
{
iters += 1; /* 1 indexing */
unsigned i, j;
unsigned **arr = (unsigned **) malloc(iters * sizeof(unsigned *));
for (i = 0; i < iters; i++)
arr[i] = (unsigned *) calloc(iters, sizeof(unsigned));
**arr = 1; /* seed */
for (i = 1; i < iters; i++)
{
memcpy(arr[i], arr[i-1], sizeof(unsigned) * iters);
for (j = 1; j < i; j++) /* add */
arr[i][j] = arr[i-1][j-1] + arr[i-1][j];
unsigned k = iters - i; /* pretty print */
while (k--)
printf("%c", ' ');
for (j = 0; j < iters; j++)
printf((!arr[i][j]) ? " " : "%u ", arr[i][j]);
printf("\n");
}
for (i = 0; i < iters; i++)
free(arr[i]);
free(arr);
}

To actually answer your specific question, no, I don't think LEDs normally store the information anywhere. Unless you have a part that intelligently manages them, but thatd be beyond want I can help you with on an anonymous tibetan manuscript appreciation website.

It is one of those LED displays where you can hook up its ports to a microprocessor. The problem is I bought a cheap china one so its documentation is useless to me. Eh I guess I have to slowly figure it out. At worst, I will just drive the ports on and off with a timer.

Thanks anyway.

Does anyone know of a good test database with financial data that is free to use? Google gives me jack shit except the Northwind DB. Which is fine, don't get me wrong, but it would have been nice having something more POS-y or Project Accountancy-ish.

Yeah, I'm writing business applications. We can't all have fun jobs writing frameworks in Java. ;_;

sometimes my program crashes and sometimes it doesn't

valgrind

Learn me a Haskell
Learn you a Haskell
Real good

i feel like i should learn c now that i've become an advanced c++ programmer

Be careful that you don't end up just reinventing vtables and other parts of standard c++ when you step to standard c. It's very easy to do.

Because bare metal requires manual memory management you fucking shithead.

I see, is that why you can run lisp interpreters on bare metal? it's widely known for its manual memory management

how can someone be this retarded?

>requires
Not necessarily, as said, but manual memory management at least implies deterministic behavior. You can have it too with garbage collection, but then the GC will have to be called asynchronously, independent of timing constraints, and that doesn't fare that well with RT systems.

There are ways around it actually. If you pool objects for reuse you won't have to GC them.

Now you might say that this smells like doing most of the memory management manually and you'd be right.

But you can get around garbage collection issues for RussiaToday systems.

The reason that it works for Lisp is because the implementations do the memory management for you. Of course a JS implementation could do the same, but I doubt anyone would be masochistic enough to implement that.

I'm trying to create a jit in C for a toy language. What I'm planning on doing is this [source code] -> parser -> [ast] -> jit -> [native x86_64 opcodes].
I'm basically thinking about mmap'ing a file with the executable bit set, write the opcodes to the file, cast the file pointer to a function pointer and exec that function pointer.
I have three questions:
1) Would this work?
2) Is there a better way?
3) Where might I find a good resource in order to learn and understand x86_64 opcodes? I know next to nothing about assembler.

Learn Go:
tour.golang.org





>inb4 YOU MEAN HASKAL

Just converted several simple-and-elegant recursive functions to messier iterative versions.

I realized some non-toy datasets could make my recursion a couple hundred million calls deep which made me nervous.

>a couple hundred million calls deep
that isn't much

>2016
>not writing functional assembly

I'm new to all of this, trying to get started doing some Data Analysis using Python. I'm running macOS and trying to setup a development environment. All I want is something simple; write Python scripts using Vim through the macOS Terminal

Everything was working fine, I was following a video to write my first script, but for some reason Python doesn't seem to be picking up that I've installed packages (scikit-learn).

So I installed Python using Homebrew, but I'm pretty sure it comes default installed on macOS anyway. I couldn't install pip using Homebrew, didn't want to cooperate, so I Googled it and used some 'easy_install' shit through terminal and it worked. Then I had to run 'sudo pip install XYZ' to get it to work and it seems that the packages all got placed in the right directories from what I saw; /Library/Python/2.7/site-packages is where it's located on macOS.

So all the packages I've installed are there, python --version yields that I'm running 2.7.13, so why the fuck when I try to run a script will it spit out an error on the first line "from sklearn import tree" ??

Maybe I'm running the version of Python that I installed using Homebrew and these packages installed to the version of Python that were default loaded into macOS? Is there anyway I could check that or switch it?

All this package management shit is a little confusing to a noobie; not sure where to find some clear info on where a package gets installed, where its config files are placed, etc, etc

>Python
>macOS
Stopped reading right there.

i can help, first answer a question: are you from reddit?

clang-analyzer.llvm.org
It's great.

Also the way you put this makes me think you're not running through a debugger with debug symbols. Which is bad.

ONE WORD: THE FORCED INDENTATION OF CODE

user I suggest you do this thing where you Google for people with the same issues.
For instance:
stackoverflow.com/questions/15274696/importerror-in-importing-from-sklearn-cannot-import-name-check-build
There's no rhyme or reason for why that'd fix the problem but do you really care?

macOS is all I've got to work with at the moment; it's what I've got and it works

As for Python, the University course I'm doing is teaching using a mixture of Python and R; not really my decision. I'm pretty sure Python is used a fair bit in the Data Science industry as well seeing as they are more Statistically & Mathematically trained and programming is seen as more of a tool to get shit done, not really the sole focus
There's not really any clear answer on that page?

Reading around a little more I'm almost certain I've fucked something up with different installs of Python everywhere. Apparently when you install Python using Homebrew (OSX package manager) it comes with Pip. But then me going and using the "easy_install pip" shit installed pip onto the versions of Python outside of Homebrew.

So now it seems I'm running the version of Python (2.7.13) I got from Homebrew but pip is installing packages outside of that version.

why did you reply to me if you didn't even answer my question?
i know how to solve your problem but first I need to know if you're from reddit.

Friendly reminder that video game programming is the highest form of programming.

>Data Science industry
is this thread a "Data science industry" thread or a programming thread? Python isn't programming and shouldn't be even mentioned here.

neg
my bad, forgot how elitest these threads are

yeah, keeping the discussion on topic is so fucking elitist. i can't even

>neg
post a singular anime image and i shall judge it

TCO.

Can someone give me an explanation on lambdas? I'm a retard, so keep it simple.

his shitlang probably doesn't have it.

anonymous functions

could i be causing heap corruptions because i'm using c libraries in a c++ program? my program isn't super complicated and i'm cleaning everything up but for some reason, it crashes sometimes, for no apparent reason, complaining about a heap corruption.

>i can't even
It's this cunt you should be hanging to dry, not me

I asked a question relating to programming, as a beginner; and because I wasn't using Arch 'holdonmumjustfixingmyosi'llsayhitodarrensoon' Linux or writing programs in fucking Binary I didn't get an answer. Seems a little elitest to me. Not to mention 'Data Science' used to just be a more Statistically trained Computer Scientist until the recent big data meme
>2d girls

If you're using them incorrectly, yes.
Run a memcheck (e.g. valgrind) it will detect when anything goes out of bounds.

as i thought, you are indeed from reddit.
you can return to your shitty website now.

Simpler please, I'm a beginner.

This is pretty much it: Imagine you did this:
def add(x, y):
return x + y

This would bind a function to the symbol 'add'.
Lambdas are functions as normal, first-class values, like so:
one = 1 # assigning a symbol an integer value
add = lambda x, y: x + y # assigning a symbol a function value

The 'point' of lambdas in languages that have adopted them (rather than being based on them) is that you can 'use' functions without giving them a name. Hence 'anonymous functions'. Here's an example:

student_tuples = [
('john', 'A', 15),
('jane', 'B', 12),
('dave', 'B', 10),
]
sorted(student_tuples, key=lambda student: student[2]) # sort by age:
# [('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]

do you know what a function is?
do you know what "anonymous" is?
combining these two concepts gives you an anonymous function aka a function with no name.

Dude, I agree with you, but for God's sake learn to spell 'elitist'. They'll eat you alive.

I'm traversing graphs and do a shitload of branching so it's not really applicable.

No, I use C#, is it the same as a method? Why would you use an anonymous method; are lambdas used for methods only appearing once in code?

Just not a big fan, I've got a few that I've taken a liking to though, rejudge?
>pic
My bad, will correctly spell it next time

looks like an image straight from reddit. you can't fool me.

obviously meant for

How do I make a switch menu so that each choice either creates an user file, deletes it, or makes text edits in it, without having to write 200 lines of code in each case?

Seems like you're the new one here

:^)

i didn't claim i wasn't new. i'm from about 2011-2012.
the more important thing is that i'm not from your website.

You seem pretty adamant on painting me as a leddit user, got something to hide, friend?

Pls answer

>You seem pretty adamant on painting me as a leddit user
which you are. just a quick look at the images you post confirms this beyond any reasonable doubt. there's also your comment about anime, but that's just additional evidence.
even if you don't watch it (which already places you pretty high on the plebbit scale), you can't possibly be a non-redditor if you don't have some anime images with older file names on your hard drive. this is just not possible.

yes sir king of Sup Forums sir, i will never disrespect you like this again sir

sir, it is my upmost priority that you keep this elitist board the way it SHOULD be

thank you sir

so here we are. you have revealed yourself, pleb.
i would have you shot and thrown into a ditch, but i am ready to pardon you if you can provide me with a non-reddit anime image.

reread my post. i said "non-reddit". or did that website rob you of every last bit of brain power you had?

How about neither?

...

it seems like you are utterly incapable of following even the simplest instructions. maybe you should write a python """""""program""""""" to help you with that?
is this thing contagious by the way? you should really leave if that's the case. i don't want your kind infecting my fellow countrymen.

...