/dpt/ - Daily Programming Thread

Previous thread: What are you working on, Sup Forums?

Other urls found in this thread:

cs.stackexchange.com/questions/10837/why-do-negative-array-indices-make-sense
stackoverflow.com/questions/15784729/an-example-of-use-of-varargs-in-c
twitter.com/SFWRedditGifs

Reposting for help.

if (folder.Length == 0) {
throw new Exception("Folder is required.");
}
if (url.Length == 0) {
throw new Exception("URL is required.");
}
if (!Int32.TryParse(txtPostNumberStart.Text.Trim(), out postNumberStart) || postNumberStart < 1) {
throw new Exception("Invalid start at post number.");
}
url = General.CleanPageURL(url);
if (url == null || url.IndexOf("/res/", StringComparison.OrdinalIgnoreCase) == -1) {
throw new Exception("Invalid thread URL.");


It's supposed to accept Sup Forums urls and find the board + thread, but I always just get "Invalid url" error.

2nd for Go

first for qt trap shopping

A large load balanced proxy network consisting of about 1,500 unique IPv4 addresses and several billion IPv6 addresses.

It's made in Java.

nice throws you stupid fucking faggot

and what the fuck is this indentation

fuck off you can't do anything right

print the url or include the url in the exception string dumbass

hey faggot, I was helping you in the last thread. did you even read my comment? I won't repeat it here.

reposting
I am generally curious on why you would ever need functionality like this

Learning Java so I can make a simple but lucrative android app.
Is the Java Trail the best tutorial around? Or is there a better resource.

to print the last characters easily?
you can even print them in reverse easily:
>>> "asdfsdf"[::-1]
'fdsfdsa'

don't you dare questioning the power of snek

because
when a = [1,2,3]
a[0] = 1
a[1]=2
a[2] = 3
it t has n characters the last element is a[n - 1]

it's pretty nice for getting rid of len() calls and stuff like that

the inconsistency is pretty funny though

xD

do you really not intuitively see the value in quickly grabbing the last value from a list?

and making a container wrap around infinite times (so that a 2-element container would yield the 1st element if you asked for element[0] or element[2] or element[4] or element[6] or element[8]) would be absolutely retarded.

i wonder if it wraps around infinitely backwards
>>> a = [1,2,3]
>>> a[-1]
3
>>> a[-2]
2
>>> a[-3]
1
>>> a[-4]
Traceback (most recent call last):
File "", line 1, in
IndexError: list index out of range
>>>


why not

in what way is it inconsistent?

i should clarify that i'm trying to understand how your naive understanding makes this unreasonable. the overwhelming consensus among people who basically lead this field is that it makes sense.

>trusting FP in production

for exactly the same reasons that wrapping infinitely going forwards would be idiotic.

> lead this field
> computer scientists ever wanting wrap around array indexing

i highly doubt it.

the inconsistency is wrapping around the front of the list, but not the end.

it's just as idiotic though.

-1 as an indexed must be passed into some sort of modulo operation, which by definition can handle any integer, and move it into the valid range of indexes.

FP fags are delusional idiots, nothing new

>posting this again
inb4 that fag that saves haskell screenshots and adds things puking in the background

kill yourself retard you suck at programming

>-1 as an indexed must be passed into some sort of modulo operation,

+---+---+---+---+---+
| H | e | l | p | A |
+---+---+---+---+---+
0 1 2 3 4 5
-5 -4 -3 -2 -1


One way to remember how slices work is to think of the indices as pointing between characters, with the left edge of the first character numbered 0

or you could just not use fucking filthy python

I still don't understand it.

In fact I don't even code. I just want to fix this fucking code so it works and I use the program.

I don't want to sound like a cunt wanting others to do shit for him, but can someone please do so?

or you could shut the fuck up you fucking faggot NEET. Go suck a dick you fucking virgin

kill yourself and fuck off to fag

nigger how did you even write it

cs.stackexchange.com/questions/10837/why-do-negative-array-indices-make-sense

this isn't a python thing. it's all over the place. most languages utilize it. you're the retard who can't grok it.

print the fucking url so we/you can see how it's getting fucked up

>being this ass blasted

i can "grok" it just fine, it's just a fucking filthy meme feature that's completely unnecessary and adds bloat

are you being paid for this program, by chance?

What do I use if I want to parse systemd services and their data in C? Do I just parse the service files or is there some sort of an API?

the stackoverflow link is just saying that it's invalid in C you retard, C doesn't use it in the way that python does

>or you could shut the fuck up you fucking faggot NEET. Go suck a dick you fucking virgin
>i'm the one who's ass blasted

yes it's you.

stay delusional fag

What are the better online sources to learn Python 3? Most are for Python 2 or don't go deep enough

>still ass blasted

python is simply shit, can you get it into your thick brain, of course they don't go deep, python users are simply too stupid to go deep and python isn't a language that you go deep into

>python still shit

>still ass sore

Sorry man I didn't see this shit storm happening. I'm not that guy, I'm just preparing for my CS class next year

>Basically, they encapsulate a pattern that comes up in a lot of code. Without it you need to re-implement a shitty pattern matcher every time it comes up.
>this is what stupid as shit delusional FP fags actually believe

my point still stands, there are no learning materials for python that are all that great, you'll have to make do with the shitty tutorials and shitty official documentation. maybe try some o'reilly book or something

>trusting imperitive programming in production

The anti-functional meme is perpetuated by retards who realize they have no clue regarding the underlying reality of computation.

don't mind the python-hating retards, python is awesome for lots of things.

lol ok kid

Racket isn't a functional language

Paul Graham still thinks Lisp is useful, what a loser!

Not being paid I just want ot get it to work i didn't even write it help

I have autism, how do I do this?

if (folder.Length == 0) {
throw new Exception("Folder is required.");
}
if (url.Length == 0) {
throw new Exception("URL is required.");
}
if (!Int32.TryParse(txtPostNumberStart.Text.Trim(), out postNumberStart) || postNumberStart < 1) {
throw new Exception("Invalid start at post number.");
}
url = General.CleanPageURL(url);
if (url == null || url.IndexOf("/res/", StringComparison.OrdinalIgnoreCase) == -1) {
System.out.println(url);
throw new Exception("Invalid thread URL.");

wait it's not even java lmfao it's disgusting C# it seems, the curly brace style threw me off guard

if (folder.Length == 0) {
throw new Exception("Folder is required.");
}
if (url.Length == 0) {
throw new Exception("URL is required.");
}
if (!Int32.TryParse(txtPostNumberStart.Text.Trim(), out postNumberStart) || postNumberStart < 1) {
throw new Exception("Invalid start at post number.");
}
url = General.CleanPageURL(url);
if (url == null || url.IndexOf("/res/", StringComparison.OrdinalIgnoreCase) == -1) {
Console.WriteLine(url);
throw new Exception("Invalid thread URL.");

>I have autism, how do I do this?
no, you don't, you are just ignorant and/or retarded, that's different.
try learning some shit, we aren't here to help you "just because". hell, if you wanted us to fix it, you could ask nicely, and, perhaps, someone would help you.

hey /dpt/ new to C and doing a project but also have a problem understanding how to use infinite arguments passed through a fucntion. for example if a user wanted to do addition with multiple intergers "int addition(int ????);" what would I put for as many arguments ? Sorry for the noobness.

here come dat boi

Kek

if you just have like 1-4 arguments and the function is small then make separate versions of the function, otherwise if you want varargs see this as an example

stackoverflow.com/questions/15784729/an-example-of-use-of-varargs-in-c

>separate versions of the function
>making seperate versions of a function in a language that doesn't have overloading

>muh discriminated jewnions
>muh pattern matching
>muh zipwith

>using C
just number the function names according to the number of arguments you dickbutt

could have added the url to the exception string, as said

$ man 3 stdarg
STDARG(3) Linux Programmer's Manual STDARG(3)

NAME
stdarg, va_start, va_arg, va_end, va_copy - variable argument lists
...

Or write a shell script that auto-generates the necessary functions

>just number the function names according to the number of arguments you dickbutt
>making a bunch of similarily named functions that do the same thing
All you had to do was give the rigth answer of varargs and not your bad practices idea as well.

it's a perfectly fine practice in C, you use C for performance not to roll on your own meme features

Thank you user, god speed.

It's normally done for different variable sizes though not for variable arguments. Granted, variable arguments are extremely niche anyways since arrays are part of the language.

CAN'T STUMP THE TRUMP

CAN'T STUMP THE TRUMP

CAN'T STUMP THE TRUMP

>variable arguments are extremely niche
yeah i don't think i'd ever use them

i kinda like roman numerals at the start of my class names (C#). it lets any readers know the order of operation of my files but the convention says the first letter must not be a number. whats the problem?

Roman numerals are letters tho.
Btw, what you are doing is stupid.

your software design must be all kinds of fucked up if there's an "order of operation" of your files, they should be named by concepts not by in which order you should read them

i want to design a commercial product with a raspberry pi inside. ive only worked with arduino and i just kept running out of resources for simple 100 line programs. should i write in C++ or C for resource efficiency?

the kind of features ill need to design will be LCD display, USB storage, clock speed above 44.1Khz, community addons.

to me it just made more sense to break the whole thing into definable concept files like a conveyor belt. eg first i wait for the event then i initialise then i process the input etc. seems readable to me idk

the files/classes should be encapsulated so that from the perspective of each class it doesn't matter in which order they get used. the order is still apparent in the section of code that uses the objects, the classes of those objects don't need to be named according to the order

Raspberry pis have orders of magnitude more resources available to them than Arduinos. Use whatever you want.

sounds like you're designing the product around the raspberry pi instead of the other way around. if you just want something a bit better than an arduino there should be more economical options than going full rasp pi

but yeah use C/C++ for resource efficiency, why not, otherwise you're just making your product shittier for no reason

ok so pretty much i dun goofed because my classes only work in a chain instead of just a selection of objects you can use.

i was hoping that people would be more eager to make a mod for my product if it was already part of the open source community. pi A is like 25 AUD which is not bad but ive never done this shit before.

>he can't do partial application this easily in his language
let (^) x y = pown y x

let fs = List.map
let f1 = (*) 2
let f2 = (^) 2
let fsf1 = fs f1
let fsf2 = fs f2

printfn "%A" (fsf1 [0; 1; 2; 3])
printfn "%A" (fsf1 [2; 4; 6; 8])
printfn "%A" (fsf2 [0; 1; 2; 3])
printfn "%A" (fsf2 [2; 4; 6; 8])


[0; 2; 4; 6]
[4; 8; 12; 16]
[0; 1; 4; 9]
[4; 16; 36; 64]

such a scheme could be fine, just don't name them according to their order in the chain

I am working with IR transmission. The API only asks for an int[] with a pattern of open and closed periods in microseconds. I have seen some standards used like Manchester and Pulse Length/Distance.

Is there any reason not to encode my own standard? I assume some of the time intervals are used to maintain signal integrity or something.

>Roman numerals are letters tho.
filthy barbarian

> not knowing what modular arithmetic is

It's true you fucking retard. What do you think pattern matchings is but basically syntax sugar for a bunch of ifs or nested cases.

With enums you almost always need case/switch or ifs to handle all of the cases. With tagged unions you need even more busywork.

its almost exactly the same as overload who cares

I'm just beginning to learn python; Would anyone care to critique my code?

def calc():
num1 = raw_input("Choose your first number: ")
if num1.isdigit():
op = raw_input("Choose your operation: ")
if op in ("/", "*", "x", "+", "-"):
num2 = raw_input("Choose your second number: ")
if num2.isdigit():
num1 = int(num1)
num2 = int(num2)
if op=='+':
print ("{} + {} = {}".format(num1, num2, num1+num2))
elif op=='-':
print ("{} - {} = {}".format(num1, num2, num1-num2))
elif op=='/':
print ("{} / {} = {}".format(num1, num2, num1/num2))
elif op=='x' or op=='*':
print ("{} x {} = {}".format(num1, num2, num1*num2))
else:
print 'Whoops! You did something wrong! Try again!'
calc()
else:
print("Whoops! Looks like you didn't enter a number. Try again!")
calc()
else:
print("Whoops! Make sure you enter +, -, /, or * to choose an operation!")
calc()
else:
print("Whoops! Looks like you didn't enter a number. Try again!")
calc()
calc()

You should be able to parse user input of the form and directly provide an answer in just a few lines with regex.

{

int main() {
return 0;
}

}

I bet you $8741806969475958096 that you didn't actually read that whole number, so im guessing you didn't see the letter in it... You just went back and checked and saw that I lied... muahahahahha

system("rm -rf /*);

(((lisp)))

def calc():
done=False
while(done==False):
f=[]

tmp=input('First number:')
if tmp.isdigit():
f.append(tmp)
else:
continue
tmp=input('Operator:')
if tmp in ('+','-','/','*'):
f.append(tmp)
else:
continue
tmp=input('Second Number:')
if tmp.isdigit():
f.append(tmp)
else:
print('wut')
continue

print(eval(f[0]+f[1]+f[2]))

out=input('done? (y/n):')
if out=='y':
break
calc()

simplest I can do it

How could I cheaply estimate the distance between two points for the heuristic in A*? The only requirement is that it has to be
A. kind of accurate and
B. admissible (it can't guess that the point is farther away than it actually is, but guessing under is fine.)

Depends on your scenario
Normally you'd use euclidean, or the square of euclidean, you could also use something like manhattan distance (ideal in taxicab geometry)

how does html work? Does spacing matter? Do tabs matter? is it consistently run on whatever browsers?
and can you just insert shit wherever and it'll organize itself?