/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

udacity.com/course/new-android-fundamentals--ud851
twitter.com/SFWRedditImages

What's the most conceptually interesting thing you guys have worked on?

A distributed hardware, software, and network resource abstraction layer. It's just a decentralized remote desktop session with some extra features taped on. Cant do more that 4 clients yet, don't even have keyboard/mouse integration working. Thinking I might give up. Im overengineering a solution that doesnt have a problem.

so, a cluster with ltsp on top?

Any recommendations for a .NET compatible GUI framework? Something minimal, I don't want to spend weeks learning something like WPF when all I need is a basic interface.

Reminder that do notation needs to be generalized.

When you have the statements x >= (\x -> bar x). Wouldn't it be better if the continuation passing style was focused on instead of limiting it to monads? Instead, those statements would be translated to foo (\x -> bar x). To recover monad syntax, use bind :: Monad m => m a -> (a -> m b) -> m b: x

Why the fuck are you all stupid plebs?

>baby's first dev board

At least it's not blinky.bin

Yes, I think everyone agrees
use rebindable syntax

Also sequencing in do notation should be seperated from continuation passing.

>implying first
it is an attiny13 running a hd44780 with a shift register. Programmed in pure C. Wasn't as easy as it sound though.
Runs at ~800 bytes atm

>use rebindable syntax
Huh, I suppose you can just define >>= to be application. Never thought of that.

>Also sequencing in do notation should be seperated from continuation passing.
Continuation passing IS sequencing.

e.g.

class Sequence a b | a, b -> c where
(>>) :: a -> b -> c
class Continue a b c | a, b, c -> d where
(>>=) :: a -> (b -> c) -> d

and

instance Applicative f => Sequence (f a) (f b) where
(>>) = (*>)
instance Monad m => Continue (m a) a (m b) where
(>>=) = (M.>>=)


Or perhaps even better, we could go even further beyond

continuation -> arrow

Not all sequencing is continuation passing

See this overly posted image for an example.

>Wasn't as easy as it sound though.

Sure it was. Now, hook up a ROM chip loaded full of pixel porn if you want to impress us.

And another way of doing this, with continuation passing, would've been to have added an extra type parameter, and make all of those cutting actions to be (some specific m) Monad m => m (), and then add Pure.

But it's unnecessary, and you don't always want people to be able to put functions into your data type

I can't think of a single justifiable reason that that would require anywhere near 800 bytes of code.

Very true, sometimes you might want only >> and not >>=.

The webm converters on gentoo wiki didn't work for my computer, so I used python and tkinter to make my own GUI to send commands to ffmpeg

I'm finally making programs that are useful (to me)

>mfw no definition of what scripting language is
>mfw can't shittalk at those, who make big program systems in scripting languages just because you can't definitely say is their programming language actually scripting language

>not invoking ffmpeg directly
you will not survive the academy

Your mom's a scripting language

sorry that was rude

Assembly is a scripting language. You're just writing a bunch of mnemonics that call microcode on the CPU.

