Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
tef
May 30, 2004

-> some l-system crap ->
design patterns are the roman numerals of computation.


(with apologies to mr pike)

Adbot
ADBOT LOVES YOU

Modern Pragmatist
Aug 20, 2008
I've developed a class that represents an image and it's corresponding metadata. Now I have some data files that were generated by a different class. My goal is to essentially import the data files and generate instances of my new class that are based on the data. What is the best way to handle this?

Currently, I'm thinking that I could have a class that represents the datafile and then define methods, one of which shares the name of the constructor of the new class. Then it would manipulate the data as necessary and pass it to the constructor. To me this seems better than modifying the parent class constructor to handle a datafile as an input. I'm having a hard time thinking of any other possibilities.

Any suggestions or opinions?

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug

Modern Pragmatist posted:

I've developed a class that represents an image and it's corresponding metadata. Now I have some data files that were generated by a different class. My goal is to essentially import the data files and generate instances of my new class that are based on the data. What is the best way to handle this?

Currently, I'm thinking that I could have a class that represents the datafile and then define methods, one of which shares the name of the constructor of the new class. Then it would manipulate the data as necessary and pass it to the constructor. To me this seems better than modifying the parent class constructor to handle a datafile as an input. I'm having a hard time thinking of any other possibilities.

Any suggestions or opinions?

Unless your program needs to access and manipulate the data from the old data files I would just write an import method. Have the import method take in the path to the data file, parse the old image data into a new image class, and returned an array of your image class.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

tef posted:

design patterns are the roman numerals of computation.

(with apologies to mr pike)
What do you mean by this?

MachinTrucChose
Jun 25, 2009
I could use some advice, guys.

I'm writing the first of several C++ Qt GUI applications that connect to a remote device (raw TCP, not web requests), send an XML-wrapped command such as "get diagnostics" or "set monitoring to off", receive a response (diagnostic value, or confirmation that configuration change was successful, etc.), parse the XML (storing the element name and value in a QMap as a key/value string pair), then use the parsed value to update the GUI accordingly. There are 150+ such commands, with more on the horizon. Some of the data can be configured by the user (eg modify existing value, click Submit).

Unfortunately, there's no way to tell the data types used in the value. Although the result of any of the 150 commands is one of maybe 10 different types (mostly decimal numbers, but also can be a date, or "ON", "OK", "Normal", etc), with about 5 "metadata" values sometimes accompanying for the main value (eg unit, minimum threshold, and so on) there's no way for me as a client-side programmer to tell. The XML follows a very basic element name/value, so when an element contains "metadata", instead of having that data in attributes or child elements, it gives me a single value like this:
%/40.00/36.00/37.00/43.00/44.00. I must then parse it manually, by going over the documentation to find out what each of those values is. Additionally, a value like "1" can mean anything from "Normal" to "Enabled" to "Selected" (I could go on) depending on the element.

The old GUI (obsolete) they used has each screen with several hundred lines dedicated to parsing, most of it not simple to follow. I was hoping to have a more flexible way of doing this, so that as little of the GUI code as possible is spent on writing parsing that can't be re-used.

I cannot change the XML protocol (I already asked) the server uses. I can only touch the GUI, but obviously I can insert a layer between the GUI and the parser. Does anyone have any advice on what I should do to make this maintainable, and scalable to the multiple GUIs I need to write?

What I've been thinking about is have a secondary parser that places the parsed values in a map where the key is the name of the command, and the value is yet another map where the secondary key indicates the metadata. For Qt people I was going for QMap <QString, QMap <QString, QVariant> >. This way, from the GUI I can update each GUI element with one or two lines like so:
code:
string OnOrOff = map["MONITOR"]["ON/OFF"].ToString();
labelOnOff.setText(OnOrOff);
DateTime uptime = map["MONITOR"]["Uptime"].toTime());
double attackBonus = map["WEAPON_BONUS"]["MainValue"];
string bonusType = map["WEAPON_BONUS"]["Type"].ToString(); //"Percentage" or "Absolute"
bool isLightning = (map["WEAPON_BONUS"]["Element"].ToString() == "Lightning");

