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
nielsm
Jun 1, 2009



JavaScript doesn't actually sound as a bad idea at all, especially not if you use something like jQuery UI.
Flash or Silverlight may also be options.
It sounds like graphical quality is important for the project, and I'd say that general desktop application languages/frameworks aren't the most suited for that.

Adbot
ADBOT LOVES YOU

nielsm
Jun 1, 2009



Either CDATA, or entity-escape all <>& characters.

(If CDATA can't contain the string ]]> then what do you do if you actually need to store that string? Leave CDATA, encode it with entities, then reenter CDATA?)

nielsm
Jun 1, 2009



Harvey Mantaco posted:

I really just needed something that would be easy for my girlfriend to update using (she doesn't know much about this stuff) and it seems like Wordpress is a pretty good choice for that. Is that a good excuse to finally buy a new windows based computer or is there a similar mac equivalent?

Wordpress is a blog software, it runs entirely on the web server so it only requires a web browser to use and post new content.
(It does require some more software to do the initial set-up and maintenance, though, but some web hosts might offer automated installation of Wordpress and other popular software packages. I.e. you'd need an FTP client and a text editor to do some configuration and upload the files.)

nielsm
Jun 1, 2009



mr. unhsib posted:

I'm having trouble coming up with a solution that isn't O(n^2) in the worst case.

Sort them by start time. (O(n log n))

Then for each job, if the start time is smaller than the end time of the previous, those two conflict. (O(n))

O(n log n) + O(n) = O(n log n)

nielsm
Jun 1, 2009



ToxicFrog posted:

I suspect that if you revise the algorithm to "if the start time is earlier than the latest recorded end time" rather than just the end time of the previous event, it'll work (and still be O(nlogn)), but I don't have a proof.

Yeah, oversight.

code:
class Job:
	def __init__(self, st, ed):
		self.start = st
		self.end = ed
		self.overlaps = False

jobs = [Job(1, 5), Job(4, 6), Job(10, 20), Job(2, 3), Job(7, 9)]

jobs.sort(lambda a, b: a.start - b.start)

prevend = None
prevjob = None
for j in jobs:
	if prevjob == None:
		prevend = j.end
		prevjob = j
	elif j.start <= prevend:
		j.overlaps = True
		prevend = max(prevend, j.end)
		prevjob.overlaps = True
	else:
		prevend = None
		prevjob = None

for j in jobs:
	print j.start, "->", j.end, j.overlaps and "(o)" or ""

python posted:

1 -> 5 (o)
2 -> 3 (o)
4 -> 6 (o)
7 -> 9
10 -> 20

nielsm
Jun 1, 2009



haveblue posted:

What am I doing wrong while trying to use SQLite under Eclipse/Ubuntu? I have the dev packages installed and pasted some example code into a new project, but it won't link to the library. It can see the header (the SQLite types work) but the linker thinks all the functions are undefined. Now what?

Did you tell it to actually link the library? -lsqlite3 on the linking commandline, don't know how you'd specify that in Eclipse.

nielsm
Jun 1, 2009



Goofankle posted:

thanks! that did it. this file was trying to link to square.java? is that what I'm getting from these errors?

Yes. "Symbol" is compiler-lingo for a name that is defined somewhere and is not a reserved word/keyword of the language. The name of a class, a method or a variable is a symbol. (Remember, a symbol talks about the name, not the thing itself. The compiler is telling you, "I have never heard of anything by the name 'Square'.")

nielsm
Jun 1, 2009



SnakePlissken posted:

(\[.*\]) is greedy, gets all hits at once. And (\[.*\])? doesn't work. All the quick documentation I've found say to use a ? after, and it's not working.

I think what you're looking for would be the expression .*?, with *? being the non-greedy zero-or-more.

Alternatively, make a negative character class: (\[[^\]]*\])
"A [, followed by a number of characters that are not ], followed by a ]."
(fe: drat beaten)

nielsm
Jun 1, 2009



Jose Cuervo posted:

I have a program that creates graphs which runs from the command line. The command
code:
gle -d pdf -o graph1 graphCode.gle arg1 arg2
creates graph1.pdf where arg1 and arg2 are two arguments unique to graph1.pdf. I have to create 30 graphs with differing arg1 and arg2 values, and I was wondering if there was a way for me to write a file with each line containing a command with the arg1 and arg2 values as appropriate, such that when I run that single file, it executes all the commands and creates all the graphs automatically.

Is there a way to do this?

I am using Win7 if that makes a difference.

Windows NT batch files can do crazy stuff with horrible syntax.

makegraphs.bat (or just enter it in a cmd window)
code:
FOR /F "tokens=1,2,3" %i IN (graphlist.txt) DO gle -d pdf -o %i graphCode.gle %j %k
graphlist.txt
pre:
graph1 arg1 arg2
graph2 arg3 arg4
graph3 arg5 arg6
I haven't tested this.

nielsm
Jun 1, 2009



Dooey posted:

Has anyone here implemented a silent updater before? I need to make one, so if anyone has any tips, they would be much appreciated. My general approach is going to be to check for updates in the main .exe, and have a separate .exe for the updater that actually downloads and applys the update. Anyone see any problems with that approach?

That'd be pretty much the standard approach yes.
Maybe rather have the main EXE do the downloading (in the background), then launch the downloaded updater which just installs itself.

Alternatively you could put most of your code (any that could need replacement) into DLLs that get loaded at runtime. Then, when updating, shut down everything except the core that loads the libraries, replace them, and reload. It may or may not be easier to keep user state that way too, if that's something you want to do.

nielsm
Jun 1, 2009



DontMockMySmock posted:

how can I take my ASCII/python data and convert it into a binary file with this format?

The struct module is what you want, for reading and producing data in binary formats.

Also, Python megathread here :)


pacheco: I'm pretty sure your DocumentRoot should point to a filesystem directory, not a virtual directory. Aliases don't work the way you're trying to use them.

nielsm
Jun 1, 2009



Unix has a utility called 'tee', which takes standard input and writes to standard output, as well as to a file. Like this commandline:

./foo | tee foorun.txt

Will run foo and print its messages to the screen. It will also write everything printed to screen, to the file foorun.txt.

(This is not completely true. If the program also writes to standard error, those messages won't be redirected. In bash, you can add 2>&1 in before the |tee part, to redirect standard error to standard out.)

nielsm
Jun 1, 2009



Moey posted:

The key I want to edit is in HKLM\Software\Microsoft\WindowsNT\CurrentVersion\WinLogon\DefaultUserName

Anyone have a code snippit on how to do this? I scrapped some stuff from google, but it's crashes when ran.

Are you sure your application has Administrator privileges? Writing to HKLM requires those.
When you get the crash, notice what exception caused it.

nielsm
Jun 1, 2009



Moey posted:

From my program, my textbox is called textBox1, on event (button click) I call String username = textBox1.ToString()

Nonono, the contents of the text box, which is what you want, is retrieved by textBox1.Text.
You do not want to call ToString(). The ToString() method is generally mostly useful for debugging, as a way of getting some description useful for debugging out of the object. You shouldn't be using it for actual problem solving.

nielsm
Jun 1, 2009



I am not a lawyer. This is just my understanding of the issues and I don't provide any guarantees of correctness.

The GPL license is "viral" in that any code that touches GPL-covered code also gets "infected" with GPL. (The license text has exemptions for "operating system libraries" and similar.)
If you write a program you want to keep closed source, don't link it to GPL code, not through dynamic libraries either.
You may be able to get away with writing a "server" program that uses the GPL library, and then have your main program communicate with the server program running in a different process, using some kind of IPC. The server program will be covered by GPL, but the main program may be able to escape.

The LGPL license is different, in that it just requires you to provide code not covered by LGPL in a form that allows the user to replace the LGPL-covered parts. If you copy-paste the LGPL code into your own source files you have to provide your code in source code form, because that's the only way to replace the LGPL code in it. If you instead statically link the LGPL code you have to provide at least object files for your code, so the user can re-link your program with replaced LGPL libraries. If you dynamically link the LGPL code it must be possible to replace the dynamically linked libraries.

The MIT/X11 and BSD-family of licenses generally don't require you to ship source code, but they do require you to credit the original authors and they do contain a disclaimer. Sometimes they require you to cite a blurb somewhere in your documentation.
Remember that it's the most restrictive terms of all covering licenses, that apply. E.g. I have an application whose source code is under a BSD license, but it links GPL code, so the final binary is covered by GPL and you can't ship that binary without disclosing the BSD-covered code.

GPLv3 is different and has several more restrictions. AGPL (Affero GPL) also gives right to users who only run the software indirectly, e.g. connecting to a server, which runs AGPL-covered code to serve the user. (AGPL-covered blogging software: Anyone who reads a blog must have access to the source.)

The safe route: Make your money off selling support contracts, not program code.

nielsm
Jun 1, 2009



Make a type="hidden" field in your form, that contains the GET variable's contents as well.

nielsm
Jun 1, 2009



slotbadger posted:

Can anyone point me to some nice tutorials about arrays and pointers and C in general?

code:
void getContents(int num, unsigned short wordArr[])
{
			memcpy(wordArr, tempArray, sizeof wordArr);		

Arrays in C don't carry their allocated size, except as far as the compiler can see at compile-time.
In this case, your wordArr is a parameter to the function, and doesn't carry any size. It's just a pointer to one or more unsigned shorts. So sizeof(wordArr) doesn't give what you expect it to. If you want to know the size or length of an array passed into a function, you also need to pass the size as a separate parameter, or pack the array + metadata into a struct, which you can then pass.
In this case, you'd also be overrunning the tempArray arrays' lengths in the memcpy(), because if the sizeof(wordArr) operator gave what you expected you'd be copying 32 bytes from the source array, regardless of how long it is. What happens when you copy 32 bytes from a 10 byte source? You get 22 bytes of garbage from the end, or an access violation if you're lucky.

It's worth remembering that the sizeof operator is resolved at compile time, it translates into a constant in the machine code. You can only measure sizes that are known at compile time.

Edit: Why is your function called getContents() when it doesn't return anything? I'd use the word "fill" rather than "get", in this case.

nielsm fucked around with this message at 16:29 on Apr 5, 2011

nielsm
Jun 1, 2009



quackquackquack posted:

I have a plugin for an existing program, and I need to automate the install of the plugin for distribution.

I'm not supposed to spend too much time on this, and it should be very easy for the programmer to update without me. What would you recommend?

A proper installer, I'd say. Personally I prefer Inno Setup, I like its declarative style over the more procedural style of NSIS.

A working installer shouldn't take a long time to write and requires very little maintenance.
When making a new release, if there aren't any new files to distribute, and the installation procedure hasn't changed otherwise, you'll just need to increment the version number in the installer source and click Build Installer again. (After dumping the updated Plugin.dll and other files where the setup compiler looks for them.)

nielsm
Jun 1, 2009



Difference Engine posted:

It says that it requires "Requires Fortran 77, C compilers, windowing support."

Taken in a Unix context, that means a Fortran 77 compiler, a C compiler and the X11 windowing system.
If you don't want to run a virtual machine with Linux, then Cygwin is probably your best bet. GNU has a Fortran and a C compiler,and Cygwin also has an X11 server for Windows. (Cygwin is a Unix-environment for Windows, which means that some things don't always work that well.)

nielsm
Jun 1, 2009



If this is in a WM_KEYDOWN handler, try checking the 24th bit of lParam instead. As far as I can tell it should also distinguish between left/right hand keys.

code:
switch (wParam) {
    case VK_MENU:
    {
        int is_right = lParam & 0x10000;
        ...
    }
}

nielsm
Jun 1, 2009



The King of Swag posted:

Ok, I've half-solved it. Turns out that Alt gets funky because Alt activates the window menu; this is fixed by using WS_POPUP instead of WS_OVERLAPPEDWINDOW, but that's only a viable solution for fullscreen mode, and I'd like to have Alt a viable key in windowed mode.

Is there a way to disable the window menu without resorting to WS_POPUP?

Are you swallowing the WM_KEYDOWN and WM_KEYUP messages (i.e. returning 0) or are you passing any at all to DefWindowProc()? I believe that if you swallow all keyboard input and don't let DefWindowProc() see it, you shouldn't get any of the menu behaviour. This of course assumes you're writing something like a game that doesn't use standard user interface.
Also try skipping TranslateMessage() in your message loop, although I don't think that matters for this.

nielsm
Jun 1, 2009



Jam2 posted:

Why _imaging.c:3017: warning: initialization from incompatible pointer type?

As rolleyes points out, that isn't the reason the build fails.

The reason the build fails seems to be that the setup_site module doesn't know how to call the C compiler properly and in other ways sets up a wrong build environment. I tried digging a bit in the PIL sources and its setup.py but didn't find anything conclusive for why it fails.
It seems that the compiler is told to build a fat binary with both PPC and x86 code in it, but your machine doesn't have an assembler for PPC installed so it fails to generate the PPC code, and then the lipo program fails because the PPC binary is missing. (Lipo is the program used on OS X to combine multiple single-platform binaries into one multi-platform fat binary.)

As for those pointer warnings, maybe the code was written against an earlier Python API version, that's my best bet. Assuming it's the 1.1.7 release version of PIL, those two lines are in static initialisers for function tables for custom types.

nielsm
Jun 1, 2009



Learning another language is never bad, although the choice of which one can be important :)

I'd suggest to keep using Python to write still more programs. Try to hold off on buying another book, instead see if how much you can pick up from reading library documentation on things you haven't worked with yet. It's a good skill to be able to figure out how to use a library from just its reference documentation.

As for a second language I'd suggest something C-like. Either pure C, C++ or C#. Java if you're feeling extra masochistic. Two reasons, first is to try a different kind of syntax (on some points more strict and others less strict than Python) and second to use a more strongly typed language.

Maybe also try dabbling with an SQL database and learn some basic relational database theory and the SQL query language. Python comes with the SQLite library that allows you to work with an SQL database without installing a database server.
Yes I just wrote Structured Query Language query language.

nielsm
Jun 1, 2009



Lysidas posted:

None of these languages are more strongly typed than Python. C in particular is weakly typed. Perhaps you mean a static type system?

You're probably right. Statically checked types is my point of suggesting those languages at least.

nielsm
Jun 1, 2009



Make a protected function in the base class to set that box, or let all your objects start out in an uninitialised state and then have an Init function that can be called whenever.

nielsm
Jun 1, 2009



Unless you are using a rather non-standard regex engine, you don't use commas in [] groups, just: [12][90][0-9][0-9]

As for not matching specifically "1080p", if you know it is always in that form and never only "1080", you can add a negated class: [12][90][0-9][0-9][^p] Just be aware that you're then catching one character too much.
If your regex engine also does irregular expressions, specifically forward assertions, you could use an assertion that the year must not be followed by a 'p'.
Another thing you might be able to do: (19|20)[0-9][0-9] Just be careful about capture groups, if you use those, you should probably use a grouping operator that doesn't capture if you have that available.

nielsm
Jun 1, 2009



rt4 posted:

I don't understand why CS courses don't start out with C. It's got everything you need and very little you don't: all the usual datatypes, pointers, arrays, conditionals, and looping, all implemented in a pretty straightforward way. None of it is very difficult, but it's all completely necessary if you're going to get very far in programming.

Already covered earlier:
C requires you to think about memory management and program organisation from the beginning, and requires much more boilerplate (#include <stdio.h> int main() {semicolons}, then get past the compiler) than many other languages. It removes focus from the task at hand: Instructing the computer how to solve a problem.
You can teach the students how to deal with the realities of the machine later.

E: Wait was that in the "coding horrors" thread? Maybe it was.

nielsm fucked around with this message at 14:44 on May 23, 2011

nielsm
Jun 1, 2009



qntm posted:

I just started learning C today and it seems like the hardest part of the language is finding a compiler for Windows that isn't Visual Studio or bundled up inside a metric tonne of Unixy stuff.

Grab the Windows SDK from MS, it includes their C/C++ compiler, C# compiler and other build tools, but not Visual Studio. It also includes the MSBuild environment needed to build VC++ 2010 projects, without VC2010.

nielsm
Jun 1, 2009



You should probably normalise that database. Even just going for 1NF should solve your problem.

Ideally, your database should be structured like this:
code:
SCHOOL:
schoolId: integer primary key (optionally with auto-increment)
schoolName: string (optionally unique)

PROGRAM:
programId: integer primary key (opt. auto-increment)
programName: string (opt. unique)

SCHOOLPROGRAM:
schoolProgramId: integer primary key
schoolId: integer foreign key referencing SCHOOL
programId: integer foreign key referencing PROGRAM
That form will make it easy to query the database for all programs a single school offers without risking e.g. typoes in how a school's name is written for one programs, and it'd also allow for querying which schools offer equivalent programs, if there is such a thing.

You can also make this simpler structure, but it will require you to ensure each school's name is always written exactly the same:
code:
SCHOOLPROGRAM:
schoolProgramId: integer primary key
schoolName: string (you'll likely want an index on this)
programName: string (probably no index needed)
unique(schoolName, programName) constraint
Then you can use this query: SELECT programName FROM SchoolProgram WHERE schoolName = 'whatever' and get your list of programs offered by a school. As a bonus, you can have any number of programs for a school.


If changing the database schema isn't an option I don't think you'll be able to use data-aware controls for the job.

nielsm
Jun 1, 2009



Is there any reason you can't instead render the object on a transparent background but make the object entirely white? When the object is pure white (and a shade of gray for shadows) you can use multiplication blending mode to mix a colour or texture onto it while keeping a transparency mask around the object. Basically the palette swapping of 256 colour VGA taken to the modern age.

nielsm
Jun 1, 2009



Unparagoned posted:

I've implemented reading such that I only look at the position of the first sector and then just read the next x sectors.

This is a really bad idea and you explained why yourself.

You haven't told in much what you're doing right now or what your constraints are, so I'll just make some guesses and assumptions.

If you can afford the memory for it, you're probably best off reading the entire file allocation table into memory for constant reference. If you want to read an entire file, what I'd suggest doing would then be to build a list of cluster numbers you need to read, possibly coalescing it into runs of contiguous clusters if it's faster to make requests for contiguous regions.

Having the entire FAT in memory should also allow you to more efficiently search it for free clusters when you need to write, although if you need to write often, it might be smarter to build a free-list when initialising the FS driver. (Again, that obviously needs memory you might not have.) If you know you will be writing fixed-size files you could even construct your free-list based on that knowledge, so you start with contiguous runs of the appropriate number of clusters, pre-calculated, and place all free space that would require you to fragment at the end of the free-list.

nielsm
Jun 1, 2009



There's two (three) ways to keep a FAT system unfragmented when you don't know what will be writing to it.
All of them depend on Win95 long file names not being written since that can bloat the directory entries a whole lot more, causing those to fragment.

One would be to make sure you only ever have one file open for writing at a time, never write to files that have been closed once, and never delete files. Then all your files should be contiguous.

Another would be to have all files be exactly the same size, and pre-allocate the files when you create them. Then you can create and delete files as long as they keep their size.

Last, which doesn't really count, is to only ever have one single, huge file.


On the other hand, if your device will be the one writing to the file system, then you're free to implement your file system driver as you wish, to avoid fragmentation in whatever way that might be most convenient for you.
The most important element in avoiding fragmentation is to plan ahead, using knowledge of the access pattern. When you need to write, if you know ahead of time what amounts of data you will be writing to a file, you can find a sufficiently large contiguous free area in the FAT and write your data there. A well-designed free-list can help in that operation.


Again, when reading, if you have enough memory you might be able to get away with throwing that at your problem: Implement a large-block cache below the FS driver. E.g. read aligned 4 MB blocks and keep them around for a while, then just read into those when you need. That can solve problems of files being scattered around, for example two files that were written in an interleaved fashion.

"I have a slow storage" -> throw faster memory at the problem

nielsm
Jun 1, 2009



Try preg_match('/R[0-9]$/', $listName)

nielsm
Jun 1, 2009



Smugdog Millionaire posted:

Is there a way to modify the data stream on your microphone before it's read by other applications? Imagine I want to create an autotune program that autotunes your voice for every application (skype, ventrilo, etc.). I'd need to A) get the input from the microphone and then B) write new data to that stream. There's plenty of information on doing A but I haven't been able to find anything about doing B.
The closest I've seen is people having their own audio device+driver but I'd rather not travel down that path if possible.
This is on Windows.

If you're okay with working only on Vista and up, I think a Audio Processing Object is what you want, it hooks directly into the audio chain.

Alternatively use something like Virtual Audio Cable to feed the microphone stream into an effect application, and have the effect application play back into another virtual audio cable which you can then point your real application to.


E: Okay after a bit more reading it seems that APOs can only be shipped as part of a complete audio driver package.

nielsm fucked around with this message at 13:29 on Jun 11, 2011

nielsm
Jun 1, 2009



Aredna posted:

When the user user enters a problem number it would call the function in the appropriate class, but it seems a bit ridiculous to just have 300+ if statements depending on which problem number they enter. I'm doing this in C#. Is there a better way I should organize my code?

The Abstract Factory pattern would probably be the standard generalised solution.

nielsm
Jun 1, 2009



Orzo posted:

That solves absolutely nothing in this case. Honestly, having a gigantic switch statement in this case is the simplest and cleanest way.

True. The choice is between a huge switch or a huge initialiser for a list of factories. The switch is probably less code.

nielsm
Jun 1, 2009



cannibustacap posted:

Also, ideally, is there a way to get my C++ functions to talk with Java also? Specifically, I compile my Matlab code into C++ shared libraries, so I have the working .DLL's and .H files, but without some kind of shell, they won't work with Java.

Java Native Interface lets you call native code from Java. It's probably a lot of effort to make it work well.

nielsm
Jun 1, 2009



tronester posted:

Any suggestions on alternate code to use to copy the files without having the user having access to the share other than within the software?

I'm not sure how feasible this actually is, but have a write-only "drop box" folder per user on the network, where a server-ish application (which has full access) will then take a file from on request or otherwise.
It could probably also be a shared (not per-user) drop box folder where the appropriate user group has write access to.

nielsm
Jun 1, 2009



CRIP EATIN BREAD posted:

we really need something can follow a variable throughout it's life and see where it get's cast to a pointer and manipulated at the byte level.

Some kind of static analysis tool, probably. Maybe you could make Clang do some of the heavy lifting for you, but I'm guessing you'd still have to write some custom code to actually detect the endianness-issues. Or it might already exist.
Anyway, static analysis is your keyword.

Adbot
ADBOT LOVES YOU

nielsm
Jun 1, 2009



Greencraft posted:

My question is, how do you go about learning a new SDK like Cocos2d? I really feel like I'm just fumbling around. I have an outline of things I want to do programming wise but its a struggle to figure out how to do any of them.

Find some working examples and fool around with those.

Then find the reference manual for the library and read through it. You don't have to remember everything in detail, just make sure you more or less visit everything so you get a feel of what the library is like, what it has and what it does not have, and where to look for the various features.
After looking through the reference, bring out those examples again and try doing more advanced things with them.

Being able to use a reference manual for some programming tool and jump right into it is a skill you will eventually develop, but it takes years.

With iOS development, you also have an advantage of a very controlled runtime environment. You will easily be able to test your game on every reasonable hardware configuration, so you can get away with "whatever works" solutions more often.

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