[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 40
File: hime c.png (1 MB, 1280x720) Image search: [Google]
hime c.png
1 MB, 1280x720
old thread: >>54771122

What are you working on, /g/?
>>
File: glitchy_gdb.png (81 KB, 938x973) Image search: [Google]
glitchy_gdb.png
81 KB, 938x973
>>54776509
I'm being confused by GDB weirdness.

Does anyone use GDB? I learned about the TUI mode today. It works fine for a bit, until eventually it really starts messing up.

The control characters stop being interpreted correctly; they are being output to the input field. The screen stops being rendered correctly. Redrawing the screen with ^L will only seemingly fix it until I enter another command in.

I'm using xterm but the same thing happens with screen-256color.

>>54776530
I thought you couldn't delete threads on 4chan.
>>
>>54776509
dumb weeb
>>
>>54776509
>trap
fap-fap
>>
File: the end of code.png (133 KB, 600x786) Image search: [Google]
the end of code.png
133 KB, 600x786
Will there ever come a day when programmers put themselves out of a job?
>>
>>54776563
They do it all the time with automation, or more precisely they put others out of work.
>>
>>54776563
We will live in AI-governed utopia by then.
DeepMind is world's top Ai company, so it's not unreasonable that they will play a large role in that. See an interview with their ceo/chief scientist http://www.theverge.com/2016/3/10/11192774/demis-hassabis-interview-alphago-google-deepmind-ai
>>
>>54776563
I think if code can code itself, then code can code the thing that builds itself. At that point, everyone will be out of a job.
>>
What's ur favorite pointer type and why is it void?
>>
>>54776617
You don't even need code rewriting, just good enough general learning. Software able to learn is a reality by all measures now. It's only a question of quality of learning.
>>
File: 1459372659891.png (718 KB, 800x600) Image search: [Google]
1459372659891.png
718 KB, 800x600
Imagine a waifu app:
a qt anime waifu on your screen
you can interact with her via typing text and even by saying phrases into the mic (say, you use google voice API)

Which cool interactions between user and could you imagine in this framework?
>>
>>54776683
[spoiler]hand holding[/spoiler]
>>
>>54776551
I discovered a workaround if y'all ever encounter this problem.

Entering TUI mode via ^xa will cause this problem for some reason, but entering TUI mode by launching gdb as
gdb -tui
this problem will not be encountered.
>>
File: get a job.webm (3 MB, 1118x834) Image search: [Google]
get a job.webm
3 MB, 1118x834
>>54776509
>What are you working on, /g/?
finding a job ;_;
>>
>>54776836
>r9k
>>
It took two fucking days but I've finally figured out how to get the Vendor and Product IDs from a drive letter.
>>
File: Capture.png (4 KB, 517x72) Image search: [Google]
Capture.png
4 KB, 517x72
>>54776509
HELP GEE

how do i get this arraylist element to equal something?! the compiler says it has to be a variable and .get wont do justice?!?!
>>
>>54777026
language?
>>
>>54777056
JAVA
>>
>>54777026

If only ArrayList had a set function.
>>
java.lang.ArrayIndexOutOfBoundsException


I swear I don't have any array index errors.
>>
>>54776596
Deepmind is not by any means world's top AI company. It's right in the middle. The only reason why you think otherwise is because it's attached to google, so there's constant sensationalism and clickbait about them.
>>
>>54777065
I SAID it has to be a variable
>>
>>54776817
[spoiler]too lewd[/spoiler]
>>
>>54777065
oh wait nevermind i think i got it
>>
>>54777105
>The only reason why you think otherwise is because it's attached to google

Actually the reason is I'm reading machine learning papers and look at who works where. DeepMind has clearly stated it's general AI goals, attracted top machine learning Phds and funding.

But I'm open to discussion. Do you think there are other better general AI companies or divisions?
>>
File: Capture.png (4 KB, 497x79) Image search: [Google]
Capture.png
4 KB, 497x79
HEY /g/UYS

can you help me with this swaping method too??
>>
File: no.gif (1 MB, 636x342) Image search: [Google]
no.gif
1 MB, 636x342
>>54776683
>on your screen
>2016
>>
My 2d mmorpg sex sim
>>
>that feel when you finish program and it works but since its going on your public portfolio you have to go back and use
>muh best practices and rewrite a shit ton of stuff just so you hope people wont judge you as bad
>>
>>54777217
do your own homework
>>
>>54777217
I have no idea what your stupid abstractions are trying to do.
int tmp = a;
a = b;
b = tmp;
>>
>>54776551
>>54776825

>linux problems

i have no idea what the fuck you just said
>>
>>54777231
Shouldn't your sex sim be single-player only?
>>
>>54777246
im in a time crunch
>>54777251
im using arraylist though
>>
>>54777291
then fail like you deserve to faggot
>>
>>54777291

Time to rewrite the whole project in Ruby.
>>
>>54777297
fuck you this is my extra DAMN CREDIT. IM NOT ENDING UP LIKE YOU
>>
>>54777288
ayy
>>
>>54777189
>Actually the reason is I'm reading machine learning papers and look at who works where.
If you did you would not think of deepmind anywhere near as highly as you do, which shows that not only you have never read a single ML paper, but I clearly hit the nail on the head when calling you out as a MSM consumer. Even baidu, despite their constant use of underhanded tactics and lies, are significantly more relevant in the grand scheme of things.
>>
>>54777217
why the fuck are you mixing primitive array and ArrayList operations.

It's fucking highlighting it for you

4/10, made me reply
>>
>>54777291
All those Java abstractions complicate things. Just write it in assembly on some paper and hand-assemble the program with an Intel manual or something for reference.
>>
>>54777306
>his grades are so shit he needs extra credit
you're not gonna make it anon
>>
>>54777306
>i can't succeed but i don't want to fail
Selfish cunt
>>
File: Capture.png (4 KB, 455x78) Image search: [Google]
Capture.png
4 KB, 455x78
>>54777327
NO i didnt explain well. but look, this is what i DID GEE R8 HOW I DID?
>>
>>54777322
>MSM consumer
>https://en.wikipedia.org/wiki/Methylsulfonylmethane#Medical_and_dietary_use
???
>>
>>54777217
not sure if trolling
>>
>>54777355
Why do you need that arraylist shit?
>>
>>54777341
>>54777344
I already aced my final, its just the last project i gotta finish. Im doing the extra credit portion

now look here>>54777355
>>
>>54777217
"a" is passed to the function you don't need to initialize it again.
>>
>>54777376
>can't implement a basic swap function
>aced the final

Wow your degree is worth shit all isn't it?
>>
>>54777368
for selection and insertion sorting, with an arraylist

its part of the extra credit
>>
>>54777359
Mainstream media
>>
>>54777390
Why can't you use a normal array?
Even if you need dynamic resizing, it's trivial to write a wrapper for it.
>>
>>54777384
Im sorry im not a swapping expert like you, the first time i swapped shit with arrays
>>
Rust is the best language I've ever used. it's simply magical. The only issue I see with it is that closures are "special" and can't easily be returned from functions or methods (as opposed to lambdas).
>>
started an internship

how the fuck do I learn this massive codebase

most of my day is spent with breakpoints and go to definition
>>
File: Capture.png (9 KB, 409x208) Image search: [Google]
Capture.png
9 KB, 409x208
>>54777401
oh yeah, because of pic
>>
File: swap_2_ints.png (10 KB, 280x305) Image search: [Google]
swap_2_ints.png
10 KB, 280x305
>>54777376
Here is how you do it.
>>
>>54777410
jesus fucking christ, why is every bit of your text fully highlighted?

it's like taking a highlighter and running it through every paragraph in the book, nothing stands out if everything is colored.

Also, I can guarantee that your CS program isn't worth jack shit if you can't even write a simple swap function.
>>
File: PhD in Incompetence.png (125 KB, 813x600) Image search: [Google]
PhD in Incompetence.png
125 KB, 813x600
saved
>>
Just doing some Unity Tutorials. Tired of only making web apps at work.
>>
>>54777429
i just need help with the arraylist man
>>
>>54777515
You don't need array lists.
>>
>>54777532
let me explain, the extra credit wants me to fill up arrays with random values but each value is unique (cant have duplicate numbers). I can only do this with arraylist because I can use Collections.shuffle to mix up the elements after i fill the lists up. I DO need arraylists
>>
>>54777322
Baidu hasn't published much and I haven't seen any baidu results on reinforcement learning at all.

By general AI I mean cutting edge reinforcement learning, not mere better voice recognition.

DeepMind isn't just hype, their reinforcement learning agents literally made impossible possible, especially the latest A3C: arxiv.org/abs/1602.01783
>>
>>54777486
iktf

no geimu no laifu

btw I'm writing a javascript game engine.
>>
>>54777564
Wow, your CS program is truly worthless.

You can't even begin to imagine how to write a random shuffler function?

This is who I'm competing with?
>>
>>54777606
You should be thankful, anon
>>
File: costanza.jpg (9 KB, 250x250) Image search: [Google]
costanza.jpg
9 KB, 250x250
>>54777570
>cutting edge
>isn't just hype
>made impossible possible
You're right. That's more than hype. That's fanboyism.
>>
>>54777680
*yawn*
debate the technical part, please
>>
>>54777606
google didnt tell me i could do that, and it looks more time consuming
>>
>>54777686
>made impossible possible
This is a useless and masturbatory way of saying "invented a new thing."
>>
>>54777570
M8, you don't even have a single clue. You don't even begin to show any hint of understanding of what you're saying. The only thing you can do by posting more is getting BTFO even further.
>>
>>54777705
ok, I'm going to bed
see ya later
>>
>>54777694
I gave it 5 seconds of thought
>take array
>create second array
>populate second array with values randomly selected from first array
>memmove overlap that value to delete it
>return new array
>>
>>54777217
>>
>>54777737
i dont know what memove is
>>
>>54777761
use your imagination you dumb kid
>>
>>54777288
underrated dubs
>>
File: progress.png (305 KB, 1825x955) Image search: [Google]
progress.png
305 KB, 1825x955
Working on refactoring. I moved from a "big-ball-of-state" main structure to one containing only two fields: one representing the player, and the other representing the quadtree. The quadtree is now the main data structure of the game, and the player field (containing another struct) is just for convenience since it needs to be passed to some of the other entities in the quadtree. This has simplified a lot of functions. For example, rendering is no longer a manually nested sequence of rendering functions for each field representing each set of entities in the game, now I just walk the tree and render entities as I go along. There's a similar process for updating the game. Now I just have to figure out a simple way of "exiting" the quadtree while in the middle of it in order to reinsert entities, for when entities fire projectiles at one another during game updates.
>>
>>54777822
>normal comments instead of doc comments
>>>/trash/
>>
>>54777406
Welcome to the enterprise life.

:^)
>>
>>54777831
>doc comments instead of normal comments
>>>/r/eddit
>>
>>54777831
I don't know what that means.
>>
File: Capture.png (15 KB, 338x376) Image search: [Google]
Capture.png
15 KB, 338x376
>>54777765
Im NOT making another array, or listening to you, disgraceful edgy BASTARD
>>
>tfw emacs STILL doesn't have proper OTF font support
ligatures and proper font rendering when?
>>
>>54777885
>ThreadLocalRandom

