/dpt/ - Daily Programming Thread

What are you working on?

Previously...

Attached: Blue Book.jpg (320x240, 12K)

Other urls found in this thread:

github.com/ayojs/ayo/pull/100
pastebin.com/uudTAtBH
pastebin.com/fV87m0kp
coursera.cs.princeton.edu/algs4/assignments/8puzzle.html
twitter.com/SFWRedditGifs

making a meme voice assistant using gTTS
it's cute
current commands are say and search, which just opens up your query in your favorite web browser

Any command recommendations?

Previous thread won't die for hours (page 2). an hero, OP

Attached: 27574001_1776208186022137_171885183891406848_n.jpg (480x480, 57K)

My assignment requires doing something we weren't taught to do help
I've never had to work with a function with multiple parameters, I barely even have experience with single-parameter functions.

Attached: Capture.png (589x172, 8K)

why would the number of parameters matter if you understand what a parameter is, you retard?

today finished up the 8 Puzzle assignment for Robert Segdwick's algorithms course on coursera

Attached: file.png (984x1060, 246K)

what is your question concretely

How check if T is instance R to return an empty stream if it is not else make a stream out of T and return it?

github.com/ayojs/ayo/pull/100

I feel like I could do... just about anything.

Attached: perl-6.png (512x512, 32K)

>if (maybeRecentState.isPresent() ) {
SearchNode recentState = maybeRecentState.get();

just use ifPresent

Be useful nigger.

Does anyone here even make a living off programming?

then i cant break out of the loop as easily tho

i do

I giggled, thanks

How can you expose variables as a file like the kernel settings on linux in C?

FUSE

Quick wrote a 14 line Fibonacci generator in Python. Trying to make a game out of those 14 lines. The idea is to type in as many steps of Fibonacci as you possibly can without messing up. If you do, the game ends.

Attached: 20171207_172912.jpg (896x1070, 512K)

i think you need to use the java reflection api

then refactor the loop into a stream :-)

delete this picture, nobody wanna see faggot men, only 2d girls allowed

Attached: 1468270963923.png (409x513, 266K)

Basically, I'm retarded, and what is the simplest way to pass a variable from an adapter to an activity. I'm using getAdapterPosition to set the value, and then I want to use it in the activity, but I don't know how to pass it and I feel like I shouldn't be having so much trouble with this simple task. I was going to just add a basic getter to the adapter but I can't call it from the activity

Attached: android-robot-holding-human-brain-3d-illustration-isolated-contains-clipping-path_1401-557.jpg (626x569, 50K)

can i map over an iterable if the function that map executes is adding items to the iterable?

i think this would just make my code harder to understand desu

you can unless you have 2 objects

can't

Type erasure and can't reflect over generic params of a method (can do that on the class but that is not relevant).
I am supposed to be getting a bunch of unknown objects and filtering them using a static generic method based on whether they are of type R or not.
Could have used fucking streams on a list of Object but fffs.

wait wouldnt you just do

```
public static Function isInstanceOf(Class clazz) {
return new Function() {
@Override
public Stream apply(T t) {
if (t instanceof clazz) {
// stuff here
}
}
};
```

how do i properly embed code here

Fucking newfag

STICKY
T
I
C
K
Y

Wrap it in [code ] [/code ] tags.

Without the spaces after the e’s

public static Function isInstanceOf(Class clazz) {
return input -> Stream.of(input).filter(clazz::isIntance).map(clazz::cast);
}

something like this?

i should learn2streamsapi

public 󠇦static 󠇦 󠇦Function 󠇦isInstanceOf(Class 󠇦clazz) 󠇦{
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦return 󠇦new 󠇦Function() 󠇦{
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦@Override
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦public 󠇦Stream 󠇦apply(T 󠇦t) 󠇦{
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦if 󠇦(t 󠇦instanceof 󠇦clazz) 󠇦{
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦// 󠇦stuff 󠇦here
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦}
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦}
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦};
}

hand-labeling 2k images for training a convolutional neural net

>functional interface
>anonymous class
never do this

Don't trust mturk to do a good job?

I need to come up with a list of concepts used in "lazy programming" for a homework. From what I looked up it doesn't seem like "lazy programming" is a thing, so maybe they meant to say lazy evaluation and related stuff. I guess one concept would be the lazy evaluation itself, another one could be memoization, but what else is there? Tell me a bunch of buzzwords that are akin to these so I can look them up and write a bullshit paper.

>public 󠇦static 󠇦 󠇦Function 󠇦isInstanceOf(Class 󠇦clazz) 󠇦{
>󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦return 󠇦new 󠇦Function() 󠇦{
>󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦@Override
>󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦public 󠇦Stream 󠇦apply(T 󠇦t) 󠇦{
>󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦if 󠇦(t 󠇦instanceof 󠇦clazz) 󠇦{
>󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦// 󠇦stuff 󠇦here
>󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦}
>󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦}
>󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦};
>}

Teach me your dark magic

never heard of it. going to check it out