This wouldn't rock the boat, since my co-workers are already using a basic map in the parser. "Oh now you can use a second key to narrow things down if you want".

A better alternative could be to store the parsed data in a class that defines the various types and assorted info. I'm not sure about the best way to design it. Have it be an aggregate of several small classes for each of the 15-odd types, with functions like:
code:
ClassOK getCommand1Result();
ClassNumber getCommand2Result();
ClassOK getCommand3Result();
ClassOnOff getCommand4Result();
ClassOnOff getCommand5Result();
ClassNumber getCommand6Result();

class ClassOnOff
   string getCommandName(); //constructor would have saved the command name
   string getResult(); //"OK", "Not OK"
   private: int m_actualResult; //0 or 1

classNumber
   private: double m_actualResult;
   double getResult();
   string getCommandName();
   string unit;
   string minimumThreshold;

usage:
labelCommand4.setText(AllMyData.getCommand4().getResult();
labelCommand6.setText(AllMyData.getCommand6().getResult() + AllMyData.getCommand6().unit()
Any advice would be greatly appreciated.

MachinTrucChose fucked around with this message at 00:13 on Jan 11, 2012

Strong Sauce
Jul 2, 2003

You know I am not really your father.





So I have some scripts that interact heavily with an Internet "Appliance" using its SOAP API

Initially I had to implement it with very few tests because of time constraints. However now that the script is running along I'm having problems figuring out the best way to implement some tests.

What is the best approach to interacting with something that is live like a web service? The options I've come across are 1) to do mocks, which for me wouldn't be that helpful unless they could replicate the functionality and responses from this appliance or 2) just run the script on development appliance and fix whatever problems you run into.

For example, one of the functions this script has to do is parse a JIRA ticket and check for specific text that contains the information I need. Do I create a mock that just replicates the response of a JIRA ticket or should I have "test" JIRA tickets on the server and have the tests point to those when it runs?

Another example: I have to create profiles on this appliance which involves sending a SOAP call (I'm using ruby so I'm essentially using the soap4r wrapper) which returns nil if it creates the profile, but throws an exception if it fails. Would I essentially do tests that mock the SOAP requests or is it better to switch to the development appliance, run actual code on that server and then parse the results from that?

Not sure if that makes any sense, I'm just looking for any ideas about how to handle testing when it involves interacting with a web service. Mock it or some other method?

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Dolemite posted:

I'm not sure whether to ask this here or in the Cavern of COBOL reading thread. I have a two-fold problem being a newer developer without a computer science background.

First: In writing my first Java / Android app, I believe my design is okay, but I just don't know. I feel that I've created solid classes that make sense in how much of certain responsibilities each one will handle. And how different classes (and objects created from them) will interact with each other. But, I'd like to really read up on software design methods so that I can go back and make things more efficiently designed.

Second: To solve the first problem, I'm not sure what I'm looking for. In my research, there seems to be two kind of tracks: Books/sites talking about software development things like Agile development, etc. Or, things that talk about design principles such as making use of factories, singletons, etc.

Now, I think what I'm looking for is closer to the design pattern type stuff. In reading more about methods like Agile development, it looks like that deals more with how a team will deliver/develop software for a client. But, I'm the only developer on this project and the client just gave us a loose spec. It doesn't really look like books on development methods will benefit me (at this time).

So if I'm looking for readings on design methods, what are good, trusted sites or authors in the industry? In my case, what is less likely to be entirely over my head? Unfortunately, I feel like I'm the most dangerous kind of developer: I can learn a language fairly quickly and have an app written for you in no time. But, I'm noticing that my apps tend to have growing pains until I spend a solid chunk of time rewriting the code to smoothly adopt the new requirement changes.

I REALLY want to avoid my vicious cycle of:

--*FURIOUS TECHNO AND CAFFEINE CODE BINGE*,

--working application,

--"Oh poo poo, I didn't think of these pitfalls",

--*FURIOUS TECHNO AND CAFFEINE CODE BINGE*,

--test app - find bugs,

--"Oh poo poo, to fix it, I need to do X. And in doing so, I should best rewrite these classes Y and Z to work with fixes to X. And now the the classes that Y and Z depend on need to be rewritten...",

--*FURIOUS TECHNO AND CAFFEINE CODE BINGE*

And so on and so forth. :(

The only development methodology that I've found really useful for improving the quality of the design is test driven development - essentially, write unit tests first, get the tests to pass, then refactor once you get stuff working.

I think it's counter-productive to sit down and try to come up with an elaborate, over-arching design - if you write the unit tests first, and force yourself to go entirely TDD, there will at least be enough discipline so that whatever you come up with will be testable, and the likelihood of coming up with an design that isn't viable is greatly reduced - and should the design suck, it's MUCH easier to refactor if you have working unit tests.

tef
May 30, 2004

-> some l-system crap ->

Orzo posted:

What do you mean by this?

A design pattern is an abstraction that the language enables but does not support. We chastise those who copy and paste code as beginners, but when experts do it is is a "design pattern".

In the early days of computing using a conditional goto in a certain way would be an 'if-pattern', or a 'while pattern'. Pushing ret onto the stack would be a "function pattern". We got past that and now we all take structured programming for granted (well, most of us).

Now we use objects to make a "strategy" or a "factory" or a "builder". Meanwhile i'm going to stay over here and use my first class functions and named/optional arguments.

Peter Norvig makes a good argument for this http://www.norvig.com/design-patterns/

gonadic io
Feb 16, 2011

>>=
Talking of first class functions, in Haskell it's common to apply a function to each element of an array so much so that it's a standard library function. Given that you can manipulate function pointers in C, is something like that possible?

A simple definition in Haskell could be:
code:
map :: (Int -> Int) -> [Int] -> [Int]
map f (x:xs) = f x : map f xs
map _ []     = []
whereas the C could be something like
code:
void map (int (*fun) (int), *int arr, int length) {
    for (int i = 0; i < length; i++) {
        arr[i] = fun(arr[i]);
    }
}
Is this valid C? Terrible C?

gonadic io fucked around with this message at 16:11 on Jan 11, 2012

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
AlsoD: I do things like that in Forth, and I think it can be a good way to abstract away loops. The main weakness of function pointers, though, is the fact that they can't easily represent partially applied functions because A C-style function pointer doesn't carry a lexical scope with it. That technique is also a little clumsy syntactically if you don't have a convenient sytax for inline/anonymous function declarations.

fuf
Sep 12, 2004

haha
I feel like a retard for not being able to work out regular expressions.

I've got a messy HTML document (converted from an Office document) and I'm trying to find and replace all the HTML tags with LaTeX tags.

So I want to turn this:

code:
<a href="#_edn1" name="_ednref1" title="">[1]</a>
into this:

code:
\footnote{1}
about 200 times (and keep the number in the square brackets each time).

I'm using Notepad++, and I can't for the life of me work out how to use the right combination of wildcards to find every instance and replace it in the right way.

Can someone point me to a simple tutorial or help get me started? :shobon:

edit: worked it out:

<a href="#_edn[0-999]" name="_ednref[0-999]" title="">\[([0-999])\]</a>

It wasn't working because I wasn't putting the escape character thing (\) in front of the square brackets.

fuf fucked around with this message at 16:50 on Jan 11, 2012

ShadowHawk
Jun 25, 2000

CERTIFIED PRE OWNED TESLA OWNER
How do I know whether someone sent me an uncompiled Gambas project or a compiled Gambas script? If it's the latter how would I run it?


Literally never heard of Gambas until today, and it seems for good reason

Dolemite
Jun 30, 2005
Thanks all for the advice on programming design. :)

Regarding the one bit of advice to use testing to work out code: Sadly, I haven't really used unit testing all that much. I primarily work in PHP (*waits for laughter to end*) and should probably sit down and try out the testing frameworks I've heard about. I've worked at three places now that don't use any kind of unit testing. But in here and in companies that seem worth working for, I've noticed a lot of unit testing goes on.

fuf posted:

Regex help

I know you worked it out already, but in the future, you ought to try Regex Pal. I've used it to help me work out a Regex pattern. You put in your subject text, then can try out different Regexs. The page will show you matches as you work it all out. Its really helped me get very good with Regexs.

Dolemite fucked around with this message at 20:52 on Jan 11, 2012

Eyecannon
Mar 13, 2003

you are what you excrete
I am having a problem with sed in a BASH script... I am trying to comment out all lines that contain a certain ip address, in this case $host... I tried a bunch of stuff but both of these:

sed -i '/$host/s/^/#/g' data2

and

sed -i '/'${host}'/s/^/#/g' data2

are only matching a single time in the file even though there are 4 lines that should match. So basically, data2 is only getting 1 commented line instead of 4, even though I have the /g in there. Any ideas why it isn't matching all the lines?

EDIT: actually it seems something else is going on here... if I change the order of the lines, no lines get commented!

EDIT2: more clues, when I run the same command on the CL with the IP instead of the $host variable, it works perfectly... I have it in an if/then statement, will sed only match once in that case?

Eyecannon fucked around with this message at 22:41 on Jan 11, 2012

ChewyLSB
Jan 13, 2008

Destroy the core
EDIT: Aw crap there's an SQL thread. I am stupid.

ChewyLSB fucked around with this message at 22:45 on Jan 11, 2012

qntm
Jun 17, 2009

fuf posted:

I feel like a retard for not being able to work out regular expressions.

I've got a messy HTML document (converted from an Office document) and I'm trying to find and replace all the HTML tags with LaTeX tags.

So I want to turn this:

code:
<a href="#_edn1" name="_ednref1" title="">[1]</a>
into this:

code:
\footnote{1}
about 200 times (and keep the number in the square brackets each time).

I'm using Notepad++, and I can't for the life of me work out how to use the right combination of wildcards to find every instance and replace it in the right way.

Can someone point me to a simple tutorial or help get me started? :shobon:

edit: worked it out:

<a href="#_edn[0-999]" name="_ednref[0-999]" title="">\[([0-999])\]</a>

It wasn't working because I wasn't putting the escape character thing (\) in front of the square brackets.

Careful. [0-999] is a character class, equivalent to [0-9]. Check that this find/replace is still working past #10. You probably want [0-9]+ instead. The + means "one or more of the preceding".

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Dolemite posted:

Thanks all for the advice on programming design. :)