It's ogre. It's all ogre.
>>
I need to select a specific element in an array and update it's contents.

I have a limit of 5 of these elements, but they are not reset in order of usage.

I need to find ONLY the first 'available' slot in the array and use it.

So bullet 0 and 3 may be active, because 1 has collided with and object (4,5 are waiting as well), thus been reset to a ready state.

Language is C, I just don't know how to do the control statement for making sure that only the first 'available' element will be chosen.
>>
>>54777885
I already gave you a solution (>>54777428)
m8.

If you're unsure what those instructions do just google them like you googled everything else.
>>
>>54777885
I'm not familiar with java, is your dumbass function duplicating your values?
>>
>>54777900
how old are you burger?
>>
>>54778012

21
>>
>>54778018
and how's the .22 riffle?
>>
>>54777973
man you dont even know what the hell is going on
>>
>>54778018
>I'm older than the OSGTP
feels superior.
>>
>>54778094

fuck off already
>>
>>54778164
who hurt you, anon?
>>
>>54778094
And it only gets worse.
>>
>>54778050
it's really not that great a feeling
>tfw you will be 30 years old and still stuck here
>>
>>54778273
>Stuck here
I guess I came here too early. I want to be stuck here; it's better than being stuck anywhere else. Fuck the real world.
>>
File: 1451035301826.jpg (64 KB, 600x687) Image search: [Google]
1451035301826.jpg
64 KB, 600x687
>>54778256

