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
mindphlux
Jan 8, 2004

by R. Guyovich
Has anyone here used Visual Studio Lightswitch? I'm not really much of a programmer, but deal with a lot of shoddy apps built using MS Access / SQL Server, and this looks like a pretty neat and easy way to build applications...

Adbot
ADBOT LOVES YOU

Shaocaholica
Oct 29, 2002

Fig. 5E

shrughes posted:

In average case scenarios or worst case scenarios? In worst case scenarios, the OS scheduler can be very important.

What about memory management? What kind of memory management are you talking about? In-process memory management (i.e. malloc?) or something else? If you're asking whether the malloc implementation is important, well hell yeah, it's very important and you can get very big speedups. It's practically not optional to swap out the default malloc with a choice of your own.

Can you elaborate on common scenarios where differences in the way the OS schedules/manages memory can greatly affect the speed at which something executes given the hardware and physical memory is the same?

Ariza
Feb 8, 2006
This is a very stupid Python question. I haven't done any programming in years and I'm trying to teach myself Python by making up a task and completing with Google and documentation but I've hit a stupid wall that makes me feel very dumb.

I've been able to scrape a webpage and put the elements I need into a list of 1500 or so strings that I'm trying to put into a csv file so I can import and manipulate it. I need to write 4 of those strings, the first 3 with a '\t' delimiter and then a '\n' after the fourth. I keep trying different loops but I keep getting the wrong results. What stupid thing am I missing?

baquerd
Jul 2, 2007

by FactsAreUseless

Ariza posted:

I've been able to scrape a webpage and put the elements I need into a list of 1500 or so strings that I'm trying to put into a csv file so I can import and manipulate it. I need to write 4 of those strings, the first 3 with a '\t' delimiter and then a '\n' after the fourth. I keep trying different loops but I keep getting the wrong results. What stupid thing am I missing?

You're missing posting your code so we can see what you're missing. And you're probably going about parsing a webpage in a very, very wrong fashion. What are you using to parse the syntax?

Ariza
Feb 8, 2006

baquerd posted:

You're missing posting your code so we can see what you're missing. And you're probably going about parsing a webpage in a very, very wrong fashion. What are you using to parse the syntax?

I'm using Beautifulsoup to parse the webpage. The syntax isn't the issue at all as I'm getting everything I need, parsed in the way I need it other than the missing new line after every fourth entry, and put into a list (I think it's a list anyways) or just straight written into a text file.

code:
for cell in splitstring:
     flogs.write(item + '\t')
That gives me a gigantic text file full of tab delimited cells that are correct, which I can import into another program, but I need to insert a '\n' after every fourth cell for the importation to work properly.

baquerd
Jul 2, 2007

by FactsAreUseless

Ariza posted:

I'm using Beautifulsoup to parse the webpage. The syntax isn't the issue at all as I'm getting everything I need, parsed in the way I need it other than the missing new line after every fourth entry, and put into a list (I think it's a list anyways) or just straight written into a text file.

code:
for cell in splitstring:
     flogs.write(item + '\t')
That gives me a gigantic text file full of tab delimited cells that are correct, which I can import into another program, but I need to insert a '\n' after every fourth cell for the importation to work properly.

Ah, OK. What you're looking to do can of course be solved in a variety of ways. The first that comes to mind is using a counter:

code:
counter = 0
for cell in splitstring:
    counter = counter + 1
    flogs.write(item + '\t')
    if counter == 4:
        flogs.write('\n')
        counter = 0

Ariza
Feb 8, 2006

baquerd posted:

Ah, OK. What you're looking to do can of course be solved in a variety of ways. The first that comes to mind is using a counter:


Thanks so much! I completely forgot about if statements and was trying to use nested for statements which I am way too dumb to use effectively. I used that and it worked perfectly. Now I can pull down tons of data to mess with.

tef
May 30, 2004

-> some l-system crap ->

