/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: 1514538739997.jpg (1018x926, 140K)

Other urls found in this thread:

en.wikipedia.org/wiki/Brainfuck
is2.Jow
hackage.haskell.org/package/base-4.11.1.0/docs/Data-Functor-Compose.html
hackage.haskell.org/package/base-4.11.1.0/docs/Data-Functor-Const.html
hackage.haskell.org/package/base-4.11.1.0/docs/Data-Functor-Identity.html
hackage.haskell.org/package/base-4.11.1.0/docs/Data-Functor-Product.html
hackage.haskell.org/package/base-4.11.1.0/docs/Data-Functor-Sum.html
twitter.com/NSFWRedditGif

>tfw learning Haskell
I love it

-- Convert time from 12 hour format to 24 hour format
-- Example: 01:31:45PM becomes 13:31:45

convertTime :: String -> String
convertTime time
| (drop 8 time) == "AM" = time
| otherwise = (show $ (read $ take 2 time) + 12) ++ (take 6 $ drop 2 time)

main = do
line

Attached: 1518353630220.jpg (346x510, 31K)

Second for anime.

Attached: 1439648511159.jpg (469x469, 116K)

What do people do with functional languages? I mean, they seem interesting, but what can I do that I can't do as an OOPsie?

i love coq!

Here's a more generic application of concurrent pattern matching:
merge : A|>B -> C|>D -> (A * C)|>(B * C|>D + A|>B * D)
merge (sig a) (sig c) = sig (a, c)
merge (evt b) cd = evt (b, cd)
merge ab (evt d) = evt (ab, d)

haskell is obsolete. learn idris

Idris?

Attached: idris-elba.jpg (978x1109, 234K)

en.wikipedia.org/wiki/Brainfuck

yes

It's wrong, because for AM it will still show AM.

Nothing, just create code thats harder for anyone lese to read but is more libidinally satisfying for mentally ill aspies who wrote it.
Nearly every company on Earth uses OOP for a reason

oh fug you're right

brainlet

Rude.

Attached: 1508022794176.gif (540x532, 850K)

You can also concurrently pattern match on multisets:
mix_all : {{Real|>1}} -> Real|>1
mix_all (sig x, sig y, r) = mix_all (sig (x + y), r)
mix_all (evt (), r) = mix_all r
mix_all x = x

Don't be fooled by the pair syntax; it's associative and commutative.

It looks nice with ligatures.

Attached: merge.png (474x97, 7K)

Oops, I missed a case:
mix_all () = evt ()

There's something done like this before, it was similar to monads and involved F#. I think it was called joinads or something? You should look into that.