Thank you for the kind words.
>>
>>54776509
ou do cast, because:

It makes your code more portable between C and C++, and as SO experience shows, a great many programmers claim they are writing in C when they are really writing in C++ (or C plus local compiler extensions).
Failing to do so can hide an error: note all the SO examples of confusing when to write type * versus type **.
The idea that it keeps you from noticing you failed to #include an appropriate header file is rather stupendously stupid. It's the same as saying "don't worry about the fact you failed to ask the compiler to complain about not seeing prototypes -- that pesky stdlib.h is the REAL important thing to remember!"
It forces an extra cognitive cross-check. It puts the (alleged) desired type right next to the arithmetic you're doing for the raw size of that variable. I bet you could do an SO study that shows that malloc() bugs are caught much faster when there's a cast. As with assertions, annotations that reveal intent decrease bugs.
Repeating yourself in a way that the machine can check is often a great idea. In fact, that's what an assertion is, and this use of cast is an assertion. Assertions are still the most general technique we have for getting code correct, since Turing came up with the idea so many years ago.
>>
Abstraction was a mistake
>>
>>54778418
Can you be more specific?
What do you mean by abstraction?
>>
Encapsulation was a mistake
>>
>>54778418
A little abstraction is good, too much and you get dumb shit like reduce map and filter.
>>
>>54778443
Beyond machine language
>>
>>54778454
Machine language is pretty abstract 2bh
>>
>>54778447

reduce, map, and filter are GOAT, though.
>>
>>54778475
Explain why without using memes.
>>
>>54778588
DRY
>>
how would you implement this in OCaml/F#
-- | The 'intersect' function takes the list intersection of two lists.
-- For example,
--
-- > [1,2,3,4] `intersect` [2,4,6,8] == [2,4]
--
-- If the first list contains duplicates, so will the result.
--
-- > [1,2,2,3,4] `intersect` [6,4,4,2] == [2,2,4]
--
-- It is a special case of 'intersectBy', which allows the programmer to
-- supply their own equality test. If the element is found in both the first
-- and the second list, the element from the first list will be used.

intersect :: (Eq a) => [a] -> [a] -> [a]
intersect = intersectBy (==)

-- | The 'intersectBy' function is the non-overloaded version of 'intersect'.
intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
intersectBy _ [] _ = []
intersectBy _ _ [] = []
intersectBy eq xs ys = [x | x <- xs, any (eq x) ys]
>>
>>54778606
that's a meme
>>
>>54778588

More compact code.
>>
>>54778636
meme

Give a real, concrete benefit of using higher order functions.
>>
>>54778653
>>54778631

do you code without using functions then?
>>
File: 1448137611091.jpg (68 KB, 526x572) Image search: [Google]
1448137611091.jpg
68 KB, 526x572
>>54776509
>posting homosexual trap degenerate crap

End yourself right now you disgusting faggot.
>>
>>54778672
hime isn't gay
>>
>>54778609

let intersectBy eq xs ys =
[ for x in xs do
if List.exists (eq x) ys then
yield x ]


