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

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 317
Thread images: 32

File: dpt_flat.png (102KB, 1000x1071px) Image search: [Google]
dpt_flat.png
102KB, 1000x1071px
Old thread: >>58485295

What are you working on, /g/?
>>
File: 1483998399141.jpg (111KB, 1024x768px) Image search: [Google]
1483998399141.jpg
111KB, 1024x768px
Convoluted but concise Haskell solutions to problems in other languages
>>
PYTHON

when I iterate through a list

for i in list:


and I delete items within the for loop with list.remove()

it confuses the iteration

what do?
>>
>>58491718
If it isn't illegibly terse, you haven't tried hard enough.
>>
>>58491718
Write an in-place quicksort.
>>
>>58491718
post some haskells
>>
>>58491725
Avoid Python.
You can flag (another list maybe?) then for destruction and do the destruction call.
>>
>>58491745
()
>>
>>58491718
this, but make sure it always starts with "in haskell, this isJust"
>>
>>58491772
describe what is it that its doing
>>
>>58491725
googlesearch and click on a few stackoverflow.com links
>>
>>58491796

lol I did exactly that and I found the solution.

thanks
>>
>>58491814
You're now an official programmer!
>>
>>58491725
> For loops in Python get reevaluated every loop
Wew
>>
>>58491725
Use filter instead.
>>
File: 2017-01-14-222129_573x613_scrot.png (31KB, 573x613px) Image search: [Google]
2017-01-14-222129_573x613_scrot.png
31KB, 573x613px
Which is better?
>>
>>58491834
That's a strange way of interpreting what is going on there.
>>
>>58491840
first
>>
>>58491840
B.
But write a macro for easier writing, those cons cells are horrible.
>>
>>58491840
First.
>>
>>58491840
top, cleaner and shorter
>>
>>58491840
first
>>
>>58491695
>What are you working on, /g/?
Learning rust, implementing the panda api, which is really just a json rest front end, I guess.
>>
>lisp can't even into pattern matching
lol
>>
>>58491846
How so?
>>
>>58491902
Lots of languages with iterators get fucked when you try to change the contents of the thing you are iterating over.
>>
>>58491725
iter_list = list[:]
for (index, element) in enumerate(iter_list):
if cnd:
list.remove(index)
>>
Why doesn't "go build" support PGP signatures?
It's a security nightmare...
>>
>>58491911
Sounds like a good way to implement a stack overflow.
>>
>>58491957
(remove-if #'cond-checker lst)


Python plebs.
>>
>>58491969
Why should a compiler have that functionality? GCC does not support PGP signatures either.
>>
>>58491991
at least i have a job
>>
>>58491991
*
(remove-if #'(lambda (x) (some-bullshit-that-takes-at-least-three-lines) list)


watch this
filter cnd


lisp plebs
>>
>>58492029
"go get" is a built-in and much used feature of go that downloads packages from remote repositories.
>>
>>58491718
>>58491736

 -- a monoid is sort of like a monad, but not (necessarily) in the category of endofunctors
import Data.Monoid
import Control.Applicative -- it's not real programming if you don't break out the S combinator at least once

-- it's important to avoid magic numbers
three :: Integer
three = 3
five :: Integer
five = 5

-- type signatures ensure self-documenting code
forb :: Integer -> String
forb = mwhenMof three "Fizz" <> mwhenMof five "Buzz"

-- point-free style is a great way to enhance readibility
mwhenMof = mwhen . ((0 ==) .) . flip rem
mwhen p m x = if p x then m else mempty

-- function and variable names must be chosen carefully
fb = rwhen (== mempty) . forb <*> show
rwhen p x y = if p x then y else x

-- et voila!
main = putStr $ foldMap (<> "\n") $ fb <$> [1..100]
>>
File: Capture.png (36KB, 787x441px) Image search: [Google]
Capture.png
36KB, 787x441px
>>58490803
Thanks, implemented into my shitty client
>>
>>58492048
>three, five, forb are monomorphic
>>
>>58492043
Exceedingly pretty code there my fellow Haskellbro.
>>
>>58492043
(defmacro filter (cond)
`(remove-if-not (lambda (i) ,cond) *that-list*))

(filter cnd)
>>
File: 1483423464145.jpg (96KB, 576x720px) Image search: [Google]
1483423464145.jpg
96KB, 576x720px
>>58492048
>>
>>58492044
"go get" != "go build" The reason is interoperability. It is designed to abstract away many sources of dependencies. Your deps might be in your GOROOT or in someone's Github repo, a self-hosted git repo, some other subversion repo, the local vendor directory. Have fun forcing every one of these to sign with PGP.
>>
>>58492135
Why a macro when you could have used a function? Too many macros bloats the icache.
>>
>>58492151
Clearly it's a shit abstraction, then.
>>
>>58492159
I doubt the instruction cache is the first thing on a lispfag's mind.
>>
Guys, is it possible to describe any non-prime number with a combinations of 2's and 3's?

for example if 198237481923894 is an even number and therefore non prime, IGNORING ALL THE PRIMES WITHIN THAT NUMBER will the rest of the factors just be 2's and 3's?
>>
anybody have any neat but doable in an evening problems?
>>
>>58492182
No you fucking idiot
>>
>>58492167
An abstraction can't enforce implementation on the things it is abstracting.
>>
>>58492159
Because with the macro you avoid the (lambda (...) ...), with that horrible macro you can:
(filter (= i n)) and you don't lose scope.
>>
>>58492189
prove it you fucking idiot
>>
>>58491991
you can just use filter in python
>>
>>58492190
it can, they just chose not to
>>
>>58492204
10
>>
>>58492204
14.
>>
>>58492210
>>58492213
ppl who dont know how to read
>>
>>58492204
1
>>
>>58492225
You need a 7 to make 14.
>>
>>58492225
>IGNORING ALL OF THE PRIMES INSIDE THAT NUMBER
all numbers are the fucking same when factorised if you just ignore all prime factors
>>
>>58492209
How? By forcing very repo in the universe to sign with PGP?
>>
>>58492230
assuming its greater than 2
>>
>>58492190
If you can't make a good abstraction then you might as well not bother with one. Downloading from an unverified source is a potential problem, so if the abstraction doesn't let you use PGP when it's highly desirable then it shouldn't be used.
>>
>>58492239
not pull from repos without it, obviously
>>
>>58492246
then make sure each source is using https or ssh and let your certstore or keyring deal with it
>>
>>58492246
>>58492252
So you are saying you should make it more complicated to host and publish libraries and invalidate any methods that can not sign with PGP? That's crippling to growing platform.
>>
>tfw use cloc and realize your project is over 10k lines of C
>>
>>58492236
apart from butchering that sentence thats what I wanted to know
>>
>>58492182
35 is 7 x 5
>IGNORING ALL THE PRIMES WITHIN THAT NUMBER
what the fuck are you talking about? all (positive natural) numbers are composed of primes
>>
>>58492309
what you said makes no sense
>ignoring the primes inside it
so ignoring the 2s and 3s
>>
I hope learning vim is worth it. Coming from sublime text
>>
>>58492327
Sublime Text with vim commands is really nice, but emacs is nicer
>>
>>58492327
vimtutor is your friend.

Eh, a lot of people love vim, a lot of people hate it. It's worth trying it out, at least.
>>
>>58492170
It sure is.

Using the macro:
; disassembly for WITH-MACRO
; 24: 498B4C2460 MOV RCX, [R12+96]
; 29: 48894DF8 MOV [RBP-8], RCX
; 2D: 488B0594FFFFFF MOV RAX, [RIP-108]
; 34: 8B78F5 MOV EDI, [RAX-11]
; 37: 498B3C3C MOV RDI, [R12+RDI]
; 3B: 83FF61 CMP EDI, 97
; 3E: 480F4478F9 CMOVEQ RDI, [RAX-7]
; 43: 83FF51 CMP EDI, 81
; 46: 741B JEQ L0
; 48: 488B1571FFFFFF MOV RDX, [RIP-143]
; 4F: 488B057AFFFFFF MOV RAX, [RIP-134]
; 56: B904000000 MOV ECX, 4
; 5B: FF7508 PUSH QWORD PTR [RBP+8]
; 5E: FF6009 JMP QWORD PTR [RAX+9]
; 61: CC10 BREAK 16
; 63: L0: CC0A BREAK 10
; 65: 06 BYTE #X06
; 66: 00 BYTE #X00


Using a function:
; disassembly for WITH-FUNC
; Size: 36 bytes. Origin: #x1002471F04
; 04: 498B4C2460 MOV RCX, [R12+96]
; 09: 48894DF8 MOV [RBP-8], RCX
; 0D: 488B159CFFFFFF MOV RDX, [RIP-100]
; 14: 488B059DFFFFFF MOV RAX, [RIP-99]
; 1B: B902000000 MOV ECX, 2
; 20: FF7508 PUSH QWORD PTR [RBP+8]
; 23: FF6009 JMP QWORD PTR [RAX+9]
; 26: CC10 BREAK 16
>>
File: 1314933628833.png (5KB, 493x402px) Image search: [Google]
1314933628833.png
5KB, 493x402px
How to learn Hasklel?
>>
>>58491695
hey /dpt

In Java, if I have
MyObjectA x = new MyObjectA();
and MyObject is derived from AllMyObjects
how do I make a copy of x?
>>
>>58492314
>>58492318
Ok I fucked up what I was trying to say

let me reintroduce the problem:

I have some number N that happens to be even, I want to construct the smallest N in which N is divisible by all numbers from 1 to 20.

Firstly I find all the primes between 1 and 20 and multiply them together, this is my lower bound.

Then heres where im stuck, there should be a very simple way for me to "fill in" the rest of the factors which are not included, e.g 4, 6, 8, 10. . . but I cant think of it for some reason, I should have to multiply my lower bound with a certain number of 2's and 3's in order to get every other possible factor
>>
>>58492384
https://www.haskell.org/platform/
https://en.wikibooks.org/wiki/Haskell
>>
>>58492384
haskellbook.com

>>58492390
Platform is controversial
>>
>>58492387
I think I have it figured out, I take the floor of every number of the i'th root of 21 numbers from 1->20, then I multiply them all together and it should give me my N

This seems correct and works but I just need to wrap my head around if its true for every scenario
>>
>>58492043
Scheme and Racket both have filter
>>
File: 1428715071265.gif (1008KB, 320x240px) Image search: [Google]
1428715071265.gif
1008KB, 320x240px
>>58492408
> $59 USD
>>
>>58492426
I mean after taking the i'th root of 21 I multiply it by that many powers of i :)
>>
>>58492433
look up the pdf on archived fpts
>>
>>58492431
remove-if == fitler, dumbass
what's in display here is partial application
>>
>>58492448
>archived fpts
on what now?
I'll just google the pdf
>>
>>58492408
That's a man.
>>
>>58492387
Is this project euler?
>>
>>58492470
yes, the answer is very common sense but I cannot seem to figure out how to program it in a reasonable way
>>
>>58492476
I mean, I cant seem to figure out how to program it in a very fast way, It can't just be correct, it has to be done very cleverly
>>
>>58492461
Partial application is basically just currying. One extra step if you're going from Lisp.
>>
>>58492387
foldl1 lcm [1..20]
>>
>>58492476
>>58492485
I'm sure there are plenty of optimizations that you can make to this, but it's at least better than the brute force approach:

1. Compute the prime factor decompositions of all the numbers from 2 to 20 inclusive
2. Represent them as maps from prime factor -> number of times it appears in the decomposition
3. Sum those maps, taking the biggest value in the case of a key collision
4. You now have a map representing the prime factor decomposition of the number you want
>>
Text editor poll continues
http://www.strawpoll.me/12023125
>>
>>58492387
... you mean you want the lowest common multiple of [1 .. 20]
>>
>>58492506
that's the problem th0ough
>>
>>58492529
Emacs, with evil-mode
>>
>>58492525
whew
also
foldl lcm 1
>>
File: akarin happy.png (234KB, 696x720px) Image search: [Google]
akarin happy.png
234KB, 696x720px
>>58492526
yes that is what I would do normally but it is not to my liking

Right now I think I'm on to something...
If I take all the non 2/3 primes and multiply them then I get a lower bound, then I take the floor of i'th root of 21 and make it a power of 2 and do the same thing for 3 and it gives me the correct result every time

this seems like absolute wizadry and best of all its O(1) time assuming we already have a list of primes... and literally so much less computation than that you described.

The only problem is why I cant figure out why "it just werks"

>>58492534
yes sorry lol
>>
File: 1424116310569.png (512KB, 2958x1461px) Image search: [Google]
1424116310569.png
512KB, 2958x1461px
Not strictly programming related, but I made an IRC channel for my decentralized TV project (#basictv on Freenode, can be accessed with webchat.freenode.net).

Strictly programming related: I'm working on establishing TCP connections, SOCKS integration, and fixing some errors. Nothing too interesting on that front
>>
>>58492043
parens are not balanced, opinion discarded
>>
File: okey dokey.png (242KB, 370x480px) Image search: [Google]
okey dokey.png
242KB, 370x480px
>>58492612
Seems to work every case, I want to know the reason behind this if anyone knows. Cant figure it out on my own
>>
>>58492612
What problem is this, exactly?
>>
>>58492679
Problem number 5. This is really fun I just discovered this yesterday. Lots of random thing you come across along the way
>>
there's no way this is the correct way to write a linked list in c. i've been fucking around trying to write this from memory and this is what i came up with.
originally i was just passing the pointers in, not passing references to the pointers. i guess i incorrectly assumed that pointers were passed by reference, but this seems not to be the case. still, this doesn't look right. can anybody explain this to me?

#include <stdio.h>
#include <malloc.h>

struct Node{
struct Node *next;
int data;
};

struct Node *Node(int _data){
struct Node *temp =
(struct Node *) malloc(sizeof(struct Node));
temp->data = _data;
temp->next = NULL;
return temp;
}

// Insert at end of list.
void insert(struct Node **head, int _data){
if (*head == NULL)
*head = Node(_data);
else{
struct Node *current = *head;
while(current->next != NULL){
current = current->next;
}
current->next = Node(_data);
current = NULL;
}
}
void removeNode(struct Node **head){
if (*head == NULL){
printf("Empty list, can't remove.\n\n");
return;
}
struct Node *current = *head;
struct Node *prev = current;
while (current->next != NULL){
prev = current;
current = current->next;
}
if (current == *head)
*head = NULL;
else
prev->next = NULL;
free(current);
current = NULL;
prev = NULL;
}
void printAll(struct Node *head){
if (head == NULL)
return;
struct Node *current = head;
while (current != NULL){
printf("%d\t", current->data);
current = current->next;
}
printf("\n\n");
current = NULL;
}
int main(){
struct Node *head = NULL;
insert(&head, 1);
insert(&head, 2);
insert(&head, 3);
removeNode(&head);
removeNode(&head);
removeNode(&head);
removeNode(&head);
insert(&head, 4);
insert(&head, 5);
insert(&head, 6);
printAll(head);
return 0;
}

again, this code works, but it just doesn't feel right.
>>
>>58492612
Okay - so the primes 11, 13, 17, and 19 are only needed once in the result, because no other numbers in [1..20] are divisible by them. So we just need to look at 2, 3, 5, and 7.

>i'th root of 21
What exactly do you mean by this? What is i?
>>
>>58492703
c is so ugly.
>>
>>58491725
if it's a static size, work backwards and that can't happen. If it needs to be linear, just reverse the order and do it backwards.
>>
>>58492718
So? It's a tool not your girlfriend.
>>
>>58492709
I explain it better here >>>/sci/8603283

I think its more relevant to /sci/
>>
Whats a good python editor?
>>
>>58492703
>there's no way this is the correct way to write a linked list in c.
At a quick drunken glance, it looks correct.
Also, you don't need to cast the malloc result.
>>
>>58492767
You are retarded my dude.
>>
>>58492784
thanks, i guess it makes sense. it's just ugly as >>58492718 said.
>>
>>58492810
explain pls
>>
>>58492703
Pointers to pointers are considered one of the "best" (most elegant) ways to deal with a linked list in C.
It removes the special case of dealing with the head of the list.
However, due to some of the things happening in your code, you probably don't understand the wonders that is two star programming.
>i guess i incorrectly assumed that pointers were passed by reference, but this seems not to be the case
Right. C is ALWAYS pass-by-value.
>this doesn't look right. can anybody explain this to me?
To save me rambling on longer than I need to, you actually understand how a normal pointer works, right?
It would allow my explanation to be a lot shorter.

><malloc.h>
Please don't do something so pointlessly non-portable.
<stdlib.h> is the header you want.

>>58492718
He appears to be a novice programmer.
They're not known for producing nice looking code.
>>
File: gnomeme.jpg (11KB, 480x360px) Image search: [Google]
gnomeme.jpg
11KB, 480x360px
>>58492054
so i see you're using WPF...
>>
>>58492822
>it's just ugly as >>58492718 said.
Maybe, but it makes sense, other languages may look prettier, using some higher level functions/api, but if you where to look at the actual implementation of said functions, it would probably look just as ugly.
That is one of the nice things about C, does it look pretty at all times?
No, but it does exactly what you tell it to, no if buts or ands.
>>
>>58492054
>>58492871
(forgot to ask my question in my haste to shitpost)

how do you implement scrubbing with the slider while also keeping its position updated? seems like the only solutions i found via google were hacks.
>>
>>58492888
This. If you want to make it look prettier, use macros.
>>
>>58492835
How can I get gcc to disallow non-portable includes?
>>
>>58492632
>decentralized TV project
what's it do?
>>
>>58492903
Pedantic, init?
>>
>>58492948
I already have it set.
>>
>>58492871
>>58492892
>You know what they say, old habits die hard.

Anyways, I update my scrubber every second. I attached to Thumb.DragStarted & Thumb.DragCompleted events, toggling a boolean variable. If the user is currently dragging it, I dont update the scrubber.
>>
>>58492903
http://en.cppreference.com/w/c/header
If you include anything not from this list "excluding your own files", it's not portable.

There are plenty of good reasons to do things which aren't strictly portable (such as simply using a library), but using <malloc.h> over <stdlib.h> is not one of them,
>>
>>58492942
it is like TV, but you can indefinitely rewind live TV, export it to other formats, have infinite amounts of channels, multi monitor setups, fueled off of Bitcoin, 4K and higher resolution, faster refresh rates, multiple different dubs and subs, 3D (red and blue), can be used over Tor really quickly, and is cryptographically secure. It also can do some more technical jargon to make it run nicer and more securely.

Essentially it is the lovechild of Bitcoin, BitTorrent, Tor, and cable TV.
>>
>>58493024
Thanks anon.
>>
>>58493024
>"excluding your own files"
I meant to put () around that. I have no idea why I did "".
>>
>this is valid C# code
how can other languages even compete?
unsafe void Main()
{
int data = 69;
int nextData = 1772;

Node* current = (Node*)Marshal.AllocHGlobal(sizeof(Node)).ToPointer();
Node* next = (Node*)Marshal.AllocHGlobal(sizeof(Node)).ToPointer();

current->Data = &data;
current->Next = next;

next->Data = &nextData;

Console.WriteLine("{0} {1}", *(int*)current->Data, *(int*)current->Next->Data);

Marshal.FreeHGlobal(new IntPtr(current));
Marshal.FreeHGlobal(new IntPtr(next));
}

unsafe struct Node
{
public Node* Next;
public void* Data;
}
>>
File: OUT-2400000.png (295KB, 1600x1600px) Image search: [Google]
OUT-2400000.png
295KB, 1600x1600px
mmmmmmmm
>>
>>58493059
What youve done literally C and Java and everything pretty much else can do.
>>
>>58493059
so what, C, but you need to define unsafe wherever you want direct memory control?
>>
>>58493108
Java has no pointer arithmetic
C has no OOP
>>
>>58493130
>C has no OOP
That's a good thing though.
OOP is fundamentally flawed.
>>
>>58491684
>Is that actually entry level or are you goofing me? That sounds highly unassuming and convoluted
It's actually a book that I found by searching for "most difficult mathematics book" :P
It's bleeding edge set theory, mathematics PhD material
>>
>>58493136
It's still much better organization-wise for large scale projects
>>
>>58493171
Better than nothing, maybe.
>>
File: image.jpg (125KB, 1062x656px) Image search: [Google]
image.jpg
125KB, 1062x656px
>>58492998
what does your client do, exactly?

i'm writing a music 'aggregator' i guess, the idea is that it can connect to pandora or youtube (or whatever other service) behind the scenes, download the music to my local disk, and stuff the metadata in a database.

eventually, i want to have it just speculatively keep downloading shit in the background, and have some sort of mechanism to identify the best version of a song if it gets multiple copies (e.g. from different youtube videos, or one from pandora and one from youtube). also, i want it to be able to tag youtube videos automatically, so i'm looking to integrate with some sort of music tagging or identification service, maybe shazam.
>>
>>58493191
How else are you going to manage any sizable amount of data?

>>58493199
That sounds cool.
>>
>>58493211
FP
>>
>>58493171
>I don't know how to organise projects other than OOP
>Therefore it's the best way
Good one.
Idiot.
>>
>>58493059
>(Node*)Marshal.AllocHGlobal(sizeof(Node)).ToPointer();
>Marshal.FreeHGlobal(new IntPtr(current));
#include <stdio.h>
#include <stdlib.h>

typedef struct Node
{
struct Node *Next;
void *Data;
} Node;

int main(void) {
int data = 69;
int nextData = 1772;

Node* current = malloc(sizeof(Node));
Node* next = malloc(sizeof(Node));

current->Data = &data;
current->Next = next;

next->Data = &nextData;

printf("%d %d\n", *(int*)current->Data, *(int*)current->Next->Data);

free(current);
free(next);

return 0;
}
>>
Working on character recognition software. We have neural network to recognize characters but not a way to convert page of characters into multiple files of characters. Working on this now (image segmentation).

Takes .png of a scanned document of handwritten words. Creates an image of each character written therein. It has a couple of bugs but WIP still.

Video related: https://www.youtube.com/watch?v=p1Fi0f1L3HQ

PS: I'm using an old Thinkpad x120e to do this one since I can't commit my home PC to Linux. It runs crazy slow.

Right now errors are caused by noise in the scanned image. A perfect image would be one written on a tablet or mouse, as the background is guaranteed to be white. Since a scanner might have dust, dirt, etc on the scanner itself, these appear in the image and might fuck with the algorithm.

I fool with noise thresholds to ignore an amount of noise per line and column. This is at 0.5% (so if a line is 1000 pixels, if it contains 5 nonwhite pixels or less, it will ignore them, otherwise it's part of a character). Problems arise with letters like p, q, j, g as the underhanging pixels are misinterpreted as noise.
>>
>>58493199
It's a basic Spotify clone I wrote in a day. You can search stuff & add it to playlists. It uses Spotify's API for metadata (like the album image).

As for best song identification, the best conclusion I came to is search the song via youtube, filter out titles that include 'video' for music videos (unless the song contains video too), use the topmost result suggested by YouTube, separate artist & name by splitting by '-' and remove anything inside parenthesis in the title.
>>
>>58493248
The point I was trying to make is that it has the best of both worlds.
>>
>>58493270
I ALSO made a song downloader, but you give it a file full of song titles and names and it gets the proper version of youtube.
>>
>>58493299
It doesn't, though.

One of C's biggest advantages is that it doesn't need .NET or the CLR or anything like that.
>>
>>58493299
Microsoft's dick is not the best of any world.
>>
>>58493299
> best of both worlds.
>still relies on a massive fucking runtime
yeah... about that...
>>
>>58493314
>libc
>>
>>58493363
libc is nothing compared to .net
>>
>>58492709
It's the union of the multiset of teh factors of all the numbers. Does that make it easier?
>>
>>58493363
C's runtime is ridiculously small.
>>
File: IMG_20170115_164912.jpg (1MB, 1920x1080px) Image search: [Google]
IMG_20170115_164912.jpg
1MB, 1920x1080px
>>58491695
The book (Automate the?boring stuff with Python) tells me to write this in idle3. So I do, and when I go to run it. It says I need to define Alice etc. Yet it never tells me to. And it says the code should just werk

I know how define, but it never tells me to, and goes on as if the code worked?with no definition.
>>
>>58493234
Without OOP, you don't get polymorphism or data encapsulation.
>>
>>58493444
Complete nonsense. The two concepts are independent of OOP.
>>
The equality relation on kinded objects (types, type families, etc.) is structural and the equality relation on typed objects (values) is based on eta-conversion.
>>
>>58493444
Polymorphism is not exclusive to OOP.
Encapsulation is not exclusive to OOP or even a good thing.
>>
>>58493248
>typedef struct foo {...} foo;
Kill yourself
>>
>tfw can't do fibonacci with the loop macro
why even live
>>
>>58493458
I think encapsulation is good when you're doing it with e.g. MonadState and lenses
>>
File: frosting.jpg (132KB, 491x539px) Image search: [Google]
frosting.jpg
132KB, 491x539px
>>58493461
>>
>>58493458
Encapsulation is fucking great when it doesn't necessarily involve marrying fields and methods in an object.
>>
>>58493458
>>58493493
Though maybe I'm mixing up information hiding in general with encapsulation.
>>
>>58493344

https://www.youtube.com/watch?v=4kiji-iZ8AI

>>58493255
>>
>>58493466
>macro
biggest meme in programming history
>>
>>58493521
>ft together
0/10 dropped reported called the cops
>>
>>58493522
Let me guess, you're some shitty java pajeet who has never used macros before?
Even a terrible text-based macro system like the C preprocessor is better than no macro system.
>>
>>58493552

Blame 4chan's font.
>>
>>58493564
>his solution can't adapt to different fonts
come back when you can identify a four year old's scribbles on pattern wall
>>
>>58493562
You are right on one thing
I have never use macros
because they are useless shit
>>
>>58493586
Enjoy your shitty almost duplicate code.
>>
>>58493600
right, because macros don't duplicate code
fucking idiot kys
>>
>>58491695
Can I just undo a git action?
I wanted to fix up my most recent commit and I didn't check hard enough in my notes to find the "amend" command so I did:
git checkout HEAD^
git branch -f master temp
git checkout master
git branch -d temp

I know, I checked the log before deleting and I just... didn't look closely enough.
Also there was a message that I didn't read because I thought it was normal, I just read it and it said I would be leaving two commits behind because they weren't connected to any branch. Why and how would that happen? I don't remember doing any branch fuckery before other than the above and "git commit --amend".
I have my current code but I lost the history of two commits.
please respond
>>
>>58493624
Good reading comprehension, idiot.
>>
>>58493642
fuck I have a backup and somehow it's even earlier than that commit, I could've sworn I backed up after that
also these commits had a lot of lines and were months apart
>>
File: 1458144041168.jpg (204KB, 1200x833px) Image search: [Google]
1458144041168.jpg
204KB, 1200x833px
Give me one sufficient reason why I should stick with C++ streams and not just move back to printf.
>>
>>58493736
You should just drop C++ entirely.
>>
http://www.strawpoll.me/12104750
>>
>>58493521
this is pretty fucking cool.

i'm assuming you'd want to feed that output into another neural network, i'm thinking you'd want maybe (x_location, y_location, character) as the inputs, then have that network try to figure out how to group the letters together to spit out coherent text output.
>>
>>58493736
Unless you are a brain-dead programmer who can't get the difference between %lu, %i and %p, none.
You can't even %x easily.
>>
>>58493758
Why is Visual Studio its own category, when you have "Other shitty IDEs" right below it?
>>
>>58493736
There's none. But I also agree with >>58493751, you should use Rust, which loves its format strings.
>>
fun :: a -> b -> Maybe [c]

We've seen signatures similar to this before, but isn't the Maybe [c] sort of redundant? What's the difference between [] and Nothing? Why not just
fun :: a -> b -> [c]
. Looking forward to your thoughts, hope you're having a great Sunday.
>>
>>58493777
Maybe the absence of any list indicates something other than an empty list would.
>>
>>58493791
But they are literally the same concept.
>>
>>58493777
They're not equivalent, which is significant like >>58493791 says. Consider a lookup function for a map of lists. Surely you'd want to be able to distinguish between the key being associated with an empty list and the key not being in the map at all.

>>58493818
Mathematics disagrees. You can't write a bijection between the two.
>>
What's wrong with eval?

Why would people get autistic if I did something like this?

function Vector(x, y) {
if(typeof x === "number") {
this.x = x;
this.y = y;
} else {
this.x = 0;
this.y = 0;
}
}

Vector.prototype.expr = function(vector, operator) {
if(vector instanceof Vector && operator.length === 1) {
return new Vector(
eval("this.x" + operator + "vector.x"),
eval("this.y" + operator + "vector.y")
);
}
};

var velocity = new Vector(0, 0);
var gravity = new Vector(0, 1);

velocity = velocity.expr(gravity, "+");


Must I write a function for every single operator?
>>
>>58493818
Yes and no.
They are both "empty" and don't have any useful data, but it's possible that the empty list is the correct result of the function, while Nothing indicates that something went wrong.
Say you have a function "get_list_from_place".
An empty list means that the list it got was just empty.
Nothing indicates that it couldn't get the list at all.
>>
>>58493839
>What's wrong with eval?
It's a massive security risk and is very inefficient.
>>
>>58493839
You just need a higher order function you spastic.
>>
>>58493867
Or a better language.
>>
>>58493876
Even then you would need a higher order function or something that amounts to the same.
>>
>>58493839
>>58493586
kek
>>
>>58493270

Assuming this is still the conversation thread about someone writing something in WPF, what books, sites, or videos would you recommend for learning how to make nice looking interfaces in WPF?
>>
>>58493736
>Give me one sufficient reason why I should stick with C++ streams and not just move back to printf.

Okay, I'll accept that challenge, even though I use printf myself.

Streams are actually pretty damn powerful. I'm not talking about just writing "Hello, World" to stdout. I'm talking about writing a class that can easily be written out and instantiated from a stream.

Streams were super cool back in the Turbo Pascal days, but I think that's because Turbo Pascal basically had RTTI enabled, making it quite a bit more powerful.

Even without RTTI, you can still make some pretty clean serialize/deserialize functionality using streams.

That said, the fact that left- and right-shift operators were overloaded for the obnoxiously fucking clever "oh look how neat it looks!" effect pisses me off to no end. IMO the two biggest flaws in C++ are 1) operator overloading and 2) member functions are non-virtual and private by default (should be virtual, protected by default).
>>
>>58494030
>Streams are actually pretty damn powerful. I'm not talking about just writing "Hello, World" to stdout. I'm talking about writing a class that can easily be written out and instantiated from a stream.
Okay, but is there a stream that could even possibly EVEN OUTPUT Madara Uchiha? Let alone read him. And I’m not talking about Edo Tensei Uchiha Madara. I’m not talking about Gedou Rinne Tensei Uchiha Madara either. Hell, I’m not even talking about Juubi Jinchuuriki Gedou Rinne Tensei Uchiha Madara with the Eternal Mangekyou Sharingan and Rinnegan doujutsus (with the rikodou abilities and being capable of both Amateratsu and Tsukuyomi genjutsu), equipped with his Gunbai, a perfect Susano’o, control of the juubi and Gedou Mazou, with Hashirama Senju’s DNA implanted in him so he has mokuton kekkei genkai and can perform yin yang release ninjutsu while being an expert in kenjutsu and taijutsu.
>>
>>58494047

Is this some kind of copy-pasta in-joke? Because I have no idea what that wall of text is supposed to mean.
>>
>>58494067
No, I wrote all of that on the spot.
>>
>>58493061
Making this run efficiently is a great feeling, tbqh
>>
>>58493839
Is it really so much of a hassle to just write one for each? And stop using autistic prototypes. The extra efficiency you get from prototypes is negligible, factory functions are comfier to read.

function createVector(x, y) {
return {
x: x || 0,
y: y || 0,
add: function(vector) {
return createVector(
this.x + vector.x,
this.y + vector.y
);
},
subtract: function(vector) {
return createVector(
this.x - vector.x,
this.y - vector.y
);
},
mulitply: function(vector) {
return createVector(
this.x * vector.x,
this.y * vector.y
);
},
divide: function(vector) {
return createVector(
this.x / vector.x,
this.y / vector.y
);
}
}
}


var velocity = createVector(0, 0);
var gravity = createVector(0, 1);

velocity = velocity.add(gravity);
>>
>>58494030
Yeah, I know about all that, and that's originally why I started using streams over printf. But it's been a while and I've realized that I literally never even use that functionality, and all the << in my code makes it so fucking ugly.
>>
>>58494112
Now make add z axis.
Oh, you have to rewrite the entire code.
Code repetition is something you have to avoid as much as possible when you are on a high level language.
>>
>>58494142
Make vector3 class extend vector, and call return createVector3(super.createVector, this.z (+-/*) vector.z)

This is the whole point of OOP
>>
Does anyanon have any experience with or know of a platform-independent (X11, Win32, Mac, and Wayland for a cherry on top) GUI library for C or C++ that doesn't doesn't need gigabytes of disk space to install/run? So not Qt, and preferably not Gtk+.
>>
>>58494206
SDL2, but it's horrible for GUIs.
I don't know how big is wxWidgets.
>>
File: 0.png (154KB, 1139x200px) Image search: [Google]
0.png
154KB, 1139x200px
I asked /sqt/ the other day, but no one know what the fuck is the name of this thing.
On visual studio 2015, does anyone how to disable this little black bar that hangs on the top middle of windows?
>>
>>58494225
SDL is an interesting idea. I'll checkout examples of both SDL and wxWidgets in the mean time.
>>
>>58494206
why
>>
File: Untitled.png (20KB, 714x121px) Image search: [Google]
Untitled.png
20KB, 714x121px
Is Excel like coding, /g/?
>>
>>58494361
>doesn't need gigabytes of disk space to install/run
especially for a development environment
>>
>>58494393
>>doesn't need gigabytes of disk space to install/run

yeah im asking why is that a concern
>>
>>58494366

Normal usage: No
Power user usage: Yes, if you're using VBA or something to that extent.

But if you're doing some seriously complex computation, it begs the question of why use Excel.
>>
>>58494247
Go to Tools –> Options –> Debugging –> General –> Enable UI Debugging Tools for XAML
uncheck that, or just uncheck 'show runtime tools in application'
>>
File: Selection_012.png (55KB, 925x300px) Image search: [Google]
Selection_012.png
55KB, 925x300px
>>58491695
>What are you working on, /g/?
>>
>>58494366
Coding? Maybe. Programming? No.
Excel has conditional functions, and you can do some neat stuff with it.
>>
File: the only way to enjoy NA dota.jpg (203KB, 1029x676px) Image search: [Google]
the only way to enjoy NA dota.jpg
203KB, 1029x676px
>no motivation to work on my project
>half a bottle of whiskey later
>motivation a maximum
Oh well, I'm still young, so I should end up at the or somewhere near the top of a liver transplant list.
>>
wondering why sbcl is still in the COMMON-LISP-USER package even though I (in-package'd) to my custom package
>>
File: 37695845410.png (55KB, 217x190px) Image search: [Google]
37695845410.png
55KB, 217x190px
>>58494720
God bless you, anon
>>
What do you call it when you change a number from positive to negative or negative to positive but keeping the same absolute value?
>>
>>58494936

Arithmetic negation.
>>
>>58494971
Is it still called negation when you change -4 to 4?
>>
In what scenario would one use dynamically allocated memory?
>>
>>58494989
https://en.wikipedia.org/wiki/Absolute_value
>>
>>58494936
An overflow
>>
>>58494936
>from positive to negative
arithmetic negation
>negative to positive
absolute value
>>
>>58494936
inverting the sign might be a better term
>>58494989
still fine to it that I guess

>>58495000
loading files into memory to parse
talking to external sources where you don't know the response size beforehand
strings also need to be converted to different formats sometimes so you'd allocate memory to hold the converted string
and other stuff
>>
>>58494936
negation?
>>
>>58491695
Starting a project with a friend in python. he's more experienced and im a super beginner.

we're making an application for quickly renaming images. It's my job to edit the little startup code he made into a ui with buttons and align them. he will do the backend.
>>
File: 1467428825103.jpg (444KB, 1280x720px) Image search: [Google]
1467428825103.jpg
444KB, 1280x720px
It seems when I pass a C++ class to printf it gets automatically converted to a pointer to that class.
I can't seem to find anything about this on google, does anyone have any info on this? does C++ really promote class types to pointer-to-class when passed through varargs?

A bit of background: I'm writing a kprintf for my kernel, and I have a format specifer %P which interprets the arg as an IPrintable* and calls it's print function.
However, when I pass in a class that inherits from IPrintable by value (without taking the pointer of with &), it works as if C++ promoted it to a pointer automatically, instead of page faulting or printing garbage.
>>
>>58494989

If you change true to false, you have logical negation. Changing false to true is similarly logical negation. Positive to negative is called arithmetic negation, so why should this not be the case of negative to positive?

>>58495027

Negative to positive can be called an absolute value or it can be called arithmetic negation, depending on the desired outcome when a positive number is used instead. You don't call the function a different thing just because you use a different subset of the same domain, and the domain is all numbers, positive and negative.
>>
>>58495037

How is this any different from just creating space in your code via arrays and variables? Wouldn't that be better
>>
>>58495085
you could overflow the stack
>>
>>58495090
No idea what that means
>>
>>58495072
>C++
>In a kernel
Why would you do something so stupid?
>>
>>58495102
whats wrong?
>>
>>58495072

It would be rather helpful to see how the hell you are implementing all of this to see in what way the C++ type system is fucking with you. This might be a case of the ABI for passing structs and the ABI for variadic functions meshing together interesting, or it may be that somehow it's being passed by reference.
>>
>>58495102
There's nothing wrong with C++ in a kernel.
>>
>>58495102

VxWorks does it, and their shit's on a rover on Mars...
>>
>>58495102
love this meme
>>
>>58495108
void puts(IPrintf &printer, const char *str)
{
for (; *str; str++)
{
printer.putChar(*str);
}
}

void vprintf(IPrintf &printer, const char *fmt, va_list ap)
{
char buf[64];

while (*fmt)
{
if (*fmt == '%')
{
fmt++;

switch (*fmt)
{
case 'i':
case 'd': // Yes I know, it's printing ints as uints. I'll fix it later.
case 'u':
uintToDecString(va_arg(ap, unsigned), buf); // It's templated
puts(printer, buf);
break;
case 'c':
printer.putChar(static_cast<char>(va_arg(ap, int)));
break;
case 's':
puts(printer, va_arg(ap, const char*));
break;
case 'p':
puts(printer, "0x");
case 'x':
uintToHexString(va_arg(ap, unsigned), buf);
puts(printer, buf);
break;
case 'b': // Byte prefix
switch (*++fmt)
{
case 'x':
uintToHexString(static_cast<u8>(va_arg(ap, unsigned)), buf);
puts(printer, buf);
break;
}
break;
case 'w': // Word prefix
switch (*++fmt)
{
case 'x':
uintToHexString(static_cast<u16>(va_arg(ap, unsigned)), buf);
puts(printer, buf);
break;
}
break;
case '%':
printer.putChar('%');
break;
case 'P':
va_arg(ap, IPrintable*)->print(printer);
break;
}

fmt++;
}
else
{
printer.putChar(*fmt++);
}
}
}


class Foo : public IPrintable
{
void print(IPrintf &printer)
{
puts(printer, "Hello from Foo");
}
};

extern "C" [[noreturn]] void kmain(BootInfo *bootInfo)
{
...

Foo f;
kprintf("printf test: %P\n", f);

...
}


...
printf test: Hello from Foo
...
>>
>>58495106
>>58495110
>>58495117
>>58495128
Most C++ features are utterly inappropriate for a kernel. Even then, C++ is just a fucking terrible language in general.
Now for the "my subset of C++" argument, which is basically just going to be C.
>>
>>58495148
Forgot the definition of kprintf:
class Kprintf : public IPrintf
{
void putChar(char c)
{
kputchar(c);
}
};

static Kprintf kprintfDriver;

void kprintf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);

vprintf(kprintfDriver, fmt, ap);

va_end(ap);
}
>>
>>58495150

Aside from maybe exceptions and the STL (you can't really use ANY standard library when developing a kernel), which features do you consider inappropriate, and why? RAII is incredibly useful for resource management, references hurt nothing, classes just allow syntactic sugar over structs, and a compile-time level of control over access to resources, and templates just reduce repeating yourself.

>>58495148
>>58495200

Unless you've got some data members in IPrintable you're not showing us, Foo is an empty object. So the only thing that can be passed in the first place is a pointer to it.
>>
>>58495219
>Foo is an empty object
But it's polymorphic, so it'd have a vtable wouldn't it? so that's something to pass.

The definition of IPrintable:
class IPrintable
{
public:
virtual void print(IPrintf&) = 0;
};


brb, adding a data member and will report back with results.
>>
>>58495246

Well I suppose it would have a vtable then.

But here's a question to ask... is the pointer that it is printing the pointer to f, or the pointer to the virtual function stored in the f's vtable? Because right now, it's starting to look like Foo is the size of exactly one pointer.
>>
>>58495219
I'm no C++ expert, so I don't know every feature and how they all work, because no mortal has enough time to learn that shit.

However, it seems like for most shit to be useful, you need dynamic memory. Sure, kernels have dynamic memory, but its not something to use pervasively.
Templates can lead to massive object code bloat.
Even then, what are you even going to use templates for?

The unstable ABI would make a module system very difficult to implement.

Most of my other complaints just have to do with C++ in general, and not related specifically to kernels.

C++ has a disgustingly large amount of hidden side-effects behind deceptively "simple" code.
You seriously cannot trust any C++ code you read at all.
Who the fuck thought it was a good idea to make references transparent?
You can't even trust a simple +.

RAII is overrated as fuck. People should be VERY aware and mindful of what is actually going on in a function. More """""""""helpful""""""""" information hiding by C++.

Inheritance (an OOP in general) is just a bad idea. It leads to extra layers of indirection and code that is very difficult to change when your precious abstractions need to change as a software naturally does.

There is just far too much implicit shit going on.
It's honestly disgusting.
>>
>>58495295
I added two integer members, it still works.

I also looked at the assembly output: (intel syntax)
    lea    eax, [esp+20]
mov ecx, OFFSET FLAT:_ZTV3Foo+8
mov DWORD PTR [esp+4], eax
mov DWORD PTR [esp], OFFSET FLAT:.LC4
mov DWORD PTR [esp+20], ecx
call _Z7kprintfPKcz


I'm not sure what some of those lines are for, but I think it is passing f as a pointer.
If it is, then what I want to know is if that's standard behavior or just an implementation detail.
>>
>>58493418

the issue isnt alice, but the variables name and age

youre testing their values which have never been set to anything

its assuming youre in a function with name and age as params

try not to be so autistic with books, they fuck up like this all the time. if it does it a lot then probably find a different one
>>
>>58495378
Why are you using cdecl or whatever that is?
>>
>>58495369
>However, it seems like for most shit to be useful, you need dynamic memory.
Not true.

>Templates can lead to massive object code bloat.
Sure, just use them sensibly.

>Even then, what are you even going to use templates for?
For being type-generic:
template <typename T>
void uintToDecString(T val, char *buf)
{
char *p = buf;

if (val == 0)
{
p[0] = '0';
p[1] = 0;
return;
}

while (val > 0)
{
*p++ = val % 10 + '0';
val /= 10;
}

reverseString(buf, p - 1);
*p = 0;
}

"Object code bloat" argument doesn't work here, because in C this would involve having multiple versions of the same function for different types

>The unstable ABI would make a module system very difficult to implement.
For Linux, modules have to be recompiled for new kernel versions anyway, so this literally doesn't matter.
Or just use
extern "C"


>C++ has a disgustingly large amount of hidden side-effects behind deceptively "simple" code.
It's called abstraction, and C++ is known for doing it with little to zero overhead.

>RAII is overrated as fuck
That's just your opinion, but I find RAII pretty useful, especially when you have containers of pointers.

>>58495441
?
I don't know, I didn't choose it.
It's on O2 optimization so maybe that has something to do with it.
>>
>>58495369

>Dynamic memory
A lot of C++'s features make it easier to deterministically manage resources, not necessarily memory. In a kernel, this means anything from file handles to pages/frames to locks, and so on. There's a lot of acquiring and releasing of these sorts of resources, and there's always a chance for errors, requiring things to be released early or whatnot. RAII allows everything to be managed based on the scope of a variable. The second a return statement is reached, every object on the stack is told to clean up its resources.

>Templates
Inevitably, there are certain functions that you are going to be using a lot on different data types, and certain abstract data types that you are going to use on a lot of other data types. You've got multiple different queues of different things, you've got multiple different vectors of different things. Ultimately, you would end up writing the functions and structs no matter what for each of these types, but at least with templates, you only need to write the code once.

>Unstable ABI
ABI for C++ is stable to a compiler, and if you write the OS, you get to make the rules on how everything interacts with everything else. That said, you can always export C functions and use C++ internally.

>RAII, hiding
It's not really hiding anything. Most people who know how RAII works know what is being added behind the scenes. But what matters is that you're getting what you wanted for free without you having to write extra code and making a difficult to maintain mess.

>You can't even trust a simple +
Anon, plenty of languages support operator overloading. It's not a big deal.

>Inheritance
Lots of OOPers prefer composition over inheritance for a lot of things. Personally, I say "use what works for your specific use case." It may be the case that it's pretty useless for a lot of kernel related shit. That doesn't mean you need to toss out everything else C++ has to offer.
>>
>>58495509
>not using the superior C macros for templating
>>
>>58495509
>For being type-generic:
>...
Why would this generality be something a kernel actually needs? This is not the sort of shit that needs to be done.
>Sure, just use them sensibly.
And you just showed that you weren't using them sensibly, by creating an overly general solution to nothing.
>It's called abstraction
No, it's fucking called invisible side-effects. Learn a functional program or some shit.
That shit is seriously unacceptable. I would throw the entire language out for this one thing alone.
>>
When are C macros useful?
>>
>>58495369
Is that you Eskil?
>>
>>58494722
Why not directly
PandaGallery::from_url(...)
?
>>
>>58495594
because I'm seeing doublke and iræs fuicking hard to prhram this wau
>>
>>58495585
Making a bunch of repetitive code shorter.
Modifying how some arguments are passed into a function.
Anything involving pasting two C tokens together.

A lot of people use macros in places where an inline function would be a lot more appropriate though.
>>
>>58495547
>It may be the case that it's pretty useless for a lot of kernel related shit.
It's useful for interfaces and drivers.
>>
>>58495585
templating
api versioning (which is honestly a terrible idea fuck you openssl)
passing values in from a build system (like program version info)
and memeing on 4chan
>>
>>58495561
Oh, you're a functional shitter.
Opinion discarded.
>>
>>58495624
Not really, but I do understand the importance of side-effects.
I guess you're just some complete retard who enjoys not being able to reason about any program you write in the slightest.
>>
Am I meant to use gVim or just Vim?
>>
#include<stdio.h>
#include<stdlib.h>


int main(int argc, char *argv[])
{

int *ptr;

ptr = (int*) malloc(1);

if (ptr == NULL)
{
printf("malloc error");
}


*ptr = 5000;


printf("%i", *ptr);

free(ptr);


return 0;
}
.

I didn't allocate enough memory so how is this working

Would appreciate if someone could explain what I'm doing wrong
>>
>>58495917
malloc implementations usually over allocate
>>
>>58495935
Your mum over allocates
>>
>>58495935
Is this compiler optimization or just on it's own
How do I stop this
>>
>>58495785
gvim if you want an easier life.
>>
>>58495935
>>58495960
I imagine malloc would have a minimum block size, which is probably the max_align_t or somewhat close.

The code is still undefined behaviour, even if it appears to work.
So just don't under allocate shit.
>>
File: 1473823311900.jpg (225KB, 1440x1920px) Image search: [Google]
1473823311900.jpg
225KB, 1440x1920px
>>58495945
you too
enjoy the random pic

>>58495960
malloc is implemented by the c library so it's not a compiler optimization
probably not a way to stop it unless you're on linux with glibc and there's a flag that causes runtime errors on this kind of stuff
>>
So I should just give up on dynamic memory allocation

This is giving me a headache
>>
>>58496017
Avoiding dynamic memory is good, but I doubt you'll be able to avoid it entirely.
>>
File: 1472977302317.jpg (117KB, 450x450px) Image search: [Google]
1472977302317.jpg
117KB, 450x450px
>>58496017
you could take a break but you'll still need dynamic memory allocation
and desu you really don't need to check for NULL on tiny little programs because if it can't allocate memory then you can't do much at that point and a crash on dereferencing a NULL pointer is fine
>>
>>58496038
>because if it can't allocate memory then you can't do much at that point and a crash on dereferencing a NULL pointer is fine
I prefer to hide this behind a "die if fail" function called xalloc.
>>
I'm trying to make a bot that goes through this site and checks for best latency server.

I'm having problem with printing option value text, cant anyone help me?
http://lookingglass.level3.net/ping/lg_ping_output.php

#!/usr/bin/python3

import requests, bs4


r = requests.get('http://lookingglass.level3.net/ping/lg_ping_output.php')
soup = bs4.BeautifulSoup(r.text, 'lxml')
element = soup.find_all('option')

for i in element:

values = {
'sitename' : i['value'],
'address' : RANDOM IP ADDRESS,
'size' : '64',
'count' : '1'

}


r = requests.post('http://lookingglass.level3.net/ping/lg_ping_output.php', data = values)
print('Time taken for %s' % *INSERT HERE PLZ*)

[\code]
>>
File: 1473873952333.png (4KB, 255x157px) Image search: [Google]
1473873952333.png
4KB, 255x157px
>>58496053
good idea anon
>>
Python is beautiful

groups = [group for group in match.groups() if group != None]
>>
File: bugs1.jpg (27KB, 400x225px) Image search: [Google]
bugs1.jpg
27KB, 400x225px
>>58496056
Ok, I need to sleep.
i.get_text
>>
>>58496017

Most useful programs involve at least some dynamic memory allocation. Learn it or stop programming altogether. If you need a guide to the basics, read this:

http://cslibrary.stanford.edu/102/PointersAndMemory.pdf
>>
>>58496103
groups = [group for group in match.groups() if group is not None]
>>
>>58496159
>malloc/free
custom allocators or gtfo brah
>>
>>58496159
I understand it, was my code not correct?
>>
>>58496180
It's to teach the fucking basics, Anon. Goddamn.

>>58496187
Which code?
>>
>>58491695
>What are you working on, /g/?
Still working on tricking the NVMe driver into making the SSD DMA blocks into an arbitrary bus address.
>>
Can I somehow build a txt file into my executable so I can always have that info in my program?

I want to make a "help" option of sorts available on the press of a button, but supplying a help.txt file, and telling people not to move it or rename it just so that my program can open it seems kinda dumb since they could simply open it in a text editor. I'm using the qt framework for c++.
>>
File: 26cad2ab6092f7f253bd2f2d7b42d55a.jpg (771KB, 1204x632px) Image search: [Google]
26cad2ab6092f7f253bd2f2d7b42d55a.jpg
771KB, 1204x632px
>>58496248
I expect progress reports every few threads
>>58496249
google it
>>
>>58496249
>Can I somehow build a txt file into my executable so I can always have that info in my program?
Yes, but it's not portable.
>>
>>58496236
>>58495917
>>
>>58496261
>I expect progress reports every few threads
Check in tomorrow, today I'm hungover as fuck and not really able to concentrate.

Alternatively, you can check out my github if you're interested.

https://github.com/enfiskutensykkel/ssd-gpu-dma

Haven't pushed the latest stuff because there's no way for me to write this in a clean and ordered fashion when I'm basically just messing around and have no idea how to some specific things.
>>
I need to make a program with C# that finds all integers under 1000 which square root is an integer.

Any tips? I'm a complete novice with programming.
>>
>>58496297
well, what do you have so far?
>>
File: 1473331782956.png (294KB, 960x800px) Image search: [Google]
1473331782956.png
294KB, 960x800px
>>58496287
nice and i've got you bookmarked now
>>
>>58496297
>which square root is an integer.

i = 1
integers = []
while i * i < 1000:
integers.append(i * i)
i += 1
>>
>>58496290
It's not portable among operating systems or compilers.
You can get your linker to add any random shit to your executable, but the way you access it is not standard.
>>
>>58496326
No need to manipulate the linker, could just add a .text section or make it a long string
>>
>>58496326
THERE IS WITH QT DID YOU NOT READ MY SPOILERED POST
>>
>>58496335
>or make it a long string
That shit takes forever to compile though.
>>
Wrote a RSS feed downloader in Python (suggestions welcome):
#!/usr/bin/env python3

import urllib.request
import os.path
import xml.etree.ElementTree

USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'
CONFIG_PATH = os.path.join(os.environ['HOME'], '.autofeed')
TORRENT_PATH = os.path.join(os.environ['HOME'], 'torrents')
TORRENT_SUFFIX = '.torrent'

with open(CONFIG_PATH) as config:
for url in config:
request = urllib.request.Request(url, headers={'User-Agent': USER_AGENT})
with urllib.request.urlopen(request) as response:
body = response.read()
root = xml.etree.ElementTree.fromstring(body)
for item in root.iter('item'):
name = item.find('title').text
name = name.replace(os.sep, '-')
name = name + TORRENT_SUFFIX
path = os.path.join(TORRENT_PATH, name)
if not os.path.isfile(path):
url = item.find('link').text
request = urllib.request.Request(url, headers={'User-Agent': USER_AGENT})
with urllib.request.urlopen(request) as response:
with open(path, 'wb') as f:
body = response.read()
f.write(body)

Gave up on Rust. The tooling, libraries and community are shit.
Now it's time to start learning Racket.
>>
>>58492431
IIRC R5RS does not. What Scheme are you thinking of? Please link spec.
>>
I want to submit a form with Python (using the Requests library). Picture related, it's the form.

Here's my POST request:

options = {"chart_length_recent_tracks": "50", "csrfmiddlewaretoken": csrf}
r = session.post("https://www.last.fm/user/myuser#recent-tracks-settings", data=n)


It doesn't work. What am I missing? I looked at the page's source and the form's ID is "/user/myuser#recent-tracks-settings", the name of the select element is "chart_length_recent_tracks".

I managed to do this once a while ago, but now I'm totally clueless about it.
>>
>>58496363
>Gave up on Rust. The tooling, libraries and community are shit.
The tools are great. The problem is that there are not enough libraries. Every second simple thing you have to implement yourself
>>
File: 2017-01-15-13:16:16.png (28KB, 655x334px) Image search: [Google]
2017-01-15-13:16:16.png
28KB, 655x334px
>>58496387

>data=n
I meant data=options. I changed it slightly from what I have, due to using shitty temporary variable names in my file.

I also forgot to upload the pic.
>>
>>58496287
great profile pic buddy
>>
>>58496284

Think about how malloc has to work for a second. There are two other functions that work directly with malloc's internal structures, realloc and free. Both of these functions need to know how big the buffer is, and the most ideal place to put that information (a capacity field) would probably be right before the buffer. This would at least require it to then be aligned to the size of a size_t (4 or 8 bytes). If you allocate 1 byte, you can't put another malloc'd buffer after this, because it's not aligned properly. So you might allocate at least the size of another capacity field to start with. And that's assuming a minimum allocation. A greater allocation may be desirable to make it so that realloc doesn't have to copy on every single allocation. Or you may wish to keep track of free blocks of memory in units that aren't incredibly small. When malloc looks for a free hole in memory with which to place an allocation, it needs to know which blocks of memory are free and which are not. In theory, the most memory-efficient way to store this sort of information is with a bitfield, with each bit representing a block of memory. If the block size is small, you might end up having a lot of bits just to keep track of the number of blocks being used. So it might make more sense to use a bigger minimum block size. Say, anything less than 32 bytes, we round up the capacity to 32 bytes. Most people aren't going to miss that little bit of extra memory.

Nothing here that I just described is necessarily the case in your malloc implementation. In fact, it's been a while since I've looked in any malloc source code. But I have looked into some of the considerations taken into account for memory allocators. And you can't just assume that 1 byte requested = 1 byte used.
>>
>>58496307

Keep in mind I don't even know the basics of C#.

public class Program
{
public static void Main(string[] args)
{
for (int i = 1; i <= 1000; i=i+1)
{
Console.WriteLine(i);
}



}
}
}

How do I put my code in a neat box like this >>58496322 ?
>>
>>58496468
[ code ] here [/ code]
without the spaces
>>
>>58496468
use <code>foo</code>
>>
>>58496297
>>58496468
https://msdn.microsoft.com/en-us/library/system.math.sqrt(v=vs.110).aspx
http://stackoverflow.com/a/2751597

put the pieces together.
>>
>>58496387
>#recent-tracks-settings

Completely useless in this case because URL fragments are exclusively client-sided.
>>
New thread:

>>58496579
>>58496579
>>58496579
>>
File: 2017-01-15-13:44:17.png (103KB, 1042x629px) Image search: [Google]
2017-01-15-13:44:17.png
103KB, 1042x629px
>>58496548

Which URL should I make the POST request on? Here's how the form looks like.
>>
>>58496647
see >>58496496
>>
>>58496647
try the same URL but without the #recent-tracks-settings
>>
>>58496647
I don't know, I'm just saying that the fragment part of the URL is redundant there since it will not be sent to the server, fuck if I know what your issue is though. Make a request in your browser and see what was sent, maybe you're missing some field.
Check what the request returns as well, maybe there's a hint there.
>>
>>58496662
>>58496673
>>58496661

Thanks, now I'm on the right track.
>>
>>58495999
>enjoy the random pic
Thanks. I saved it.
>>
File: 1483930295515.jpg (5KB, 228x221px) Image search: [Google]
1483930295515.jpg
5KB, 228x221px
>>58496103
>>58496162
>Python is beautiful
>list comprehensions, lifted directly from Haskell
Thread posts: 317
Thread images: 32


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.