is this enuff? :(
FUCK YOU'RE MOM YOU STUPID NIGGER

If I ask you guys to help me with [spoiler]my homework[/spoiler] will that be okay or should I just fuck off back to /sqt/?

Make a calculator

I'm not seeing any big ole anime tiddies on there

you can do fizzbuzz you'reself, m80

Forgot spoilers don't work on this board.

Is PyQt shit?

Fizzbuzz for homework? I'm not so sure I've heard that one yet.

Kill yourself, shit stain.

...

CPU doesn't execute raw mnemonics, they get translated into binary.

Wow, it's almost like you managed to define the "mnemonic" in "mnemonics"!

CPU doesn't execute raw binary, they get translated into electrical signals

this
>implying binary actually exists at a low level
HIGH and LOW are just an abstraction

>HIGH and LOW are just an abstraction
No

>binary doesn't actually exist

Then explain decapping. You can actually see the bits under a microscope.

It's more like high/low are only good as relative quantifiers, not absolute.

No, you are 100% wrong.

void fn() {
int x[128];

for (int i = 0; i < 128; i++) {
if (x[i]) return 1;
}

return 0;
}


Is this guaranteed to return 0 in C?

A Perl script to AutoTag all my music files and update Album Art from CoverArtArchive

It seems WM_NC(L/R)BUTTONDOWN just blocks until the event ends. I found you can get the clicked object by passsing WM_NCHITTEST into DefWindowProc. I'm just blocking right clicks to the title bar, allowing left click on maximize/minimize/close to go through, and re-implementing window dragging myself with clicks to the title bar.

It wasn't exactly what you said, but it did lead me to the answer so thanks for the help. This is a problem I've had for a long time and I'm glad to have a real solution.

No. all of x is uninitialised, so all you're reading is garbage. Maybe it'll be 1, maybe it'll be 0, but really, it's undefined behaviour.
If you want to zero initialise an array, do this:
int x[128] = {0};
Also note that you're trying to return a value from a void function.

They're right, you idiot.
"High", "Low" and their tolerances are whatever the hell you define them to be.
You really need to learn some basic electronics.

AoC day 9 is being a bitch.
How do I decompress 10GB worth of data without actually storing any of it?

I don't have that much ram.

I'm not following the advent of memes or whatever, but I suppose I'll look at it.

Why do you even need to store anything? You only need to get the length of the output.
When you come across one of the markers, just calculate the length it would take, then jump forward.

In part 2, you're also supposed to keep expanding any markers that were duplicated by previous markers.
If I just keep multiplying the length and adding it, It won't come out to anywhere near 10GB.

any of you lads ever design your own lang

>part 2
Does this unlock or something when you submit the first solution?
I have no intention of signing up to this site to find out.

>he doesn't know how to return void literals

I64 Cnt(I64 n)
{
I64 i;
for(i=0;i

in haskell this is just

cnt _ = 0

doh!! I meant return n;

int main() { return 0; }

int main() { }

> C++

Are you one of those non-free javascript autists?
You sound like one.

Part 2 unlocks once you finish the original puzzle.
It basically punishes you for terrible program design if you tried to take the easy way out with the first part, like for example, blindly counting numbers and not actually simulating what they represent.

okay
Class Main { public static final void main(String[][] theArgs) { return void; } }

>non-free javascript autists
what does this even mean

daily haskell nigger thread

watch each of your queries receive a tangential response that always relates back to haskell, no matter what language you were discussing initially

main = pure 0

Are you one of those proprietary javascript autists who needlessly slaps social media and other shit onto every website?
You sound like one.

nice timing

You don't have to be so bitter.

Anyways, I just set it to auto-truncate every million iterations.
It should take about 3 hours to finish.
I'm going to bed~

>It should take about 3 hours to finish.
Jesus christ, I don't know exactly what you're doing, but it's completely wrong.

pls dont bully
size_t decompress_v2(char **loc)
{
char *arr = *loc; /* realloc */
size_t i, j, length = 0;
for (i = 0; arr[i]; i++)
{
char *next = strstr(&arr[i], "(");
i = (!next) ? strlen(arr) : (size_t) (next - arr);
if (!arr[i]) break;

/* extract and parse marker */
unsigned dist, iters;
for (j = 0; arr[i + j] != ')'; j++);
j += 1; /* catch last parens */
char *mark = (char *) malloc(sizeof(char) * j + 1);
memcpy(mark, &arr[i], j);
mark[j] = '\0';
memmove(&arr[i], &arr[i + j], strlen(&arr[i + j]) + 1);
sscanf(mark, "(%ux%d)", &dist, &iters);
free(mark);

/* extract region from string and copy back */
char *cpy = (char *) malloc(sizeof(char) * dist + 1);
memcpy(cpy, &arr[i], dist);
cpy[dist] = '\0';
memmove(&arr[i], &arr[i + dist], strlen(&arr[i + dist]) + 1);
unsigned inserted = dist * iters;
arr = (char *) realloc(arr, strlen(arr) + inserted + 1);
for (j = 0; j < iters; j++)
{
memmove(&arr[i + dist], &arr[i], strlen(&arr[i]) + 1);
memcpy(&arr[i], cpy, dist);
}
free(cpy);
if (i > 1000000) /* truncate */
{
length += i;
printf("v2 length: %zu bytes\n", length);
size_t trunc = strlen(&arr[i]);
memmove(&arr[0], &arr[i], trunc + 1);
arr = (char *) realloc(arr, trunc + 1);
i = 0;
}

}
*loc = arr;
return length + i;
}

Post a screenshot of part 2. I want to try and solve it.
What you're doing there seems needlessly complicated

Read chunk
Decompress chunk
Write chunk
Repeat for next chunk

...

Disgusting.

Can you also pastebin the input or whatever?

do it yourself

How the fuck do I get
Symbol: Open: Close:
___________________________________________
BAC 13.20 13.38
PFE 28.11 28.26
S 7.34 7.24
MRK 48.60 48.19
GE 23.38 23.86
CSCO 24.55 24.49
MSFT 34.96 35.67
F 15.44 15.73
INTC 24.65 24.59
MS 25.41 27.00


to show me which one of these lines gained value or lost value in Python

>he doesn't know how to parse CSV
kys cuck

>parse CSV
show me fampai

To extend on this:
Symbol: Open: Close:
___________________________________________
BAC 13.20 13.38
PFE 28.11 28.26
S 7.34 7.24
MRK 48.60 48.19
GE 23.38 23.86
CSCO 24.55 24.49
MSFT 34.96 35.67
F 15.44 15.73
INTC 24.65 24.59
MS 25.41 27.00


needs to show up like this:
Symbol: Change: Change(%):
__________________________________

Gainers:
BAC +0.18 +1.36
PFE +0.15 +0.53
GE +0.48 +2.05
MSFT +0.71 +2.03
F +0.29 +1.88
MS +1.59 +6.26

Losers:
S -0.10 -1.36
MRK -0.41 -0.84
CSCO -0.06 -0.24
INTC -0.06 -0.24


I've tried splitting the entire line into an array
I've tried using dictionaries
Nothings really working out...

im writing a compiler using Bison and trying to get the ternary tree for the parsed code up and going, but then i got to this bit
FOR IDENTIFIER IS expression BY expression TO expression DO statement_list ENDFOR


is the correct solution to split this into two clauses (one for the loop head, one for the body), or to expand the tree nodes to fit the number of arguments?

Ok, here is my entire solution. I don't have the input data, so I can't give the answer, but it works for their examples.
It's a bit light on the error handling, but I don't think it's that important for code like this.
Also note, it's likely that your text editor will add a newline at the end of your input file, which may make the length be 1 bigger than it's supposed to be. Turn automatic newline off in your text editor.
#include
#include

#include
#include

regex_t re;

int length(size_t len, char str[static len + 1])
{
int n = 0;
char saved = str[len];

/* Null terminate substring, to stop regexec looking too far */
str[len] = '\0';

for (char *ptr = str; ptr < str + len;) {
regmatch_t m;

if (regexec(&re, ptr, 1, &m, 0) == REG_NOMATCH) {
n += str + len - ptr;
break;
}

/* String leading up to marker */
n += m.rm_so;

int num_chars, repeat;
sscanf(ptr + m.rm_so, "(%dx%d)", &num_chars, &repeat);

int sublen = length(num_chars, ptr + m.rm_eo);

n += sublen * repeat;
ptr += m.rm_eo + num_chars;
}

str[len] = saved;
return n;
}

int main(int argc, char *argv[])
{
if (argc != 2) {
return 1;
}

FILE *fp = fopen(argv[1], "rb");
if (!fp) {
perror(argv[1]);
return 1;
}

fseek(fp, 0, SEEK_END);
long len = ftell(fp);
fseek(fp, 0, SEEK_SET);

char *str = malloc(len + 1);
fread(str, 1, len, fp);
str[len] = '\0';

regcomp(&re, "\\([0-9]+x[0-9]+\\)", REG_EXTENDED);

printf("%d\n", length(len, str));

regfree(&re);
free(str);
fclose(fp);
}

I have a game, and in this game multiple classes have collision functions, each of which uses ~10 mega flops of computing.

How would I use multi threading to make this more efficient? Can I create a threaded class which has half of these calculations sent to it, and have it return the values?
All of the classes need to be able to send values back and forward
I'm using Java btw

>multiple classes have collision functions
That's the wrong way to do collision.
You want a single quadtree (or similar data structure) and do all of your collision calculations from that.
Damn OOPfags.

Also, I forgot to mention:
I assume you're doing 2D. If it's 3D, shit gets more complicated.

Happy to have helped.

You decided to do OOP (probably).
Best re-learn programming before you go any further.

>each of which uses ~10 mega flops of computing.
This is per function right? Why are all your classes collision functions used equally? Why are you measuring that and not what an individual iteration takes on average and worst/best case?
Why are you not measuring what you'd expect the computation to take in cycles?

I assume Box2d has its own quadtree, if it does, I'll rewrite my code and create sensor objects
But there doesn't seem to be any documentation on this

Currently working on r/dailyprogrammer challenge #294.

"Today's challenge is inspired by the board game Scrabble. Given a set of 7 letter tiles and a word, determine whether you can make the given word using the given tiles."

>inb4 reddit i suppose

>i suppose
I wonder who could be behind this post

Theres collision detection being done in Box2d, and some being done in liquidfun. I have no idea how many flops it takes to do this.

Theres also a bunch of functions that are only called under certain conditions etc. It's not a standard platformer with 100 rectangle objects, so I can't easily quantify the total flops for the collisions

My name is actually Brett Keane, from God-TV Radio, make sure you check out my gaming channel (gamesUlove), and subscribe to me on youtube.

I am going to learn Android development.
Is the udacity course good?
udacity.com/course/new-android-fundamentals--ud851

Or do you have any other suggestions on where to start of learning Android that's better?

>so I can't easily quantify the total flops for the collisions
Well user I'd say you need to put yourself to work to learn to profile your code before you aim to optimize.

Trying to fix something from a broad overview of the performance of the situation just doesn't get you much since you don't know where to focus your effort.

You have to know the problem before you solve it.

...

...

...

Why the fuck wont it update the database

You wrote it in Java.

type Scrabble = ExceptT () (State String) ()

stricken :: Char -> Scrabble
stricken c = do
b String -> f Char -> Bool
check tiles word = run (mapM_ stricken word)
where run = isRight . flip evalState tiles . runExceptT

building a remote for muh EOS700D

gonna make it wireless with either 433mhz receivers or nrf24l01 modules not sure.
Prolly the latter ones. A little bit overkill, but wanna get used to em