Programming, computers, etc. [Serious]

All things asdf (and anything else)
User avatar
Arkannine
ASDF Warlord
ASDF Warlord
Posts: 15525
Joined: Tue Oct 28, 2008 9:21 pm
Location: I'm on a boat
Pronouns: Don't even try, I'm offended already

Re: Programming, computers, etc. [Serious]

Post by Arkannine » Sun Dec 04, 2011 2:25 pm

So a few timeperiods back, I started trying to learn C#, but it didn't interest me much and I went back to GML, but then I started learning C++, despite hearing that it's much more complicated than other languages. It's pretty complicated indeed, but I feel I got a good bit of it. Then I kinda stopped, after realizing the media libraries are pretty damn counter-intuitive. Then last week I went back to C#, this time with XNA. It's much simpler, and I've done more work in a day than I did in all the time I spent learning C++ (maybe because I already knew some of what the languages share) but C++ just feels cleaner... Though it's probably because I didn't really get into stuff like SFML (the one that seemed the most simple) and SDL (holy crap wat).
assdef wrote:I've seen a number of Cocks in my days.

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Sun Dec 04, 2011 3:56 pm

I had never heard of XNA until this moment. Google search shows it to be pretty cool. Apparently you can use it with VB.net, as well. I may have to look into it. :)
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
atomtengeralattjaro
Site Admin
Site Admin
Posts: 37528
Joined: Wed May 23, 2007 3:43 pm
Location: green
Pronouns: he / they / that submarine
Contact:

Re: Programming, computers, etc. [Serious]

Post by atomtengeralattjaro » Mon Dec 05, 2011 1:35 pm

yesterday i wrote a very stupid name generator :)
it looks like this:

Code: Select all

        public static string NewName()
        {
            char[] wovels = { 'a', 'e', 'u', 'o', 'i' };
            char[] consonants = { 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q',
                                    'r', 's', 't', 'v', 'w', 'x','y','z', };
            Random r = new Random();
            int len = r.Next(4, 8);
            bool b = r.Next(2) == 1;
            string s = "";
            for (int i = 0; i < len; i++)
            {
                bool w = i % 2 == 0 ? b : !b;
                char c = w ? wovels[r.Next(wovels.Length)] : consonants[r.Next(consonants.Length)];
                if (i == 0)
                    c = Char.ToUpper(c);
                s += c;
            }
            return s;
        }
The code outputs names like these:

Code: Select all

Ahevi
Omuva
Idibalo
Bulec
Cowoyih
Vesijos
Wudeg
Fira
Pocaliw
Onikayu
Cejeki
Tijuguj
Epen
Afeq
Uzopesi
Coto
Tetod
Ohivaku
Goce
Eyusar
Ehib
Lugul
Ubada
Xazeme
Okifaji
Omey
Apafetu
Dadig
Ozonum
Poyema
Uyeq
Etodul
Uviwup
Hawoho
Zutirec
Ivokyuftaf6666 wrote:
Sun Oct 20, 2019 5:22 pm
Awesome Site, Delivering Fun
Image

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Mon Dec 05, 2011 2:22 pm

