/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: 187719974_e41592d388_z.jpg (375x500, 110K)

Other urls found in this thread:

github.com/cfenollosa/os-tutorial
osdev.org/
hackage.haskell.org/package/stm-2.4.5.1/docs/Control-Concurrent-STM-TVar.html
en.cppreference.com/w/c/thread
calver.org/
stackoverflow.com/questions/6062191/f-getting-a-list-of-random-numbers
wiki.haskell.org/Simple_StateT_use
prng.di.unimi.it
hackage.haskell.org/package/MonadRandom-0.1.3/docs/Control-Monad-Random.html
repl.it/repls/
repl.it/languages
twitter.com/SFWRedditGifs

Actually it's GHC/Haskell

Attached: 1537198279816.png (663x801, 174K)

Some typescript and vue.js so I can convince my boss we can stop writing untyped js like it's fucking 2014

Attached: 1537378172918.png (849x1200, 1.58M)

>no Belle Delphine OP pic
fuck outta here

sigh

excellent taste in 2d women user
good luck with the types

Attached: 1491582807006.png (298x293, 137K)

how do I into OS design

also, how do I am I supposed to allocate memory, broadly speaking. If I'm linking a binary for a flat address space of xMB, how can I get a pointer to the start of memory not occupied by the binary + the free space's size. or just any other way to gain access to the rest of the memory on the system.

Reading Type Driven Development with Idris. I'm too tired to program, so I'll leave that for tomorrow.

github.com/cfenollosa/os-tutorial

>How to create an OS from scratch

currently thinking about how to render foliage properly
method 1:
the "regular" way by using big static meshes. ue4 uses this method
downside: massiv cpu overhead because of the need for culling.

method 2:
purely gpu based. provide a bitmap density map and create some foliage in the geometry shader and simply draw it onto the visible geometry. outterra uses this method.
downside: didnt use it yet and dont know about the performance. low diversity of foliage

method 3:
provide meshes for a single instance of the geometry and a density map. instead of creating foliage in the geometry shader simply utilise the provided ones.
downside: performance?

anyone with some experience in this? seems really fucked if you want nice diverse, dense foliage that moves in the wind.

Attached: file.png (1600x900, 2.49M)

shut your prescriptivist mouth

ghc is the only decent general-purpose implementation of haskell with language features that everyone uses but aren't included in haskell itself yet

Good luck friend.

I dont really like typescript, but it sounds fitting and interesting to pair it with vuejs. Do you like it? Do they work well together?

>What are you working on, Jow Forums?
Making another "release" of a personal project (tag on GitHub/GitLab with binaries attached). I'm the only user, but I guess it's good practice?

osdev.org/

Can I vent a little and ask for some guidence?

I am trying to make two processes communicate with each other. One of which is a Haskell program I made. While I love function programming languages and ML syntax, Im kind of a Haskell scrub. I decided to look into making a webserver in Haskell I could connect to locally. One of my project requirements is that the Haskell webserver has state and persists certain information between http requests.