let intersect x y = intersectBy (=) x y
>>
>>54778707
lazy version - use Seq.exists and wrap the whole thing in seq { } rather than [ ]
>>
>>54778707
Wait, you can just do this
let intersect xs ys = List.filter (fun x -> List.contains x ys) xs
>>
I'm a total webdev noob, hoping someone can help.

I'm trying to make a website using django that uses the steam api to show info about a user whose id you input. I can get it to retrieve and show the info with json but I can't figure out how to get that json stuff into an html template. Help please?
>>
>>54778707
>>54778748
cheers
>>
I'm writing R functions to do arithmetic with arbitrarily large integers. A package exists for this but I want the experience of building it.

Btw, will posting things like this on github help land a job or make me look like a helpless autist?
>>
>>54778609
By using rust instead.
>>
>>54778909
Rust is garbage
>>
>>54778909
Rust has that intersect function?
>>
anyway here it is, haskell copied functions (since it wasn't apparently in the standard library)
doing >>54771500 with >>54772078

let span p = 
let rec loop k = function
| x :: xs' when p x ->
let f (ys, zs) = x :: ys, zs
loop (f >> k) xs'
| xs -> k ([], xs)
loop id

let groupBy eq =
let rec loop k = function
| [] -> k []
| x :: xs ->
let (ys, zs) = span (eq x) xs
let f zss = (x :: ys) :: zss
loop (f >> k) zs
loop id

//Special case of 'groupBy', group by equality.
let group xs = groupBy (=) xs
//intersect with duplicates
let intersect xs ys = Seq.filter (fun x -> Seq.contains x ys) xs

finally
let longestStreak x y = List.ofSeq (y |> intersect x) |> group |> List.map (List.length) |> List.max

> "AGR" |> longestStreak "AABGZZZARRRRRR";;
val it : int = 6
>>
>>54779071
you should look into the parser monad
>>
>>54778761
>>54746692
>>
>>54778928
>Rust is the best language
FTFY
>>
>>54779345
let's compromise

Rust is the best garbage
>>
>>54779353
Let's compromise: Every language that's not rust is garbage.
>>
>>54779403
I don't deal with terriblists
>>
>>54779604
use monads
>>
>>54779604
use you're mum's anu's
>>
so what's the best 'functional' language to learn?
perl6?
ruby?
haskell?
lisp?
>>
>>54779604
C++ supports short-circuiting
Just test it dude
if (foo1() || foo2())
;
// only foo1 should execute if it returns true
>>
>>54779910
NIGGER
>>
>>54779902
Rust
>>
>>54779902
Haskell
>>
>>54779902
>haskell
>functional
top kek people actually believe this
>>
>>54779902
out of those 4 Haskell is really the only one that is a "functional language". the rest support FP but that's not what they're specifically meant for
>>
>>54780129
Haskell isn't functional, it's dysfunctional
>>
>>54780217
xD good pun upvoted XDDDDD
>>
>>54780224
Are you new here?
>>
>>54780236
yes i just joined yesterday, can u show me the ropes plz??????
>>
>>54780246
>>
File: 1464274380541.jpg (87 KB, 953x960) Image search: [Google]
1464274380541.jpg
87 KB, 953x960
>>54780086
>>
It's time to do that thing again where I program in Java for assignments and shit. In a few weeks though, all of this shall be over, and summer will start.

Java... it's like an office chair. Not the most comfortable sitting experience, but not extraordinarily painful. That said, I'd rather program from my bed or while sitting on a couch.
>>
>>54780418
>Java
>not extraordinarily painful
>>54780267
>>
>>54779317
o shit thanks
>>
Ok so I'm _still_ (day 3, not 8 hours every day) trying to build http://mosra.cz/blog/magnum-doc/getting-started.html
Found Corrade: C:/Magnum/magnum-bootstrap-base/corrade/src  found components:  Containers Utility rc PluginManager 
CMake Error at corrade/modules/UseCorrade.cmake:333 (add_custom_command):
add_custom_command called with OUTPUT containing a "#". This character is
not allowed.
Call Stack (most recent call first):
magnum/src/Magnum/Shaders/CMakeLists.txt:26 (corrade_add_resource)


CMake Error at corrade/modules/UseCorrade.cmake:333 (add_custom_command):
add_custom_command called with OUTPUT containing a "#". This character is
not allowed.
Call Stack (most recent call first):
magnum/src/Magnum/TextureTools/CMakeLists.txt:26 (corrade_add_resource)


Found Corrade: C:/Magnum/magnum-bootstrap-base/corrade/src found components: Containers rc Utility PluginManager
Configuring incomplete, errors occurred!
See also "C:/Magnum/magnum-bootstrap-base/build/CMakeFiles/CMakeOutput.log".
See also "C:/Magnum/magnum-bootstrap-base/build/CMakeFiles/CMakeError.log".

I've progressed quite far now.

But where do I even go to ask about shit like this? Do I just open an issue on the github? Seems a bit obnoxious to clutter their dev stuff.
At what point can I consider it their fault? Really this process is getting quite onerous considering they're saying
"Setting up a new project can be pretty gruesome and nobody likes repeating the same process every time. Magnum provides "bootstrap" project structures for many use cases, helping you get up and running in no time."
At the top of the page..
>>
Is there some kind of "project generator for the uncreative but wanting to work on something programmer"
>>
>>54780633
you've just given yourself a project to make
>>
Can anyone figure out a better way to solve this in Javascript?
Someone posted a really cool answer in Haskell today, but javascript doesn't have a function like 'intersect'. This is my 1st time using reduce().
It would be cool if there was a way to solve this without using "curr" and "longest" to keep track of the longest and current streaks.

array.length would be vital to solving this in a functional way, I'm sure. If there was a way to split the 'str' into substrings or subarrays, then a function could just loop through the array of arrays/substrings and check if currentSubArray.length > longest. but even that's using assignment, which apparently isn't pure functional

/*
Given a string of repeating characters and a list of targets,
find the longest consecutive string of target letters in the
given string.

findConsecutive("AAAZZGYYYYYYYYQ", ["G", "Q", "Z"]);
// returns 2, because two Z's
*/

var str = "AACCCVVVHGJJJDKDNWIEUDNDNDDDLLLWEEJJJTTTIIILWWWWITUENXXNGXGFFFFFF";
var targets = ["A", "B", "C", "W"];

var curr = 0, longest = 0;
str
.split('')
.reduce(
function(previousValue, currentValue, currentIndex, array) {
curr = (targets.indexOf(currentValue) == -1) ?
0 : (previousValue == currentValue) ?
curr + 1 : 1;

longest = curr > longest ? curr : longest;

return currentValue;
});

console.log(longest); // 4
>>
File: Untitled.png (12 KB, 979x512) Image search: [Google]
Untitled.png
12 KB, 979x512
I am proud of my tables.

They adapt to fit the content.

wahoo
>>
>>54776836

>winnipeg

rip my man

basically worst province in canada
>>
>>54780708
arr.filter((x) => arr2.includes(x))
>>
>>54780732
>"Name" and "Handle" are right-adjusted but "PID" and "Title" are left-adjusted
>>
>>54780732
Why not use box drawing characters?
>>
>>54780745
ah i tried something like that earlier, only i used indexOf, rather than includes.

problem is, that will make separated target characters suddenly joined.

like so:
'aaazaaa', // target: a
would turn into 'aaaaaa'.
so then that'd be a streak of 6, but that's wrong because the original only had a longest streak of 3
>>
>>54780633
Go to that list of integer sequences and pick a random sequence.
Make a program that generates that sequence.
Optimize it to the best of your ability.
Submit it.
Find another sequence.
>>
>>54780781
i mean that's javascript intersects
>>
>>54780732
senpai you programming your own console? I think we might have some code to exchange.
>>
>>54780708
What if there are two or more longest streaks, such as AGGAAAZZ for G and Z?
>>
>>54780809
i guess the answer would just be the longest? so 2.
>>
>>54780752

it's because it looks fucky when there's a long title or process name if name is left aligned or title is right aligned. I think its better to keep the headings together rather than super spread apart.
>>
if there was a way to break
'aaadddyylrr'
into
'[ [aaa], [ddd], [yy], [l], [rr] ]'
that'd probably be key to solving the problem.

String.split('') would be perfect if i could pass it a callback which takes two args and returns true if they're different and false if the same (and splits the current string if true)
>>
>>54780806

wow what is this
>>
>>54780809
>two or more longest streaks
>two or more
>longest

maximum :: Ord a => [a] -> a
>>
>>54780835
what?
>>
>>54780832
https://github.com/Wunkolo/SaiPal/releases

I did ElDorito too if you've heard of that and some other little off-hands.
>>
>>54780835
what language?
how does it work?
what does it do?
>>
>>54780849
that's fucking neato
>>
>>54780845
>>54780850

the function maximum takes a list of items of type a (where a is an instance of the Ord typeclass) and returns an a
>>
>>54780860
How does that answer the question?
>>
File: Untitled.png (15 KB, 977x515) Image search: [Google]
Untitled.png
15 KB, 977x515
>>54780806

it's a general purpose console app for putting input into other processes message queues at a low level. I guess it could be used for automation when it's finished, the one big problem is that it's up to the user to structure the messages correctly. I don't want to rewrite Spy++ for a tiny console app.
>>
>>54780830
Just write a function that keeps track of the previous character and the first index it saw it on. Iterate over the string. When it encounters a new character type save the string/indexes in some way. (maybe in a list since that's what you wanted) and begin counting for the new character type.

Are you writing python?
I'm really surprised that someone would have trouble figuring this out.
>>
>>54780863

there's only ever going to be one result
>>
>>54780884
In your implementation. I was asking what the original task requested.
>>
what's better than strings for haskell
I know some people use OverLoadedStrings pragma
is Data.Text better?
>>
>>54780894
in the original task you numpty
>>
>>54780881
I mean, I solved the prompt.
I'm just trying to come up with ways to solve the problem in a 'more functional' way, rather than relying on the big chunk of code I used in reduce in >>54780708
>>
>>54780781
>so then that'd be a streak of 6, but that's wrong because the original only had a longest streak of 3
I'm pretty sure the Haskell solution actually fails in this case as well.
>>
>>54780898
What for? If you want to support Unicode, you should use something like Text or ByteString.

>>54780899
ok kid
>>
>>54780908
Sounds fairly arbitrary but good luck.
>>
>>54780919
Corrected Haskell version:
longest :: String -> [Char] -> Int
longest str targ =
maximum
$ map length
$ filter ((`elem` targ) . head)
$ group str
>>
>>54777606
Typical CS student at no doubt a 100% Java school who aren't taught anything beyond "if you type this, this should happen"
>>
>>54780982
neat

>>54780925
yeah, i know. im trying to impose this requirement on myself that I go for a 'functional as possible' answer.
>>
>>54780924
just string parsing to interpret 4chan json
hoping to make the binary size smaller and more efficient too

is bytestring better?
>>
>seeing C# code ITT
It's like C++ with Java's inelegance. How do people bare it for things other than Unity? I already know ASP.NET is shit
>>
>>54781008
Yes, ByteString are faster, because they're implemented more reasonably, but consequently dissecting them character by character (why you shouldn't really have the need to) as with regular lists is ineffective.

In comparison to String, which is, as you presumably know, just a linked list of Chars, they're much more efficient for the usual string-handling tasks, though.
>>
>>54780982
That's not total, though.
>>
>>54781076
Forgot to mention that you need Text if you want to work with the JSON as UTF-8 and so on. Also see https://stackoverflow.com/q/7357775
>>
>>54781086
Haskell isn't total.
total < correct
>>
>>54781095
You can easily make it total. Don't be lazy, family.
>>
This will give you a sequence of (char, int) pairs for consecutive occurrences
You can use that to pick the longest
(F#)
let consecutives s = 
let s = Seq.map fst (Seq.filter ((<||) (=)) (Seq.pairwise s))

Seq.fold (fun subs x ->
match Seq.tryHead subs with
| Some (c,i) when c=x -> seq { yield (x,i+1); yield! Seq.tail subs }
| _ -> seq { yield (x,1); yield! subs }
) Seq.empty s
>>
>>54781109
What, it's not total because I used head? group either returns an empty list, or a list of non empty lists, so head is guaranteed to be correct.
I could write excess code to handle this, such as rewriting group, but I like my solution.
>>
>>54781140
maximum is not total either.
>>
>>54781137
actually, this is slightly broken
works weirdly with length 1s and with the edges of the string
>>
>>54781137
Ok, just remove the

let s = Seq.map fst (Seq.filter ((<||) (=)) (Seq.pairwise s))

and it'll work
>>
>>54781076
dissecting char by char is the only way, right?
using other libs which don't even work (json, aeson) won't help
>>
>>54781043

It's pretty hard to beat c# when it comes to writing simple utilities or desktop applications for windows.

It's easy to learn, hard to fuck up, and has a library for most things unless you're doing something weird. Plus you can always just import and call externally the lower level windows API functions if you need them.

It's a productive language. I'll agree with you about ASP.NET though, utter shit, widely used but utter shit.
>>
>>54781152
import Data.List(group)
longest :: String -> [Char] -> Int
longest str targ =
foldl max 0
$ map length
$ filter (any (`elem` targ))
$ group str


>>54781001
The javascript-functional way would be to use callbacks.
function groups (arr, cb)
{
var val = arr[0], n = 1;
for (var i = 1; i < arr.length; i++) {
if (arr[i] == arr[i - 1]) {
n++;
} else {
cb(val, n);
val = arr[i];
n = 1;
}
}
cb(val, n);
}

function longest (str, targ)
{
var n = 0;
groups(str, function (char, len) {
if (targ.includes(char)) {
n = Math.max(n, len);
}
});
return n;
}
>>
>>54780925
man, this took me WAY too long.
But I used reduce and I didn't use a counter :)
although I did have to use a 'return' array and a 'current streak' array

function differenceSplit(str){
var ret = [], curr = [];

str.reduce(
function(previousValue, currentValue, currentIndex, array) {
if (currentValue != previousValue){
if (currentIndex == 1)
ret.push([previousValue]);
else
ret.push(curr);

curr = [currentValue];
if (currentIndex == array.length - 1)
ret.push(curr);
}
else {
if (currentIndex == 1)
curr.push(previousValue);
curr.push(currentValue);

if (currentIndex == array.length - 1)
ret.push(curr);
}

return currentValue;
});

return ret;
}

Array.prototype.diffSplit = function () {
return differenceSplit(this);
};

console.log([1,2,2,3,4,5,5].diffSplit());
console.log(("AAGHJJYYYLRRYRRYRRRRY".split('')).diffSplit());
>>
>>54781219
wow that is some MEAN looking javascript it's going to take me a while to get how it works.
>>
>>54781219
ah that's dope how your callback function references longest's 'targ' parameter, you made a clojure
>>


let consecutives s =
Seq.fold (fun subs x ->
match Seq.tryHead subs with
| Some (c,i) when c=x -> seq { yield (x,i+1); yield! Seq.tail subs }
| _ -> seq { yield (x,1); yield! subs }
) Seq.empty s
let intersectsBy f a b = Seq.filter (fun x -> Seq.exists (f x) b) a
let longestConsecutiveOf chars s = Seq.maxBy snd (seq {
yield! intersectsBy (fst >> (=)) (consecutives s) chars;
yield (' ',0)
})
let soltn c s = snd (longestConsecutiveOf c s) // final solution (just returns length)
printfn "%A" (longestConsecutiveOf "AZQ" "AAAZZGYYYYYYYYQ") // ('A', 3)
printfn "%A" (longestConsecutiveOf "AZY" "AAAZZGYYYYYYYYQ") // ('Y', 8)
>>
>>54781253
>>54781260
Hopefully informative comments for groups() procedure. longest() should be easy to understand
/* calls cb(val,n) for every grouped
sequence of 'val' in 'arr', of length 'n'
e.g.
groups("AABCCC", f)
calls
f("A", 2);
f("B", 1);
f("C", 3); */
function groups (arr, cb)
{
var val = arr[0]; // current value in sequence
var n = 1; // length of sequence
for (var i = 1; i < arr.length; i++) {
// is there a break in sequence?
if (arr[i] == arr[i - 1]) {
n++; // if no, increase seq length
} else {
// if yes, send callback about old seq
cb(val, n);
// create new sequence based on this value
val = arr[i];
n = 1;
}
}
// call again for the last sequence in the array
cb(val, n);
}
>>
Optimized some file I/O code, mostly the "I" part.

Now I can load and parse the same amount of stuff in 100-150 milliseconds that previously took 1.5-2 seconds. It also helps by not reading stuff one byte at a time, but in larger chunks. This in non-optimized builds. In optimized builds I routinely get <50 millisecond times.

Remember kids: I/O is always slow, avoid it as much as possible. When you have to do it, read and write large chunks.
>>
>>54781219
oh my fuck you used a clojure on 'n' as well

i like how in groups, you start your for loop with the 2nd element and compare to the prior. you can carry on with a normal for loop that way without checking to see if you're too close to the end.

not only is your answer badass, it's also shorter than mine, AND you didn't try to cut corners - you used curlies even when you didn't have to, like the if statement in the callback declared in longest.

god damn i wish i could write code like you. it seriously just took me like 7 minutes to wrap my head around your code, fuck. are you like the Mozart of programming or what
>>
File: a.png (258 KB, 500x351) Image search: [Google]
a.png
258 KB, 500x351
>>54781283
Isn't that common knowledge?
>>
>>54781268
hey F# dude if you're interested in converting people to F#, tell us why you like F#
>>
File: 1450210916535.gif (295 KB, 700x704) Image search: [Google]
1450210916535.gif
295 KB, 700x704
>>54781289
>clojure
lol, "clojure" is a language and "closure" is a function with scope. But I'm glad you understand what makes a closure a closure, people get that terminology confused so often.

>AND you didn't try to cut corners - you used curlies even when you didn't have to,
I'm trying to get used to this coding style. I used to aggressively omit curlies when there was only one statement.

>>54781283
>Remember kids: I/O is always slow, avoid it as much as possible. When you have to do it, read and write large chunks.

>mfw people microoptimizing their for-loops and integer averaging functions when the bottleneck is ALWAYS IO (or the cache)
>>
>>54781318
the code can be really clean and concise
it's nice to write in

though there could be significant improvements, namely
>higher kinded polymorphism
>macros & compile time evaluation
>performance
>>
>>54781343
cool thx
>>54781335
I'm pretty sure I'm going to save your answer and just look at it every day until I can write code like it, that's just how crazy cool I think it is.

Earlier today I wrote some code like this:
while((function(){
// something with somevar
})())
somevar++;


and was pretty proud of myself cuz i felt like i was thinking outside of the box
>>
Is /pol/ the only board being slid right now?
>>
>>54781317
Illya is a cuck and that's a fact.
>>
>>54781460
Women can be cucks if they want
>>
>>54781428
Hopefully.
>>
File: wow anon.jpg (78 KB, 884x574) Image search: [Google]
wow anon.jpg
78 KB, 884x574
int i = 1;
++i++;
printf("%d", *(int *)&i)
>>
I was looking through my shelf the other day and I noticed I had this book. My parents must've bought it for me when I was in high school several years ago, anyone have experience with this book? I've been recently looking to relearn C++ since I only ever did an introductory CS class 2 years ago, never did anything with C though so I suppose it's fine to start there. Table of Contents has a chapter titled "On to C++" as well. Worth a read?
>>
>>54781590
look at me im so smart anons!
>>
>>54781343
Ok except macros are really not needed
>>
>>54781622
you could have read the book instead of asking about it
>>
>>54781676
your parents could've aborted you instead too
>>
>>54776509
Hey guys. I'm trying to make a CrackMe program in C++ using CLion. It works fine, but when I try to compile it using G++ for use on Windows 7(to use Olly/Ida on it) it doesn't work.

How do you do cross platform C/C++? I figure now is as good a time as any to learn.
>>
>>54781685
I could have came in your dad's ass instead of your mom's pussy when the three of us planned to attempt to conceive you, but I really wanted a brother.
>>
File: oDCku2OIub5lDuf7fCdTkg-wide[1].jpg (19 KB, 300x400) Image search: [Google]
oDCku2OIub5lDuf7fCdTkg-wide[1].jpg
19 KB, 300x400
>>54781709
easy there m8
>>
>>54781730
we're blood brothers. destined to mate for life.
>>
>>54781667
(You)
>>
>>54781751
Thank fuck the core team agrees with no macros
HKT will be added by C#8 though, which is good
>>
File: gourmet.webm (1 MB, 720x404) Image search: [Google]
gourmet.webm
1 MB, 720x404
/dpt/-chan, dai suki~

>>54781708
Have you installed mingw ?

You then do mingw32-g++ foo.c -o foo.exe

>>54781708
>I'm trying to make a CrackMe
Source ?

>>54781428
pol is gossip now, they goes nut on depp vs amberd.
>>
>>54781708
>I'm trying to make a CrackMe program in C++ using CLion. It works fine, but when I try to compile it using G++ for use on Windows 7(to use Olly/Ida on it

Don't. It will be a shit crackme if you target Windows with gcc because of all the extreme bloat mingw or cygwin will add.

>How do you do cross platform C/C++
With preprocessor macros used at the lowest level possible, then you build your functionality on that so compiling with gcc (on Linux) is no different than using MSVC on Windows.
>>
>>54781795
Implementing macros is a good thing, and it's incredibly odd to see a language which has so many DSL features saying no to macros. At the very least I hope we get something more like monad comprehensions in F# rather than the less concise computation expressions


also, source on HKT?
>>
>>54781799
Here's my source.

It's nothing special and I threw it together in 2 minutes, and and my C++ sucks.

http://pastebin.com/NBMVEVc6
>>
>>54781842
Well shit.
So do I just stick to using VMs for reverse engineering?
>>
>>54781848
what

And that doesn't compile everywhere?
>>
>>54781880
Nope.
You know what really pisses me off? I just compiled the EXACT SAME source file in Clion IN MY WINDOWS 7 VM and it's still fucking bitching about missing the same DLL. Maybe it's a problem with my Windows setup.
>>
>>54781921
OK GOT IT!
I had to compile it like this:
i686-w64-mingw32-c++ -static main.cpp -o CrackMe.exe
>>
File: msp430_ircl_channel_43oh.png (10 KB, 400x400) Image search: [Google]
msp430_ircl_channel_43oh.png
10 KB, 400x400
I'm writing an IRC bot. It needs to process incoming messages and reply to them.
Is it a good idea to dump all incoming messages in a queue and have a thread processing them (while also have the same thing for outgoing messages)?
>>
>>54781972
What are you writing it in?

I suggest the Twisted library if it's in Python.
>>
>>54781972
As long as you join the threads before sending any replies to the same server or user. Is your processing really this heavy?
>>
>>54781972
The delay between messages will likely be MUCH MUCH MUCH MUCH longer than it takes you to process a small string.
>>
>>54781972
if your bot has an user interface, then you should have two threads: gui and network. if not, one thread is enough.
>>
File: idiot sandwich.jpg (58 KB, 552x621) Image search: [Google]
idiot sandwich.jpg
58 KB, 552x621
>>54781998
I'm indeed writing it in Python, but with raw sockets. Twisted does not sound like a good time, I'll pass.

>>54782007
>>54782032
I guess I should explain the reason for my question.
(I warn you it's a pretty dumb entry-level OOP question)

There are two classes, IRC and Bot. IRC handles all the rx/tx stuff and Bot handles all the command parsing and figuring out what to reply with.
Both IRC and Bot need to use each other's methods: for example IRC needs to give a message to Bot for handling it, and IRC sometimes needs to just send something using a method from IRC.
How does one make it work?

Currently I do this:
bot = Bot()
irc = IRC(bot)

But that doesn't allow Bot to use any of IRC's methods, only IRC use Bot's methods.
I want this:
irc = IRC(bot)
bot = Bot(irc)

but it's obviously wrong.

The queue idea solves this problem, but it's maybe overkill.
>>
>>54782131
What you really want is:
irc_bot = IRC<Bot>();
>>
>>54782131
A queue isn't a bad idea (I'm assuming that's just a basic array structure in python).

I just wanted you to keep in mind that most likely there won't be more than 1 item in that queue, due to the speed it takes a computer to process a string with the length you'd usually get in a chat message, is laughable.
>>
>>54782179
I have no idea what this does.

If it wasn't clear again, my code snippet basically indicated that I passed Bot object as an argument, stored it as a bot variable in the IRC object and then had
self.bot.someBotMethod()
in the IRC class any time I wanted to use methods from it.

I don't think that's how this whole OOP thing is supposed to be done, but that's what I hacked together and now it's falling apart. I should read up on some higher-level OOP concepts or something.
Any pointers?
>>
>>54782229
The most simple solution for you currently would probably be, to create a function in each of those classes that accepts the other class as a parameter and sets it to a local variable.

I have no clue how python works, but probably something like that.

bot = Bot()
irc = Irc()

bot.setIrc(irc);
irc.setBot(bot);

This is obviously terrible, and I don't even know if it's valid python. But it should work if I understand what you've been trying to say.
>>
>>54782131
Why not have a class that contains an instance of both objects and acts as a controller?
>>
>>54782227
>there won't be more than 1 item in that queue
I know. "Queue" could not be a queue at all, for all I care. I just need some medium for two way communication between objects. Two queues is what I came up with.

>>54782275
That will probably work, but it only makes me once again realize that the whole structure of the program is flawed and I just don't know any better.
Thanks anyway, I'll try that.

>>54782319
Huh, I never thought of that. Thanks, I'll look into this.
>>
Programming fast Fourier transform in Haskell's type system.
>>
>>54782750
Is it Turing complete? I wouldn't doubt it.
Thread replies: 255
Thread images: 40

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.