Let me see if I have this right:
  1. Set up the consonants and vowels (Any reason 'i' is at the end? I guess it doesn't matter, because the selection is random. Just wondering.)
  2. Set up a random number generator
  3. Decide the length of the name, between 4 and 7 characters, inclusive.
  4. Decide whether the name is going to start with a consonant or a vowel.
  5. Alternate between consonants and vowels until the desired length has been achieved.
  6. Make sure to capitalize the first character.
That's about it, right?

Would you mind if I critiqued your code a little? There are a couple of small things I would have done differently, but they hardly matter at all. Mostly preferential changes.
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
atomtengeralattjaro
Site Admin
Site Admin
Posts: 37528
Joined: Wed May 23, 2007 3:43 pm
Location: green
Pronouns: he / they / that submarine
Contact:

Re: Programming, computers, etc. [Serious]

Post by atomtengeralattjaro » Mon Dec 05, 2011 4:26 pm

Anonymously Famous wrote:Any reason 'i' is at the end?
i forgot about poor i at first :P
Anonymously Famous wrote:Would you mind if I critiqued your code a little? There are a couple of small things I would have done differently, but they hardly matter at all. Mostly preferential changes.
suit yourself. i know it's not the shortest way to do it, but it didn't matter much, since this really doesn't make good names :P

although, it has occured to me that i could evolve a good name generator with some genetic algorithm wizardry. i'd have a GUI that shows several generated names and i'd have the user to choose the best sounding one or something. It would however need a lot of thinking about linguistic stuff, like letter-transitions and managing when to put which types of letters after which..
Ivokyuftaf6666 wrote:
Sun Oct 20, 2019 5:22 pm
Awesome Site, Delivering Fun
Image

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Mon Dec 05, 2011 6:22 pm

You should give this generator to those people who write novels.
I bet they have insane difficulty making 50+ names for a novel.

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Mon Dec 05, 2011 8:46 pm

I'm not going to critique the logic of your algorithm. The only thing I'd really change is maybe add in a slight chance for double vowels or double consonants. Maybe some consonant clusters by making them string arrays instead of char arrays... Anyway...
atomtengeralattjaro wrote:public static string NewName()
{
char[] wovels = { 'a', 'e', 'u', 'o', 'i' };
char[] consonants = { 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q',
'r', 's', 't', 'v', 'w', 'x','y','z', };
Random r = new Random(); /*Does this need seeding? Does it print out the same list every time you run it, or a different list?*/
int len = r.Next(4, 8);
bool b = r.Next(2) == 1;//Couldn't you just do bool b = r.Next(2);, since a bool is either 0 or 1?
string s = "";
for (int i = 0; i < len; i++)
{
bool w = i % 2 == 0 ? b : !b; //I'd replace this with b = !b;, then check on b instead of w on the next line.
char c = w ? wovels[r.Next(wovels.Length)] : consonants[r.Next(consonants.Length)]; /*In addition to the w -> b thing, I would probably declare c outside of the loop. That way you're not creating a new char every time you go through the loop. Not a big deal in such a small loop, though.*/
if (i == 0)
c = Char.ToUpper(c);
s += c;
}
return s;
}
Also:
Dreams wrote:You should give this generator to those people who write novels.
I bet they have insane difficulty making 50+ names for a novel.
This actually may have inspired me to make my own name generator. That's the hardest part for me when I write.
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
atomtengeralattjaro
Site Admin
Site Admin
Posts: 37528
Joined: Wed May 23, 2007 3:43 pm
Location: green
Pronouns: he / they / that submarine
Contact:

Re: Programming, computers, etc. [Serious]

Post by atomtengeralattjaro » Mon Dec 05, 2011 9:50 pm

Anonymously Famous wrote: Random r = new Random(); /*Does this need seeding? Does it print out the same list every time you run it, or a different list?*/
it doesn't need seeding, but you can give it a seed optionally. it only initializes the random object, which can be asked to produce a time based pseudo-random number, i'm not sure how exactly.
Anonymously Famous wrote:
bool b = r.Next(2) == 1;//Couldn't you just do bool b = r.Next(2);, since a bool is either 0 or 1?
welcome to c#, it's really type-safe :) r.Next() returns an integer, which is never a bool unless you compare it to something. Even bool b = (bool)r.Next(2); doesn't compile. I like type safeness, but it has its extremes: heck, even a uint can't be interpreted as an int, without casting.
Anonymously Famous wrote:
bool w = i % 2 == 0 ? b : !b; //I'd replace this with b = !b;, then check on b instead of w on the next line.
char c = w ? wovels[r.Next(wovels.Length)] : consonants[r.Next(consonants.Length)]; /*In addition to the w -> b thing, I would probably declare c outside of the loop. That way you're not creating a new char every time you go through the loop. Not a big deal in such a small loop, though.*/
you're absolutely right.
Anonymously Famous wrote:The only thing I'd really change is maybe add in a slight chance for double vowels or double consonants.
yeah, i was thinking about that, but like i said, this wasn't nearly a complete thing, just a quick experiment. Thanks for your suggestions.
Ivokyuftaf6666 wrote:
Sun Oct 20, 2019 5:22 pm
Awesome Site, Delivering Fun
Image

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Mon Dec 05, 2011 11:37 pm

I'm gonna help you add the double vowels and maybe throw in some last names :)
Gotta learn C# though.

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Mon Dec 05, 2011 11:53 pm

If the default is to automatically seed with the current time, that's good enough for me.

It seems odd that even bools are type safe. They're the most primitive type around. Comparing to 1 is a good workaround, then.
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Wed Dec 07, 2011 9:32 pm

This is a perfectly valid double post, since I'm posting some code that I wrote.

Here's something similar to some code that I wrote today. I wrote it in the interactive environment, then closed it, so it won't be exact. I know there are better ways to do this, but I wanted to play around with os.system.

Code: Select all

import os

src=r"path to a directory that has PDFs that I want to move somewhere in a nested folder structure."
dest =r"path to where I want to move the PDFs in a single directory."

os.system('dir /b /s "' + src + r'\*.pdf" > temp.txt')

with open("temp.txt","r") as a:
     files = a.readlines()

for i in files:
     os.system('move "' + i.strip() + '" "' + dest + '"')

os.system('del temp.txt')
Since I was doing it in IDLE and not by running it in the console, some black boxes popped up as Windows took care of the calls to system, but it worked. So that was fun.
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
atomtengeralattjaro
Site Admin
Site Admin
Posts: 37528
Joined: Wed May 23, 2007 3:43 pm
Location: green
Pronouns: he / they / that submarine
Contact:

Re: Programming, computers, etc. [Serious]

Post by atomtengeralattjaro » Thu Dec 08, 2011 1:49 pm

i just took an exam of VHDL (language for programming an FPGA board (a panel that has a programmable chip on it and some buttons and leds and whatnots))
it was pointless and stressful and i thought i'd failed but it turns out i passed 8)

@AF: what does os.system() do?
edit: nevermind, i think it just runs a system command.. cool.
isn't all this possible with only a batch file?
Ivokyuftaf6666 wrote:
Sun Oct 20, 2019 5:22 pm
Awesome Site, Delivering Fun
Image

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Thu Dec 08, 2011 7:27 pm

It is possible with only a batch file, only I don't know how I would loop through the results of "dir /b /s pattern". I know there's a way to loop in a batch file, but I haven't really looked into it.

Edit: And then I did some Googling and found this.
Last edited by Anonymously Famous on Thu Dec 08, 2011 7:30 pm, edited 1 time in total.
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Thu Dec 08, 2011 7:28 pm

How do you make a batch file and what does it do?

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Thu Dec 08, 2011 7:37 pm

A batch file is a list of things that you can write on a command prompt (The DOS window). There are a few other things in there, like loops and stuff. It's really handy sometimes. If you have things on your PATH environment variable, you can put it in a batch file. (Like Python)

You just create a text file with the commands, and save it as a .bat
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Thu Dec 08, 2011 7:44 pm

That makes sense. So no compiling or stuff liek that?

User avatar
atomtengeralattjaro
Site Admin
Site Admin
Posts: 37528
Joined: Wed May 23, 2007 3:43 pm
Location: green
Pronouns: he / they / that submarine
Contact:

Re: Programming, computers, etc. [Serious]

Post by atomtengeralattjaro » Thu Dec 08, 2011 8:07 pm

no, because they're all standard commands that you could just type in the command prompt one by one.
Ivokyuftaf6666 wrote:
Sun Oct 20, 2019 5:22 pm
Awesome Site, Delivering Fun
Image

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Thu Dec 08, 2011 10:17 pm

Batch files are my friends. :)