I know its inherently frustrating to learn new stuff, but god damn is Haskell confusing. Look at this example code for scotty, one of the most popular Haskell webserver frameworks
{-# LANGUAGE OverloadedStrings, GeneralizedNewtypeDeriving #-}
newtype AppState = AppState { tickCount :: Int }

instance Default AppState where
def = AppState 0

newtype WebM a = WebM { runWebM :: ReaderT (TVar AppState) IO a }
deriving (Monad, MonadIO, MonadReader (TVar AppState))

webM :: MonadTrans t => WebM a -> t WebM a
webM = lift

gets :: (AppState -> b) -> WebM b
gets f = ask >>= liftIO . readTVarIO >>= return . f

modify :: (AppState -> AppState) -> WebM ()
modify f = ask >>= liftIO . atomically . flip modifyTVar' f

main :: IO ()
main = do
sync

I just got into front-end and vuejs so I can't tell you about. Typescript is a jewel of language however, you can do lot and lot of shit with it, easy to write and maintain, modern (read algebraic) type system and compiler, man I love it. Like a scripting of Rust in the browser.

Thanks friendo.

newTVarIO is presumably a function that creates a new "TVar" (whatever T stands for) in the IO monad. It probably uses def as the initial value.

update
TVar = (software) transactional variable
hackage.haskell.org/package/stm-2.4.5.1/docs/Control-Concurrent-STM-TVar.html

1/1 cont

Theres no reason it cant be simple either. It could look like this.

import Kirk


data App = App { counter :: Int }


data Route
= Increment
| GetCount


main :: IO ()
main =
Kirk.init server (App 0)


server :: (Route, Maybe Json) -> App -> (App, Response)
server (route, mJson) app =
case route of
Increment ->
(App $ counter app + 1, success)


GetCount ->
(app, sendCount $ counter app)

hey /dpt/ i just started CS and just finished my first java project for school, very very much a beginner still
what are some projects i should start workin on for my own benefit/for fun

>luaJIT development is dead and its not coming back

There will never ever be a language to surpass it in elegance and ease of use paired with incredible performance. God giveth, God taketh away.

Attached: sayak mem face.png (614x356, 45K)

HaskellJIT when

Don't worry user, Python and JS are at least more elegant and easy to use

Im a front end developer, and lately I have had to work on a typescript project.

It seems like you have to write OO code to get the most out of typescript. At work our typescript project is trying really hard to be functional with typescript and I feel like it just doesnt work that way.

Thats why I wonder if its a nicer experience with vuejs. It seems like it would be.

don't use transformers when you don't understand them

>>>>brainlet BTFO

Anyone want to help code a Jow Forums spambot that exploits audio recaptcha in python?

>needless hostility to Haskell newfriends

Attached: 1514600538134.jpg (298x169, 10K)

help me senpai

I want to learn

I'd just use a bunch of jpegs

How does C handle multiple threads?? Take my best Ran.

Attached: 1537111712759.png (2289x1253, 3.98M)

stop using code snipplets this isn't JS
read a book
then you probably can use transformers. probably

otherwise just go with the solution you think is the simplest and will work. advanced techniques come later

C doesn't have threading support in its standard library. However, you can use POSIX threads on POSIX compliant operating systems like Linux.

Thanks, I will read up on that package. Maybe I can make progress then using Scotty.

Thanks. Yeah I can see that 'def' is the initial value.

Do you recommend a book? I had that famous purple book for a while. I got some nice simple code working, but for my project I needed to persist state.

JS is a heap of shit shoved down our throats by desperate webmonkeys trying to branch out.

Python is fun to work with if performance is not an issue

Attached: 243t7yz7jz401.png (1241x1009, 989K)

Persistent over different runs of the program?

en.cppreference.com/w/c/thread

thoughts on this calver.org/

Why is it so fucking hard to get a god damned piece of shit random function?

I understand that there are many times to get predictable "randoms". I understand that if you're doing something important like encryption you can't rely on simple random functions.

But jesus. I just want a somewhat random number between 1 and 10. Why does it need to take more than 1 line of code?

Attached: dumb frogposter 4.jpg (500x500, 39K)

>But jesus. I just want a somewhat random number between 1 and 10. Why does it need to take more than 1 line of code?
Which language?

>JS
>elegant

>Rust's module system is the hardest part of the language

God why did they make it so confusing.

Attached: 1531385184862.jpg (824x1568, 376K)

F#, I've been looking and trying but I can't for the life of me find something much better than stackoverflow.com/questions/6062191/f-getting-a-list-of-random-numbers

No, like for example if I hit the end point "/count" it would add one to a counter, and then when I hit "/getcount" or something it would give me the count at that moment.

My project is different. Im generating audio, and I need to modify the audio after certain signals come in through the end points. But I need the same audio to persist between api calls that has all the mutations from the previous api calls.

I've seen it in a few python libraries, wouldn't work that well on languages that well, like how distinct python 2 and 3 is, and maybe some frameworks, like how confusing af Angular is right now (its not calver, but these constant jumps make it confusing)

why not just use a state monad?

to add: but it would definitely work in pretty much every other case

try using a language that isn't complete shit then? I've never used one that doesnt come with a built-in random function

Could you show me what that code looks like?

So I have code right now that persists state, but its not a webserver. That code looks like this:
main :: IO ()
main = do
scoreData TE.decodeUtf8
|> Model.init
|> init


init :: Result Error Model -> IO ()
init result =
case result of
Ok model ->
Input.init model

Err err -> do
putStrLn (Error.throw err)

It just recursively gets input, applies something to the Model, and then calls another "init" function which returns another IO () to wait for the next input.

yeah I have to say I'm pretty let down at the moment

>python
garbage
>js
yes

wiki.haskell.org/Simple_StateT_use

It doesn't.
#include
return (clock()&127)/12

There's your RNG. Doesn't need a seed either.
If you want many sequential numbers, either try your luck or use LCPRNG, which is one line too:
static uint32_t seed = clock();
return seed *= 1103515245 += 12345;

The link you posted lists random functions, though. What's wrong with them?
If they're not good enough, try .
For more serious uses, there are these: prng.di.unimi.it

Thank you.

Would you recommend R or Python for stats (or both)? Already know some SAS but it's not exactly as accessible as I'd want

>The link you posted lists random functions, though. What's wrong with them?
There's nothing at all wrong with them, they're great. My annoyance comes from the fact that I think it shouldn't be more difficult than
let randNum = nextRandom().

Not the same lang sadly.

I recommend the haskell book.
purple and shit. there's a free copy on a dpt discord

So I hear ya, and I dont know anything about F#, maybe its shit.

But your function right there "nextRandom()" is impure. And having a fully pure functional programming language is really nice, even if randomness it a little harder.

You could have
let (randNum, nextSeed) = nextRandom(seed)

Which is almost the same.

I already have that one. I guess Ill start reading it again.

just use monads

stop posting

Should I make a paint app for windows 2-in-1s? As in touch focused interface rather than the junk out there now. Would this sell?

yeah, it's very impure.
Thing is though F# lets you do some of those impure things already, if you really want to.

A random function is like a burrito.

hackage.haskell.org/package/MonadRandom-0.1.3/docs/Control-Monad-Random.html

i need an efficient way to store and query data consisting of specific points in time and nothing else
so just a notion of something happening at some given unix timestamp and a way to query (for example) how many events happened between two given timestamps
what do i use? i'd probably go with postgres, but what schema do i choose? i just need one column, which would be the timestamp

Currently learning Python through the Lydia.com course module (my school has a subscription) so that I can analyze data with Python instead of R.

I couldn't run a loop to apply a couple functions to a vector through my data folders in R so I gave up. R didn't have permission or something so I gave up.

t. brainlett here

R by far.
Its ecosystem is still miles ahead for stats.
It also has a CLOS-like object system which is nicer for interactive development.

Should I use multi-detached-threading or multi-process for a server program and why?

lmdb would be the fastest, I think. You can do range queries, it's written in C, and it's the fastest in all the benchmarks I've seen.

Async/event-driven.

>downside: massiv cpu overhead because of the need for culling.
Use indirect drawing to do culling on the GPU.

lynda.com*

#include
#include

char wav_to_char(const float f)
{
return "_,.-*`''"[(unsigned char)((f + 1.f) * (7.f / 2.f))];
}

int main(void)
{
float f;
for (f = 0.f; f < (8.f * M_PI); f += (M_PI / 8.f))
putc(wav_to_char(sin(f)), stdout);
putc('\n', stdout);
return 0;
}

>downside: massiv cpu overhead because of the need for culling.
You cull using an octree, or any other bounding volume hierarchy, there isn't massive CPU overhead

>Learning haskell
>Write a function
>4.5 * square x
>Haskell spits out an error

Why is something so simple so complicated in haskell? I have no idea how to fix this issue.

What's the error?

"No instance for (Fractional Integer)
arising from the literal ‘4.5’

Any trouble with R using RAM only?

Show us the code of square.

Is there any API for a Google handwriting recognition?

Attached: 1522628021619.jpg (1224x1128, 170K)

4.5 is a literal for a fractional type, it's 45/10
either square or x is working on integers here
integers aren't fractional

Why does git push to the server? It's asymmetric.
>someone who wants the source downloads it from the server
>the server gets it pushed from the maintainer
>the maintainer downloads the patches from the contributors/server
It would make much more sense to run a gitweb server, and then have the server pull it from the maintainer. This would also get rid of all the ssh madness, in lieu of much simpler public key/dns auth.

square :: Num a => a -> a
square x = x * x

test :: Fractional a => a -> a
test x = 4.5 * square x

works on my machine

That code doesn't work on your machine?

that's literally the exact opposite of what i just said

Attached: 1537243547192.png (318x318, 133K)

The book I'm using I guess assumes haskell would infer all this type nonsense. Back to learning so I can understand this

I thought you were sarcastic (typical Jow Forums paranoia).

Works without type sigs for me in GHCI.

I'm using an online REPL because I didn't want to install all that shit

link?

repl.it/repls/

Haskell isn't that hard to install.

Have fun downloading 200MB GHCI and Haskell runtime update every 2 days

I just get endless loading
Anyway see if this works: put
{-# LANGUAGE NoMonomorphismRestriction #-}
at the top

>Have fun downloading 200MB GHCI and Haskell runtime update every 2 days
Pretty sure all of GHC is < 200MB
Also, "runtime update"? Wtf are you smoking?
Just install stack and you can use it to install and run ghc

repl.it/languages

Try this link

meanwhile in better languages
test(x) = 4.5 * x^2

>better languages
Only in your mind.

he does it in a convoluted way brainlet

(also your line works in haskell)

Attached: file.png (447x43, 3K)