Author Topic: Programming Megathread  (Read 106437 times)

is ruby on rails good for websites? or is there a better one

so are you all gonna ignore the main point of my post or
TBH you might have more luck in the Game Design thread.
I've only ever done a game loop once, so I don't really have any advice.

is ruby on rails good for websites? or is there a better one
What are you planning on doing?

is ruby on rails good for websites? or is there a better one
if you want to use ruby that is probably your best option
if you don't care about the language, there are other choices too, like Python with Django or Flask, or Node with Express (I think there are more full-featured frameworks for Node too?)
even PHP may be a reasonable option if you hate yourself

there's also Java and C#, but I've never even touched any of those web frameworks, so I don't have anything useful to say about them

there's also Java and C#, but I've never even touched any of those web frameworks, so I don't have anything useful to say about them
C#/.NET is lovey, but requiring a windows OS may be an inconvenience for some

people good with python, please assist:

import random

name1 = ['Suleiman',
         'Osman',
         'Bayezid',
         'Mehmed',
         'Orhan',
         'Murad',
         'Selim']
name2 = []
name3 = [' the Magnificent',
         ' the Lawgiver',
         ' the Conqueror',
         ' the Terrible',
         ' the Stammerer',
         ' the Fair',
         ' the Great',
         ' the Silent']

for x in range(10):
    name2.append(random.choice(name1))
    name2[x] = 'Sultan ' + name2[x]
    # check if name has already been stored before, if yes then apply regnal numbering
for y in range(3):
    name2[random.randint(0, 9)] = random.choice(name2) + random.choice(name3)

print('\n'.join(name2))


I'm trying to make an ottoman lineage/dynasty generator

part of a dynasty's naming convention comes down to regnal numbering (Elizabeth I, Mehmed II, Pope Gregory VII). how would I go about doing that in python? I think what I need is for a loop to compare each list index to see what is what and where is where, but I'm not sure how to actually implement that

in other words, if my code outputs (example):
Sultan Mehmed
Sultan Suleiman
Sultan Mehmed


I want it to instead say:
Sultan Mehmed I
Sultan Suleiman
Sultan Mehmed II


sorry for my lack of intuition when it comes to explaining this but any help is appreciated

Disclaimer: I don't actually do python. :cookieMonster:

Basically you just want to check the currently generated value of name2 against all the other values of name2. If it encounters a match, it increases a counter. After looping through all the values, whatever the counter is at is appended to the end of the name in Roman numeral format.
Code: [Select]
import random

name1 = ['Suleiman',
         'Osman',
         'Bayezid',
         'Mehmed',
         'Orhan',
         'Murad',
         'Selim']
name2 = []
name3 = [' the Magnificent',
         ' the Lawgiver',
         ' the Conqueror',
         ' the Terrible',
         ' the Stammerer',
         ' the Fair',
         ' the Great',
         ' the Silent']

#Variable i started at -1 instead of 0 since the second for loop is guaranteed to run into it's own value at least once (i.e. name2[x] == name2[z] if x and z are 3 -> name2[3] == name2[3] will always be true).
#We could put an extra if here to take care of that, but it only increases the number of calculations the computer has to do every loop. There are other ways to do it as well, but this code is simple enough to have this work just fine.

i = -1
roman = [' I', ' II', ' III', ' IV', ' V', ' VI', ' VII', ' VIII', ' IX', ' X']
name4 = []

for x in range(10):
    name2.append(random.choice(name1))
    for z in name2:
        if name2[x] == name2[z]:
            i++
    #Use new variable to avoid confusing our array comparison.
    name4[x] = 'Sultan ' + name2[x] + roman[i]
    i = -1
   
for y in range(3):
    name2[random.randint(0, 9)] = random.choice(name4) + random.choice(name3)

print('\n'.join(name2))

Untested, but it should work. Let me know if something doesn't.

loving QuickBooks Online API
Whoever wrote this stuff doesn't have enough English skills to give descriptive error messages that makes sense
"Can not instanti specified is unsupported or invalid"
pls

oh stuff i didnt know this thread was a thing

did we establish which of the following the blf prefers?

Code: [Select]
stuff {
    more stuff
}

or

Code: [Select]
stuff
{
    more stuff
}

as well as tabs vs spaces and vim vs emacs

Untested, but it should work. Let me know if something doesn't.
there is no increment operator in python, you have to use x += 1 instead
also, for loops in python give you the item in the list, not the indices. so instead of for z in name2 you'd have to use for z in range(len(name2)), where range is a function that returns a generator that generates a "list" using integers with a length equal to the argument, which in this case is the length of name2
so range(10) generates "0, 1, 2, 3, 4, 5, 6, 7, 8, 9"
range() also has more functionality but that's irrelevant right now

one problem (??) with your code jairo is that the last for loop picks a random name from name2, which, as it turns out, can include a name that has already had one of the suffixes appended to it. which means you can get names like "Sultan Selim the Lawgiver the Great"
but idk, maybe that's intentional?

anyway here
http://pastebin.com/N5H6Ybcz
I included a function somebody else made for the part that actually converts a number to a roman numeral
besides what you asked for, I also changed a few other things to make it better (sometimes subjectively):

more descriptive variable names
in the for loops, changed the letters to i, j, and k
shortened the contents of the first loop
speaking of for loops, instead of adding the roman numeral bit to the first one, it does that in a second loop. the loop goes backwards, because that was the easiest way I could think of for doing it
and fixed the problem with the last loop that I mentioned before, where you'd get repeats. my edits will not allow more than one suffix to be added to a single name, nor will it allow one suffix to be used more than once. if that was intentional, it should be easy to switch either part back. if you want both to be the same I also left the original code at the top of the loop, but commented. the only changes I made to it were selecting a name considering the length of the list and splitting it into two lines to keep it under 80 characters long
I think that's all of it

here's some example output:
Sultan Suleiman
Sultan Selim
Sultan Orhan
Sultan Bayezid
Sultan Bayezid II the Silent
Sultan Bayezid III the Lawgiver
Sultan Orhan II
Sultan Bayezid IV the Great
Sultan Selim II
Sultan Bayezid V


clearly, the Bayezids were exceptional leaders

did we establish which of the following the blf prefers?
I prefer the first bracket to be on the same line that it starts on, like the first one
also spaces are better. I don't know of any reason to use tabs intentionally

for me it's { on the same line, tabs (spaces are dumb), and neither because i'm on windows so i just use atom

why do you use tabs?
spaces are always one character long. but tabs are unpredictable. someone may have theirs set to 2 characters or 8. so it is impossible to ensure that your lines will fit within 80/100 columns if you use tabs

spaces don't provide enough space, tabs provide like a mile of space so it separates the code a lot easier and imo they make code more readable

spaces don't provide enough space, tabs provide like a mile of space so it separates the code a lot easier and imo they make code more readable
what
you don't use just one space, you use four

what
you don't use just one space, you use four
but then why hit the spacebar four times when you can just hit tab once

what
you don't use just one space, you use four
Why does it matter? You pick on everyone when they do something just slightly different.