Edit: Timer until my birthday:

Code: Select all

import Tkinter

root = Tkinter.Tk()
root.title("Time until AF's Birthday")

Tkinter.Label(root, text="Time until AF's Birthday:", font=(None,18)).pack()

lblTimeLeft = Tkinter.StringVar()

Tkinter.Label(root, textvariable=lblTimeLeft, justify = Tkinter.RIGHT).pack()

import datetime

def getTime():
    now = datetime.datetime.now()
    birthday = datetime.datetime(now.year, 12, 24)
    if (birthday-now).days < 0:
        birthday.year += 1
    difference = birthday-now
    retval = "Days: " + "%2d"%(difference.days)
    secondsLeft = difference.seconds
    retval += "\nHours: " + "%2d"%(secondsLeft/3600)
    secondsLeft %= 3600
    retval += "\nMinutes: " + "%2d"%(secondsLeft/60)
    secondsLeft %= 60
    retval += "\nSeconds: " + "%2d"%(secondsLeft)
    lblTimeLeft.set(retval)

import threading


i = True

def tickTock():
    myTimer = threading.Timer(0.1, getTime)
    myTimer.start()
    while i:
        if not myTimer.is_alive():
            myTimer = threading.Timer(0.1, getTime)
            myTimer.start()

threading.Thread(target=tickTock).start()