Regarding the one bit of advice to use testing to work out code: Sadly, I haven't really used unit testing all that much. I primarily work in PHP (*waits for laughter to end*) and should probably sit down and try out the testing frameworks I've heard about. I've worked at three places now that don't use any kind of unit testing. But in here and in companies that seem worth working for, I've noticed a lot of unit testing goes on.

Things I've noticed about unit testing in addition to previous comments:
1. It forces developers to use object oriented programming. If your 'design' isn't object-oriented, you're going to have a bitch of a time writing unit tests.
2. It forces developers to properly mock objects and write scaffolding code - say you're writing a program that displays CR images on a screen, and you use a DLL from another company to do the image processing (sharpening/edge enhancement). And say you need to swap out the old DLL for a new one. If you haven't written unit tests that mock out the component and scaffolding code, then you're in for a hell of a time doing guess and check when people start blaming the new module for issues QA is finding.
3. The unit tests themselves serve as MUCH better documentation than documentation. They're all example code demonstrating how the system works, and should cover every capability - rather than having to page through a reference, you have sample code exercising all the intended code of a module sitting right in front of you - that is huge.
4. Good unit tests make continuous integration worthwhile - if you make your CI tool run the unit tests, and you have good unit tests, you can instantly figure out who broke the build.

Eyecannon
Mar 13, 2003

