Programming, computers, etc. [Serious]
- Arkannine
- 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]
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.
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
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
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- atomtengeralattjaro
- 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]
yesterday i wrote a very stupid name generator
it looks like this:
The code outputs names like these:
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;
}
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
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
Let me see if I have this 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.
- 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.)
- Set up a random number generator
- Decide the length of the name, between 4 and 7 characters, inclusive.
- Decide whether the name is going to start with a consonant or a vowel.
- Alternate between consonants and vowels until the desired length has been achieved.
- Make sure to capitalize the first character.
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
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- atomtengeralattjaro
- 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]
i forgot about poor i at firstAnonymously Famous wrote:Any reason 'i' is at the end?
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 namesAnonymously 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.
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..
- Dreams
- 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]
You should give this generator to those people who write novels.
I bet they have insane difficulty making 50+ names for a novel.
I bet they have insane difficulty making 50+ names for a novel.
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
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...
Also: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, ;
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;
}
This actually may have inspired me to make my own name generator. That's the hardest part for me when I write.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.
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- atomtengeralattjaro
- 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]
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: Random r = new Random(); /*Does this need seeding? Does it print out the same list every time you run it, or a different list?*/
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 b = r.Next(2) == 1;//Couldn't you just do bool b = r.Next(2);, since a bool is either 0 or 1?
you're absolutely right.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.*/
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.Anonymously Famous wrote:The only thing I'd really change is maybe add in a slight chance for double vowels or double consonants.
- Dreams
- 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]
I'm gonna help you add the double vowels and maybe throw in some last names
Gotta learn C# though.
Gotta learn C# though.
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
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.
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
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
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.
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.
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')
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- atomtengeralattjaro
- 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]
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
@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?
it was pointless and stressful and i thought i'd failed but it turns out i passed
@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?
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
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.
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
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- Dreams
- 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]
How do you make a batch file and what does it do?
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
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
You just create a text file with the commands, and save it as a .bat
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- Dreams
- 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]
That makes sense. So no compiling or stuff liek that?
- atomtengeralattjaro
- 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]
no, because they're all standard commands that you could just type in the command prompt one by one.
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
Batch files are my friends.
Edit: Timer until my birthday:
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
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- Dreams
- 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]
Won't you have to import time?
Also, for me this line would be:
lol. I can read code!
Also, for me this line would be:
Code: Select all
birthday = datetime.datetime(now.year, 12, 08)
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
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.
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
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.