root.mainloop()
i=False
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Fri Dec 09, 2011 6:28 pm

Won't you have to import time?
Also, for me this line would be:

Code: Select all

birthday = datetime.datetime(now.year, 12, 08)
lol. I can read code!

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Fri Dec 09, 2011 9:38 pm

No need to import time. Though I've been thinking that there's got to be a better way to do the repeat timer. The way I did it was horribly inefficient.

I'll edit this in not too long with improved code.

Edit: Here it is. This is more efficient than before, as it's only running one additional thread instead of two. It also runs more smoothly. This also introduces custom classes in Python, raising exceptions, inheritance, and the feature that Python has to define functions inside of functions.

Code: Select all

import Tkinter

root = Tkinter.Tk()
root.title("Time until AF's Birthday")

Tkinter.Label(root, text="Time until AF's Birthday:", font=(None,18)).pack()

lblTimeLeft = Tkinter.StringVar()

Tkinter.Label(root, textvariable=lblTimeLeft, justify = Tkinter.RIGHT).pack()

import datetime

def getTime():
    now = datetime.datetime.now()
    birthday = datetime.datetime(now.year, 12, 24)
    if (birthday-now).days < 0:
        birthday.year += 1
    difference = birthday-now
    retval = "Days: " + "%02d"%(difference.days)
    secondsLeft = difference.seconds
    retval += "\nHours: " + "%02d"%(secondsLeft/3600)
    secondsLeft %= 3600
    retval += "\nMinutes: " + "%02d"%(secondsLeft/60)
    secondsLeft %= 60
    retval += "\nSeconds: " + "%02d"%(secondsLeft)
    lblTimeLeft.set(retval)

import threading

class RepeatTimer(threading.Thread):
    def __init__(self, elapse, function, *args):
        self.function = function
        self.elapse = elapse
        self.ticking = True
        self.args = args
        self.myThread = None

    def start(self):
        if self.myThread != None:
            raise Exception("Cannot start thread that is already running")
        def tick():
            import time
            while self.ticking:
                time.sleep(self.elapse)
                self.function(*(self.args))
        self.myThread = threading.Thread(target = tick)
        self.myThread.start()

    def stop(self):
        self.ticking = False

    def restart(self):
        if self.myThread == None or self.ticking:
            raise Exception("Cannot restart what has not been started")
        self.myThread = None
        self.ticking = True
        self.start()

    def is_alive(self):
        return self.ticking
        
countDown = RepeatTimer(0.1, getTime)
countDown.start()

root.mainloop()

countDown.stop()
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

Post Reply