you are what you excrete
OK, I fixed my previous problem... turns out I had the wrong brackets around my if statement.

Now I need it to check that a line is not already commented before it adds the #, to prevent multiple #'s from being added.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

hieronymus posted:

Things I've noticed about unit testing in addition to previous comments:
1. It forces developers to use object oriented programming. If your 'design' isn't object-oriented, you're going to have a bitch of a time writing unit tests.

You've never used a functional programming language, have you?

fuf
Sep 12, 2004

haha

qntm posted:

Careful. [0-999] is a character class, equivalent to [0-9]. Check that this find/replace is still working past #10. You probably want [0-9]+ instead. The + means "one or more of the preceding".

Thanks! It did indeed stop working past 10. I fixed it by fiddling around but it's nice to know why.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

hieronymus posted:

1. It forces developers to use object oriented programming. If your 'design' isn't object-oriented, you're going to have a bitch of a time writing unit tests.

I think what you really mean is that your code is broken up into components instead of a giant spaghetti mess. Which really makes sense... if you can't pick a unit to test independent from the rest of the system, you can't really write unit tests.

You certainly can write unit tests for code written in C, which doesn't have any object-oriented features built-in to the language.

Zombywuf
Mar 29, 2008

It amazes me when people think object orientation was the first attempt to add structure to code. There is this little thing called structured programming.