baquerd posted:

Ah, OK. What you're looking to do can of course be solved in a variety of ways.

there is more than one way to do it ?

code:

>>> splitstring = ['a', 'b', 'c', 'd', 'A', 'B', 'C', 'D', '1', '2', '3', '4', 'w', 'x', 'y', 'z']
>>> chars = "\t\t\t\n"
>>> output = []
>>> for idx, val in enumerate(b):
...     output.extend((val, chars[idx%4]))
... 
>>> print "".join(output)
a       b       c       d
A       B       C       D
1       2       3       4
w       x       y       z
or even with zip and slices

code:
>>> print "\n".join("\t".join(x) for x in zip(splitstring[::4], splitstring[1::4], splitstring[2::4], splitstring[3::4]))
a       b       c       d
A       B       C       D
1       2       3       4
w       x       y       z
itertools :q:

code:
>> print "\n".join("\t".join(zip(*y)[1]) for x,y in itertools.groupby(enumerate(splitstring), lambda x:x[0]//4))
a       b       c       d
A       B       C       D
1       2       3       4
w       x       y       z

JawnV6
Jul 4, 2004

So hot ...

Ariza posted:

This is a very stupid Python question. I haven't done any programming in years and I'm trying to teach myself Python by making up a task and completing with Google and documentation but I've hit a stupid wall that makes me feel very dumb.
I mean normally I wouldn't call this a faulty learning method, but

Ariza posted:

I completely forgot about if statements
:stare:

qntm
Jun 17, 2009

tef posted:

code:
>> print "\n".join("\t".join(zip(*y)[1]) for x,y in itertools.groupby(enumerate(splitstring), lambda x:x[0]//4))
a       b       c       d
A       B       C       D
1       2       3       4
w       x       y       z

And that's why you don't provide more than one way to do things

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I love how, when it comes to these coding questions, you'll probably get a few good solutions and then one guy who does it completely wrong. Not because he is dumb, but because he is an entertaining jerk.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
The production of
code:
a       b       c       d
A       B       C       D
1       2       3       4
w       x       y       z
is kind of fun to golf :shobon:

Barring heredoc shenanigans, I'll set par at 85 bytes. How low can you go?

Blotto Skorzany fucked around with this message at 07:20 on Nov 2, 2011

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Welp, not gonna beat 85 bytes, but here's a 101 byte solution in Forth:
code:
: e CO ! ;
: t e 6 for 32 e next ;
: l 2 for dup t 1 + next e 10 e ;
: main 97 l 65 l 49 l 119 l halt
edit: wait, poo poo- those are real tabs, not seven spaces:
code:
: e CO ! ;
: l 2 for dup e 9 e 1 + next e 10 e ;
: main 97 l 65 l 49 l 119 l halt
81 bytes.

And if I rewrite it to work in GForth rather than my own dialect,
code:
: e emit ;
: l 2 for dup e 9 e 1+ next e 10 e ;
97 l 65 l 49 l 119 l
68 bytes. :)

Internet Janitor fucked around with this message at 14:10 on Nov 2, 2011

Opinion Haver
Apr 9, 2007

code:
intercalate"\n"$intersperse '\t'<$>["abcd","ABCD","1234","wxyz"]
62, if you ignore the two imports you need to get intercalate/intersperse and <$>. If you don't, then it's shorter if you use
code:
import Data.List
intercalate"\n"$map(intersperse '\t')$["abcd","ABCD","1234","wxyz"]
which is 82.

Vanadium
Jan 8, 2005

import List
"aA1w">>=(++"\n").intersperse '\t'.take 4.iterate succ

:colbert:

tef
May 30, 2004

-> some l-system crap ->
code:
a([]).
a([A,B,C,D|X]):-writef('%w\t%w\t%w\t%w\n',[A,B,C,D]),a(X).
66 in prolog :v:

code:
?- a([a,b,c,d,'A','B','C','D',1,2,3,4,z,x,y,z]).
a       b       c       d
A       B       C       D
1       2       3       4
z       x       y       z
true.

tef
May 30, 2004

-> some l-system crap ->

yaoi prophet posted:

which is 82.

if your input data is a list of strings rather than a flattened list, it is much shorter in python


code:
"\n".join("\t".join(x) for x in ["abcd","ABCD","1234","wxyz"])

tef
May 30, 2004

-> some l-system crap ->

Otto Skorzeny posted:

Barring heredoc shenanigans, I'll set par at 85 bytes. How low can you go?

actually shall we start a thread? as much as I enjoy diverting a megathread now and then it looks like this deserves its own thread

shrughes
Oct 11, 2008

(call/cc call/cc)
*perl*

code:
print join("\t",@$_),"\n"for[a..d],[A..D],[1..4],[w..z]
Edit:

code:
perl -E'$,="\t";say@$_ for[a..d],[A..D],[1..4],[w..z]'
Or

code:
use v5.10;
$,="\t";say@$_ for[a..d],[A..D],[1..4],[w..z]
Edit 2:

code:
use v5.10;
$,="\t";say(chr$_..chr$_+3)for 97,65,49,119
or
code:
perl -E'$,="\t";say chr$_..chr$_+3 for 97,65,49,119'

shrughes fucked around with this message at 18:38 on Nov 2, 2011

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Maybe someone can post a solution in J?

Zombywuf
Mar 29, 2008

The output is 31 characters. No-one seems to be anywhere near that yet.

Plorkyeran
Mar 22, 2007

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

Zombywuf posted:

The output is 31 characters. No-one seems to be anywhere near that yet.
it's spaces, not tabs

qntm
Jun 17, 2009

Zombywuf posted:

The output is 31 characters. No-one seems to be anywhere near that yet.

PHP:

code:
a       b       c       d
A       B       C       D
1       2       3       4
w       x       y       z

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Ariza posted:

Thanks so much! I completely forgot about if statements and was trying to use nested for statements which I am way too dumb to use effectively. I used that and it worked perfectly. Now I can pull down tons of data to mess with.

You're writing a (dialect of a) CSV file, so use the CSV module

qntm posted:

PHP:

hah nice

edit: unless you count the HTTP headers :\

Munkeymon fucked around with this message at 21:00 on Nov 2, 2011

Zombywuf
Mar 29, 2008

qntm posted:

PHP:

code:
a       b       c       d
A       B       C       D
1       2       3       4
w       x       y       z

Now make it smaller than 31 bytes :colbert:

gonadic io
Feb 16, 2011

>>=
Going back to topic, I've been asked to do some basic image manipulation. All I really need to do is pull individual pixels or regions from jpeg image, do various calculations on their RGB/greyscale values and then produce new images.

I'd ideally prefer to do this in Haskell because I'm a special functional snowflake academic but the Data.Bitmap library doesn't really seem like it does what I want it to do. The is also a binding to the DevIL library which seems much better. Has anybody has any experience with this sort of thing?

Failing that I'll probably do it in Java, is the Image2D library any good?

I guess I'm looking for recommendations of libraries/good tutorials (preferably in Haskell of course)

Omits-Bagels
Feb 13, 2001
So this is something a 5th grader could probably figure out so sorry for the dumb question...

I work for a small vacation apartment rental company and we spend a crazy amount of time giving people rental quotes and booking instructions over email. Nothing is automated so we have to do like 5 things to answer each email. There has got to be a simple way to make this whole process easier.

Here is our process:

The guests email us asking if we have vacancy during their requested dates.

We put the dates into our database to see if the apartment is available.

If it is available we open an excel spreadsheet that shows the rates. We then find the rate for their booking.

We have 14 separate pre-written emails (one for each apartment) that contain information for booking the apartment. So we copy & paste the text into a new email.

Then we go through the email "template" and manually replace the information like their name, the rental date, the total days of the rental and the price of the rental.

Sometimes they request multiple properties so we have to manually add up the rental price for each property they request and it takes forever.

Then we send the email.

-----
Is there a program (excel or something) that will allow me to simply enter the client's name and travel dates and it and populates an email with the price and all the other information? The email would look something like this (the bold parts are what would be populated):

Hello Jim,
Thank you for contacting XZY rentals. The Goon Virgin Chamber and the WOW Gamers Heaven apartments you've requested are available for your dates of 1 December - 8 December (7 nights).

The total rental price for Goon Virgin Chamber is $1000. This price includes all taxes and fees. To reserve you're dates you must pay a deposit of $500 (50% of the rental fee).

The total rental price for WOW Gamers Heaven is $1200. This price includes all taxes and fees. To reserve you're dates you must pay a deposit of $600 (50% of the rental fee).

Etc...

This would save me an hour or two on slow days and 4+ hours on busy days. Im not looking for anything fancy but spending half my day doing boring copy & paste is getting really lame.

nielsm
Jun 1, 2009



Omits-Bagels posted:

stuff about form emails

Not entirely sure, I haven't looked at it for ages, but maybe Word mail merge can be coaxed to do this.

Edit: The article I linked is for Word 2003, here's something for 2007. I imagine you could make it work by having an Excel sheet where you fill in the relevant data, you may be able to add some calculations to do menial lookups as well, and use that as data source for the merge.

nielsm fucked around with this message at 22:08 on Nov 2, 2011

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Since you mentioned Excel, you could do it with Word's form letter / mail merge functionality:

http://support.microsoft.com/kb/294683/en

Omits-Bagels
Feb 13, 2001

nielsm posted:

Not entirely sure, I haven't looked at it for ages, but maybe Word mail merge can be coaxed to do this.

Edit: The article I linked is for Word 2003, here's something for 2007. I imagine you could make it work by having an Excel sheet where you fill in the relevant data, you may be able to add some calculations to do menial lookups as well, and use that as data source for the merge.

How much would it cost to get someone to set this up for me?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Omits-Bagels posted:

How much would it cost to get someone to set this up for me?

It'd probably be a couple of hours depending on how complex the cases for your 14 emails are. The real stumbling block is going to be extracting the dates/location out of the original email.

If you go down this road though, I strongly suggest you inhouse it (e.g. have someone in your organization learn it) because mail merge is finicky as hell, so if it breaks suddenly you're screwed and there's no one around who knows how to fix it. That and it's not that hard to learn up on yourself.

Just speaking out of my rear end, but what sounds like a better solution might be a web site where they can plug in dates/choose from location, click submit, it hits a database to get answers, and then just shows them their requested info with an option to book immediately.

downout
Jul 6, 2009

I've got a weird segmentation fault that occurs when a 2D vector I've created goes out of scope. For some example code:

code:
else
{
        vector< vector<arr_info> > val_arr;
        val_arr.resize(input_val.size());
	for (int i = 0; i < input_val.size(); i++)
	{
		val_arr[i].resize(input_val.size());
		for (int j = 0; j < input_val.size(); j++)
		{
				
			val_arr[i][j].max_flag = false;
			val_arr[i][j].min_flag = false;
				
			if (i == j) 
			{
									
				//Initialize some val_arr values
					
			}
		}
	}
        function (val_arr);
}
SEG FAULT
The vector is an nxn vector of structs. It actually does everything in the function correctly, but seg faults when it goes out of scope from the else statement. I don't even need the vector after it goes out of scope, but I need to figure out a way to get rid of the seg fault. From what I can tell it is seg faulting in the library code when it gets deleted. I tried manually erasing the vector, and it still seg faulted. Anyone seen something like this before or have any suggestions?

Edit: Nevermind, I tried on a different compiler, and it worked fine. It looks like my library has a problem.

downout fucked around with this message at 05:29 on Nov 4, 2011

TasteMyHouse
Dec 21, 2006
I'm having difficulty using gcc to link object files compiled from C source using gcc to object files assembled by yasm. I'm on RHEL on a 64 bit machine, though the asm was originally written on windows for a 32 bit machine. I'm using the yasm flags "-f elf -m amd64". No porting has been done on the asm, but I can confirm it works on windows. When I attempt to link the files, I get a whole mess of "undefined reference" errors. yasm outputs no errors during assembly, and nm shows that the object files produced by yasm do contain references to the stuff I need.

Is there something special I need to do to get yasm object files to link to gcc object files?

e: HAH. solved it. needed -elf64
:frogbon:

TasteMyHouse fucked around with this message at 16:14 on Nov 4, 2011

Shaocaholica
Oct 29, 2002

Fig. 5E
I'm generating a bunch of shell commands in python and I want to start running them in parallel with a concurrent limit equal to some factor of the local cpu count. How should I go about doing this? Right now I'm just using subprocess.call() on each of the commands which runs them sequentially.

edit: I think I need to use this multiprocessing.Pool

Shaocaholica fucked around with this message at 18:04 on Nov 4, 2011

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Shaocaholica posted:

I'm generating a bunch of shell commands in python and I want to start running them in parallel with a concurrent limit equal to some factor of the local cpu count. How should I go about doing this? Right now I'm just using subprocess.call() on each of the commands which runs them sequentially.

I had to do something similar a while ago but being lazy and under a deadline, I just modified the calls so they called at.

Like

code:
echo "command" | at now
instead of just command

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Otto Skorzeny posted:

It doesn't always return NULL when it can't actually allocate the amount of memory you requested.
I thought vm.overcommit_ratio was common knowledge by now.

Meldonox
Jan 13, 2006

Hey, are you listening to a word I'm saying?
I'd like to get back into my programming as a hobbyist thing, and hell, maybe even go back to school for it if I get into it well enough. Is there a good resource out there for simple practice programs? I can read the books well enough, but the one thing I'm missing from when I took CS classes is the occasional "apply what you've learned to write a program to do x" assignment.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

Meldonox posted:

I'd like to get back into my programming as a hobbyist thing, and hell, maybe even go back to school for it if I get into it well enough. Is there a good resource out there for simple practice programs? I can read the books well enough, but the one thing I'm missing from when I took CS classes is the occasional "apply what you've learned to write a program to do x" assignment.

If you're up for a bit of math to mix in with your programming, Project Euler has a list of things to work on.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


PDP-1 posted:

If you're up for a bit of math to mix in with your programming, Project Euler has a list of things to work on.

Project Euler has always struck me as a bit of programming to mix in with your math rather than the other way around. Some of the early problems are good, but the later ones can get pretty esoteric.

Adbot
ADBOT LOVES YOU

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde
This is something that I've never found a nice solution to over the years, so I'm not expecting much, but here goes:

Has anyone ever found a nice OO way of wrapping/lifting a bidirectional graph/hierarchy of objects into another bidirectional graph/hierarchy? Let's say you store in the database relationships from type A to type B. Two tables in SQL. Easy. But in code you want to make further distinctions. Some As are actually A1s, others A2s etc. which implies the corresponding Bs are B1s, B2s etc.

You can do this sort of thing in OO, and graphs that just go one way are fine, but with two-ways it gets messy and error prone ensuring your A1s points to your B1s and vice versa.

Another example would be wrapping the Excel PIA objects like Workbook, Worksheet, Range into MyWorkbook, MyWorksheet, MyRange (there can be good reasons for doing this sort of thing e.g. being able to re-use the same code for PIAs and newer Excel libraries which query the Xml instead but have less functionality).

For the purposes of the discussion, let's ignore ORMs that support inheritance with table per subtype.

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