PDA

View Full Version : Coding Programmers in the Playground II: It's not a bug, it's a feature



TSGames
2013-12-21, 08:06 AM
Hello fellow Playgrounders!

The return of the infamous programming thread: a place to posit all your programming queries, brag about your latest accomplishments, and complain about how language X is so bad compared to language Y.

Here's a picture to kick off the discussion:
http://crossthebreeze.files.wordpress.com/2007/08/feature.jpg
=P

Drumbum42
2013-12-21, 12:45 PM
Here's a fun story about using Java to fix a simple problem:

At work I was migrating <Software Product> from one server to another, and updating the software to the latest version. I got the software installed and running and pulled over the database. When I started the software it said: "Error: Can not have more then 64 keys!" I tries this 3-4 times and got the same result, so I looked online. The internet pretty much said: "You're dumb, why are you using that many keys? Recompile MySQL to allow more keys or better yet, fix your DB code." I have run this software on several servers before and I never had to do this, so this did not sound right.

So I opened a ticket with <Software Product's Company>. They said "have you tried recompiling MySQL from source to allow for MySQL to have more then 64 keys?" (Apparently 5min on google was all their IT dept was capable of) My boss didn't like it either so he spent several hours sifting through <Software Company>'s FAQ pages and found a nugget from 2006: "If you receive and error "Can not have more then 32 keys" while upgrading the database, please delete all duplicate entries under "indexes" for each table.

Ah Ha! Problem solved, except there were approximately 1500-2000 entries that needed to be removed, and my boss expected me to do this by hand. Yea right. So I whipped up a java program that went through every table and deleted all redundant entries, and I did it in under 3 hours. Also I haven't made Java talk to a database in a few years so it was a good refresher course too! For the next 15 min I sat back like a proud parent and watched my code clean the database. When it was done the software ran like a charm, no issues.

When I notified <Software Company>'s helpdesk, there were uninterested in my solution. The tech asked me to submit a feature request and closed the ticket. All of this could have been avoided if their software cleaned up after itself when it updated, instead of making a new copy every index in the DB each time it was updated. To be fair, this issue did end with my boss being very impressed with my ability to use code to solve problems quickly.

TSGames
2013-12-27, 08:18 AM
XD

Yeah... I've run into the 'feature request for nearly-essential functionality that the program should already have' before. It's never ended productively, or well for me.

I figure I'll kick off the discussion then: Anyone got a project they feel like posting/ranting/bragging about?

valadil
2013-12-27, 02:03 PM
Sure. I feel like gushing about docopt. If you're not into the command line you probably won't care.

My least favorite task in writing cli apps is parsing the options and arguments. When I'm done with that I have to go back and update the documentation to match the new options.

Docopt fixes that.

There are many libraries for handling command line options. Docopt's approach is to define those options in the documentation. So you come up with your help message that describes the options, where they can be used, what their defaults are, whether they're required or optional, etc. Just write the documentation, let docopt parse that and your options all in one fell swoop. Now your options and documentation won't get out of sync again.

I'm gushing about docopt because I finally got the bash version to work. (There's a core python version and support for calling it from a number of languages, but the bash one was tricky. Actually the problem was that github was eating some of the syntax which ruined the example, but that's another matter.)

I rewrote a music selection script I had using docopt. The switch made it a whole lot more versatile and cut down LOC by about 25%. I hate bragging, but it's probably the most beautiful shell script I've made so far. You point it at your music directory, describe the directory (ie, the default is genre/artist/album, but if yours is ordered by artist/year/album you could change that with the --structure option), tell it which criteria to filter by, and it lets you pick one of those items and plays it. So I could call my script with "-l album" and it'll let me choose an album and play it. Or "-l genre" would let me single out a genre. Or I could combine that with "--random" and it'd pick the same type of item randomly.

Here's the script. The eval at the top is the docopt documentation I've been babbling about. dmenu is a program that takes stdin, prints it all, and lets you select a line, and prints it back out for further processing. cmus-remote controls cmus, my music player of choice.



#!/bin/bash

# applies filters to cmus based on your music directory's structure
# requires docopts and dmenu
eval "$(docopts -A args -V - -h - : "[email protected]" <<EOF
Usage: cmus_select.sh [--list <tag>] [--random] [--structure=</alt/dir/structure>] [--dir=/path/to/music]

-h --help Show help
-r --random Randomize selection instead of using a dmenu
-l --list TAG List music by tag. Unless you use -s, genre, artist, album, and song are expected. [default: song]
-s --structure STRUCT Directory structure for your music. [default: genre/artist/album/song]
-d --dir DIR Location of music [default: $HOME/Music/]
----
cmus_select.sh 0.0.1
EOF
)"

# find position of this tag in the given dir strcuture
for tag in ${args['--structure']//\// } ; do
POS=$(( $POS + 1 ))
[[ "${args['--list']}" == "$tag" ]] && break
done

# set up find args to get this item
if [[ "${args['--list']}" == "song" ]] ; then
FINDARGS=" -mindepth $POS -type f -iregex .*\.\(mp3\) " # no maxdepth - some albums have cd1/cd2 subdirs
else
FINDARGS=" -mindepth $POS -maxdepth $POS -type d"
CAP='/*'
fi

# Prep our pipes. FORMAT affects display. SELECT runs the dmenu.
OFFSET=$(echo ${args['--dir']//\// } | wc -w )
FORMAT="cut -f $((POS + $OFFSET + 1)) -d/"
SELECT="dmenu -i -l 20 -b -s 0"
[[ "${args['--random']}" == 'true' ]] && SELECT="shuf -n 1"

# Get a song or dir and send it to cmus
DIR=$(find "${args['--dir']}" $FINDARGS | $FORMAT | sort | $SELECT )
if [[ "$DIR" != "" ]] ; then
cmus-remote -C "live-filter ~f */$(echo $DIR | tr '()' '*')$CAP" # cmus treats parens as grouping.
cmus-remote -C "echo Playing: $DIR"
cmus-remote -n -p
fi

eidreff
2013-12-27, 05:21 PM
I've been playing with Project Euler to keep my hand in. I have finally realised that Python is easier to write, and far faster to play with in this kind of case. (I'm a C++ chappie with a chunk of Java thrown in) got to problem 18 in less than a week. I'm out of practice so please don't rant at me for being slow!

Razanir
2013-12-27, 07:15 PM
Is anyone here experienced with adding holidays to KDE? I'm trying to add LITERALLY hundreds of religious holidays, and some have semi-complex rules for calculating the date. Such as "Normally on this day, unless it's less than a week before Easter, when it's this other day instead"

I'm trying the following, but not only will my computer not accept it, it'll actually ignore any lines after it.

(Actually all on one line)


white "Solemnity of the Annunciation of the Lord" white
on ([easter] - [25.3] <= 7 ? [easter plus 8 days] : [25.3])

TubaMortim
2013-12-28, 10:30 AM
The thread starter tells to brag about achievements so here goes:

I just finished a course in mobile development, which was basically about making html/Javascript apps for Android using Phonegap. I had only went to a basic Java course before, and had never done anything with Javascript.

I'm proud to present my final product: Javascript Trainer - an app that presents you with a block of code, and your job is to spot the errors in it. The idea came from myself noticing that I spent lots and lots of time trying to fix my code by tweaking the logic of it, when the problem was in a simple syntax error that I just didn't notice.

The app is available on Google Play (https://play.google.com/store/apps/details?id=com.jstrain) :smallsmile:

Finlam
2013-12-30, 07:34 AM
I've been playing with Project Euler to keep my hand in. I have finally realised that Python is easier to write, and far faster to play with in this kind of case. (I'm a C++ chappie with a chunk of Java thrown in) got to problem 18 in less than a week. I'm out of practice so please don't rant at me for being slow!

Another Pythonist is born! Welcome to the land of easy coding.

As for me, I don't have much to brag about at the moment, but I did just finish up a huge project experimenting with multi-threading in python. Contrary to popular belief, it handles it quite well and I was able to speed up execution time by a factor of 8 on a 4 core system. =D

razark
2013-12-30, 11:04 AM
Another Pythonist is born! Welcome to the land of easy coding.
Any advice on where to pick up information on Python? As of a few days ago, I've got a Raspberry Pi on my desk, and Python seems to be the intended language of choice.

I've been rather light on programming lately, and most of my experience is in C. I'd like a quick overview/intro that would also be a decent reference, rather than something intended for a complete beginner with no experience.

Solse
2013-12-30, 11:23 AM
Any advice on where to pick up information on Python? As of a few days ago, I've got a Raspberry Pi on my desk, and Python seems to be the intended language of choice.

I've been rather light on programming lately, and most of my experience is in C. I'd like a quick overview/intro that would also be a decent reference, rather than something intended for a complete beginner with no experience.

The best place to go is the official Python tutorial. Note that there are two types of Python: Python 2.7, and Python 3. 3 is newer, but 2 is more portable. Here are links to both tutorials:
2.7: http://docs.python.org/2/tutorial/
3: http://docs.python.org/3/tutorial/

Tyndmyr
2013-12-30, 02:29 PM
Hey, I code all the things! Java's the main language these days, but I dabble in all manner of stuff. Python was the last language picked up, and I must say, it's reasonably easy to pick up. JMonkey is my current dabblin' project, though finding spare time for more coding is rough.

razark
2013-12-30, 02:37 PM
The best place to go is the official Python tutorial. Note that there are two types of Python: Python 2.7, and Python 3. 3 is newer, but 2 is more portable.
Thank you. I'll have to find some time to look over it. 2.7 is what is installed on the load I'm currently using. Hopefully I can find something fun and useful to do with this thing.

Drumbum42
2013-12-30, 04:16 PM
Any advice on where to pick up information on Python? As of a few days ago, I've got a Raspberry Pi on my desk, and Python seems to be the intended language of choice.

I've been rather light on programming lately, and most of my experience is in C. I'd like a quick overview/intro that would also be a decent reference, rather than something intended for a complete beginner with no experience.

Gratz on getting the Raspberry Pi! Yea, they have Python preinstalled when you use the default raspbian, but you can use many languages on it. I'm sure that you can find a C/C++ compiler for it too, I mean I got Java running on mine.

Balain
2013-12-30, 05:34 PM
I would like to brag that I made it through last semester with B's. As much as learning assembly and machine code was a pain, I appreciate not programming in assembly and really really really appreciate not programming in machine code.

shawnhcorey
2013-12-30, 06:16 PM
I would like to brag that I made it through last semester with B's. As much as learning assembly and machine code was a pain, I appreciate not programming in assembly and really really really appreciate not programming in machine code.

Obligatory xkcd: Real Programmers (http://xkcd.com/378/).

Razanir
2013-12-30, 07:57 PM
I would like to brag that I made it through last semester with B's. As much as learning assembly and machine code was a pain, I appreciate not programming in assembly and really really really appreciate not programming in machine code.


Obligatory xkcd: Real Programmers (http://xkcd.com/378/).

Only machine code... REAL programmers make their own processors. (Like *I* did for class last semester)

Solse
2013-12-30, 08:18 PM
Only machine code... REAL programmers make their own processors. (Like *I* did for class last semester)

How did you do it? Could it run anything?

Razanir
2013-12-30, 08:31 PM
How did you do it? Could it run anything?

Well we only had to design one with Quartus. It ran on an FPGA, so we didn't have to build anything. But yes, it could run stuff. My group had ours read in a number from some switches, triple it, then display it in binary and hex.

Finlam
2013-12-31, 07:14 AM
Well we only had to design one with Quartus. It ran on an FPGA, so we didn't have to build anything. But yes, it could run stuff. My group had ours read in a number from some switches, triple it, then display it in binary and hex.

Yeah, you can do a lot of cool stuff with FPGAs. VHDL is awesome to program in, but I found (for me) that it took a little while to get into the everything asynchronous mindset. After you're there, it can be a ton of fun, plus working on the hardware at that level makes it really really fast.

Ashtar
2014-01-03, 06:40 AM
This year, we acquired two new customers for our software and we now optimize the power portfolios of the three largest Swiss power companies (among others). Pretty good for a two man company and with the software written by one person (me!). :smallbiggrin:

Razanir
2014-01-03, 01:01 PM
Yeah, you can do a lot of cool stuff with FPGAs. VHDL is awesome to program in, but I found (for me) that it took a little while to get into the everything asynchronous mindset. After you're there, it can be a ton of fun, plus working on the hardware at that level makes it really really fast.

Fun was making a circuit diagram for multiplication.

CombatOwl
2014-01-07, 08:03 PM
Only machine code... REAL programmers make their own processors. (Like *I* did for class last semester)

Processors? Real programmers mill their own gears.

Tyndmyr
2014-01-08, 04:14 PM
Processors? Real programmers mill their own gears.

I print mine on a 3d printer. Have not yet made a mechanical computer on one, though I suppose it's possible if you want to burn the plastic.

Drumbum42
2014-01-08, 04:33 PM
Processors? Real programmers mill their own gears.

A REAL programer uses a "binary-like system of ropes, knots, and simple machines operated by a rotating cylindrical cogwheel"

See Heron of Alexandria (http://en.wikipedia.org/wiki/Hero_of_Alexandria)

Rope computers, go big or go home.

Razanir
2014-01-08, 04:55 PM
This seems relevant:

K'nex calculator (http://knexcomputer.blogspot.com/2007/03/knex-calculator.html)

shawnhcorey
2014-01-08, 07:40 PM
Real programmers make it out of Lego (http://www.youtube.com/watch?v=RLPVCJjTNgk).

Razanir
2014-01-08, 07:45 PM
Real programmers make it out of Lego (http://www.youtube.com/watch?v=RLPVCJjTNgk).

Well, I'm glad to see from google search recommendations that I'm not the first to look for instructions.

Neftren
2014-01-09, 12:30 PM
Anyone here any good with databases? My knowledge of them is limited to "Hi, I'm a frontend dev. Here is some stuff I want to save."

I'm looking for something nice and simple that just lets me save my structured data somewhere, without having to write queries. Something similar to Google's NDB (https://developers.google.com/appengine/docs/python/ndb/), but for Node/Javascript.

Best case scenario would be Redis backed by schemaless Postgres (9.3 using the new JSON type if possible)... anyone?

Grinner
2014-01-09, 12:49 PM
Real programmers make it out of Lego (http://www.youtube.com/watch?v=RLPVCJjTNgk).

I recall there was once a computer made from billiard balls. I think it was supposed to be a proof of concept demonstrating how a computer could be made from anything.

Drumbum42
2014-01-09, 12:58 PM
This seems relevant:

K'nex calculator (http://knexcomputer.blogspot.com/2007/03/knex-calculator.html)

That.... is perhaps the coolest thing I've seen all day.

That is DEFINITELY the coolest thing I've seen all month.

Wookieetank
2014-01-09, 02:49 PM
That.... is perhaps the coolest thing I've seen all day.

That is DEFINITELY the coolest thing I've seen all month.

This is the coolest thing I've seen all YEAR! :smallwink:

Tyndmyr
2014-01-09, 02:56 PM
Anyone here any good with databases? My knowledge of them is limited to "Hi, I'm a frontend dev. Here is some stuff I want to save."

I'm looking for something nice and simple that just lets me save my structured data somewhere, without having to write queries. Something similar to Google's NDB (https://developers.google.com/appengine/docs/python/ndb/), but for Node/Javascript.

Best case scenario would be Redis backed by schemaless Postgres (9.3 using the new JSON type if possible)... anyone?

Ehhh, not sure. I've used Hibernate quite a bit for Java, and it's generally pretty good at what it does, but I've not looked for a similar tool for that context. I'm sure you could google around for hibernate-like frameworks, though.

Razanir
2014-01-09, 06:03 PM
Anyone here any good with databases? My knowledge of them is limited to "Hi, I'm a frontend dev. Here is some stuff I want to save."

I'm looking for something nice and simple that just lets me save my structured data somewhere, without having to write queries. Something similar to Google's NDB (https://developers.google.com/appengine/docs/python/ndb/), but for Node/Javascript.

Best case scenario would be Redis backed by schemaless Postgres (9.3 using the new JSON type if possible)... anyone?

Not particularly. My experience is limited to the small amounts of SQL and JBDC *shudders at the memory* that we used last year in a CS class I took. Try asking again in a year, though. I'm planning on taking a class entirely on databases in the fall.

(The horrible memory isn't even that I had to use JDBC. I was finishing homework the night before it was due, but had trouble debugging, so I went to bed. Then in the morning, I skipped breakfast to finish it before it was due. Partly because of the 10 am deadline, and partly because of religious reasons. I learned an important lesson that morning. Never debug on an empty stomach)

EDIT: Oh, and I also used JPA in that class.

Razanir
2014-01-14, 12:45 AM
Linux question: Does anyone know how to activate a wired internet connection in KDE?

factotum
2014-01-14, 03:03 AM
Wouldn't
ifup eth0 (or whatever) from a command line do it, assuming the interface was configured properly in the first place? Or is it the whole "configuration" part you need assistance with?

Razanir
2014-01-14, 09:05 AM
Wouldn't
ifup eth0 (or whatever) from a command line do it, assuming the interface was configured properly in the first place? Or is it the whole "configuration" part you need assistance with?

Didn't work.


$ sudo ifup etho
Ignoring unknown interface eth0=eth0.

However, it does list eth0 if I run ifconfig

Here's more about why I ask:

Even in Linux (specifically Kubuntu), I'm still just using the little wireless button in the corner of my screen. Catch is, I can't find the option for turning on an ethernet connection, just for wireless connections.

valadil
2014-01-14, 09:11 AM
I can't speak for Kubuntu, but in plain old Ubuntu there's supposed to be an internet connection applet in your system tray. It sometimes gets lost though or stops spawning. Regardless you can run it with nm-connection-editor or nmcli if you prefer the command line.

Drumbum42
2014-01-14, 03:29 PM
Didn't work.


$ sudo ifup etho
Ignoring unknown interface eth0=eth0.

However, it does list eth0 if I run ifconfig

Here's more about why I ask:

Even in Linux (specifically Kubuntu), I'm still just using the little wireless button in the corner of my screen. Catch is, I can't find the option for turning on an ethernet connection, just for wireless connections.

So the command is not:

sudo ifup eth0
it's:

sudo ifconfig eth0 up

After which you need to tell it to get a dhcp reservation and such. "ifup" usually only works if there's already a recognizable connection, and if there was one, Kubuntu would have auto configured it.

godshawk
2014-01-16, 02:55 PM
Linux question: Does anyone know how to activate a wired internet connection in KDE?

Hrmmm...



## I totally doubt this will work :)
$ ip link set $(ip a | grep "" | awk '{print $2}' | sed -e 's/://' | egrep -i --color 'enp2s0f0|eth0') up

TSGames
2014-01-21, 11:21 PM
Quick question: Do you listen to music when you program?

factotum
2014-01-22, 02:30 AM
Quick question: Do you listen to music when you program?

No--I find it distracting.

Horizon
2014-01-22, 02:50 AM
I love web design, but my college would only teach me HTML and CSS. So I took a JavaScript class from CodeCademy and then made a clickable Web version of the Periodic Table of Storytelling (http://designthroughstorytelling.net/periodic/). All the information is in HTML5, but if you have JavaScript enabled the graphics get better. I'm quite proud of it. :smallsmile:

Incidentally, if anyone knows of an entry-level job opening for a graphic designer near Denver, let me know...

TSGames
2014-01-22, 10:34 AM
No--I find it distracting.
I find there's a time for silence and a time for music. When I'm working on a hard problem (not necessarily in the NP sense) then I prefer silence while I figure out my algorithm, otherwise I find rock is pretty boss for churning out good code.

Lately my list has been:

Metallica - Kill em All (http://www.youtube.com/watch?v=aAITxlCsj4Y)
AWOL Nation - Megalithic Symphony (http://www.youtube.com/watch?v=rSxUVrmTM5U)
Danzig - Mother (http://www.youtube.com/watch?v=vgSn0SbQJQI)
The Wallflowers - One Headlight (http://www.youtube.com/watch?v=Zzyfcys1aLM)

The first two are whole albums, the last two are more winding down songs. It really gets me in the zone =D


@Horizon: That's pretty cool. Congratulations on teaching yourself HTML5 and JS. It also looks really nice; you have pretty good design taste.

razark
2014-01-22, 11:53 AM
No--I find it distracting.
I can't listen to anything with lyrics while working. I also find TV and movies in the background to be too distracting for working problems or reading.

I do tend to listen to instrumental music, though. It helps to drown out the rest of the world so I can focus on the issue. Unfortunately, I usually need to keep one ear uncovered in case the phone rings, and we've got one person in our office that sings to herself, sighs/yawns constantly (about once a minute for fifteen minutes), laughs loudly, and talks to herself.

FrankLuke
2014-01-22, 03:16 PM
Quick question: Do you listen to music when you program?

Unfortunately I sit right under the speaker at work and have discovered that my coworkers and I have almost no intersection on what we like in music. I'd prefer to listen to my own choices under the headphones, but that isn't allowed.

Similarly, I've found that while I like Marty Robbins, his music is not conducive to a good workout rhythm.

valadil
2014-01-22, 09:33 PM
Quick question: Do you listen to music when you program?

Sometimes. Maybe for a quarter to a half of my work day. It is distracting, but it's less distracting than whatever I overhear in the hallway. It's almost like putting the headphones on seals my head shut and prevents my focus from leaving.

Music can also help my mood. One of the other devs pisses me off a lot. If I just sit there trying to work through it, I stay pissed off. If I put on some Priest or Maiden, 20 minutes later I feel good again.

I've also noticed that headphones send a signal. When a project manager comes by with questions, they usually pick someone without headphones. If I don't want to be interrupted I'm not above putting on my headphones.

-- edit --

I'm not happy with that explanation. It's not inaccurate but it misses something important.

I'm distractable. Some days I just want to talk to coworkers or drink coffee. Some days I've slept too much or drank too much coffee and can't sit still. Other days there's a thread on a forum I just can't stop refreshing.

When I'm having one of those days I accept that I'm going to seek distraction. Listening to music is a distraction I can deploy easily that doesn't derail me much at all. It's less optimal than if I were totally focused, but when total focus isn't possible music is the least disruptive distraction I have access to.

Astral Avenger
2014-01-22, 10:12 PM
Quick question: Do you listen to music when you program?

I haven't done any projects much bigger than a project euler problem, so it depends exclusively on if I already had music playing. (edit: all of my previous programming has been in python)

That being said, I have 2 weeks to learn R for my statistics class, I'm also in intro to C++ (and a linux OS for the lab computers) and rumor has it that I need to learn MatLab for my Differential equations and linear algebra class. Should be a fun semester if I don't go bonkers :smallsmile:

Krazzman
2014-01-23, 07:35 AM
I am wary if I fit in this Thread... to expand on this:

I completed an Apprenticeship as a "Fachinformatiker Anwendungsentwicklung" a better way to say Programmer. But afterwards I started working as an "Anwendungsbetreuer" so basically application caretaker...

I don't really develop... more like analysis, bugfixing, transporting data into production or similar.
Now comes the catch: COBOL.

Currently at work I am in a Project but not like normal projects with 100% workload on that project more like next to my other responsibilities...

Anyway the project is the parallel use of DB2 and IMS databases as we want to switch from IMS to DB2 to reduce costs. Now I am short of completing this but the problems I am having...
If I want to test it out I have to Build my whole job (where the programmfiles are in) then I either already get an error due to syntax or can proceed with a Promote Report to get it into the test environment. After reading the report and being sure that nothing bad goes into the test environment comes the real Promote. Then I can test it by using a custom JCL (Job Control Language) that executes a Batchjob to run the program.
This will take around 5 minutes.
Additionally the part of the project I am doing features 2 Programms. One Cobol program and one DeltaCobol program. And our Development Environment tool doesn't really get the syntax of DeltaCobol and as such I oversee small mistakes basically once every Build.
But back a bit. Due to working with sensitive data I need to make sure that DB2 handles the data exactly like IMS and well the compare between the datasets is... the main problem atm. But at least I know that I will be done tomorrow as I made some significant process today...

About music:
I would but this is rude as I share the room with 2 colleagues and it's annoying to deplug my earphones all the time if I need to ask a question or answer the phone. If I could I mostly listen to Soundtracks from Movies/Games and Metal. Since my iPod wasn't hooked to my PC in the past year I don't have the music I want to listen to anyway.

Grinner
2014-01-23, 09:29 AM
I've got a question.

Where do variables go when they die?

I've got a bit of code:

int isPassable(int targetX, int targetY) {
//check boundaries
if (targetY < 0 || targetY > MAP_HEIGHT - 1 ||
targetX < 0 || targetX > MAP_WIDTH - 1) {
return 0; //false
}

short int targetTileType = tileIndex[map[targetY][targetX]].tilePassibility;

//check the passibility of the target tile's type
if (targetTileType == 1) { return 0; } //false
else { return 1; } //true
}

...and I'm wondering if this will result in a memory leak. Should I be calling free() on targetTileType at the end of this function? Or is the variable merely discarded into the ether and the memory to be reallocated as needed?

shawnhcorey
2014-01-23, 10:30 AM
If that is C, the variables declared inside a function are allocated on the stack and are freed when the function returns. Unless they are declared static. Then they are allocated on the heap, like all the global variables, and are never freed.

razark
2014-01-23, 11:24 AM
Unless they are declared static. Then they are allocated on the heap, like all the global variables, and are never freed.
Just to clarify: it is allocated once and reused each time the function is called, instead of being allocated each time the function is called, correct?

Grinner
2014-01-23, 11:30 AM
If that is C, the variables declared inside a function are allocated on the stack and are freed when the function returns.

Alright. Good to hear.


Unless they are declared static. Then they are allocated on the heap, like all the global variables, and are never freed.

...I really need to learn Assembly.

So globals are never freed? Even when the program terminates? (I suppose the answer to that question might depend upon the OS, though.)

shawnhcorey
2014-01-23, 11:36 AM
So globals are never freed? Even when the program terminates? (I suppose the answer to that question might depend upon the OS, though.)

All memory used by a process is freed when the process is terminate. That includes the code, the heap, and the stack.

shawnhcorey
2014-01-23, 11:38 AM
Just to clarify: it is allocated once and reused each time the function is called, instead of being allocated each time the function is called, correct?

Not exactly. The heap and it's initialized variables are loaded with the code. They are not allocated at runtime. They are there when the code starts to execute.

Grinner
2014-01-23, 11:39 AM
All memory used by a process is freed when the process is terminate. That includes the code, the heap, and the stack.

Okay. Thanks for the help. :smallsmile:

Amidus Drexel
2014-01-23, 11:39 AM
That being said, I have 2 weeks to learn R for my statistics class, I'm also in intro to C++ (and a linux OS for the lab computers) and rumor has it that I need to learn MatLab for my Differential equations and linear algebra class. Should be a fun semester if I don't go bonkers :smallsmile:

Hey, I'm in an intro-level C++ course! *high-fives* Which reminds me, I need to install Visual Studio...

And I've done some (fairly small) stuff with MatLab; it's not too bad to work with.

Razanir
2014-01-23, 03:45 PM
I haven't done any projects much bigger than a project euler problem, so it depends exclusively on if I already had music playing. (edit: all of my previous programming has been in python)

That being said, I have 2 weeks to learn R for my statistics class, I'm also in intro to C++ (and a linux OS for the lab computers) and rumor has it that I need to learn MatLab for my Differential equations and linear algebra class. Should be a fun semester if I don't go bonkers :smallsmile:

R and Unix I can help with.

factotum
2014-01-23, 04:54 PM
int isPassable(int targetX, int targetY) {
//check boundaries
if (targetY < 0 || targetY > MAP_HEIGHT - 1 ||
targetX < 0 || targetX > MAP_WIDTH - 1) {
return 0; //false
}

short int targetTileType = tileIndex[map[targetY][targetX]].tilePassibility;

//check the passibility of the target tile's type
if (targetTileType == 1) { return 0; } //false
else { return 1; } //true
}


Silly question: why are you using an intermediate variable at all there? You could do the comparison directly with tileIndex, unless there's some other code you're not showing that also references targetTileType.

Astral Avenger
2014-01-23, 05:40 PM
Hey, I'm in an intro-level C++ course! *high-fives* Which reminds me, I need to install Visual Studio...

And I've done some (fairly small) stuff with MatLab; it's not too bad to work with.
*high-five* I need to get that done too.

R and Unix I can help with.
Awesome, so far R isn't to bad, even if its indexing is confusing after getting used to python (python: x=[4,2,9], x[1]==2. R: x=c(4,2,9), x[1]==4)

Emmerask
2014-01-23, 05:41 PM
Quick question: Do you listen to music when you program?

if its a difficult part i am working on then no, if on the other hand its more or less boring stuff then i like to listen to old audio dramas while coding (sherlock holmes, The Three Investigators etc ^^)
I dont know why but I actually get more done that way ?!

/edit though I work a lot from home, when I am in the office it more then likely is because of a meeting or to discuss something in person...
would be kind of rude to put headphones on then and there :smallbiggrin:

Grinner
2014-01-23, 06:42 PM
Silly question: why are you using an intermediate variable at all there? You could do the comparison directly with tileIndex, unless there's some other code you're not showing that also references targetTileType.

That....is a very good question....In retrospect, there's no good reason.

I attempted to make a roguelike a couple months ago, and I rediscovered the source code just yesterday. Thinking it might be fun to spend my day off working on this, I searched for a guide on writing roguelikes and found this (http://www.kathekonta.com/rlguide/). Therein, it was suggested that referencing a table would be more efficient than individually testing for each possible tile. In addition to using this table idea, I also adapted the code used to test it to my own game.

As you've pointed out, it seems to be totally unnecessary, both in my own source code and the original source code. It's possible it was done for aesthetic purposes, though.

That aside, I've made great progress on that game, which I've been meaning to gloat about.

After spending much of yesterday cleaning up my original code (making functions more modular, lessening dependence on globals, applying optimizations, etc.), I tried adding color rendering to the draw function this morning.

I ran into a little trouble though. See, while my compiler (tcc) includes a copy of conio.h, it appears to only be partially implemented. When I tried to invoke colortext(), the compiler gave me an error about an undefined reference, in spite of the fact that my program uses two other functions from that library for user input.

After searching for a solution, I discovered the source code to what I believe is an open-source version of conio. It also would not compile. However, it occurred to me to look for colortext() inside of conio.c, and I discovered that the function was just a wrapper of a native Windows function.

After copying it into a new source file, including windows.h, creating a prototype in a new header, and including that header in my main file, IT WORKED. And I was very pleased.

...I was also a bit annoyed at the fact that I was now including two versions of the same library, but I then realized that conio.h only contained prototypes of the functions. To that end, I cut and pasted those prototypes into the new header, and that too worked. I was then able to ignore conio.h entirely in favor of my own library, minicon.h.

I made my own library, and I'm feeling pretty clever right now. :smallbiggrin:

reaverb
2014-01-26, 11:00 AM
Programmer joke:

A professor assigned her students to write some Haskell code and print a hard copy. The next class she asked a student to write his code on the whiteboard and give her his printed copy. She noticed he wrote working code on the whiteboard but gave her a blank paper and asked him:

"Why is this paper blank?"

The student responded:

"You're the one who keeps praising lazy evaluation."

Drumbum42
2014-01-27, 01:39 PM
Quick question: Do you listen to music when you program?

Not during the design stage when I need to really think about how to do stuff, but when it's time to churn out some code I really like some music playing. It keeps my mind from wandering too much. (As I tend to keep changing working code before the program works if my mind wanders too much. This generally leaves me with a non-usable program, but some really great chunks of code)

Finlam
2014-01-30, 08:40 AM
I thought this was worth a read:

A Brief And Mostly Wrong History Of Programming Languages (http://james-iry.blogspot.mx/2009/05/brief-incomplete-and-mostly-wrong.html)

TSGames
2014-02-06, 06:54 PM
So I came across this map generator (http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/) the other day. The demo is here (http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/demo.html).

This is pretty cool and various implementations already exist in a couple of languages, including Java. I'm thinking of delving into this guy's code to see if I could rebuild it in python. Maybe I'm insane, but I thought it was pretty cool project...

Tirunedeth
2014-02-06, 10:20 PM
So I came across this map generator (http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/) the other day. The demo is here (http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/demo.html).

This is pretty cool and various implementations already exist in a couple of languages, including Java. I'm thinking of delving into this guy's code to see if I could rebuild it in python. Maybe I'm insane, but I thought it was pretty cool project...

I actually did (nearly) just that a few months ago when I came across that terrain generator. The main difference from Patel's version is that I couldn't quite get the Voronoi grid stuff to work, so it uses a hexagonal grid as the basis for terrain generation. I also used a slightly different function for distributing elevation in order to produce flatter lowlands and peakier peaks, and modified the generation of lakes slightly to avoid multiple outlets and get rid of the uplifted water visible around the edges of lakes in the 3D view of the demo.

If you'd like to see the code, I could send you a copy, although I warn you that it is in pretty bad shape.

Rosstin
2014-02-06, 10:45 PM
As a programmer: this thread is the best idea ever.

Balain
2014-02-08, 05:52 AM
So I have been learning Haskell in my programming paradigm course. In the past when I was young I hated functional languages (like miranda) But now I have grown to really really like Haskell.

Miklus
2014-02-10, 08:59 PM
You know, programming is one thing. Real-time programming is quite another. At work we have an application that has to run real-time because it is linked to external hardware. Our biggest fear is that windows will start to clean up the heap and thus cause a lag that makes us miss incoming signals. That is why we, in general, don't use the heap at runtime and some threads run at insanely high priority (31).

Unfortunately, we have at problem. The application has been observed to freeze up for 13.7 minutes at a time! The whole computer freezes, the mouse can not be moved for this time. Then the application continues as if nothing happend! This is a rare occurance, but it is always 13.7 minutes. Our test computer ran full tilt for 33 days before the first occurance. This "bug" has been observed on several different (although identical) pieces of hardware a total of maybe 10-12 times. We are all losing hair over this.

My own pet theory is that this is some kind of heat problem and not a software problem at all. Some of the hardware gets too hot to touch. I have tried to convince my know-it-all colleges to heat-test the damn thing but they won't listen because they never do. They would rather screw around with the thread priorities. That has not fixed the problem yet.

So any idea as to what this could be? Any ides are welcome, because we will not hear the end of this before it is fixed. And how do I get my thick-skulled coworkers to listen to my ideas once in a while?

factotum
2014-02-11, 02:43 AM
I doubt a heat issue would be so specific as to last for exactly 13.7 minutes each time--that sounds far more like a programming fault. Since your application is running at maximum priority, if it starts gobbling up loads of CPU cycles it will override the system threads that collect mouse and keyboard input (those run at priority 15, IIRC), which would make the entire system appear to lock up.

How you would debug such a thing is a different matter entirely, especially since it's so long in between occurrences. All I can think of is to lower the priority of the app to 30 and have a small monitor program running at priority 31 that just checks the CPU usage of the main app and raises some sort of warning if it goes above a certain value--that at least would tell you it's definitely the app at fault.

shawnhcorey
2014-02-11, 10:32 AM
You know, programming is one thing. Real-time programming is quite another. At work we have an application that has to run real-time because it is linked to external hardware. Our biggest fear is that windows...

Found your problem. If you're doing real-time programming, use a real-time OS (http://www.qnx.com/).

factotum
2014-02-11, 11:48 AM
Found your problem. If you're doing real-time programming, use a real-time OS (http://www.qnx.com/).

That too, of course. :smallsmile:

Miklus
2014-02-12, 02:47 PM
I doubt a heat issue would be so specific as to last for exactly 13.7 minutes each time--that sounds far more like a programming fault. Since your application is running at maximum priority, if it starts gobbling up loads of CPU cycles it will override the system threads that collect mouse and keyboard input (those run at priority 15, IIRC), which would make the entire system appear to lock up.

How you would debug such a thing is a different matter entirely, especially since it's so long in between occurrences. All I can think of is to lower the priority of the app to 30 and have a small monitor program running at priority 31 that just checks the CPU usage of the main app and raises some sort of warning if it goes above a certain value--that at least would tell you it's definitely the app at fault.

So maybe the others are right in trying with the thread priorities. They thought they had fixed the problem several times, but test have proven otherwise. A monitor program is probably a good idea. So far they have made a program that spams the IO and networks ports. That did not provoke the error. I think our only hope is to find some way to provoke the error because if it can hide for a month, how long do you have to test before you can declare that the lastest fix removed the problem? A year? :smallsigh:

I can understand the computer freezing up, what I can't understand is how it can recover. Is tere some counter that needs to go into overflow or what? The number 13.7 minutes comes up, but I think 5 minutes have been observed too, but on different hardware. At one point they caught two of these errors within ten minutes.

QNX? Sounds interresting. But the chance of us migrating to that platform, or any other platform, is slim to none.

factotum
2014-02-13, 02:18 AM
I can understand the computer freezing up, what I can't understand is how it can recover.

If the app stops using 100% CPU then the system will recover just fine. Question does occur to me: how many threads does your app have, and how many processor cores are available on the machine it's running on?

Ashtar
2014-02-18, 11:46 AM
I was wondering if any of you would have any input as to the problem of unit commitment (assigning power generation in large scale electrical systems to a set of units).

I've got a question up on Reddit/Algorithms (http://www.reddit.com/r/algorithms/comments/1y6uxb/unit_commitment_power_market_looking_for_test/) currently, but I'm not getting much traction. I guess it is pretty specific.

Astral Avenger
2014-02-18, 01:42 PM
I made a tic tac toe game in python, its either one or two player, but I haven't had the time to actually make the computer play smart in 1p mode. Regardless, this is probably the most complex thing i've made and had the patience to actually make work. :smallbiggrin:




win=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
import t3grid
import random

def printgrid(movelist):
print t3grid.t3grid(movelist)[0]
print t3grid.t3grid(movelist)[1]
print t3grid.t3grid(movelist)[2]
print t3grid.t3grid(movelist)[3]
print t3grid.t3grid(movelist)[4]

def checkwin(movelist):
win=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
#[[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]
winx=[0,0,0,0,0,0,0,0]
wino=[0,0,0,0,0,0,0,0]
for n in range(0,8):
for m in range(0,3):
if(movelist[win[n][m]]==1):
winx[n]=winx[n]+1
if(winx[n]==3):
return "P1 wins!"
elif(movelist[win[n][m]]==2):
wino[n]=wino[n]+1
if(wino[n]==3):
return "P2 wins!"
return 1

gametype=input('One player or two player? (1/2) ')
movelist=[0,0,0,0,0,0,0,0,0]
movecount=0
if(gametype==2): #two player
while(movecount<9):
if(movecount%2==0):
printgrid(movelist)
move=input('P1 Please enter your move: ')
while(movelist[move-1]!=0):
move=input('P1, that is not a valid move. Please enter a move: ')
movelist[move-1]=1
elif(movecount%2==1):
printgrid(movelist)
move=input('P2 Please enter your move: ')
while(movelist[move-1]!=0):
move=input('P2, that is not a valid move. Please enter a move: ')
movelist[move-1]=2
movecount=movecount+1
if(checkwin(movelist)!=1):
print checkwin(movelist)
printgrid(movelist)
movecount=10
print checkwin(movelist)

elif(gametype==1): #one player
dif=input("Easy or Hard? (1/2) ")
dif=1 #Hard mode not yet functional
if(dif==1):
first=input('Would you like to go first or second or random? (1/2/3) ')
print "Don't tell it I said so, but the computer isn't very good."
if(first==3):
if(random.randint(1,2)==1):
first=1
print "You go first!"
else:
first=2
print "You go second!"
movelist=[0,0,0,0,0,0,0,0,0]
movecount=0
if(first==2):
while(movecount<9):
if(movecount%2==0):
move=random.randint(0,8)
while(movelist[move]!=0):
move=random.randint(0,8)
movelist[move]=1
print "Computer's move: ", move+1
elif(movecount%2==1):
printgrid(movelist)
move=input('P2 Please enter your move: ')
while(movelist[move-1]!=0):
move=input('P2, that is not a valid move. Please enter a move: ')
movelist[move-1]=2
movecount=movecount+1
if(checkwin(movelist)!=1):
if(checkwin(movelist)=="P1 wins!"):
print "Computer wins!"
printgrid(movelist)
movecount=10
print "Suck it meatbag, you cant beat silicon"
elif(checkwin(movelist)=="P2 wins!"):
print checkwin(movelist)
printgrid(movelist)
movecount=10
print checkwin(movelist)
movecount=10
if(first==1):
while(movecount<9):
if(movecount%2==1):
move=random.randint(0,8)
while(movelist[move]!=0):
move=random.randint(0,8)
movelist[move]=2
print "Computer's move: ", move+1
elif(movecount%2==0):
printgrid(movelist)
move=input('P2 Please enter your move: ')
while(movelist[move-1]!=0):
move=input('P2, that is not a valid move. Please enter a move: ')
movelist[move-1]=1
movecount=movecount+1
if(checkwin(movelist)!=1):
if(checkwin(movelist)=="P2 wins!"):
print "Computer wins!"
printgrid(movelist)
movecount=10
print "Suck it meatbag, you cant beat silicon"
elif(checkwin(movelist)=="P1 wins!"):
print checkwin(movelist)
printgrid(movelist)
movecount=10
print checkwin(movelist)
movecount=10




def t3grid(movelist):
if(movelist[0]==0):
line1=" |"
if(movelist[0]==1):
line1="x|"
if(movelist[0]==2):
line1="o|"
if(movelist[1]==0):
line1=line1+" |"
if(movelist[1]==1):
line1=line1+"x|"
if(movelist[1]==2):
line1=line1+"o|"
if(movelist[2]==0):
line1=line1+" "
if(movelist[2]==1):
line1=line1+"x"
if(movelist[2]==2):
line1=line1+"o"
if(movelist[3]==0):
line3=" |"
if(movelist[3]==1):
line3="x|"
if(movelist[3]==2):
line3="o|"
if(movelist[4]==0):
line3=line3+" |"
if(movelist[4]==1):
line3=line3+"x|"
if(movelist[4]==2):
line3=line3+"o|"
if(movelist[5]==0):
line3=line3+" "
if(movelist[5]==1):
line3=line3+"x"
if(movelist[5]==2):
line3=line3+"o"
if(movelist[6]==0):
line5=" |"
if(movelist[6]==1):
line5="x|"
if(movelist[6]==2):
line5="o|"
if(movelist[7]==0):
line5=line5+" |"
if(movelist[7]==1):
line5=line5+"x|"
if(movelist[7]==2):
line5=line5+"o|"
if(movelist[8]==0):
line5=line5+" "
if(movelist[8]==1):
line5=line5+"x"
if(movelist[8]==2):
line5=line5+"o"
line2=line4="-+-+-"
l1=" 1|2|3"
l2=" -+-+-"
l3=" 4|5|6"
l5=" 7|8|9"
line1=line1+l1
line2=line4=line2+l2
line3=line3+l3
line5=line5+l5
return line1, line2, line3, line4, line5






>>> ================================ RESTART ================================
>>>
One player or two player? (1/2) 1
Easy or Hard? (1/2) 1
Would you like to go first or second or random? (1/2/3) 3
Don't tell it I said so, but the computer isn't very good.
You go second!
Computer's move: 3
| |x 1|2|3
-+-+- -+-+-
| | 4|5|6
-+-+- -+-+-
| | 7|8|9
P2 Please enter your move: 1
Computer's move: 9
o| |x 1|2|3
-+-+- -+-+-
| | 4|5|6
-+-+- -+-+-
| |x 7|8|9
P2 Please enter your move: 6
Computer's move: 5
o| |x 1|2|3
-+-+- -+-+-
|x|o 4|5|6
-+-+- -+-+-
| |x 7|8|9
P2 Please enter your move: 7
Computer's move: 4
o| |x 1|2|3
-+-+- -+-+-
x|x|o 4|5|6
-+-+- -+-+-
o| |x 7|8|9
P2 Please enter your move: 2
Computer's move: 8
>>>



>>> ================================ RESTART ================================
>>>
One player or two player? (1/2) 1
Easy or Hard? (1/2) 1
Would you like to go first or second or random? (1/2/3) 3
Don't tell it I said so, but the computer isn't very good.
You go first!
| | 1|2|3
-+-+- -+-+-
| | 4|5|6
-+-+- -+-+-
| | 7|8|9
P2 Please enter your move: 1
Computer's move: 5
x| | 1|2|3
-+-+- -+-+-
|o| 4|5|6
-+-+- -+-+-
| | 7|8|9
P2 Please enter your move: 9
Computer's move: 7
x| | 1|2|3
-+-+- -+-+-
|o| 4|5|6
-+-+- -+-+-
o| |x 7|8|9
P2 Please enter your move: 3
Computer's move: 8
x| |x 1|2|3
-+-+- -+-+-
|o| 4|5|6
-+-+- -+-+-
o|o|x 7|8|9
P2 Please enter your move: 2
P1 wins!
x|x|x 1|2|3
-+-+- -+-+-
|o| 4|5|6
-+-+- -+-+-
o|o|x 7|8|9
P1 wins!
>>>


The things I do to avoid getting bored in math class :smallamused:

edit: if I'm not following typical conventions in python, its because i was introduced to the language over the course of about 3 hours by a software engineer and had no formal instruction in programming other that that until I started an intro to c++ class 4 weeks ago.

Razanir
2014-02-18, 03:25 PM
I'm taking a class on Unix and wanted practice scripting. So for fun, I decided to make a shell script to calculate the date of Easter.


#!/bin/bash

Y=$1
G=$(expr \( $Y % 19 \) + 1)
C=$(expr \( $Y / 100 \) + 1)
X=$(expr \( 3 \* $C / 4 \) - 12)
Z=$(expr \( \( 8 \* $C + 5 \) / 25 \) - 5)
D=$(expr \( 5 \* $Y / 4 \) - $X - 10)
E=$(expr \( 11 \* $G + 20 + $Z - $X \) % 30)

if [ $E -eq 25 ] ; then
if [ $G -gt 11 ] ; then
E=26
fi
elif [ $E -eq 24 ] ; then
E=25
fi

N=$(expr 44 - $E)

if [ $N -lt 21 ] ; then
N=$(expr $N + 30)
fi

N=$(expr $N + 7 - \( \( $D + $N \) % 7 \) )

if [ $N -gt 31 ] ; then
echo "Easter" $Y "is on" $(expr $N - 31) "April."
else
echo "Easter" $Y "is on" $N "March."
fi

Balain
2014-02-18, 05:19 PM
EDIT: Okay never mind I figured it out...silly me, have to remember to use {}

Does anyone know LaTex well. I have to type my proof up for Cpsc413 an algorithms course in latex.

I typed
A = $n_c^0$

I was hoping this would give n with a subscript of (c with a superscript of 0)

Instead I get n with a superscript 0 and subscript c

So what should I use to get n subscript (c with superscript 0)

IthilanorStPete
2014-02-18, 09:38 PM
EDIT: Okay never mind I figured it out...silly me, have to remember to use {}

Does anyone know LaTex well. I have to type my proof up for Cpsc413 an algorithms course in latex.

I typed
A = $n_c^0$

I was hoping this would give n with a subscript of (c with a superscript of 0)

Instead I get n with a superscript 0 and subscript c

So what should I use to get n subscript (c with superscript 0)

In case you haven't got it working yet: you want $A = n_{c^{0}}$.

For the future, a good reference for LaTeX is the Wikibook on it (http://en.wikibooks.org/wiki/LaTeX). There's also a handy cheat sheet here (http://www.stdout.org/~winston/latex/).

Miklus
2014-02-19, 05:15 AM
If the app stops using 100% CPU then the system will recover just fine. Question does occur to me: how many threads does your app have, and how many processor cores are available on the machine it's running on?

There is only one core, this is the smallest version of the hardware platform. How many threads does it have...Hmmm...GUI, Analysis, Editor, IO, Network...

Come to think of it, there is some serial communication with some external components. This is also the "new" thing with this set up, that is, the external components are of a new type. This could very well be some network communication hiccup caused by the new components. Not that tere is any need to communicate with these components once the machine is up and running, but you never know.

Anyway, we are all doing something else right now, but mark my words: The first time a customer sees a 13,7 min lag, he's going to send the machine back with a post-it saying WTF on it. We sould never have shipped this if you ask me, but you know deadlines.

factotum
2014-02-19, 07:26 AM
Well, if it's a single core machine that makes it all the more likely a misbehaving thread could lock up the system--at least on a dual core system the keyboard and mouse input threads could run on the other core while the rogue thread burns CPU cycles, making the system generally more responsive.

Ashtar
2014-02-19, 09:56 AM
There is only one core, this is the smallest version of the hardware platform. How many threads does it have...Hmmm...GUI, Analysis, Editor, IO, Network...

Come to think of it, there is some serial communication with some external components. This is also the "new" thing with this set up, that is, the external components are of a new type. This could very well be some network communication hiccup caused by the new components. Not that tere is any need to communicate with these components once the machine is up and running, but you never know.

Anyway, we are all doing something else right now, but mark my words: The first time a customer sees a 13,7 min lag, he's going to send the machine back with a post-it saying WTF on it. We sould never have shipped this if you ask me, but you know deadlines.

I recommend you get a copy of the Windows Internals (4th edition or whatever is the latest) to have a look at the explanations of the scheduler (p 325 and later).
Edit: Microsoft has chapter 5 - Threads, available for free on their website. http://download.microsoft.com/download/1/4/0/14045A9E-C978-47D1-954B-92B9FD877995/97807356648739_SampleChapters.pdf
http://technet.microsoft.com/en-us/sysinternals/bb963901.aspx

http://technet.microsoft.com/library/Cc958314
What I would recommend is running in Thread Priority 24 (RealTime / Normal) because there are processes which must run from time to time. The application in RealTime will get allocated most of the CPU anyway. If you have really no time to give up on that task, then you should have a dual core system, with one CPU allocated only to it.

Running anything at Priority 31 for a long time might lock the system up since some processes have to run and are never allowed to reach that level.


Real-Time Priorities
You can raise or lower thread priorities within the dynamic range in any application; however, you
must have the increase scheduling priority privilege to enter the real-time range. Be aware that many
important Windows kernel-mode system threads run in the real-time priority range, so if threads
spend excessive time running in this range, they might block critical system functions (such as in the
memory manager, cache manager, or other device drivers).

Also a possible explanation for the lockups in there:

Once per second, this thread scans the ready queues for any threads that have been in the ready
state (that is, havenít run) for approximately 4 seconds. If it finds such a thread, the balance-set
manager boosts the threadís priority to 15 and sets the quantum target to an equivalent CPU clock
cycle count of 3 quantum units. Once the quantum expires, the threadís priority decays immediately
to its original base priority. If the thread wasnít finished and a higher priority thread is ready to run,
the decayed thread returns to the ready queue, where it again becomes eligible for another boost if it
remains there for another 4 seconds.
The balance-set manager doesnít actually scan all of the ready threads every time it runs. To
minimize the CPU time it uses, it scans only 16 ready threads; if there are more threads at that priority
level, it remembers where it left off and picks up again on the next pass. Also, it will boost only 10
threads per passóif it finds 10 threads meriting this particular boost (which indicates an unusually
busy system), it stops the scan at that point and picks up again on the next pass.

The assigned quantum is not long enough for the starved system thread to finish, thereby continuing to lock up the system.

Could you simply run the program at 15 Priority?

Razanir
2014-02-20, 05:30 PM
I just used ^ and |= in a Java program for homework in a discrete math class. I don't think I've ever used them before.

HalfTangible
2014-02-28, 04:06 PM
So I'm in a game engines course, and trying to make an RTS in UDK for our final project . The only info I can find on making an RTS in udk, however, is how to make one for a mobile device. I have no idea what to change or alter so that it works on a PC. Or even where to begin with this code. Too late to change to a platformer or anything simpler.

...Halp? ._.

Grinner
2014-02-28, 05:03 PM
If you're having a problem with the RTS Starter Kit, take note of this line from the kit's page:


Platform abstraction - The RTS Starter Kit is able to distinguish which platform the player is playing on. Depending on which platform the player is using, different player controllers and HUD classes are used. However, the PC and Console platform classes have only been stubbed out. Currently, only the mobile platform is fully supported.

I'd start by expanding the PC class to add keyboard and mouse support for the controls. Something like this. (http://udn.epicgames.com/Three/DevelopmentKitGemsCreatingAMouseInterface.html) Apart from that, the rest of the code should probably work as is. Probably. You may also wish to modify the HUD, though.

If you need an example to work off, there is an open-source, PC-only RTS made in UDK. It's called Hostile Worlds (http://www.hostile-worlds.com/). You can find the source code at Github (http://www.github.com/npruehs/Hostile-Worlds).

Seerow
2014-02-28, 05:36 PM
So, I'm taking CS2 as an elective (not sure why all of the IT students think I'm crazy for this. It's weird I always thought IT was the place for CS students who didn't want quite so much math, not the place for CS students who don't like programming), and had a fun experience earlier this week. Go in to class on Tuesday, and I'm discussing the previous test with someone next to me. They ask me if I've finished the current programming assignment yet, I'm like "Nah, it's not due til Sunday, I figure I'll work on it over the weekend".

Well I'm sure you can all guess where this is going. His response was "Dude, that assignment's due tonight at midnight". Of course I still have a full day of classes plus an hour+ drive home before I can work on it, so I can't get started until around 7:00pm. The assignment? Create a class in Java to take in a graph of nodes. Then develop two methods to topologically sort the graph. The first method using the DFS algorithm, the second using the Decrease-by-One algorithm.

Got it done with 30 minutes to spare. It was awesome.

HalfTangible
2014-02-28, 05:40 PM
If you're having a problem with the RTS Starter Kit, take note of this line from the kit's page:

That's why I'm asking :smalltongue:


I'd start by expanding the PC class to add keyboard and mouse support for the controls. Something like this. (http://udn.epicgames.com/Three/DevelopmentKitGemsCreatingAMouseInterface.html) Apart from that, the rest of the code should probably work as is. Probably. You may also wish to modify the HUD, though.

If you need an example to work off, there is an open-source, PC-only RTS made in UDK. It's called Hostile Worlds (http://www.hostile-worlds.com/). You can find the source code at Github (http://www.github.com/npruehs/Hostile-Worlds).

Found the hostile world sourcecode, actually, and it looks pretty good. I'm not really sure how to put it into my UDK, though, and the README has proven thoroughly unhelpful.

TSGames
2014-02-28, 10:30 PM
I played around with Markov chains today. I downloaded the latest Random Banter thread and added in the complete work known as "Hamlet". The resulting markov chains were pretty good. Check it out (http://www.topsecretgames.net/blog/?p=249).

IthilanorStPete
2014-02-28, 10:51 PM
I played around with Markov chains today. I downloaded the latest Random Banter thread and added in the complete work known as "Hamlet". The resulting markov chains were pretty good. Check it out (http://www.topsecretgames.net/blog/?p=249).

Nice. :smallbiggrin: Have you seen King James Programming (http://kingjamesprogramming.tumblr.com/)

TSGames
2014-03-01, 08:46 AM
Nice. :smallbiggrin: Have you seen King James Programming (http://kingjamesprogramming.tumblr.com/)

Actually, that is exactly what inspired this project!

I think I'll be improving the Markov chain algorithm I'm using a bit, and I may try to add in scripts from Ninja Turtles. Anybody got any other good 'accents' that would be fun to add to the Playground?

Razanir
2014-03-01, 04:20 PM
They ask me if I've finished the current programming assignment yet, I'm like "Nah, it's not due til Sunday, I figure I'll work on it over the weekend".

Oh, please. At least you won't be programming on an empty stomach. One time I was debugging a program a couple hours before it was due. (For whatever reason, my IDE made the ANT file incorrectly, and the class files from an external jar weren't being packaged) Except I was fasting that day for religious reasons, and used that as an excuse to completely skip breakfast.

HalfTangible
2014-03-01, 06:45 PM
... Sorry to ask again, but I've bit off a bit more than I can chew with this one.

Where exactly in UDK do I GO to put in a mouse interface? Engine? UDKGame? UDKRTS, since that's what I'm making? ... lost here...

Grinner
2014-03-01, 07:50 PM
... Sorry to ask again, but I've bit off a bit more than I can chew with this one.

Where exactly in UDK do I GO to put in a mouse interface? Engine? UDKGame? UDKRTS, since that's what I'm making? ... lost here...

I've only ever thought about using UDK, so this is a shot in the dark.

The RTS Starter Kit's page mentions that it automatically detects the platform, implying that it then runs the code contained within the relevant class. The idea behind this is that it forms a layer of abstraction, allowing the game's code to remain maintainable. That means the core game logic remains the same for all platforms, and only the control method changes.

I'd start by looking at the mobile device class and writing down what variables and functions it references (i.e. how it knows what units to select). With that, you'll know what you need to be working with.

After doing that, start adapting the mobile device code to the PC class, replacing the touchscreen code with mouse/keyboard code.

Balain
2014-03-02, 08:43 PM
I need some haskell help. I am not sure what I am missing. I have the data type and declared trees:



data GTree a = Leaf a | Gnode [GTree a]
t1 :: Gtree Int
t1 = Leaf 4

t2:: GTree Int
t2 = Gnode [Leaf 3]

t3 :: GTree Int
t3 = Gnode [Leaf 1, Gnode[Leaf 2, Leaf3]]


Then I tried to create a function to count the leaves:



countLeaf :: GTree a -> Int
countLeaf (Leaf a) = 1 -- If tree is leaf = 1
countLeaf (Gnode []) = 0 -- found an empty [] = 0
countLeaf (Gnode h:t) = countLeaf (h) + countLeaf (t) -- h is head of list, t is tail of list


I don't get the errors I am getting, since a GTree can be a Gnode of a list of Gtrees.

So Gnode h:t should match a list pattern, What am I missing?


Errors:

a2.hs:41:12:
Couldn't match expected type `GTree a'
with actual type `[GTree t0]'
In the pattern: Gnode h : t
In an equation for `countLeaf':
countLeaf (Gnode h : t) = countLeaf h + countLeaf t

a2.hs:41:35:
Couldn't match expected type `GTree a0'
with actual type `[GTree t0]'
In the first argument of `countLeaf', namely `h'
In the first argument of `(+)', namely `countLeaf h'
In the expression: countLeaf h + countLeaf t

a2.hs:41:49:
Couldn't match expected type `GTree a1'
with actual type `[GTree t0]'
In the first argument of `countLeaf', namely `t'
In the second argument of `(+)', namely `countLeaf t'
In the expression: countLeaf h + countLeaf t

Castaras
2014-03-05, 07:09 AM
Hi guys, I'm learning Prolog as part of my university course. However, the notes that I have are pretty awful for learning Prolog from, and I'm very confused by a large amount of it. What resources online would you recommend for examples and documentation? I seem to find loads of stuff for how to setup different prolog packages from the terminal and how to compile, but very little on defining logical variables for predicate queries. Specifically, using arithmetic logic within a query (e.g. querying a set of data on all the data that has a code between two integers).

Razanir
2014-03-08, 11:15 AM
I actually found a use for shift ops in Java. I'm working with BigIntegers, so my hunch is that they're faster.

TSGames
2014-03-08, 11:52 AM
I actually found a use for shift ops in Java. I'm working with BigIntegers, so my hunch is that they're faster.

Speaking of speeding things up. I've been working on that map gen project that I mentioned earlier (in Python) and I switched from using lists to dictionaries for tiles and OhMAIGOSHSSOMUCHFASTER!!! Using Kivy I can now render 10x the number of tiles with no lag. I figure after improving my algorithms a bit, I can probably get at least another factor of 5 performance increase.

I had no idea a map generator could be such a fun problem! :smallbiggrin:

Reinboom
2014-03-10, 11:46 AM
I actually found a use for shift ops in Java. I'm working with BigIntegers, so my hunch is that they're faster.

What a dangerous thing to hear.
Hunches are bad. Profile!

Tyndmyr
2014-03-10, 05:16 PM
So, I actually have a question for ya'll...I am, purely for my own entertainment, screwing around with graphics engines and the like, and I find myself curious...what's actually a decent mmo middleware package that's accessible to people who are just messing about? Red Dwarf seems to have been interesting, but mostly dead at this point...there's a number of options out there, but the whole field is fairly obscure, and filled with dead ends, and it'd be nice to get tips rather than mucking about with trying all the options myself.

Grinner
2014-03-10, 06:05 PM
*snip*

Are you looking for 2D or 3D?

For 2D, I've had some success with Eclipse (http://www.freemmorpgmaker.com/) in the past, but the results were wholly unimpressive.

For 3D, I've only tried Multiverse, but the software relies on outdated versions of MySQL and Java. It turned out a mess.

Other 3D MMO projects I've heard of but have never tried include Planeshift and Ryzom. Planeshift has a strong community behind it, and Ryzom includes a massive number of assets. I've never actually looked at the source code either, so I don't know how easily they'll compile.

Tyndmyr
2014-03-10, 11:17 PM
Are you looking for 2D or 3D?

For 2D, I've had some success with Eclipse (http://www.freemmorpgmaker.com/) in the past, but the results were wholly unimpressive.

For 3D, I've only tried Multiverse, but the software relies on outdated versions of MySQL and Java. It turned out a mess.

Other 3D MMO projects I've heard of but have never tried include Planeshift and Ryzom. Planeshift has a strong community behind it, and Ryzom includes a massive number of assets. I've never actually looked at the source code either, so I don't know how easily they'll compile.

3D in particular, though I'd imagine that some elements will be similar. I looked into Multiverse briefly before realizing that it too looked kind of unsupported, good to hear that this impression was accurate.

A strong community and a big asset pile is worth quite a lot, I'll definitely investigate them further, thanks!

JeenLeen
2014-03-12, 02:05 PM
I have some SQL code that works, but it runs very slowly. I'm using MS Access. Could one of you look at it and give me some pointers to increase its efficiency?


SELECT Stats.ItemID, Stats.Subject, Stats.TestAdmin, Stats.ItemFunction, Stats.EmbeddedField
FROM ItemStatistics AS Stats
WHERE Stats.ItemID NOT IN
(SELECT Scr.UIN
FROM ItemStatus AS Scr)
ORDER BY Stats.Subject, Stats.ItemID, Stats.TestAdmin;


ItemStatistics has about 10000 records and ItemStatus about 15000. ItemID and UIN are the 'same' value; UIN is the primary key of ItemStatus, but an ItemID may appear multiple times in ItemStatistics (but ItemID is indexed).

The point of the query is to determine if any items in the ItemStatistics table are not also in the ItemStatus table (that is, there is not a UIN to match to an ItemID). If any ItemIDs do not have a corresponding UIN, I want the query to display information about the ItemID(s).

I feel like using a JOIN of some sort could speed it up, but I'm not sure how, since what I want is more like the inverse of a JOIN.


---

And while I'm posting there, could anyone tell me a good way, or give me a link to a good tutorial, of how to download a trial version of SQL Server and actually run it? I've downloaded trial versions before (and I think downloaded all the parts it needed), but could never get it to run on my computer. Not that I got an error message; I think I never figured out how to open it, like what to click on to activate it. I think I'm thinking of opening it like one opens Access, but it's more complicated than that.

factotum
2014-03-13, 02:36 AM
Not particularly familiar with Access, but this is how I'd do that in SQL server:

SELECT Stats.ItemID, Stats.Subject, Stats.TestAdmin, Stats.ItemFunction, Stats.EmbeddedField, Scr.UIN
FROM ItemStatistics AS Stats
LEFT OUTER JOIN ItemStatus AS Scr
ON Stats.ItemID = Scr.UIN
WHERE Scr.UIN IS NULL
ORDER BY Stats.Subject, Stats.ItemID, Stats.TestAdmin;

It's doing a left join, so *all* the rows from ItemStatistics are included along with those rows that match up from ItemStatus; any rows in ItemStatistics that do not have a corresponding entry in ItemStatus will populate the ItemStatus columns for those rows with NULL, hence the check for a column in that table being NULL.

As for your other question, SQL server is not an application like Access, it's a service that runs on your system. Once it's installed you need to use SQL Server Management Studio to connect to the service and do stuff like setting up databases.

JeenLeen
2014-03-13, 07:46 AM
Not particularly familiar with Access, but this is how I'd do that in SQL server:

SELECT Stats.ItemID, Stats.Subject, Stats.TestAdmin, Stats.ItemFunction, Stats.EmbeddedField, Scr.UIN
FROM ItemStatistics AS Stats
LEFT OUTER JOIN ItemStatus AS Scr
ON Stats.ItemID = Scr.UIN
WHERE Scr.UIN IS NULL
ORDER BY Stats.Subject, Stats.ItemID, Stats.TestAdmin;

It's doing a left join, so *all* the rows from ItemStatistics are included along with those rows that match up from ItemStatus; any rows in ItemStatistics that do not have a corresponding entry in ItemStatus will populate the ItemStatus columns for those rows with NULL, hence the check for a column in that table being NULL.

As for your other question, SQL server is not an application like Access, it's a service that runs on your system. Once it's installed you need to use SQL Server Management Studio to connect to the service and do stuff like setting up databases.

Thank you. That worked, & profoundly more quickly. I think I understand why it was faster, too: as you have it, it's a simple pull from the tables, then it excludes non-Null UINs; with mine, it was checking each ItemID against every UIN, so something like 10k x 15k comparisons.

That makes sense for SQL Server. I'll try downloading a trial version again soon.

factotum
2014-03-13, 08:07 AM
It's just occurred to me that you don't need to include Scr.UIN in the SELECT list...won't make much difference in terms of performance not having it there, but it will mean you won't get a spare NULL appended to every row.

Capt Spanner
2014-03-13, 11:05 AM
Here's a topical one for you guys.

I made a slightly crazy dice roller.

I'm pretty sure it can handle any dice roll you care to dream up. If it can't, let me know.

I've posted it here: http://www.giantitp.com/forums/showthread.php?p=17171563

I challenge you all to break it!

Teddy
2014-03-15, 03:51 AM
A little earlier this week, I created a custom smilie set based on the forum smilies. However, I felt I couldn't just keep them in a file for me to copy the code into my document whenever I wanted one, because that would be terribly tedious, and terribly time-consuming, since I like using smilies quite a lot... http://i.imgur.com/ZRHtTJs.png

Now, I'm the type of person who thinks that if something's worth doing, it's worth overdoing, so I just went ahead and learned how to program my very first Firefox extension, which detects the smilie hotbar whenever I write something on these forums and replaces its content with my custom smilies, as well as make them paste the code into my post instead of the usual :smallsmiliename:. http://i.imgur.com/haudcUB.png

The result looks like this:
[IMG]http://i159.photobucket.com/albums/t160/AirMarshalTeddy/Assorted%20Computer%20Stuff/NallesmiliesinAction_zps11bd406e.png~original

All the teddybears paste their own code into my posts, but the :smallcool: paste 1d6 instead, because I've always wanted a quicker way of rolling a die... http://i.imgur.com/jLvmsd9.png

The smilie menu and windows are kept the same, so I can still use the standard smilies whenever I want to... http://i.imgur.com/jLvmsd9.png


Now, there was some popular demand on me telling how to create such an extension for your own, so I'm providing a slightly modified version of the code below. The spoiler tree corresponds to the folder/file structure, with the name of the folders and files in the spoiler header. All files are renamed .txt files, so all can be recreated by pasting the code into Notepad (or any other plain text editor of your choice) and saving them as the filenames in the spoiler headers. The content of each file is included in the first
block in each file spoiler. Grey text doesn't exist, and any following
blocks are for explaining possible code modifications.

Disclaimer: Since this was my first time making an Firefox extension, and my second time programming in JavaScript (I'm an experienced programmer, though), I know practically nothing about security. There are apparently issues where script priority can escalate if you modify the HTML of pages without using the proper functions, but I don't know which those functions are or how to use them, so I can't guarantee that my code is safe in that regard. I can't see how the code would cause such and escalation, since it only modifies non-script content, and the only pages it should modify to start with are all on these forums, but I don't know. So before you recreate this script on your own, I want you to consider the risks and free myself of any liability if anything would go wrong. Thanks. http://i.imgur.com/jLvmsd9.png

Also, this extension builds closely upon my own extension, but I haven't tested the modifications. It should work just fine, because I haven't changed the logic, but there is always the chance of small errors which may make it crash (in which case you won't see any behaviour at all, as Firefox has a pretty good error handler for its extensions).

Also also, this extension will only work with Firefox, just saying... http://i.imgur.com/ZRHtTJs.png

This file holds the meta-information about the extension. Name, description, version and creator all appear in the Extensions tab. Unless you're making any drastic changes to the code, I suggest you just leave this alone. If you want to localise the description to your own language, copy the content within the <localized> tags (starting with <Description>) and paste it just before </localized>. Then you can change the content of the three tags within <Description> to localise it to the language you like.

The version number of 1.2 is because this builds upon my own extension (even though it has another name and id), which is of version 1.1.

And also, unless you do any dramatical changes to the code, I would ask of you to let me stand as the creator. If you tweak it to your liking and want to give yourself some recognition for it, you can add an <em:developer> tag after the <em:creator> tag.

[CODE]<?xml version="1.0"?>

<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">

<Description about="urn:mozilla:install-manifest">
<em:id>{d484875e-6669-3042-b033-227c35769edc}</em:id>
<em:name>Teddy's Smilie Customiser</em:name>
<em:description>A smilie customisation tool for the Giant in the Playground forum.</em:description>
<em:version>1.2</em:version>
<em:creator>Teddy</em:creator>
<em:type>2</em:type>

<!-- Mozilla Firefox -->
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>4.0</em:minVersion>
<em:maxVersion>30.*</em:maxVersion>
</Description>
</em:targetApplication>

<em:localized>
<Description>
<em:locale>sv-SV</em:locale>
<em:name>Teddys personliga smilies</em:name>
<em:description>Ett verktyg f46;r att skr28;ddarsy smilies f46;r Giant in the Playground-forumet.</em:description>
</Description>
</em:localized>
</Description>

</RDF>

This file tells the extension where all files are to be located. If you localise your extension, you may want to add another locale line, but I don't think that's necessary...


content smiliecustomiser content/
skin smiliecustomiser classic/1.0 skin/
locale smiliecustomiser en-US locale/en-US/
locale smiliecustomiser sv-SV locale/sv-SV/

overlay chrome://browser/content/browser.xul chrome://smiliecustomiser/content/browserOverlay.xul


This file is basically the skeleton of an extension on which we grow all the muscle. It also handles the look of the extension, much like HTML, but since this extension is intentionally kept as discreet as possible, there's only a reference to our JavaScript script and an initialisation of our string bundle with the replacement smilies within it.

[CODE]<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin/" ?>
<?xml-stylesheet type="text/css"
href="chrome://smiliecustomiser/skin/browserOverlay.css" ?>

<overlay id="smiliecustomiser-browser-overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<script type="application/x-javascript"
src="chrome://smiliecustomiser/content/browserOverlay.js" />

<stringbundleset id="stringbundleset">
<stringbundle id="smiliecustomiser-string-bundle"
src="chrome://smiliecustomiser/content/browserOverlay.properties" />
</stringbundleset>

</overlay>

This file contains the bundle of all your replacement smilies. In order to replace the smilies, just paste the link to your replacement image after the equals sign on the line with the name of the smilie you want to replace. Note, whitespace characters [I]do count, so don't add any spaces unless they're supposed to be there.

If you want to make your smilie button do something else than just insert a image, you can add a second row ending with something else than "img" before the equals sign (I used "content" for my :smallcool: replacement), and I'll explain below how to change the script into acting accordingly.


smiliecustomiser.smallamused.img=
smiliecustomiser.smallannoyed.img=
smiliecustomiser.smallbiggrin.img=
smiliecustomiser.smallconfused.img=
smiliecustomiser.smallcool.img=
smiliecustomiser.smalleek.img=
smiliecustomiser.smallfrown.img=
smiliecustomiser.smallfurious.img=
smiliecustomiser.smallmad.img=
smiliecustomiser.smallredface.img=
smiliecustomiser.smallsigh.img=
smiliecustomiser.smallsmile.img=
smiliecustomiser.smalltongue.img=
smiliecustomiser.smallwink.img=
smiliecustomiser.smallyuk.img=

This is the muscle of the extension which intercepts all pages upon loading, checks them for the correct URL, and passes the incorrect ones along. For any page containing a smilie hotbar, it changes the HTML code into displaying your new smilies. Since it always runs as soon as you load a page, it will affect performance, but I should quit it soon enough whenever you're loading a page which it won't do anything to that it won't be noticable. I don't think it'd be noticable even if I let it run at full, but you should pay some consideration to performance anyway...

I won't go over how the code itself works, it's fairly readable to anyone who knows programming, and for anyone else, it may be a bit hard to explain comprehensibly. In short, however, it localises the smilie hotbar, loops through the 15 buttons and replaces eachone with the new smilie provided in the browserOverlay.properties file. The smilie buttons themselves work as images who paste their "alt" attribute upon clicking. This is important to know if you want to modify their behaviour.


/**
* SmilieCustomiser namespace.
*/
if ("undefined" == typeof(SmilieCustomiser)) {
var SmilieCustomiser = {};
};

/**
* Controls the browser overlay for the Teddy's Smilie Customiser extension.
*/
SmilieCustomiser.BrowserOverlay = {

/**
* Replaces the standard smilies on the smilie hotbar
* with their custom counterparts.
*/
customise : function(event) {

let doc = event.target;

/*
* This check should be robust enough to only pass the GiantitP forums.
*/
if(!(/^[^\/]*\.giantitp\.com\/forums/.test(doc.URL))) {
return;
}

let smilieHotbar = doc.getElementById("vB_Editor_001_smiliebox");

if(smilieHotbar == null) {
return;
}

let stringBundle = document.getElementById("smiliecustomiser-string-bundle");

let smilieTable = smilieHotbar.lastElementChild.lastElementChild;
let smilieRows = smilieTable.children;

for(let i = 0; i < smilieRows.length - 1; i++) {
let smilieCols = smilieRows[i].children;
for(let j = 0; j < smilieCols.length; j++) {
let img = smilieCols[j].firstElementChild;
let type = /:(\w+):/.exec(img.alt);

/*
* The following rows replaces the smilies for other images
* and make them paste the corresponding [IMG] code into the post.
* If you want them to paste something else, you must change the img.alt
* line.
*/
let newSmilie = stringBundle.getString("smiliecustomiser." + type[1] + ".img");
img.alt = "[IMG]" + newSmilie + "";
img.src = newSmilie;

}

}

}

};

window.addEventListener(
"DOMContentLoaded", SmilieCustomiser.BrowserOverlay.customise, false);

If you want to keep some smilies, or change the behaviour of some smilies into something else, you'll have to wrap the three last lines before the four curly parentheses into an if case where you decide which smilies will show which behaviour. One easy way of doing the test is through a regular expression:

if(/(?:smilie1)|(?:smilie2)|(?:smilie3)/.test(type[1]) {
behaviour1;
} else if(/(?:smilie4)|(?:smilie5)|(?:smilie6)/.test(type[1]) {
behaviour2;
} else {
defaultBehaviour;
}
Where smilieX are the smilies you wish to alter, and behaviourY is the code for how to alter them. You can add any number of smilies into the same if case for as long as you wrap and separate them as above (if you only want to test for just one smilie, the (?: ) wrapping isn't necessary). If the default behaviour is to not alter a smilie, you can exclude the last else case entirely.

If you want a smilie to not change its image, you'll just have to delete the row starting with img.src for that smilie. If you want it to paste anything else than its image, you'll have to change the value img.alt is set to for it. You can use the browserOverlay.properties file to store any alternative content, using this line to access it:

newContent = stringBundle.getString("smiliecustomiser." + type[1] + ".content")
(Assuming you've created a .content attribute for that smilie.)

Note that you must add the corresponding line to the browserOverlay.properties file for every stringBundle string you wish to retrieve.

I'm pretty sure these two folders aren't needed, but I'll keep them here for clarity's sake.

(empty)

(empty)

I'm not entirely sure if this file has to be here, but I won't delete it in case it actually has to. We'll just leave it empty for now.


(empty)

When you're finished with your extension, select the content of the smiliecustomiser folder (not the folder itself) and send it to an .zip archive. Then, rename that archive "smiliecustomiser.xpi" (note that the filename extension must be changed as well. Sadly, I can only describe the process of showing filename extensions (so they can be edited) in Swedish, but Google is your friend in this regard ("windows show file extensions")). Finally, drag the .xpi file from your file browser into an open Firefox window and it'll install automatically. Just restart the browser and it'll be running for you. http://i.imgur.com/jLvmsd9.png

EDIT:
Broken for now, will be fixed...

Razanir
2014-03-15, 02:43 PM
In other programming news, Java 8 gets officially released in 3 days.

Grinner
2014-03-16, 03:51 PM
@Teddy: You, sir, are deserving of an Internet.

Really cool stuff. :smallsmile:

Teddy
2014-03-17, 03:02 AM
@Teddy: You, sir, are deserving of an Internet.

Really cool stuff. :smallsmile:

Heh, thanks! http://i.imgur.com/gh2zaGF.png

I love to use programming in this way. I always like to program, but I especially like it when the programming itself isn't the end I'm striving for, but I rather have another problem I want to solve, and realise that programming will be my means to reach that end. It just makes your progress so clear, and your accomplishment greater... http://i.imgur.com/jLvmsd9.png

Drumbum42
2014-03-17, 09:17 AM
In other programming news, Java 8 gets officially released in 3 days.

Oh wow, how did that get past me? I hope we can all now kill Java 6(and make it NOT the default on Macs). Time to start digging into change notes!

Razanir
2014-03-17, 10:06 AM
Oh wow, how did that get past me? I hope we can all now kill Java 6(and make it NOT the default on Macs). Time to start digging into change notes!

The main feature to look for is lambda expressions, which I'll probably use similarly to function pointers in C.

matt123miller
2014-03-17, 02:31 PM
Hello Playground! Just the sort of thread I was looking for. So I'm currently making a game and cannot get this prototype code to work. We've been told to use Javascript and this is using Unity3D. I'm trying to create a loop that makes GUI buttons on the screen equal to an int value. The first button starts at the bottom of the screen and subsequent buttons are created going up the screen. However with the code below, nothing happens on my screen. I've tried many variations of this now and it looks like it will work TO ME but I'm only a first year uni student. Any suggestions?

#pragma strict
var buttonNo : int;
var hello : AudioClip;
private var originY : int;

function Start(){
originY = Screen.height/15;
}

function OnGUI(){
for(var i = 1; i<=buttonNo; i++){
originY += 100;
if(GUI.Button(Rect(30, originY, 50, 50),"words")){
audio.clip = hello;
audio.Play();
print("log");
}
}
}

Emmerask
2014-03-18, 02:06 PM
buttonNo never seems to get a value in your code snippet
which means the loop is never executed, hence why nothing happens on your screen ^^

I assume the if(GUI.button...) stuff is unitys way of creating buttons and that its correct and that onGUI() is called somewhere either by unity or you ;).

/edit easy way to test if I am correct with my assumption is to test it with:



#pragma strict
var buttonNo : int; // <--- no value assigned?
var hello : AudioClip;
private var originY : int;

function Start(){
originY = Screen.height/15;
buttonNo = 2; // buttonNo now has a value!
}

function OnGUI(){
//this should create two buttons on the screen
for(var i = 1; i<= buttonNo; i++){
originY += 100;
if(GUI.Button(Rect(30, originY, 50, 50),"words")){
audio.clip = hello;
audio.Play();
print("log");
}
}
}


I do not know much about unity but what you are actually doing is create a button at ScreenHeight/15 +100 and go down the screen arent you?
(coordinate 0/0 usually is the top left point on the screen/window).
unless unity uses an inverted y axis?

which would mean the buttons y startcoordinate would be (assuming 1920*1080):
1) 172
2) 272
etc

matt123miller
2014-03-18, 05:56 PM
Unity generally uses onGUI() to create any GUI assets on the screen. Also because the variable buttonNo is not private ie. public, it is available to change at any point in the Unity program instead of having to go into the code.

I just wanted to create some code that I could reuse and call in a dialogue system I'm using that allows you to dynamically create the amount of options at each stop of the conversation. Then the loop can make the correct amount of button for me. :smallfrown:

Lokiare
2014-03-20, 03:58 AM
I've worked through the Havok Anarchy (http://www.projectanarchy.com/) video tutorials and am making a modified version of the game. I'll probably release it for $0.99 on the Google play store, but I don't expect it to sell well.

However I'm having problems with moving wall objects that block the ball. I'm pretty new to lua and I don't know the inner workings of Anarchy. I'm going to have to dig through a bunch of documentation to find out what I'm doing wrong.

JeenLeen
2014-03-21, 08:20 AM
This isn't a coding issue, but it's related to computer software.

My company uses Cerberus for its SFTP site, and we've run into a problem with assigning users to different rights-access groups.
For example, we have a user named 'Jake' who needs access to folders A and B. Group A has rights to folder A, and group B has rights to folder B. Current members of Group A should not be able to see folder B, and vice-versa. In essence, is it possible to assign Jake to both Group A and Group B, so he has rights to both but the other users do not?

Using Google (http://www.cerberusftp.com/phpBB3/viewtopic.php?f=2&t=2692), I figured out this feature was not possible in version 5, but they were thinking of implementing it in version 6 or higher. Is anyone here familiar with this system or knows if this feature is allowed?

(I'm not the IT guy in charge of this project, so I'm not very familiar with how the system works, but I have pressure to get on them about it, so if I can find a solution or figure out if there's no solution while they are (quite legitimately) too occupied with other projects, it would save a lot of time all-around.)

pendell
2014-03-21, 10:48 AM
Hi guys, I'm learning Prolog as part of my university course. However, the notes that I have are pretty awful for learning Prolog from, and I'm very confused by a large amount of it. What resources online would you recommend for examples and documentation? I seem to find loads of stuff for how to setup different prolog packages from the terminal and how to compile, but very little on defining logical variables for predicate queries. Specifically, using arithmetic logic within a query (e.g. querying a set of data on all the data that has a code between two integers).

Hello, Castaras. Unfortunately, I can't really tell you anything google can't , as it's been ages since I looked at prolog. Still...

Starting point 1 (http://stackoverflow.com/questions/401635/good-beginners-material-on-prolog)

Online guide (http://kti.mff.cuni.cz/~bartak/prolog/contents.html)

Quick 'n dirty prolog tutorial (http://www.cs.utexas.edu/~cannata/cs345/Class%20Notes/12%20prolog_intro.pdf) .

I hope these are useful!

Respectfully,

Brian P.

Emmerask
2014-03-21, 01:22 PM
This isn't a coding issue, but it's related to computer software.

My company uses Cerberus for its SFTP site, and we've run into a problem with assigning users to different rights-access groups.
For example, we have a user named 'Jake' who needs access to folders A and B. Group A has rights to folder A, and group B has rights to folder B. Current members of Group A should not be able to see folder B, and vice-versa. In essence, is it possible to assign Jake to both Group A and Group B, so he has rights to both but the other users do not?

Using Google (http://www.cerberusftp.com/phpBB3/viewtopic.php?f=2&t=2692), I figured out this feature was not possible in version 5, but they were thinking of implementing it in version 6 or higher. Is anyone here familiar with this system or knows if this feature is allowed?

(I'm not the IT guy in charge of this project, so I'm not very familiar with how the system works, but I have pressure to get on them about it, so if I can find a solution or figure out if there's no solution while they are (quite legitimately) too occupied with other projects, it would save a lot of time all-around.)

Could you not just create a new Group called "Group AB" that has access rights to both folder A and B and assign jake to that?

Its not perfect but better then nothing :)

JeenLeen
2014-03-21, 01:40 PM
Could you not just create a new Group called "Group AB" that has access rights to both folder A and B and assign jake to that?

Its not perfect but better then nothing :)

I think that could work. However, in my situation, it's more that there's about 50 - 100 people, each with different access rights. (Well, not all of them have different access rights, but there's at least 4 folders, and each user might need access to one to all four of them, etc.) The team handling it isn't willing to create 100+ groups for individual group for 100+ people, which I can understand... especially since who has rights to what could potentially change annually.

I think it might be that the SFTP system we have just doesn't work for the purpose we (i.e., others in my office) want it for.

I did ask the Cerberus help desk, and they said there isn't a way to assign people to multiple groups... or said something close to that. I forwarded it and the jargon to the team handling the issue. Cerberus told me

You cannot currently map a user to multiple groups. With AD authentication, you can map AD groups to Cerberus groups and get the same benefits of multiple group mapping, but you can't assign a user as a member of more than one group with native accounts or LDAP authentication.

but IT told me that the work-around it hints at doesn't work for us.

TSGames
2014-03-31, 08:15 AM
Our own sub-forum! Yeah! :smallcool:

JeenLeen
2014-03-31, 10:23 AM
SQL coding thing. Not a question, but something I wanted to share.

As an exercise, I created a database to use for char-gen for Pathfinder.

Tables are

0_CharList = where character information is loaded. A form auto-loads with the database to let you view/edit/add new characters.

0_Classes = classes, with recording whether the BAB and saves are 'Good', 'Bad', or 'Med' (medium)

Attributes = ability scores 1-30, with bonuses and, as applicable, point-buy cost

BAB = BAB by level for good, bad, and med

count = just counts 1-20. Used for a query.

Race = races, with racial mods to each stat

Saves = saves by level for good and bad

WBL = starting gold by level


Queries are:
class_chart = makes a chart of each class, levels 1-20, with their saves and BAB

Display Char Stats = displays a 'character sheet' info. On the form that loads when the database opens (to let you enter new character info), there's a button to load this query into an easy-to-view form.

Code for class chart:


SELECT C2.ClassName, count.ID AS [Level],
SWITCH(C2.BAB = "Good", (SELECT BAB.Good FROM BAB WHERE BAB.Level = count.ID), C2.BAB = "Med", (SELECT BAB.Med FROM BAB WHERE BAB.Level = count.ID), C2.BAB = "Bad", (SELECT BAB.Bad FROM BAB WHERE BAB.Level = count.ID)) AS BAB,
SWITCH(C2.Fort = "Good", (SELECT Saves.Good FROM Saves WHERE Saves.Level = count.ID), C2.Fort = "Bad", (SELECT Saves.Bad FROM Saves WHERE Saves.Level = count.ID)) AS Fort,
SWITCH(C2.Refl = "Good", (SELECT Saves.Good FROM Saves WHERE Saves.Level = count.ID), C2.Refl = "Bad", (SELECT Saves.Bad FROM Saves WHERE Saves.Level = count.ID)) AS Refl,
SWITCH(C2.Will = "Good", (SELECT Saves.Good FROM Saves WHERE Saves.Level = count.ID), C2.Will = "Bad", (SELECT Saves.Bad FROM Saves WHERE Saves.Level = count.ID)) AS Will,
(count.ID * C2.Skills) AS TotalSkills, C2.HD AS HD
FROM 0_Classes AS C2, [count]
ORDER BY C2.ClassName, count.ID;


Code for Display Char Stats


SELECT C.Character_Name, C.Level, C.Race, C.ClassName AS Class,
(C.Str + (SELECT Race.StrMod FROM Race WHERE Race.RaceName = C.Race)) AS Str,
(C.Con + (SELECT Race.ConMod FROM Race WHERE Race.RaceName = C.Race)) AS Con,
(C.Dex + (SELECT Race.DexMod FROM Race WHERE Race.RaceName = C.Race)) AS Dex,
(C.Int + (SELECT Race.IntMod FROM Race WHERE Race.RaceName = C.Race)) AS [Int],
(C.Wis + (SELECT Race.WisMod FROM Race WHERE Race.RaceName = C.Race)) AS Wis,
(C.Cha + (SELECT Race.ChaMod FROM Race WHERE Race.RaceName = C.Race)) AS Cha,
(SELECT class_chart.BAB FROM class_chart WHERE (class_chart.Level= C.Level AND class_chart.ClassName = C.ClassName)) AS BAB,
(
(SELECT Attributes.Bonus FROM Attributes WHERE Attributes.Score = ((SELECT Race.ConMod FROM Race WHERE Race.RaceName = C.Race) + C.Con))
+
(SELECT class_chart.Fort FROM class_chart WHERE (class_chart.Level= C.Level AND class_chart.ClassName = C.ClassName))
) AS Fort,
(
(SELECT Attributes.Bonus FROM Attributes WHERE Attributes.Score = ((SELECT Race.DexMod FROM Race WHERE Race.RaceName = C.Race) + C.Dex))
+
(SELECT class_chart.Refl FROM class_chart WHERE (class_chart.Level= C.Level AND class_chart.ClassName = C.ClassName))
) AS Refl,
(
(SELECT Attributes.Bonus FROM Attributes WHERE Attributes.Score = ((SELECT Race.WisMod FROM Race WHERE Race.RaceName = C.Race) + C.Wis))
+
(SELECT class_chart.Will FROM class_chart WHERE (class_chart.Level= C.Level AND class_chart.ClassName = C.ClassName))
) AS Will,

IIF( (SELECT Attributes.Bonus
FROM Attributes
WHERE (C.Int + (SELECT Race.IntMod FROM Race WHERE Race.RaceName = C.Race) = Attributes.Score))
+
(SELECT class_chart.TotalSkills FROM class_chart WHERE (class_chart.Level = 1 AND class_chart.ClassName = C.ClassName )) >1
,
C.Level * ( (SELECT Attributes.Bonus
FROM Attributes
WHERE (C.Int + (SELECT Race.IntMod FROM Race WHERE Race.RaceName = C.Race) = Attributes.Score))
+
(SELECT class_chart.TotalSkills FROM class_chart WHERE (class_chart.Level = 1 AND class_chart.ClassName = C.ClassName ))), C.Level) AS [Skill Points],

(SELECT WBL.Gold FROM WBL WHERE WBL.Level = C.Level) AS [Starting Gold (WBL)],
(CStr(C.Level)&(SELECT class_chart.HD FROM class_chart WHERE (class_chart.Level= 1 AND class_chart.ClassName = C.ClassName))) AS HD,
IIF(C.Race = "Human" OR C.Race = "Half-Elf" OR C.Race = "Half-Orc",
2 + SWITCH(C.Level < 4, 0, C.Level >= 4 AND C.Level < 8, 1, C.Level >= 8 AND C.Level < 12, 2, C.Level >= 12 AND C.Level < 16, 3, C.Level >= 16 AND C.Level < 20, 4, C.Level = 20, 5),
SWITCH(C.Level < 4, 0, C.Level >= 4 AND C.Level < 8, 1, C.Level >= 8 AND C.Level < 12, 2, C.Level >= 12 AND C.Level < 16, 3, C.Level >= 16 AND C.Level < 20, 4, C.Level = 20, 5)) AS [Bonus Ability Score],

IIF(((SELECT Attributes.Points FROM Attributes WHERE Attributes.Score = C.Str) + (SELECT Attributes.Points FROM Attributes WHERE Attributes.Score = C.Dex) + (SELECT Attributes.Points FROM Attributes WHERE Attributes.Score = C.Con) +
(SELECT Attributes.Points FROM Attributes WHERE Attributes.Score = C.Int) + (SELECT Attributes.Points FROM Attributes WHERE Attributes.Score = C.Wis) + (SELECT Attributes.Points FROM Attributes WHERE Attributes.Score = C.Cha))
IS NULL, "error: invalid scores",
(SELECT Attributes.Points FROM Attributes WHERE Attributes.Score = C.Str) + (SELECT Attributes.Points FROM Attributes WHERE Attributes.Score = C.Dex) + (SELECT Attributes.Points FROM Attributes WHERE Attributes.Score = C.Con) +
(SELECT Attributes.Points FROM Attributes WHERE Attributes.Score = C.Int) + (SELECT Attributes.Points FROM Attributes WHERE Attributes.Score = C.Wis) + (SELECT Attributes.Points FROM Attributes WHERE Attributes.Score = C.Cha))
AS [Point-Buy]

FROM 0_CharList AS C;


It was challenging and a good mental exercise to figure out how to pull all those tables together. I tried at first to not use class_chart, but I couldn't get the code to work before creating that intermediary query. I'm somewhat at a lost to make any easy/user-friendly way to do multi-classing, though. It seems like it would require a field for each class one has a level in, which means recoding for each time a class is added to the Classes table. But I'm pretty happy with it as is.
Comments or critiques?

factotum
2014-03-31, 03:00 PM
It seems like it would require a field for each class one has a level in, which means recoding for each time a class is added to the Classes table. But I'm pretty happy with it as is.


What you're looking at there is a many-to-many relationship--you have multiple characters, each of whom may have multiple classes. The usual way to do that in SQL server is to have (at least) three tables: one for the characters, one for the class selections, and one that links the two together.

Simple example:

Character table:
ID 1, name Factotum
ID 2, name JeenLeen

Classes table:
ID 1, 10th level mage
ID 2, 12th level warrior
ID 3, 6th level rogue

Link table:
Character ID 1, class ID 1
Character ID 2, class ID 2
Character ID 1, class ID 3

The above would show that Factotum is a 10th level mage/6th level rogue while JeenLeen is a single-classed 12th level warrior. Obviously any real example would be a deal more complicated than this, but you get the gist of the idea.

Gralamin
2014-03-31, 11:16 PM
I've been working on an Android app for a bit in my spare time (a character management tool), and I'm finding my usual workflow is really against Android development.

Some of the main issues I'm having are:
1) Documentation is largely irrelevant without reading the actual source code included.
2) Most of the solutions to common issues are horribly out of date. Getting an image from the gallery on modern versions took me two days to figure out, since there is so much misleading / out of date information.
3) There are so many different things that need to be kept updated etc. related to each view and activity.

Anyone know of any good resources for Modern app development? I'm particularly interested in articles discussing architecting your code: Managing the number of different classes and anonymous classes is proving to be a pain, and I'm frequently finding the need to refactor as I learn new things are required?

Also, any development libraries people would suggest?

Razanir
2014-04-01, 08:11 AM
Simple example:

Character table:
ID 1, name Factotum
ID 2, name JeenLeen

Classes table:
ID 1, 10th level mage
ID 2, 12th level warrior
ID 3, 6th level rogue

Link table:
Character ID 1, class ID 1
Character ID 2, class ID 2
Character ID 1, class ID 3

Better might be:

Character table:
ID 1, name Factotum
ID 2, name JeenLeen
ID 3, name Axebeard Beardaxe

Classes table:
ID 1, mage
ID 2, warrior
ID 3, rogue

Link table:
Character ID 1, class ID 1, 10th level
Character ID 2, class ID 2, 12th level
Character ID 1, class ID 3, 6th level
Character ID 3, class ID 2, 20th level

(I added Axebeard Beardaxe to show the benefit)

factotum
2014-04-01, 10:20 AM
Better might be:

Undoubtedly--I did say that a real-world example would be more complicated than my simple one, I wasn't going for the Normalisation Award :smallsmile:

JeenLeen
2014-04-01, 02:34 PM
Thank you for the ideas.

I'm progressing towards getting multi-classing working now, but I'm run into a ditch trying to get HD to work out. Maybe I'm just looking at it in the wrong way.

TABLES
0_CharList (removed Level & Class)
has ID (Primary Key), Character_Name, Race, Str, Dex, Con, Int, Wis, Cha, Notes

0_Classes
Unchanged

1_Char_Class (aka, linking table)
ID (Primary Key), CharID (foreign key from 0_CharList), ClassName (foreign key from 0_Classes), Level

class_chart has a new field, giving HD per level


SELECT C2.ClassName, count.ID AS [Level],
Switch(C2.BAB="Good",(SELECT BAB.Good FROM BAB WHERE BAB.Level = count.ID),C2.BAB="Med",(SELECT BAB.Med FROM BAB WHERE BAB.Level = count.ID),C2.BAB="Bad",(SELECT BAB.Bad FROM BAB WHERE BAB.Level = count.ID)) AS BAB,
Switch(C2.Fort="Good",(SELECT Saves.Good FROM Saves WHERE Saves.Level = count.ID),C2.Fort="Bad",(SELECT Saves.Bad FROM Saves WHERE Saves.Level = count.ID)) AS Fort,
Switch(C2.Refl="Good",(SELECT Saves.Good FROM Saves WHERE Saves.Level = count.ID),C2.Refl="Bad",(SELECT Saves.Bad FROM Saves WHERE Saves.Level = count.ID)) AS Refl,
Switch(C2.Will="Good",(SELECT Saves.Good FROM Saves WHERE Saves.Level = count.ID),C2.Will="Bad",(SELECT Saves.Bad FROM Saves WHERE Saves.Level = count.ID)) AS Will,
(Count.ID*C2.Skills) AS TotalSkills,
C2.HD AS HD, (CStr(count.ID)&C2.HD) AS HD_Count
FROM 0_Classes AS C2, [count]
ORDER BY C2.ClassName, count.ID;


Part 1 of the code (z_v4_Part1) calculates the BAB, saves, & HD from each class.


SELECT Link.ID, Link.CharID, Link.ClassName, Link.Level,
(SELECT class_chart.BAB FROM class_chart WHERE (class_chart.Level= Link.Level AND class_chart.ClassName = Link.ClassName)) AS BAB,
(SELECT class_chart.Fort FROM class_chart WHERE (class_chart.Level= Link.Level AND class_chart.ClassName = Link.ClassName)) AS Fort,
(SELECT class_chart.Refl FROM class_chart WHERE (class_chart.Level= Link.Level AND class_chart.ClassName = Link.ClassName)) AS Refl,
(SELECT class_chart.Will FROM class_chart WHERE (class_chart.Level= Link.Level AND class_chart.ClassName = Link.ClassName)) AS Will,
(SELECT class_chart.HD_Count FROM class_chart WHERE (class_chart.Level= Link.Level AND class_chart.ClassName = Link.ClassName)) AS HD,
(SELECT class_chart.TotalSkills FROM class_chart WHERE (class_chart.Level = Link.Level AND class_chart.ClassName = Link.ClassName)) AS Skills
FROM 1_Char_Class AS Link LEFT JOIN 0_Classes AS Class ON Class.ClassName = Link.ClassName
ORDER BY Link.ID, Class.ID;


v_v4_Part2 creates one row per character, summing up their level, BAB, and saves. But is there any code to, for example, make it do 2d8 + 1d10 for a Cleric 2/Fighter 1?

Edit: in the below, I added a line for character name (even though not really needed) and for skills. (Skills line also added in the above.) Also, for some reason it wouldn't work unless I assigned an alias to 0_CharList. Any idea why?


SELECT DISTINCT Scr.CharID,
(SELECT CharList.Character_Name FROM 0_CharList AS CharList WHERE CharList.ID = Scr.CharID),
(SELECT SUM(Scr2.Level) FROM z_v4_Part1 AS Scr2 WHERE Scr.CharID = Scr2.CharID) AS [Level],
(SELECT SUM(Scr2.BAB) FROM z_v4_Part1 AS Scr2 WHERE Scr.CharID = Scr2.CharID) AS BAB,
(SELECT SUM(Scr2.Fort) FROM z_v4_Part1 AS Scr2 WHERE Scr.CharID = Scr2.CharID) AS Fort,
(SELECT SUM(Scr2.Refl) FROM z_v4_Part1 AS Scr2 WHERE Scr.CharID = Scr2.CharID) AS Refl,
(SELECT SUM(Scr2.Will) FROM z_v4_Part1 AS Scr2 WHERE Scr.CharID = Scr2.CharID) AS Will,
(SELECT SUM(Scr2.Skills) FROM z_v4_Part1 AS Scr2 WHERE Scr.CharID = Scr2.CharID) AS Skills
FROM z_v4_Part1 AS Scr
GROUP BY Scr.ID, Scr.CharID;


I also imagine it will be hard to make an easy entry form (a la Access Forms) to let someone enter multiple classes per character, but that's another question for another day. Making this user-friendly is something I hope to do after finishing the code.

factotum
2014-04-01, 03:38 PM
But is there any code to, for example, make it do 2d8 + 1d10 for a Cleric 2/Fighter 1?


Tricky one--SQL server really isn't set up to handle non-deterministic things like random numbers like this; it has a RAND() function, but I think if you used it in a table select it would return the same value for each row. Also, if you *did* somehow get it to do it, the numbers it returned would be different each time you called your SELECT, which is presumably not what you want to happen! I would suggest calculating the hit points for each class and putting them in your class table when you populate it--that way, the value wouldn't change between iterations and you could do a simple SUM to get the total HP.

JeenLeen
2014-04-01, 03:52 PM
Tricky one--SQL server really isn't set up to handle non-deterministic things like random numbers like this; it has a RAND() function, but I think if you used it in a table select it would return the same value for each row. Also, if you *did* somehow get it to do it, the numbers it returned would be different each time you called your SELECT, which is presumably not what you want to happen! I would suggest calculating the hit points for each class and putting them in your class table when you populate it--that way, the value wouldn't change between iterations and you could do a simple SUM to get the total HP.

I don't want to actually get SQL to do the dice-rolling, but just to 'sum' up the hit die like it does the other things. My goal would be to, in the end, have it say for (for example, a level 2 Fighter/lv 1 cleric with 12 Con) 2d10 + 1d8 + 3. I can get the 2d10 + 2 or 1d8 + 1 through my solo-class code, but I'm not sure how to get it to combine "2d10" and "1d8" into the same string.

gomipile
2014-04-01, 08:30 PM
Some of the main issues I'm having are:
1) Documentation is largely irrelevant without reading the actual source code included.
2) Most of the solutions to common issues are horribly out of date. Getting an image from the gallery on modern versions took me two days to figure out, since there is so much misleading / out of date information.
3) There are so many different things that need to be kept updated etc. related to each view and activity.

Anyone know of any good resources for Modern app development?

This may be why people pay for the subscription that updates The Busy Coder's Guide to Android Development and gives access to the forums for it. I haven't read it, nor am I sure if it is any good, but I have gotten recommendations for it. It is supposedly updated regularly, and the author has semi regular Q&As with subscribers. Also, if you find actual errors in the most recent text, you get extra time on your subscription.

I'd check out the most recent openly downloadable version to see if you like the writing style (the book is published via a Creative Commons license, but the easily available download isn't updated very often compared to what subscribers supposedly get.)

factotum
2014-04-02, 02:41 AM
I can get the 2d10 + 2 or 1d8 + 1 through my solo-class code, but I'm not sure how to get it to combine "2d10" and "1d8" into the same string.

So, essentially you want to take one or more rows of data and concatenate them into a string? That's tough--I don't think there's any easy way to do it. All the methods I can find with a Web search involve using things like CTEs (Common Table Expressions), the PIVOT statement, or even (*spit*) cursors; I'm not really familiar with the first two, and small children will point at you in the street and laugh if you use a cursor in anything. This might be a situation where it's easier to do this in the front-end code rather than the SQL back end.

JeenLeen
2014-04-02, 07:54 AM
So, essentially you want to take one or more rows of data and concatenate them into a string? That's tough--I don't think there's any easy way to do it. All the methods I can find with a Web search involve using things like CTEs (Common Table Expressions), the PIVOT statement, or even (*spit*) cursors; I'm not really familiar with the first two, and small children will point at you in the street and laugh if you use a cursor in anything. This might be a situation where it's easier to do this in the front-end code rather than the SQL back end.

That is correct.

I think I have a (horribly complicated) idea that might work, where at least you a row per class & what the HD from it are, so the person can easily do the concatenation in their head. I think the COALESCE function might work, but it's not supported in Access SQL.

Shame there's no CONCATENATE function like there is a SUM function. (Using SUM gives a large number, as one could expect.) I did find something a little helpful here (for Oracle), (http://www.oracle-base.com/articles/misc/string-aggregation-techniques.php)so I'll try to see if I can figure out and utilize that in Access. Oracle's LISTAGG looks perfect, but it's not in Access.

By 'front-end code', do you mean Design View? I'm stuck with Access (no SQL Server at the moment).
On a side note, I'm glad to see my ignorance of cursors isn't necessarily a detriment, if your opinion of them is commonplace. :smallbiggrin:

Edit: something that might work in SQL Server (http://connect.microsoft.com/SQLServer/feedback/details/389883/string-aggregate-function-something-like-sum-for-numbers)

factotum
2014-04-02, 09:17 AM
The main problem with cursors is that they're a really, really hideously slow way to tackle any problem in SQL server, and I get twitchy when people try to extend a solution that works OK for a dozen rows of data to handle hundreds of thousands. :smallsmile: In your particular example it's entirely probable you'll never have enough data in there to make it an issue, but I don't know if Access supports cursors.

I think you may have to use VBA code in the presentation layer to perform the concatenation you require, but as I said earlier, Access is not a strong suit of mine so I don't know for sure.

Tyndmyr
2014-04-02, 10:18 AM
IMO, keep your DB dumb. Don't put business logic in the database, that's what code is for. Build a table(or a bunch) for whatever char sheet data you have, and do any processing application side as you build the char sheet object.

Woodzyowl
2014-04-05, 03:53 PM
I'm attempting to program a basic computer in JAVA, but I'm having trouble getting said computer to receive instructions from a text file. How does one go about doing that? Is using String[] args and a massive if statement really the most efficient way?

Grinner
2014-04-05, 07:19 PM
I'm attempting to program a basic computer in JAVA, but I'm having trouble getting said computer to receive instructions from a text file. How does one go about doing that? Is using String[] args and a massive if statement really the most efficient way?

Probably not (and such a method is likely to have inherent inflexibilities), but the instructions do need to be parsed (read and interpreted) by the computer at some point. There's no simple way around that problem.

What sort of instructions are they?

Edit: I've got an only slightly more elegant solution: data-driven programming. The idea is to define a bunch of data (the instructions) in an array and cycle through that array, looking for something that matches. It's effectively a more compressed form of a massive if statement.

I can't tell you how to do it in Java, unfortunately. Another issue is figuring out how to actually run the relevant functions once it's found a match...

factotum
2014-04-06, 01:00 AM
I can't tell you how to do it in Java, unfortunately. Another issue is figuring out how to actually run the relevant functions once it's found a match...

Well, in C I'd do that by creating a structure which contains a string (the command) and a function (which processes the command), then have an array of those...no idea if that's even possible in Java, though, particularly since the functions would probably need to be able to accept a variable number of arguments.

Woodzyowl
2014-04-06, 11:23 AM
Well, in C I'd do that by creating a structure which contains a string (the command) and a function (which processes the command), then have an array of those...no idea if that's even possible in Java, though, particularly since the functions would probably need to be able to accept a variable number of arguments.

In this specific case, the functions don't. However, I have no clue how to implement it in Java anyways. I suppose I'll just use the massive if. Thanks for the suggestions, though!

Grinner
2014-04-06, 12:14 PM
Well, in C I'd do that by creating a structure which contains a string (the command) and a function (which processes the command), then have an array of those...no idea if that's even possible in Java, though, particularly since the functions would probably need to be able to accept a variable number of arguments.

I was excited about that idea for a second. Tried it, but the compiler gave me an error.



#include <stdio.h>

struct structure {
void printStuff() {
printf("Hello World.");
}
};

int main() {
struct structure structFunc;

structFunc.printStuff();
getchar();

return 0;
}
Did you mean C++? Might be able to do it with classes.

factotum
2014-04-06, 02:49 PM
I was excited about that idea for a second. Tried it, but the compiler gave me an error.
Did you mean C++? Might be able to do it with classes.

No, I meant C--I should have said that the "function" part of the structure would actually be a function *pointer*; you'd declare all the individual functions as usual, then assign them to the function pointer in the structure. Been a very long time since I did C, but I think that would work (code not tested, almost certainly won't work, but should give an idea):



typedef struct tagStructure
{
void (*printStuff)();
} structure;

structure st;

int main()
{
st.printStuff = &myPrintStuff;

st.printStuff();
}

void myPrintStuff()
{
printf("Hello World!\n");
}

Grinner
2014-04-06, 05:16 PM
No, I meant C--I should have said that the "function" part of the structure would actually be a function *pointer*; you'd declare all the individual functions as usual, then assign them to the function pointer in the structure. Been a very long time since I did C, but I think that would work (code not tested, almost certainly won't work, but should give an idea):

With the exception of one little missing return statement in main(), it works perfectly.

Cool trick. :smallsmile:

Neftren
2014-04-06, 05:47 PM
With the exception of one little missing return statement in main(), it works perfectly.

Cool trick. :smallsmile:

If I remember correctly, main does not actually need to return in C. The behavior is undefined, but not invalid.

factotum
2014-04-07, 02:15 AM
If I remember correctly, main does not actually need to return in C. The behavior is undefined, but not invalid.

Yeah, but you're supposed to declare main() with a return type of void if you don't care what it returns, so that was still a mistake. I've just impressed I remembered enough about C after 15 years of disuse to get as close as I did! :smallsmile:

Neftren
2014-04-07, 02:21 AM
Yeah, but you're supposed to declare main() with a return type of void if you don't care what it returns, so that was still a mistake. I've just impressed I remembered enough about C after 15 years of disuse to get as close as I did! :smallsmile:

I'm pretty sure void main() was never valid either. At one point, I think compilers considered main to be implicitly of integer return type, but I'd have to double check the standard. Not that I care that much.



Woodzyowl, are you asking how to do file I/O in Java or something? I think it's called BufferedReader in Java, but I haven't touched that language in a while.

SMEE
2014-04-08, 07:12 AM
Today I am doing what most programmers dread.

I am opening Pandora's box... I am going to do maintenance to code I wrote 8 years ago and haven't laid my eyes upon since.

Some daemons have already left the box... How many more are there, I don't know.
Wish me luck. I will need it.

Wookieetank
2014-04-08, 08:24 AM
Today I am doing what most programmers dread.

I am opening Pandora's box... I am going to do maintenance to code I wrote 8 years ago and haven't laid my eyes upon since.

Some daemons have already left the box... How many more are there, I don't know.
Wish me luck. I will need it.

You should write up an adventurer's journal of your perils and exploits for prosperity :smallwink:

Seerow
2014-04-08, 08:55 AM
You should write up an adventurer's journal of your perils and exploits for prosperity :smallwink:

Definitely do this.

SMEE
2014-04-08, 09:38 AM
I have already lost count of how many functions I have rewrote and how many times I've read my comments (at least my younger self was kind enough to comment the code), looked at the code and thought "What the heck was I thinking when I wrote this mess." and redid the whole code so it is better and more readable.

I am losing my sanity and I am in dire need of a time travel machine so I can punch my younger self in the face. :smallannoyed:

Amidus Drexel
2014-04-08, 11:03 AM
I have already lost count of how many functions I have rewrote and how many times I've read my comments (at least my younger self was kind enough to comment the code), looked at the code and thought "What the heck was I thinking when I wrote this mess." and redid the whole code so it is better and more readable.

I am losing my sanity and I am in dire need of a time travel machine so I can punch my younger self in the face. :smallannoyed:

And to think that I have similar thoughts when I look at code I wrote only a month or two ago... :smalleek:

Razanir
2014-04-08, 07:01 PM
I have already lost count of how many functions I have rewrote and how many times I've read my comments (at least my younger self was kind enough to comment the code), looked at the code and thought "What the heck was I thinking when I wrote this mess." and redid the whole code so it is better and more readable.

I am losing my sanity and I am in dire need of a time travel machine so I can punch my younger self in the face. :smallannoyed:

Oh, please. I can do better. At a programming competition 2 years ago, I wrote a program that included 7 layers of nested for-loops and if-statements. Except I wasn't very keen on commenting at the time. And I didn't bother with curly braces, because at the time I didn't like using them unless strictly necessary. So now there's a program out there that's just declaration after declaration of fors and ifs, with not a curly brace in sight until the very deepest point, where I had two lines of code.

Grinner
2014-04-08, 07:28 PM
Oh, please. I can do better. At a programming competition 2 years ago, I wrote a program that included 7 layers of nested for-loops and if-statements. Except I wasn't very keen on commenting at the time. And I didn't bother with curly braces, because at the time I didn't like using them unless strictly necessary. So now there's a program out there that's just declaration after declaration of fors and ifs, with not a curly brace in sight until the very deepest point, where I had two lines of code.

That's the problem with elegant code; it's often completely inscrutable.

Wookieetank
2014-04-09, 08:44 AM
Oh, please. I can do better. At a programming competition 2 years ago, I wrote a program that included 7 layers of nested for-loops and if-statements. Except I wasn't very keen on commenting at the time. And I didn't bother with curly braces, because at the time I didn't like using them unless strictly necessary. So now there's a program out there that's just declaration after declaration of fors and ifs, with not a curly brace in sight until the very deepest point, where I had two lines of code.

You wouldn't happen to still have to code for this? I'm intrigued to see this madness.

Rosstin
2014-04-09, 10:01 AM
Hey all, I have a simple (I think) question that I think would be right up your alley.

I want to write a SQL Stored Procedure that periodically checks the filesystem it lives on to see if any folders have been deleted.

My plan is to basically use the Windows Command Line or PowerShell for this. I'll just call the script from the SQL Stored Procedure, it will check the filesystem, and then if something has changed alert the users.

I'm curious if anyone has some dead-simple solution for this. I know that matching directories is already a common task, and I suspect I'll be reinventing the wheel a bit with my solution.

reaverb
2014-04-09, 08:45 PM
Hey all, I have a simple (I think) question that I think would be right up your alley.

I want to write a SQL Stored Procedure that periodically checks the filesystem it lives on to see if any folders have been deleted.

My plan is to basically use the Windows Command Line or PowerShell for this. I'll just call the script from the SQL Stored Procedure, it will check the filesystem, and then if something has changed alert the users.

I'm curious if anyone has some dead-simple solution for this. I know that matching directories is already a common task, and I suspect I'll be reinventing the wheel a bit with my solution.

A) You want to use a cron job (or more precisely the Windows equivalent of a "scheduled task") , an SQL Stored Procedure is overcomplicated. (http://technet.microsoft.com/en-us/library/cc772785%28WS.10%29.aspx)

B) Not enough info. Does "alert the users" mean send an email, writing it to a file or popping up a window? Is this data meant to never change in the history of the system or are people going to add and change files?

Razanir
2014-04-09, 08:49 PM
You wouldn't happen to still have to code for this? I'm intrigued to see this madness.

Alas, I think it was only ever saved on the laptops we used for the competition. No luck. I could try to recreate it, though. It was just a brute force solution.

Wookieetank
2014-04-10, 08:00 AM
Alas, I think it was only ever saved on the laptops we used for the competition. No luck. I could try to recreate it, though. It was just a brute force solution.

Naw, no need to have to start from scratch just to feed my curiosity.

Razanir
2014-04-10, 08:11 AM
Naw, no need to have to start from scratch just to feed my curiosity.

I might anyway. Those 7 layers of loop were the entire method, pretty much. (Except for a small amount of file input at the start and standard I/O at the end)

TSGames
2014-04-12, 02:37 PM
Hey guys!

I have a slightly more relevant project to brag about this time.

I just finished turning Bhu's Critters thread (http://www.giantitp.com/forums/showthread.php?74654-Critters) into a PDF (http://www.topsecretgames.net/blog/pdfs-for-friends/bhus-monster-compendium/). But why do I bring this up in the programming thread?

Because it was 90% generated by scripting and 100% generated by programming.

Looking at the thread, I noticed that Bhu had been fairly consistent with his formatting of monsters; this meant that I could scrape the thread and pull down the monster posts with a high degree of accuracy. After about an hour of writing and fine tuning a Python script, I was done. I copied the results into a LaTeX document, added a cover, background image, and logo page, and then did a small amount of manual touch up. Oddly enough, I probably spent more time on the images than on the script: finding free to use images that are licensed for non-attributable reuse is a surprisingly challenging problem.

Anyway, the script isn't perfect. It generates a fair bit of superflous code, and the algorithm for determining a section entry isn't 100% spot on i.e. it tends to pick up a fair bit dialog and render it as section titles. The biggest problem was, of course, encoding, but most of that could be fixed with a bit of LaTeX coding.

All in all, it turned out OK. If I have a lot of free time in the future I may revisit it and produce a better version, but that is highly unlikely. Of course, if anyone wants to take a crack at improving it, I will gladly share the LaTeX source =D

Grinner
2014-04-12, 03:10 PM
All in all, it turned out OK. If I have a lot of free time in the future I may revisit it and produce a better version, but that is highly unlikely. Of course, if anyone wants to take a crack at improving it, I will gladly share the LaTeX source =D

That's really cool.

I'm more interested in the Python source, though. How did you get it to pull and parse individual posts?

TSGames
2014-04-12, 06:54 PM
That's really cool.

I'm more interested in the Python source, though. How did you get it to pull and parse individual posts?
I normally only update Mon and Wed, but I think I'd like to a more detailed writeup on the blog (http://www.topsecretgames.net/blog/) about this very topic. Web scraping is a pretty interesting subject, and Python is hands down the best language for it. I'll post an update here when I've got it typed out.

TSGames
2014-04-13, 11:02 AM
The writeup is done (http://www.topsecretgames.net/blog/?p=341)!

I cover the algorithm in a fair amount of detail without bogging down the reader by throwing up lines of code. I hope that answers your questions about the Python part; if not let me know and I'd be happy to answer more specific questions =)

Grinner
2014-04-14, 12:35 AM
Interesting. That library you mentioned...Is that how you actually got the data from the Internet in the first place? Or did you copy it to a local file manually?

TSGames
2014-04-14, 02:46 PM
Interesting. That library you mentioned...Is that how you actually got the data from the Internet in the first place? Or did you copy it to a local file manually?

Yep. I used urllib2 (which comes in the standard distribution of Python) to query the page. The server returns the raw html data which gets shoved into a list (think of it as a dynamically adjustable buffer in memory).

Now that we have the html stored in memory, we copy over only the parts that we want to a second list (memory buffer). We do this for each page in the thread, writing over the first list and copying the data we need to the second list.

After we are done querying pages, we delete the first list. All that is left to do is transform the data in the second list into usable LaTeX formatted code. This entire process will happen in memory and the result is written to a file.

-------
It's a little sloppy, but text takes up virtually no space on a modern computer, which means that the whole process can be done in memory. This implies that we can do this almost as fast as the server can give us data =)

However, I try to be nice to the server and wait a few seconds in between page requests. I'm sure that the new server can handle it, but I'd rather be polite about harvesting data.

Seerow
2014-04-15, 12:40 PM
I've got a probably dumb question, but it's bugging me so hopefully one of you guys can help me.

Basically, using Java, I'm trying to figure out how to create something like a hashmap, that only allows 1 value per key. ie I want to be able to enter Map(X, Y), and later be able to call Map(X) to get Y. But Maps seem to be used for multiple values per key, is there anything similar that allows a 1:1 connection, or do I need to design a separate class myself to cover that? Or can I just use a Map and just ignore the extra functionality of extra potential values?

Edit: I'm dumb. HashTable is what I am looking for, isn't it?

Edit2: Also, is there an already existing class in Java that will let you check if a number is prime? (maybe something in the Math class?), or is that something I would need to implement myself? (A quick google search shows it's a problem that has plenty of examples online already that I could grab, but if there's something in the java library already that would be better)

IthilanorStPete
2014-04-15, 03:10 PM
Edit2: Also, is there an already existing class in Java that will let you check if a number is prime? (maybe something in the Math class?), or is that something I would need to implement myself? (A quick google search shows it's a problem that has plenty of examples online already that I could grab, but if there's something in the java library already that would be better)

The Big Integer class has the isProbablePrime() method (http://docs.oracle.com/javase/6/docs/api/java/math/BigInteger.html#isProbablePrime(int)) which you could use. That looks like your best bet in the core library.

Astral Avenger
2014-04-16, 04:20 PM
So I got bored in math class again and fixed up (most of) the bugs in my Tic Tac Toe program, hard mode actually plays fairly intelligently now.


# Tic Tac Toe V1.2
# priority for moves:
# 1) Win
# 2) Prevent opponent win
# 3) Set up multiple 2 in a rows
# 4) Set up 2 in a row in single spot (favor playing corners)
# 5) Play corner
# 0,1,2
# 3,4,5
# 6,7,8

#as of 11:50 am 4.14.2014 this is fully functionall except the hard difficulty
#is still playing at random. The computer's move for hard difficulty begins at
#line 127.
# t3win is saved in the library:
# C:/Python27/Lib/t3win.py
# t3grid is saved in the library:
# C:/Python27/Lib/t3grid.py

import t3grid
import random
import t3win
win=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
# 0 1 2 3 4 5 6 7

def printgrid(movelist):
for n in range(0,5):
print t3grid.t3grid(movelist)[n]

def checkwin(movelist): # Returns 0: no winner, 1: x, 2: o
win=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
#[[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]
winx=[0,0,0,0,0,0,0,0]
wino=[0,0,0,0,0,0,0,0]
for n in range(0,8):
for m in range(0,3):
if(movelist[win[n][m]]==1):
winx[n]=winx[n]+1
if(winx[n]==3):
return 1
elif(movelist[win[n][m]]==2):
wino[n]=wino[n]+1
if(wino[n]==3):
return 2
return 0


contin="n"
no="no"
No="no"
yes="yes"
while(contin!="no"):
gametype=input("one or two player? (1/2) ")
movelist=[0,0,0,0,0,0,0,0,0] #0 empty, 1 is x, 2 is y
movecount=0
if(gametype==2): #two player
while(movecount<9):
if(movecount%2==0):
printgrid(movelist)
move=input('P1 Please enter your move: ')
while(movelist[move-1]!=0):
move=input('P1, that is not a valid move. Please enter a move: ')
movelist[move-1]=1
elif(movecount%2==1):
printgrid(movelist)
move=input('P2 Please enter your move: ')
while(movelist[move-1]!=0):
move=input('P2, that is not a valid move. Please enter a move: ')
movelist[move-1]=2
movecount=movecount+1
if(checkwin(movelist)!=0):
winStatement=["Tie game!","Player 1 Wins!","Player 2 Wins!"]
print winStatement[checkwin(movelist)]
printgrid(movelist)
movecount=10
print winStatement[checkwin(movelist)]
contin=input("would you like to play again? (yes/no) ")
if(movecount==9):
printgrid(movelist)
print winStatement[checkwin(movelist)]
contin=input("would you like to play again? (yes/no) ")
#
#
if(gametype==1): #one player
dif=input("easy or hard? (1/2) ")
first=input("would you like to be first, second or random?(1/2/3) ")
if(first==3):
first=random.randint(1,2)
if(first==1):
print "you go first!"
else:
print "you go second!"
#
# easy mode (dif==1)
while(movecount<9 and dif==1):
if(movecount%2==first-1):
printgrid(movelist)
move=input('Human Please enter your move: ')
while(movelist[move-1]!=0):
move=input('Human, that is not a valid move. Please enter a move: ')
movelist[move-1]=first #1 is x, 2 is o
elif(movecount%2!=first-1): #x is first, o is second
printgrid(movelist)
move=random.randint(0,8)
while(movelist[move]!=0):
move=random.randint(0,8)
compSymb=[0,2,1]
movelist[move]=compSymb[first]
print "computer's move is ", move+1, "."
movecount=movecount+1
if(checkwin(movelist)!=0):
if(checkwin(movelist)==first):
print "Well done Human, you are victorious!"
printgrid(movelist)
movecount=10
print "Well done Human, you are victorious!"
if(checkwin(movelist)!=0):
print "Puny meatbag, you are no match for Intel i7!"
printgrid(movelist)
print "Sucker, I win!"
movecount==11
contin=input("would you like to play again? (yes/no) ")
if(movecount==9):
printgrid(movelist)
print "Tie game!"
contin=input("would you like to play again? (yes/no) ")
#
# hard mode (dif==2)
while(movecount<9 and dif==2):
if(movecount%2==first-1 and movecount!=11):
printgrid(movelist)
move=input('Human Please enter your move: ')
while(movelist[move-1]!=0):
move=input('Human, that is not a valid move. Please enter a move: ')
movelist[move-1]=first #1 is x, 2 is o
elif(movecount%2!=first-1 and movecount!=11): #Computer's move
compSymb=[0,2,1]
altSymb=[0,1,2]
spot=t3win.tryToWin(movelist,compSymb[first]) #win
printgrid(movelist)
if(spot<9):
movelist[spot]=compSymb[first]
elif(t3win.tryToWin(movelist,altSymb[first])<9): #Stop opponent win
spot=t3win.tryToWin(movelist,altSymb[first])
movelist[spot]=compSymb[first]
elif(t3win.two2Row(movelist, compSymb[first])<9): #2x 2 in a row, 1x 2 in row
spot=t3win.two2Row(movelist, compSymb[first])
movelist[spot]=compSymb[first]
elif(t3win.corner(movelist,compSymb[first])<9): #play corners
spot=t3win.corner(movelist,compSymb[first])
movelist[spot]=compSymb[first]
else: #all that fails, play randomly.
spot=random.randint(0,8)
while(movelist[spot]!=0):
move=random.randint(0,8)
movelist[spot]=compSymb[first]
print "computer's move is ", spot+1, "." #end of computer's move
movecount=movecount+1
if(checkwin(movelist)!=0):
compSymb=[0,2,1]
if(checkwin(movelist)==first):
print "Well done Human, you are victorious!"
printgrid(movelist)
movecount=11
print "Well done Human, you are victorious!"
elif(checkwin(movelist)==compSymb[first]):
print "Puny meatbag, you are no match for Intel i7!"
printgrid(movelist)
print "Sucker, I win!"
movecount=11
contin=input("would you like to play again? (yes/no) ")
if(movecount==9):
printgrid(movelist)
print "Tie game!"
movecount=11
contin=input("would you like to play again? (yes/no) ")

win=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
# 0 1 2 3 4 5 6 7
xwin=[0,0,0,0,0,0,0,0]
owin=[0,0,0,0,0,0,0,0]
def possibleWins(movelist):
xwin=[0,0,0,0,0,0,0,0]
owin=[0,0,0,0,0,0,0,0]
win=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
for n in range(0,8):
for m in range(0,3):
if(movelist[win[n][m]]==1):
xwin[n]=xwin[n]+1
if(movelist[win[n][m]]==2):
owin[n]=owin[n]+1
if(xwin[n]>0 and owin[n]>0):
owin[n]=owin[n]=-1
return xwin,owin

def tryToWin(movelist, player): #1:x 2:o
# returns the move position for the specified player to win this turn
winlist=possibleWins(movelist)[player-1]
win=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
for n in range(0,8):
if(winlist[n]==2):
for m in range(0,3):
if(movelist[win[n][m]]==0):
return win[n][m]
return 10

def two2Row(movelist, player):
winlist=possibleWins(movelist)[player-1]
testlist=winlist
movescore=[0,0,0,0,0,0,0,0,0]
bestmove=-1
win=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
for n in range(0,8):
if(testlist[n]==1):
for m in range(0,3):
if(movelist[win[n][m]]==0):
movescore[win[n][m]]=movescore[win[n][m]]+1
for n in range(0,9):
if(movescore[n]==2):
return n
for n in range(0,9):
if(movescore[n]==1):
return n
return 10

def corner(movelist, player):
corners=[0,2,6,8]
for n in range(0,4):
if(movelist[corners[n]]==0):
return corners[n]
return 10

# tic tac toe grid, requires list of 9 elements, all elements must be either
# 0,1,2
def t3grid(movelist):
if(movelist[0]==0):
line1=" |"
if(movelist[0]==1):
line1="x|"
if(movelist[0]==2):
line1="o|"
if(movelist[1]==0):
line1=line1+" |"
if(movelist[1]==1):
line1=line1+"x|"
if(movelist[1]==2):
line1=line1+"o|"
if(movelist[2]==0):
line1=line1+" "
if(movelist[2]==1):
line1=line1+"x"
if(movelist[2]==2):
line1=line1+"o"
if(movelist[3]==0):
line3=" |"
if(movelist[3]==1):
line3="x|"
if(movelist[3]==2):
line3="o|"
if(movelist[4]==0):
line3=line3+" |"
if(movelist[4]==1):
line3=line3+"x|"
if(movelist[4]==2):
line3=line3+"o|"
if(movelist[5]==0):
line3=line3+" "
if(movelist[5]==1):
line3=line3+"x"
if(movelist[5]==2):
line3=line3+"o"
if(movelist[6]==0):
line5=" |"
if(movelist[6]==1):
line5="x|"
if(movelist[6]==2):
line5="o|"
if(movelist[7]==0):
line5=line5+" |"
if(movelist[7]==1):
line5=line5+"x|"
if(movelist[7]==2):
line5=line5+"o|"
if(movelist[8]==0):
line5=line5+" "
if(movelist[8]==1):
line5=line5+"x"
if(movelist[8]==2):
line5=line5+"o"
line2=line4="-+-+-"
l1=" 1|2|3"
l2=" -+-+-"
l3=" 4|5|6"
l5=" 7|8|9"
line1=line1+l1
line2=line4=line2+l2
line3=line3+l3
line5=line5+l5
return line1, line2, line3, line4, line5

>>>
one or two player? (1/2) 1
easy or hard? (1/2) 2
would you like to be first, second or random?(1/2/3) 3
you go first!
| | 1|2|3
-+-+- -+-+-
| | 4|5|6
-+-+- -+-+-
| | 7|8|9
Human Please enter your move: 1
x| | 1|2|3
-+-+- -+-+-
| | 4|5|6
-+-+- -+-+-
| | 7|8|9
computer's move is 3 .
x| |o 1|2|3
-+-+- -+-+-
| | 4|5|6
-+-+- -+-+-
| | 7|8|9
Human Please enter your move: 7
x| |o 1|2|3
-+-+- -+-+-
| | 4|5|6
-+-+- -+-+-
x| | 7|8|9
computer's move is 4 .
x| |o 1|2|3
-+-+- -+-+-
o| | 4|5|6
-+-+- -+-+-
x| | 7|8|9
Human Please enter your move: 9
x| |o 1|2|3
-+-+- -+-+-
o| | 4|5|6
-+-+- -+-+-
x| |x 7|8|9
computer's move is 8 .
x| |o 1|2|3
-+-+- -+-+-
o| | 4|5|6
-+-+- -+-+-
x|o|x 7|8|9
Human Please enter your move: 5
Well done Human, you are victorious!
x| |o 1|2|3
-+-+- -+-+-
o|x| 4|5|6
-+-+- -+-+-
x|o|x 7|8|9
Well done Human, you are victorious!
would you like to play again? (yes/no) no
>>>
I'm almost entirely self taught in python, so any weird code is morst likely a work around I've come up with for not knowing a better way.

5a Violista
2014-04-17, 10:47 PM
Frustration is a feeling I have right now.

I'm using MATLAB (an interpreted language) to program a finite element code, and I'm stuck trying to figure out how to implement the Greville-Abscissae or whatever they're called into the abomination of a function-calling nested for loop that I have.

Well, the programming is the easy part. It's the math that's difficult, and trying to decide to program how the math works. I use the comments liberally to think through the math.

Fun facts about my program: It has four nested for loops. The Main is a couple hundred lines long and calls 6 functions (and I'm trying to implement the seventh...not very well).

Actually, looking at it, it makes me laugh. There's only 75 lines of actual code. The rest of it is all comments. Over three-quarters of my code are comments. I should probably clean that up. Does that happen to anyone else? You reach the end of your code and notice you explain so much that it becomes difficult to understand what's going on?

Amidus Drexel
2014-04-17, 11:57 PM
Frustration is a feeling I have right now.

I'm using MATLAB

This appears to be par for the course, as far as MatLab's concerned. :smallwink: :smalltongue:

Seriously, though, MatLab can be both simple and infuriating, depending on what you're using it for. It seems like you've fallen into the second category...


Fun facts about my program: It has four nested for loops. The Main is a couple hundred lines long and calls 6 functions (and I'm trying to implement the seventh...not very well).

Actually, looking at it, it makes me laugh. There's only 75 lines of actual code. The rest of it is all comments. Over three-quarters of my code are comments. I should probably clean that up. Does that happen to anyone else? You reach the end of your code and notice you explain so much that it becomes difficult to understand what's going on?

You have a... main function in MatLab? Or just a primary function that you call that calls other ones? The second sounds more likely, as I've never used a main function (or seen one used) in MatLab. Then again, I'm using the word "main" as it pertains to C++, so...

Four isn't too bad (well, depending on what they're looping for). I used three nested for loops fairly consistently when we covered image processing in MatLab.

I have the opposite problem - I comment so rarely that there might not be any comments in my code at all. >.> Then again, I name my functions and variables in such a way that it tends to be easy for me to recognize what they mean without having comments for explanation.

5a Violista
2014-04-18, 12:46 AM
I just call it "Main" because it's easier that way and I'm used to there being one and (besides having loops and if-elseif-elseif-end combos) it pretty much only calls the other functions.

One of the for loops covers the element processing; another takes care of Gaussian Quadrature; the other two deal with the stiffness matrices, forcing functions, derivatives, and so on. Or, more accurately, they call the functions that do that stuff.

Anyway, I think I'm finished with it. Hopefully. I mean, I've got to find that last bug, but that's it. So, in other words, I'm finished with it for tonight.

Razanir
2014-04-18, 10:52 AM
I have the opposite problem - I comment so rarely that there might not be any comments in my code at all. >.> Then again, I name my functions and variables in such a way that it tends to be easy for me to recognize what they mean without having comments for explanation.

That's also what I do. I only comment if it's not immediately obvious how the code works. Fun fact, though. As a TA, I'll actually count smart variable/function names as having comments in your code.

Seerow
2014-04-18, 01:55 PM
The Big Integer class has the isProbablePrime() method (http://docs.oracle.com/javase/6/docs/api/java/math/BigInteger.html#isProbablePrime(int)) which you could use. That looks like your best bet in the core library.

Thanks for this. I wound up just writing my own method because while the "probable" part is most likely "certain" for any inputs I'm likely to use, I didn't want to take a chance with a false positive screwing me up. Found a suitably fast algorithm to implement and used that.


Now to figure out how to make memoization work when you have 4 different possible cases all recursively calling the same function. Fun!

Edit: And done. And holy cow memoization makes a ridiculous impact on performance. Without it, the program literally froze up with a input size of 300, and took several seconds at 100. With it, input size 1000 calculates nearly instantly, and it stays pretty much instant up to around 8500 where you hit a stack overflow error. I like it.

TSGames
2014-05-08, 07:04 AM
While it's not much of a programming feat: we did just upgrade the site (http://www.topsecretgames.net/). I'm proud to say that I got down and dirty with some php and it wasn't all that bad. The worst part was/still is the javascript. Why couldn't Python have been on the web instead? :smallsigh:

Kaworu
2014-05-08, 10:46 AM
Well, theoretically you can use Python as scripting language one the web. Theoretically...

TSGames
2014-05-08, 05:09 PM
Well, theoretically you can use Python as scripting language one the web. Theoretically...

I still remember my excitement the first time I saw Brython (http://www.brython.info/)'s ticking clock. But oh how the magic fades as you dig deeper and find that your magic carpet is really more of a welcome mat with strings on it.

Kaworu
2014-05-09, 05:20 AM
I dunno, I am not a real programmer :-)

So, basically, you are claiming that even the little clock demands much knowledge of JS?

TSGames
2014-05-09, 07:30 AM
So, basically, you are claiming that even the little clock demands much knowledge of JS?

It's javascript or HTML 5, sadly. You can do it with other technologies in other ways, but most of the technologies are hacks and hand-waving that ultimately rely on either javascript or HTML 5 and the rest of the technologies are browser or plugin specific implementations.

At least that's my experience. This is one case where I would definitely love to be proven wrong.

Ashtar
2014-05-09, 08:33 AM
I recommend watching Birth and Death of Javascript (https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript), it's an interesting view of where the world might go and why you probably don't need to learn javascript after all. :smallbiggrin:

TSGames
2014-05-11, 01:16 PM
I recommend watching Birth and Death of Javascript (https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript), it's an interesting view of where the world might go and why you probably don't need to learn javascript after all. :smallbiggrin:

Thank you for linking to that. I saw it all over the web after Pycon, but I never actually got around to watching it until just now.

That was a surprisingly entertaining talk. I really hope his prediction is right and I think it might be: it's not the first time I've seen javascript called "the assembly language of the internet".

Sivarias
2014-05-16, 02:15 AM
I have a question for this collection of (to me) experts.

I have fiddled with code in the past, mostly MatLab, and the Lua amalgamation found in ComputerCraft to program turtles. I have also played with Python (A Diffy teacher wanted us to use it for one project, he thought it was an acceptable substitute for MatLab, I just focused on the syntax changes and pretended I was in MatLab).

My knowledge of Code essentially boils down to if, then, for, while loops. Sometimes I can actually read the code people post. Sort of.

I want to learn more but I have found that merely reading it doesn't help. I'm a kinesthetic learner. I learn by DOING something.

Does anyone have a place I can start. I was REALLY getting into Lua because I was using it for ComputerCraft, but once I figured out a (rather) clean way of doing the project I wanted, I felt there was no purpose to learning. Just, projects for newbie coders. Something to do that can TEACH me. Or a good online class or something?

Thanks in advance,
Siv

Wookieetank
2014-05-16, 08:51 AM
Something to do that can TEACH me. Or a good online class or something?


edX (https://www.edx.org/) is a collection of free online courses started by MIT and Harvard, with current contributions from a "few" others. (https://www.edx.org/schools-partners) Some of the classes are self-paced and can be done whenever. Others are active classes where if you manage a passing grade you get a certificate of completion at the end.

Try python (http://www.trypython.org/) gives a nice general overview of python, and lets you program in browser while you're reading what different bits do.

Hope these help!

Neftren
2014-05-16, 03:45 PM
If you're interested in Python specifically, you should start with Learn Python the Hard Way (http://learnpythonthehardway.org/).

When you've got a grip on Python, you might want to check check this out (http://newcoder.io/). It's new and still being updated the last I checked.

As you noted, it's hard to learn something without actually doing it (i.e. practice). That being said, it's pretty tough to just learn by "doing" for the sake of doing. This is called busywork.

You'll get the most out of self-directed programming (especially outside the confines of a structured class) if you actually have some project goal in mind. I've brought up this sentiment before in this thread, but at its core, programming is meant to solve problems. Languages are tools. As you would pick the right tool for the right job, learn (and use) the right language for the right problem.

So, what are you looking to achieve?

factotum
2014-05-17, 01:55 AM
I agree with Neftren--no amount of websites will help you unless you have a goal, a personal project you want to achieve. (A goal beyond "just learn language X because reasons", that is).

Sivarias
2014-05-18, 12:56 PM
I don't have a specific project in mind, mostly because I don't know what I can DO with Python and other code. I'm not sure what a reasonable goal/objective for codes are so I don't have a basis for setting them.

So what are some things you guys do with code, Python preferably?

FLHerne
2014-05-18, 02:05 PM
I don't have a specific project in mind, mostly because I don't know what I can DO with Python and other code. I'm not sure what a reasonable goal/objective for codes are so I don't have a basis for setting them.

So what are some things you guys do with code, Python preferably?
Well, everything you interact with on a computer is coded in something, and Python is a fairly flexible language with lots of libraries available. So you could do, like, anything. :smalltongue:

Things I did/am doing with Python:
- Little widgets to start Steam games and ebooks from Calibre without poking through their respective clunky interfaces.
- Assorted single-use scripts to pull numbers out of forum/wiki tables and do stuff to them.
- Strange vertical roguelike thing. Doesn't work properly.

I'm also writing an overcomplicated diagram/flowchart/schematic program, but that's in C++ (and also isn't finished yet).

Astral Avenger
2014-06-03, 11:26 PM
I don't have a specific project in mind, mostly because I don't know what I can DO with Python and other code. I'm not sure what a reasonable goal/objective for codes are so I don't have a basis for setting them.

So what are some things you guys do with code, Python preferably?

Project Euler! (http://projecteuler.net/)

Speaking of which, I've run into a problem with my program for #17.
If anyone has the free time, can you tell me if you're seeing where the error is creeping in?
If the numbers 1 to 5 are written out in words: one, two, three, four, five,
then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were written out in
words, how many letters would be used?

NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-
two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters.
The use of "and" when writing out numbers is in compliance with British usage.



one =3
two =3
three =5
four =4
five =4
six =3
seven =5
eight =5
nine =4
ten =3
eleven =6
twelve =6
thirteen =8
fourteen =8
fifteen =7
sixteen =7
seventeen =9
eighteen =8
nineteen =8
twenty =6
thirty =6
fourty =6
fifty =5
sixty =5
seventy =7
eighty =6
ninety =6
hundred =7
hundred and =10
one thousand =11


def charcount(n):
if(n%1000==0):
return 11
snum=[[0,0],[1,3],[2,3],[3,5],[4,4],[5,4],[6,3],[7,5],[8,5],[9,4],[10,3],
[11,6],[12,6],[13,8],[14,8],[15,7],[16,7],[17,9],[18,8],[19,8],[20,6]]
lnum=[[0,0],[1,0],[2,6],[3,6],[4,6],[5,5],[6,5],[7,7],[8,6],[9,6]]
length=0
if(n>=100):
length+=snum[n/100][1]+7
if(n%100==0):
return length
else:
length+=3
n=n-100*(n/100) #subtracts the hundreds value from n: n=212 becomes 12
if(n!=0):
if(n<=20):
length=length+snum[n][1]
print n
return length
elif(n>20):
length=length+lnum[n/10][1]+snum[n%10][1]
print n
return length

summ=0
for n in range(1,1001):
summ=summ+charcount(n)
print summ
#answer 21124
#currently 21224

I have sporadic internet access for the summer, please PM me in a reply.

Avloren
2014-06-04, 02:13 AM
Project Euler! (http://projecteuler.net/)

Speaking of which, I've run into a problem with my program for #17.
If anyone has the free time, can you tell me if you're seeing where the error is creeping in?
If the numbers 1 to 5 are written out in words: one, two, three, four, five,
then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were written out in
words, how many letters would be used?

NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-
two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters.
The use of "and" when writing out numbers is in compliance with British usage.



one =3
two =3
three =5
four =4
five =4
six =3
seven =5
eight =5
nine =4
ten =3
eleven =6
twelve =6
thirteen =8
fourteen =8
fifteen =7
sixteen =7
seventeen =9
eighteen =8
nineteen =8
twenty =6
thirty =6
fourty =6
fifty =5
sixty =5
seventy =7
eighty =6
ninety =6
hundred =7
hundred and =10
one thousand =11


def charcount(n):
if(n%1000==0):
return 11
snum=[[0,0],[1,3],[2,3],[3,5],[4,4],[5,4],[6,3],[7,5],[8,5],[9,4],[10,3],
[11,6],[12,6],[13,8],[14,8],[15,7],[16,7],[17,9],[18,8],[19,8],[20,6]]
lnum=[[0,0],[1,0],[2,6],[3,6],[4,6],[5,5],[6,5],[7,7],[8,6],[9,6]]
length=0
if(n>=100):
length+=snum[n/100][1]+7
if(n%100==0):
return length
else:
length+=3
n=n-100*(n/100) #subtracts the hundreds value from n: n=212 becomes 12
if(n!=0):
if(n<=20):
length=length+snum[n][1]
print n
return length
elif(n>20):
length=length+lnum[n/10][1]+snum[n%10][1]
print n
return length

summ=0
for n in range(1,1001):
summ=summ+charcount(n)
print summ
#answer 21124
#currently 21224

I have sporadic internet access for the summer, please PM me in a reply.




NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-
two)...


...
thirty =6
fourty =6
fifty =5
...

Fixed by changing:

lnum=[[0,0],[1,0],[2,6],[3,6],[4,6],[5,5],[6,5],[7,7],[8,6],[9,6]]
to:

lnum=[[0,0],[1,0],[2,6],[3,6],[4,5],[5,5],[6,5],[7,7],[8,6],[9,6]]


(PM sent, duplicating it here for the elucidation of the general forumgoers)

Razanir
2014-06-12, 08:50 AM
TIL: Postincrementing occurs before dereferencing.

I'm writing a C program that works with calendars, and I took the admittedly naÔve approach of storing the year, month, and day in separate variables. So I wrote a pass-by-reference method to increment it. Turns out I was supposed to write (*day)++; not *day++;

Grinner
2014-06-12, 09:05 AM
Turns out I was supposed to write (*day)++; not *day++;

You know, I had been going to write a post about C's elegant, comprehensible, and altogether sensible syntax with generous helpings of blue text, but I just realized that makes total sense.

Consider this:
2+2*5

Versus this:
(2+2)*5

factotum
2014-06-12, 10:38 AM
If in doubt, bracket. Applies to any language, because forcing the reader to know the operator precedence for the language in order to figure out what the code is doing is bad coding, IMHO.

Tev
2014-07-27, 03:46 AM
I'm lazy to search extensively and this thread needs bumping sooo . . .

Our company (small one) is currently looking for new CMS. We're even pondering making our own from scratch, because our boss has a "vision" . . . you know, he's used to the interface of the old one :D
One collegue was poking around and got impressed by Umbraco (maybe because we just finished big MVC5 project). It does look nice from what I've found . . .

So I'm asking the playground - anyone working/having experience with Umbraco? Some good/bad experiences related to user-(un)friendliness of content management? (especially for non-IT people)

(I think I'll add more questions and requirements later, but feel free to post anything related)

EDIT: forgot the most important thing: we're coding in C#

shawnhcorey
2014-07-27, 07:30 AM
If you are changing your CMS, go with the most popular ones, like git or Drupal. I worked in shops with custom CMS and it takes several weeks for a new hire to learn it. With a popular CMS, you can hire people with experience with it. And you get any bug fix and security updates without having dedicated staff for it.

valadil
2014-07-27, 08:43 PM
If you are changing your CMS, go with the most popular ones, like git or Drupal. I worked in shops with custom CMS and it takes several weeks for a new hire to learn it. With a popular CMS, you can hire people with experience with it. And you get any bug fix and security updates without having dedicated staff for it.

I can give advice on Drupal as a cms if you have specific questions. Less sure how you'd go about using git as one, unless you play on using Github pages plus writing markdown in Github's editing.

MCerberus
2014-07-30, 06:30 PM
Hey windows people with a foot in the IT world, can bartender be configured to force convert new files?

Problem is I'm writing an xml into a print folder. A proprietary tool set to write XMLs there... writes .dat files
A C# class called through an assembly explicitly to write .xml files... writes .dat files
bcp when explicitly told xml files... WRITES FREAKING .dat files.

I'm currently being yelled at for this, but haven't had time to verify this hunch so far.
The good news is that these .dat files spit out contain proper xml, written to the first line of the file (because why would I go through the pain to format that to look pretty as straight-text after I got my FOR XML selects right).

More deets if it matters - I'm writing an xml string into a new file through two scalar functions, one generates an xml string based on parameters. the other one takes this string and a filepath and writes it out.. Yah, the assembly .DLL is pretty trivial, just one static function in one empty class. At no point does anything throw an error or timeout. I'm writing to a server outside of the caller (permissions work). Only issue is right now the assembly method has a completion time over 200ms.