stray
Jun 28, 2005

"It's a jet pack, Michael. What could possibly go wrong?"
At work, I periodically need to turn a file (such as a Word document) into a PDF, but we don't have a PDF creator. However, my Mac at home can do it easily.

I'd like to set up a way to send an email with an attachment to a specific email address which Mail is watching, have my computer automatically open the file in Pages, turn it into a PDF, quit Pages, email the PDF back to me and delete the original file and/or mail message.

I've got a feeling this is the sort of thing that AppleScript can do. Anyone know how?

baquerd
Jul 2, 2007

by FactsAreUseless

stray posted:

At work, I periodically need to turn a file (such as a Word document) into a PDF, but we don't have a PDF creator. However, my Mac at home can do it easily.

I'd like to set up a way to send an email with an attachment to a specific email address which Mail is watching, have my computer automatically open the file in Pages, turn it into a PDF, quit Pages, email the PDF back to me and delete the original file and/or mail message.

I've got a feeling this is the sort of thing that AppleScript can do. Anyone know how?

You're over-complicating things, there are many available for free. If you're not overly concerned about document security, there is even http://www.freepdfconvert.com/

yippee cahier
Mar 28, 2005

baquerd posted:

You're over-complicating things, there are many available for free. If you're not overly concerned about document security, there is even http://www.freepdfconvert.com/

Yeah, this works for me when I'm on Windows: http://sourceforge.net/projects/pdfcreator/

rolleyes
Nov 16, 2006