>Teach me your dark magic
Never.

Attached: smug_laugh.png (782x1021, 330K)

actually if anyone was willing to provide code review i'd be really appreciative

pastebin.com/uudTAtBH
pastebin.com/fV87m0kp

coded for the following assignment coursera.cs.princeton.edu/algs4/assignments/8puzzle.html

>jaba
There is your review.

It's Java, I forgot to mention.

his code is actually really shit

>It's Java
Isn't that Java?

command to open porn site with most frequently browsed tags.

yes it is

jesus fucking christ you've JS'ized Java.
That's fucking horrendous.

󠇦 󠇦 󠇦 󠇦 󠇦N
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦O
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦T
󠇦 󠇦 󠇦 󠇦 󠇦D
󠇦A
R
󠇦 󠇦 󠇦K
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦M
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦A
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦G
󠇦 󠇦I
C
󠇦 󠇦J
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦U
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦S
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦T
󠇦 󠇦 󠇦U
N
󠇦I
󠇦 󠇦 󠇦 󠇦 󠇦C
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦O
󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦 󠇦D
󠇦 󠇦 󠇦 󠇦E
#include
#include

int main(int argc, char **argv)
{
int i, q = 5, t = 0;

for (i = 0; i < argc; ++i) {
int c;
char *s;

s = argv[i];

for (c = 0; s[c]; ++c) {
int n, ind;

ind = sin(t) * q + q;

for (n = 0; n < ind; ++n) {
printf(" \xf3\xa0\x87\xa6");
}

printf("%c\n", s[c]);

++t;
}
}

return 0;
}

Employed Haskell programmer here

Attached: 1474325315193.jpg (636x616, 44K)

Ahh, I see.
As real as an anime girl.

so you work at mcdonalds and do haskell as a hobby?

are you real

Attached: dunecat.jpg (439x392, 30K)

No I'm integer

Streams.
You could write about the Normal Order Y Combinator and the lambda calculus definition of IF and AND.
Difference Lists work by delaying evaluation, creating a continuation of sorts.

Lambda Calculus and System F are traditionally evaluated lazily.

Laziness is added to eager languages by creating zero argument lambdas.

Buzzwords used in languages which happen to be lazy? Monad/Functor, Effect, Thunk, Closure, Pattern Matching, Unification (aka muh equational reasoning)

how is haskell?

C# master race

for((int i, char c, string s) = (0, 'a', "a"); i < 100; i++) {
// code here
}

Reminder that man pages for the C++ STL come with GCC.

is there a better way to return a decimal from binary hardware switches on an Arduino?
uint16_t dip2int() {
int value = 0;
if (digitalRead(dip[0]) == LOW) { //dip ON is low because INPUT_PULLUP
value = value + 1;
}
if (digitalRead(dip[1]) == LOW) {
value = value + 2;
}
if (digitalRead(dip[2]) == LOW) {
value = value + 4;
}
if (digitalRead(dip[3]) == LOW) {
value = value + 8;
}
if (digitalRead(dip[4]) == LOW) {
value = value + 16;
}
if (digitalRead(dip[5]) == LOW) {
value = value + 32;
}
if (digitalRead(dip[6]) == LOW) {
value = value + 64;
}
if (digitalRead(dip[7]) == LOW) {
value = value + 128;
}
if (digitalRead(dip[8]) == LOW) {
value = value + 254;
}
if (value == 0) {
value = 1; //because address 0 is reserved
}
return value;
}

Attached: file.png (412x429, 64K)

I have several years work experience and a senior engineer title. What should I expect for job interviews when I start looking for a new position? Do I need to relearn all the CS fundamentals that I never use in my job?

for (int i = 0; i

Yup.
Because in each case (except dip[8]) you essentially do 2^(number-in-index), you could do the following:

for(int ind = 0; ind < 8; ind++)
{
if(digitalRead(dip[ind]) == LOW)
value += (1

No.

Generally senior roles don't ask too much questions.

IT's like acting.

When you start, you have to do a lot of auditions.

After a few years in the fields, you just get roles directly.

In Haskell, if I have a complex exponential data type that has as parameters a magnitude and a phase, and if I want to implement the absolute value function such that it returns just the magnitude, how would I do that?

The type signature for abs is
:t abs
abs :: Num a => a -> a


But what I want is essentially
abs :: (Num a, Num b) => (ComplexExp a b) -> a
abs (ComplexExp mag phase) = mag


When I try to do this, I get the following error:
Couldn't match expected type ‘ComplexExp n1 n2’
with actual type ‘n1’
‘n1’ is a rigid type variable bound by
the instance declaration at EE.hs:23:10
• In the expression: mag c1
In an equation for ‘abs’: abs c1 = mag c1
In the instance declaration for ‘Num (ComplexExp n1 n2)’

>Haskell
?

Thanks, why did I not think about that?
(don't answer, I know why)

Attached: lDKQ4R7.jpg (312x560, 59K)

>abs
engineer detected. You want a norm my nigga which would have a type of anything to a positive number. Not sure how to describe that type in haskell.

useless, encourages unreadable code, but neat nonetheless

return value ? value : 1; // value ? : 1; with gcc extensions


You can also use a logical OR instead of an ADD (and you should) as it will generate better assembly.

Don't sweat it. Bitwise operators are hard, and it's not immediately clear when/where to use them.

>abs vs norm
I mean, abs is just the L2-Norm, right?

This is what the norm function should look like:
norm :: (Floating a) => a -> a-> a-> a
norm x y l_val =
sum ** (recip l_val)
where sum = (x ** l_val) + (y ** l_val)


So I'm just having trouble seeing how I'd apply this to a complex exponential, as they already have the magnitude within it (so I don't need x/y values)

ub

k

I knew it when I was typing my post
answer is 'no'

Attached: cortana.jpg (640x760, 53K)

what fucking compiler are you using where any non-zero integer doesn't evaluate to true?

or are you talking about
value |= 1

It's not what it should look like. Norm formally is just a generalization of length on a vector space which is not limited to numbers. You can take norms of functions.

what are some programming interview questions you've received?

Given a string of open and close parenthesis, determine if it is valid or not, and if it is not, make it valid by removing close parentheses.

e.g.
(()()) -> valid
(()) -> valid
())() -> invalid
(()())(()) -> invalid

Given a string of parenthesis, square brackets, and curly braces, determine if the string is balanced or not.
e.g.
([]{}) -> valid
(([{}{}])) -> valid
{([})] -> invalid

>(()())(())
>invalid
#;1> '(()())'(())
(() ())
(())

works on my machine

I typed it out not really paying attention, sorry

So were you supposed to code solutions to these? If so, what kind of job were you applying for where they wanted to see whether you knew your context free languages?

Reverse a string, design a UML, do Fibonacci, refactor some code.

kotlin?

"no"

Yeah. First was from Facebook, second was from Riot Games. Don't read too far into the problems, they are just meme "can you program more than fizzbuzz?" problems.

i want to make a mid-long text based game in c++ for my friends community, but i dont remember most things how should i do it, so do you know any tutorial/guide to help me with this lil shit?

Make a directed graph where each scenario is a node and each edge coming out of that node is an option the player can select. Add side effects to edges and a player state for extra fun.

Making a minimalist 2D MMO. Ask me anything.

Attached: autism-training-for-education-professionals850x450Web.jpg (850x450, 79K)

What are you using?

why are you wasting your time?

He might be having fun, user.

- Meteor for sockets
- Webgl for graphix
- hosting on a vultr vps

You know we hate webdev/js here, right?

this desu. it's not going to make any money

You think I care? And who is this "we"?

Ahh ok. Decided to do this the old fashioned way anyway even though I wrote a parser I can use. Might as well make sure I can get hired to facebook.

(define (fix-parens parens)
(let loop ((stack '()) (parens parens))
(if (null? parens)
'() ;don't care about excess ('s
(case (car parens)
((#\() (cons #\( (loop (cons #\( stack) (cdr parens))))
((#\)) (if (null? stack)
(loop stack (cdr parens))
(cons #\) (loop (cdr stack) (cdr parens)))))))))

(define (check-brackets parens)
(define (matching? op close)
(eq? op
(case close
((#\)) #\()
((#\]) #\[)
((#\}) #\{))))
(let loop ((stack '()) (parens parens))
(if (null? parens)
(null? stack)
(case (car parens)
((#\( #\[ #\{) (loop (cons (car parens) stack) (cdr parens)))
((#\) #\] #\})
(cond ((null? stack) #f)
((matching? (car stack) (car parens)) (loop (cdr stack) (cdr parens)))
(else #f)))))))


I knew a guy who did that (in VB.Net).

Yes
The majority of /dpt/ posters
Have fun with your project

If you started writing lisp, I don't know how they'd react. Very neat.

you guys i'm gonna fucking lose it. i have to program some shit. it's not even hard shit. but my teammates said something discouraging yesterday about the scope of the project and i let it get to me. i could just knock it out easy as pie if i could just focus on it, but i'm so full of anxiety now that i can't function at all. i'm gonna go buy junk food and get fucking fat because i'm so stressed that i can't imagine any other respite but food. wat do. wat fuckin do. i'm losin it boyos help

>Norm of functions
Wait, what?
I thought norm only applied to vectors? Or can you have vectors of functions?

And just out of morbid curiosity, how would you write the generalized norm function.

Take a windowed average (ie, if the window size is 5, take the running average of the first five numbers in the sequence, and after that, limit the window to five numbers). Once you do that, make it O(n)

I mean, not that my words will be of any help, but don't ever let other people discourage you. You know if you're a good programmer or not.
If you are, congrats! Then your teammates were just being jerks.
If you aren't, then you know there's room for improvement. And what better way to improve than by proving your teammates wrong?

I believe in you, user!

Attached: magnificent.png (217x251, 88K)

where the fuck do I learn C? any good books?