Made a Jow Forums image downloader to learn Haskell.
Still an FP idiot, anybody got tips on how I can improve this?
{-# LANGUAGE OverloadedStrings #-}

import ChanData
import Data.Aeson
import Control.Monad
import System.Directory
import System.Environment
import Control.Applicative
import qualified Data.Text as T
import qualified Data.ByteString.Lazy as B
import Network.HTTP.Conduit (simpleHttp)

jsonURL :: String -> String -> String
jsonURL b t = " IO B.ByteString
getJSON = simpleHttp

imageURL :: String -> String -> String
imageURL b n = "is2.Jow Forums.org/" ++ b ++ "/" ++ n

saveUrl :: String -> String -> IO ()
saveUrl url name = do
let path = "download/" ++ name
exists do putStrLn (name ++ " exists, skipping... ")
False -> do jpg Maybe String
getPostFileName p = liftA2 (\n e -> (show n) ++ (T.unpack e)) (tim p) (ext p)

imageURLAndName :: String -> Post -> Maybe (String, String)
imageURLAndName b p = liftA2 (,) url fileName
where fileName = getPostFileName p
url = imageURL b fileName

downloadPostImage :: String -> Post -> IO ()
downloadPostImage b p =
maybe (return ()) (uncurry saveUrl) (imageURLAndName b p)

processURL :: String -> String -> IO ()
processURL b t = do
d putStrLn err
Right ps -> mapM_ (downloadPostImage b) (posts ps)

main :: IO ()
main = do
args putStrLn $ "usage: " ++ name ++ " board thread"

Is it worth getting the verified CS50 certificate? I'm a finance fag but sort of hate it and want to start slowly moving in an IT direction. Seems like it's gimmicky but then again maybe that's what it's all about.

You could use printf from Text.Printf for a start. Second, I would use the either function rather than doing a case expression on d in processURL.
either f g x == case x of Left a -> f a ; Right b -> g b

i want to learn programming, how do i go about it? I googled some shit some time ago but I figured it would be best to ask here instead of checking every search result one for one. What I followed through in the past was doing a intro to programming course on Khan Academy, but after a while I got really pissed at it because it was childish as fuck and only taught you how to redimensionate figures and the like. Or at least I wasn't willing to spend a ton of time with childish shit until getting to the gist of it.

Also, if anyone works with it and wants to share some experiences I'd be more than happy to listen. What kinds of projects you do, for whom, etc. I noticed that the hardest thing about choosing a career path to follow is that it's hard to find people who work with it to discuss the daily reality of the area, and college teachers sure as hell don't elucidate any of it.
Programming and general IT work has been a trend for a while, do you think that "high tide" will continue to allow one to make some decent money? Preferrably working remotely

Attached: 1509544931176.jpg (490x988, 169K)

The Harvard CS50 course is generally considered the gold standard for online resources for beginners. It's a bit more challenging than some beginner courses but very doable if you're committed.

This guy needs help:

Attached: 1535761862919.png (542x728, 64K)

I'm happy it's on youtube, I don't normally like doing courses in websites like coursera and edx, for whatever reason it seems to stunt my productivity. Since there are hours of lectures I think I might as well ask beforehand: is there interaction in the sense that they ask you to download this or that program to write your code and keep up with it or is it "just lectures"? This might be a dumb question, but I have no experience with it, so I figure it's better to ask now than going through 12 hours of lectures to find out

Attached: 1483158435696.png (1920x1080, 1.72M)

There's exercises. I think you can get them marked for free but you'd have to use whatever course website it's on I believe.

Ok I'll start doing it tomorrow to see how it goes.
Still open to any suggestions, mainly regarding stuff like market experience. I'm truly clueless

Attached: 1511214320770.jpg (1848x2500, 625K)

thanks btw

did terry die

Language?
Build some array get 8 cell corner

If I want to listen for an event, and handle the message queue in a function. Is the only way to implement this, with threads?

My current approach is to create a thread that polls for events forever, and then in a specific function, check if events were received by simply checking the state of a shared address.

Is this an appropriate use of threads or is there a convention of doing this pattern without them?
I just really want to handle a signal at a central point, but that signal will come in at an arbitrary time.

Attached: a5ee2a26844405ac39b8c9a699699e4112773a36c7b46a3fe4046bb6d29337a3.jpg (600x450, 117K)

Can you apologize to >for AM it will still show AM
Sensible.

Attached: AM - Allied Mastercomputer.jpg (1920x1080, 480K)

>Nearly every company on Earth uses OOP for a reason
Nearly every company you have a hope of working for, you mean.

Is WASAPI the lowest-level audio API or is there some Nt/Zw/whatever fuckery further down?

Why doesn't Java have Compose, Const, Identity, Product, and Sum?

>const
it has final but its not the same thing :^(
>Compose, Identity, Product, and Sum
???

Yeah I hope for the exact opposite than to work for some soi startup that uses FP

>Compose
hackage.haskell.org/package/base-4.11.1.0/docs/Data-Functor-Compose.html
>Const
hackage.haskell.org/package/base-4.11.1.0/docs/Data-Functor-Const.html
>Identity
hackage.haskell.org/package/base-4.11.1.0/docs/Data-Functor-Identity.html
>Product
hackage.haskell.org/package/base-4.11.1.0/docs/Data-Functor-Product.html
>Sum
hackage.haskell.org/package/base-4.11.1.0/docs/Data-Functor-Sum.html

Imagine being this paranoid and upset about a paradigm

>tfw her dick is bigger than mine

Nah I've just been burned before by a faggot ruining a project by overhauling everything into garbled functional shit that made no practical sense

????

it has compose, for the rest check if vavr.io has it maybe

if you are serious, i dont think its going to be at all easy.
but if you insist on doing it you can use languages like verilog or VHDL to program FPGAs
you are basically programming at the ANDs and ORs level here, so thats why i said its not going to be easy.

In a game loop you can check for events once a loop, but I'd imagine that whether or not you would use threads would depend on if you need to constantly be polling or if you could poll every once in a while.

Anybody can make code unnecessarily complicated, FP done right will make things simpler.

>or if you could poll every once in a while
This is the conclusion I was coming to myself. I'm implementing something that may fall under the observer pattern.
It still polls in the background, adding to an event queue. But that queue is processed as late as possible, instead of as early as possible.
I'm not sure if it will work out yet.

invoke callbacks as soon as the event is fired

I meme'd my way into a programming job, but I want to meme my way into a job in the gaming sector, even if it's as horrible as I've heard. Do they value experience or education more? I have a meme degree in an unrelated field, but I've been doing games in my spare time.

Experience > education, always
Check job listings, see what roles you want, check what ability they need and then make something with it

whats a better alternative to spring boot for large enterprise applications

that garbage reminds me of perl

>Experience > education
for entry level job maybe

I'm trying this at the moment with function pointers on structs.

Basically making sure the code path funnels into a specific function, that then processes the queue, makes callbacks if appropriate, then yields back

if that makes sense

sounds like you're just another OOPsie. sorry that your skills are becoming irrelevant

>vavr
No, it doesn't. It's not even close. Stop suggesting it.

Now that Java has lambdas there's no longer any reason for Haskell to exist. Java has everything you could possibly want.

this, but unironically

back to pcj you go

Check #haskell
Your code is wrong

The name's Bond. Jamal Bond.

braindead OOPsies belong in

where do i find source or time complexity info for javascript built-ins?

The place where most (if not all) events are generated is the main game loop. So you can first do a main loop logic, then handle events. It's asynchronous , but not parallel. If you're familiar with it, it's like running a Go program with GOMAXPROCS=1.

>programming work
I debugged, wrote code, and did tool writing for a company. It was a very weird role. Most of the time I was rooting out bugs and updating/writing new tools. C for code, Perl for tools. Also bash and batch here and there. Sometimes it took weeks to find a bug. I'm currently unemployed, but it was for software solutions to analog telephony-era stuff. Had to learn a lot of the standards and history before I was supposed to be working (I was suppose to learn for like literally a year before I was expected to do more code, not joking). We mostly used Epsilon, I also used Notepad++.

>wrote tools to tear apart our 300+ columns too-many-lines-to-count config file
The configuration file was one ASCII grid. It handled defines and undefs, to turn on code paths, compiler options, features, fixes for compiler bugs. Most of the people had long-term roles, so anytime someone wanted to turn an option on or off, they could do it for current settings, but not a place in the grid. Once I had the ability to exactly locate a spot in the grid, I had most of the ability to search, show information, some other things.

I wrote an automated windows build thing. They had a primitive linux script which would watch for some file changes, and then compile a master, subrevision, and specific-person code patch. Rewrote it to run on a windows server(in Perl), and handle parallel builds because MSVS is way slower than gcc compiling.

Wrote a ton of scripts to handle rsnapshot on FreeNAS box. Automated backups, deltas, logging, a few other little bits.

I'll continue code specific stuff in the next post.

>get rejected from summer jobs
>perfect time to go through my side projects instead
>do shitall progress on any of them
>uni starts again in 2 weeks
I'm a piece of shit

Attached: 34913841834901.jpg (1191x670, 63K)

Code specific:

I worked in fax code mostly. One thing I found that was a "happy accident": we didn't write TIFF files properly. The only symptom was a transfer would work once, but if you browsed through it would do strange things, the resolution would get a little warped. You transfer that file back, and you start getting corruption at the end of each page. I think it took a month or so to figure it out (while doing other stuff). We were writing the wrong amount of bytes. Every time a fax comes in, we decompress, and recompress it (feature). If it was recompressed to the same format, and only the same format, it would have the wrong amount of bytes it thought it should write - it used the original transmission bytes, which have extra 0's for timing synchronization stuff. We'd run through a circular buffer writing too many bytes. Couldn't figure out why the hell it was doing it, and *only* for the same compression, so had an if incompression == outcompression, count up the bytes for conversion, and use that value over in the TIFF writer instead of whatever if the bytes weren't 0. A lot of behavior was implicit, for performance reasons, and I couldn't find where the byte count even got modified outside of the original function.

Another time, I was asked to put headers on faxes. Faxes are normally considered line by line, never all at once. I had to create an entire font system (because faxes are different resolutions), string converter, storage, editing the line while it's uncompressed, and updating all the pointers and stuff properly. All statically allocated, no dynamic memory because some systems don't support dynamic memory allocation or customers wanted predictable memory use.

During debugging, I was handed some fax errors. The end-of-file one should've fixed a few faxes that erred. One of the first ones was while I was ripping apart the binary: we got the opener of the wrong opening bytes for the compression. Cont.

The wrong opening bytes meant we interpreted those bytes as data, and it fucked up the whole data stream, because the format, MMR, doesn't have error recovery built in. Had to write a hacky cruncher to watch for an error in the opening section.

Related, I was asked to CAUSE some error recovery for MMR, despite it having none. I found a probabilistic workaround: for the compression, data is more compressed because repetitions in image data can be represented as binary 1's (it's not hard to understand but I won't go into detail). Well probabilistically, Repetitions are also caused by a bunch of white lines. If we had a line error, and junked data until we had the first full byte of ones, it was either new repetitions or white lines. If we crunch all the 255s (a full byte), we *may* be at the end of a white line section, and can recover. I don't know if it ever worked, but it could've and if failed, tried again until we ran out of data.

Late at the job was writing code to support a telephony card. They thought a middleware might be limiting performance, so I was just handed the card and said "go to it, I'm too busy to look into it". The goal was that card would be directly connected to 24 machines - no dialing plan etc needed, which is an unusual use of the technology. Took me a while, ran into issues because the code was so old (C89) that the newer compiler C standard interpreted the syntax slightly differently. Only like one or two people EVER ran into this issue online, and it was a small section of a GCC update. Ran into some other things, which I eventually discovered and found solutions for. Submitted the patch, never heard back.

Last bit which I didn't fully do, we add automated testing to the build process. Normally we just compile the code and assume it works but that's not true. One guy was doing a lot of new stuff, so some testing would be useful. I had it almost done, there were issues with relative directories. Cont.

The patch and test scripts worked manually, they just failed in the automation process.

Environment:
The office was single people in rooms, collaborating when need be. We were mostly left to our own devices, but reported stuff. Very small company (not a dozen people, even before I had to leave).

I had to leave because income was low, and inconsistent. The first time I got the boot in February, and they re-hired me next month at part time. I got one check, but then nothing for a long time. I had to leave otherwise in two weeks I had to choose between paying bills and eating. If I did 2 10-hour days I could've gotten some unemployment, but the money was enough when it came in, and I was supposed to be going back to full time. Right now I'm unemployed.

After I left I "hurt some feelings" because I demanded I be paid or I'd be contacting the state (I got paid monthly - and they were two months overdue).

They didn't let me take code with me, but I did learn a LOT there, including useful skills. I'm going to rewrite some of the tools I wrote, and probably personally use my back-up scripts. I kept some code as I went, because I wanted to show some private people online, and so I had an extra copy.

I'm having fun so I'll continue:

One code issue in a logger function, vsprintf, is that the windows version has a limit on it's arguments. Our guy wanted to print like 34 data points at once, because it was one long tab-separated line for excel. gcc handled it fine, the MSVS compiler shat itself and crashed the program at runtime. Broke it up into chunks, worked perfectly. Also added some options to a menu system, nothing fancy, just some strings and value prints. An interesting thing, we wanted to know how many files were in use. In Linux this is relatively easy: you check /proc/ for your process. This requires knowing your programs running process ID, and directly accessing the directory. Well ironically, when we're looking in our directory, we have the directory open, so it counts, but if you have the processes split, you're not accessing your own process. It was a little thing, but I'd be off-by-one on the file descriptors in use if I didn't hack in a way to know we were running in a single-application vs dual-application mode.

The people:
A few of the people there were "long term" guys, i.e. possibly 20+ years. There was one middle-aged guy starting a family, and a few younger people. The owner was present up until he couldn't be for health reasons, and he was a hard ass. Liked to be looked up to, and tried to be commanding without being a bully, something he took very personally. Not a bad guy, just difficult at times (expected me to be there from 6:45AM to 6ish PM M-F). Friday we took off slightly earlier, but weeks were often 55 hours. I seriously miss the job because I felt useful for something, even if I was on average not productive enough (salary was 50k, and I have a relatively low debt burden)

>I debugged, wrote code, and did tool writing for a company. It was a very weird role. Most of the time I was rooting out bugs
The first four months of my current job was fixing the mess the last guy left behind. He practically ignored every logged error for years. Parsing exceptions, invalid operations, web exceptions, etc..

Attached: 1444565647324243.png (1166x1216, 658K)

I've written a decent chunk of a C parsing thing in Perl 6 that is intended to make writing NativeCall bindings as simple as pointing the program at a .h file.

Hardest part so far was trying to understand the direct abstract declarator token and figure out how to unpack that into something that made sense.

I'm getting into Lua for WoW addons but am having an issue with chat events. For example, the below code will, for some reason, infinitely loop itself when anyone in guild chat says anything:
local frame = CreateFrame("Frame")
frame:RegisterEvent("CHAT_MSG_PARTY")
frame:SetScript("OnEvent", function(self, event, ...)
SendChatMessage("test", "PARTY", nil, 1)
end)

Am I missing an end somewhere?

Anyone in party chat*

JaneStreet uses OCaml. They're a private finance company who writes trading algos, very prestigious.

you are triggering something everytime someone sends a party message and are sending a party message..that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...that triggers your script which sends a party message...

Yeah, I get that. My question is about how I would limit it in such a way that would make it usable.

ok so serious question. iv been trying to get into coding for awhile now but i cant seem to find a start point. everything i can find it seems like i need to already know some coding before i can understand that one. basically does anyone know where i can find a coding for dummys or something??

Google something like "programming practice problems". Everyone who knows anything learned by doing shit, and practice problems are probably a good way to get your feet wet.

Use whatever language. Python is probably most beginner friendly. C itself is okish, but the toolchain is a bitch.

As soon as possible, get a pet project and obsess over it. Don't worry about failure or sucess or whatever, the point is to learn, and as long as you are programming a lot (which you will if you are obsessed) you will learn; so even if you "fail" you still win because you learned.

Dockerfag for yesterday, it works
Dockerfile I made to create my build env
FROM debian:stretch

RUN apt-get update && apt-get install -y \
gcc-6 \
g++-6 \
meson

# SRC directory for the project
# that's where the main meson.build should be
RUN mkdir /src

# That's the folder meson will output to
RUN mkdir /build

WORKDIR /src

CMD ["/bin/bash"]

then you just need to run # docker build -t cppenv Dockerfile

In my project dir I have 2 bash scripts, one to build my project like I would without docker: build.sh
#!/bin/bash

if [ -z "$1" ]; then
printf "Usage: "$0" [meson args]\n"
printf " where is the build directory\n"
exit 1
fi

if [ ! -d "$1" ]; then
mkdir -p "$1"
fi

BUILDDIR=$1
MESON_ARGS=${@:2}

# meson was never run
if [ ! -f "$BUILDDIR/build.ninja" ]; then
meson $MESON_ARGS "$BUILDDIR"
if [ $? -ne 0 ]; then
printf "Something went wrong while running meson\n"
exit 1
fi
fi

# compile project
cd "$BUILDDIR" && ninja


and one that uses the build.sh script to build inside my docker container: dbuild
#!/bin/bash

# Build with docker
# Root build directory is build/
# All builds are inside this folder

if [ -z "$1" ]; then
printf "Usage: "$0" [dir] [meson args]\n"
printf " where is the name of the build\n"
printf " [dir] is the build directory, by default ./build\n"
exit 1
fi

NAME=$1
BUILDDIR=build
MESON_ARGS=${@:3}

if [ ! -z "$2" ]; then
BUILDDIR="$2"
fi

if [ ! -d "$BUILDDIR" ]; then
mkdir -p "$BUILDDIR"
if [ $? -ne 0 ]; then
printf "Error while creating build directory\n"
exit 2
fi
fi

# save the user starting this script
cur_user=$(id -u -n)

# start compilation
sudo docker run --rm -it -e CXX=g++-6 -v "$BUILDDIR":/build -v "$PWD":/src:ro cppenv /bin/bash build.sh "/build/$NAME" $MESON_ARGS &&

# if the compilation succeeded, take ownership of files created inside docker
sudo chown "$cur_user:$cur_user" -R "$BUILDDIR"

Fucking gookmoot why do I have to complete 5000 capthchas to post a long post reeee

Anyway, any bash wizards here to tell me I'm a huge faggot because I did something wrong?
And tell me what I did wrong too, don't just call me a fag u fag

Why do you need docker for that?
Just use it properly on your own system.

Because I want to compile shit for older setups and because I use arch, any bin I create on my machine won't work on others because of libstdc++ version clash

Just realized there's a mistake, I added
BUILDIR=$(readlink -f "$BUILDDIR")


just before the compilation because docker volumes need absolute paths

Need to write test code for the 1.5k new lines.

Attached: reaktion.jpg (396x385, 51K)

dumb frogposter

Is the offset for an array element calculated with every instance? Wouldn't it be faster if I do:
pointer = function_array[x];

pointer(0,2);
pointer(2,0);
// n more
pointer(5,1);
pointer(7,9);

Instead of:
function_array[x](0,2);
function_array[x](2,0);
// n more
function_array[x](5,1);
function_array[x](0,9);

?

The compiler would surely optimise that out, assuming you're not doing anything dumb.
There is nothing wrong with doing the first one, though.

X is supposed to be a variable so I don't see how it could optimize it.

I want, in java, to draw pixels on a canvas. Similar to how it's done in processing, but preferably faster. I don't need a constant refresh rate, it would be fine if it only updates when i tell it to. Would be nice if this thing could be embedded in javafx.

Is there such a thing? Some framework?

Attached: file.png (577x27, 2K)

If the variable can't change, the compiler can still optimise it.
I'll load the pointer into a register and just keep using it.

It can silently rewrite your code to the first form

i want to make a scraper and build a searchable database. redpill me on non-meme stacks.

Haskell or Scheme/Lisp?

C

Scheme.

haskell easily

there isn't, spring boot is the best

GAMH
>gentoo
>apache
>mysql
>server side haskell

Hey /dpt/,

My C project uses Makefiles on Linux. On Windows it uses nmake, the MSVC Makefile utility for building from the command line.

vcvarsall.bat is the script that comes with Visual Studio that you have to execute to enable command line builds. You have to execute it with a given architecture as a parameter, like x86 or x86_amd64.

Is there any way I can tell in my Makefile if the script was called with the x86 or x86_amd64? I want to set my library path depending on that so that it will correctly use 64 bit libraries for 64 bit builds and vice versa.