Sometimes you have to roll the hard... two?
Also, Word 2010 (and maybe 2007? Can't remember) can save directly to PDF.

Sab669
Sep 24, 2009

Expanding on the other responses, http://www.doc2pdf.net/ is my favorite. You don't even need to provide an email, or anything. You just upload a document and then it just shoots it back to you and you can download it right away.

Drape Culture
Feb 9, 2010

But it was all right, everything was all right, the struggle was finished. He had won the victory over himself. He loved Big Brother.

The End.
If I'm not mistaken there's a service connected with Amazon's Kindle that does this, too. It's not free though.

I second the PDFCreator though, it adds a printer just like Acrobat Pro does so any program can use it.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

sund posted:

Yeah, this works for me when I'm on Windows: http://sourceforge.net/projects/pdfcreator/

I've used this one and it's very nice, it shows up as a regular printer (at least on Windows). Just be careful when you install it because there is a sneaky 'install Yahoo Toolbar' option that is enabled by default.

ToxicFrog
Apr 26, 2008


OpenOffice/LibreOffice also has "export to PDF" built in, if you already have that installed.

mobby_6kl
Aug 9, 2009

by Fluffdaddy
I'm having some trouble with R, when trying to create transactions for mining with arules. My data in the DB looks like this:
code:
|Cust_ID  |Item    |
|---------|--------|
|123      |Milk    |
|123      |Bread   |
|123      |Glock17 |
|456      |Bananas |
|789      |Cookies |

# or in CSV:
123;Milk
123;Bread
...
Everything works if I import in the CSV like this:
code:
tr <- read.transactions("transactions.csv", format = "single", sep=";", cols=c(1,2))
But I just can't get the direct SQL approach to work. I tried a few more different ways with about the same success:
code:
my_data <- sqlQuery(ch, paste("SELECT BLAH BLAH"))
my_data <- data.frame(lapply(my_data, as.factor), stringsAsFactors=TRUE)
tr <- as(my_data, "transactions")
I'd appreciate any input as reading documentation and googling like mad didn't get me anywhere so far...

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I'm finally joining the 21st century and I'm going to write my first webapp.

I'm thinking that I'm going to write a "server" component that you only interact with via JSON and then different mobile apps (Android/iOS/whatever) work via that. I'm also thinking that the web interface will basically be HTML and JS with JSON calls to to the server.

Is this naive? Is this the way webapps already work and my super awesome idea is just the way things are done? Am I retard and this won't ever work well?

Zombywuf
Mar 29, 2008

Thermopyle posted:

I'm finally joining the 21st century and I'm going to write my first webapp.

I'm thinking that I'm going to write a "server" component that you only interact with via JSON and then different mobile apps (Android/iOS/whatever) work via that. I'm also thinking that the web interface will basically be HTML and JS with JSON calls to to the server.

Is this naive? Is this the way webapps already work and my super awesome idea is just the way things are done? Am I retard and this won't ever work well?

You need to think in terms of resources and representations. As an example, a post is a resource but you can represent it as HTML, plain text, JSON, etc... This is done through content negotiation. Having a HTML representation of all of your resources is handy as it lets you debug in a browser by following links between things. If you need different representations of things then add them and use the HTTP content negotiation mechanism to get them.

tef
May 30, 2004

-> some l-system crap ->

Thermopyle posted:

I'm finally joining the 21st century and I'm going to write my first webapp.

I'm thinking that I'm going to write a "server" component that you only interact with via JSON and then different mobile apps (Android/iOS/whatever) work via that. I'm also thinking that the web interface will basically be HTML and JS with JSON calls to to the server.

Is this naive? Is this the way webapps already work and my super awesome idea is just the way things are done? Am I retard and this won't ever work well?

It looks like you're trying to reinvent an RPC mechanism tunnelled over HTTP.

You can try:

Using a format with hyperlinks in, as to maintain the nice web like properties. Quintessentially you write a 'web 1.0' app that can be 'scraped'. This can be as simple as an XHTML page that links to resources in some other format be it json or xml for example. There are a couple of nice properties that fall from this like being amenable to caching, a uniform interface, and loose-coupling.

Using someone else's homebrew rpc mechanism. There are plenty already out there.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Thermopyle posted:

I'm finally joining the 21st century and I'm going to write my first webapp.

I'm thinking that I'm going to write a "server" component that you only interact with via JSON and then different mobile apps (Android/iOS/whatever) work via that. I'm also thinking that the web interface will basically be HTML and JS with JSON calls to to the server.

Is this naive? Is this the way webapps already work and my super awesome idea is just the way things are done? Am I retard and this won't ever work well?

Eh, not so far off. I believe the Twitter website nowadays is a bunch of JavaScript that calls their public API, for example.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


mobby_6kl posted:

I'm having some trouble with R, when trying to create transactions for mining with arules. My data in the DB looks like this:
code:
|Cust_ID  |Item    |
|---------|--------|
|123      |Milk    |
|123      |Bread   |
|123      |Glock17 |
|456      |Bananas |
|789      |Cookies |

# or in CSV:
123;Milk
123;Bread
...
Everything works if I import in the CSV like this:
code:
tr <- read.transactions("transactions.csv", format = "single", sep=";", cols=c(1,2))
But I just can't get the direct SQL approach to work. I tried a few more different ways with about the same success:
code:
my_data <- sqlQuery(ch, paste("SELECT BLAH BLAH"))
my_data <- data.frame(lapply(my_data, as.factor), stringsAsFactors=TRUE)
tr <- as(my_data, "transactions")
I'd appreciate any input as reading documentation and googling like mad didn't get me anywhere so far...

You'd be better off asking here.

Sab669
Sep 24, 2009

I'm a masochist and am making this school project way larger than it needs to be. For my advanced .NET class I'm developing a shopping cart application for a website.

Anyways, foolishly, I just went and pulled down over 400 images of products my website will be 'selling'. I'm curious what would be the easiest way to deal with all of these images? Like, write 400 loving insert statements for the database, then parse through a result set in ASP? Quickly re-name all of the images to be numerically incremental and then just loop through that in ASP?

I'd like it so the user can click the image and take them to a page that shows more detailed information, but I think this might start interfering with my other classes' homework.

shrughes
Oct 11, 2008

(call/cc call/cc)

Sab669 posted:

I'm a masochist and am making this school project way larger than it needs to be. For my advanced .NET class I'm developing a shopping cart application for a website.

Anyways, foolishly, I just went and pulled down over 400 images of products my website will be 'selling'. I'm curious what would be the easiest way to deal with all of these images? Like, write 400 loving insert statements for the database, then parse through a result set in ASP? Quickly re-name all of the images to be numerically incremental and then just loop through that in ASP?

code:
foreach (var file in directory) {
    insert (file.filename, other data) into database;
}

Xguard86
Nov 22, 2004

"You don't understand his pain. Everywhere he goes he sees women working, wearing pants, speaking in gatherings, voting. Surely they will burn in the white hot flames of Hell"
small python questions:

I've got very, very basic coding knowledge and I'm trying to brush up by doing some really simple python exercises, I bought a textbook and I've been working my way through it. The book was written for 2.x python, but I am doing it in 3.x and running into some syntax issues I don't understand. The book has a 3.0 edition, so I have downloaded the example programs from that version, to compare

My first question is pretty specific, I have the 3.0 version:

code:
 #change.py
def main():
	print ("Please enter your change values:")
	quarters = eval(input("Quarters? "))
	dimes = eval(input("Dimes? "))
	nickels = eval(input("Nickels? "))
	pennies = eval(input("Pennies? "))
	total = quarters * .25 + dimes*.1 + nickels * .05 + pennies * .01
	print()
	print ("Your Total: ",total)
So in 2.0, you don't need to use eval() when inputting the data, but in 3.o you have to or it throws an error on using floats and int in the operation. What does eval() do exactly? I googled it but I am afraid I still don't understand the necessity. Is it just for when you're using different number types?

Second question: Is there a somewhat easy to understand resource for the differences between python 2 and 3? Are they different enough that I should just uninstall 3 and work with 2 for the sake of learning?

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
You should just install Python 2. Most of the working world is using Python 2, and it's not worth the pain to learn Python 2 after learning Python 3.

eval evaluates Python expressions. It's a controversial language feature, given that it allows your application to have security holes if you're not careful:

code:
>>> eval("(3 + 4) * 2")
14
>>> def foo():
...     print "I am a banana!"
...
>>> eval("foo()")
I am a banana!
>>>
If you just want to parse numbers, you should just use int:

code:
>>> foo = int(raw_input("Nickles? "))
Nickles? 20
>>> foo
20

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply