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
Vanadium
Jan 8, 2005

^^^ Apparently there is an extra parameter to let you control that behaviour? http://msdn.microsoft.com/en-us/library/ef48waz8.aspx

Adbot
ADBOT LOVES YOU

Vanadium
Jan 8, 2005

I would probably just do something silly like (int) (val * 100 + 0.5) / 100.0, but then again, no one is paying me to write decent C#. :shobon:

Vanadium
Jan 8, 2005

Bonus posted:

Wow, what a substantiated claim. Those are probably exactly what you want.

Well, at least half of them is not what you want. :colbert:

Vanadium
Jan 8, 2005

nasoren posted:

Whoa look at all this thin ice we're on :can:

gently caress I tried to make a joke about how we better avoid emacs in that case but then I accidentally opened emacs and :q! is not doing anything

Vanadium
Jan 8, 2005

Vince McMahon posted:

However, some users click "save image as" instead and end up just getting the thumbnail.

Perhaps you can replace the thumbnail imgs with divs with the thumbnail as background image so that no "save image as" option appears to begin with?

Vanadium
Jan 8, 2005

Pipe it through lynx --dump

Vanadium
Jan 8, 2005

Well, the compiler cannot actually inline them if there is no definition available in the translation unit in which they are used.

Vanadium
Jan 8, 2005

ShoulderDaemon posted:

Yeah, you're right. Javascript has crazy scoping. In this case, at least, the distinction doesn't really matter.

It matters if you want to return more than one closure.

code:
var a = []
for (var i = 0; i < 10; ++i) {
  var y = i
  a.push(function() { print(y) })
}

for (var i = 0; i < 10; ++i)
  a[i]()
Here you need to do something crazy like a.push((function(y) { return function() { print(y) } })(i)) instead because the only way to introduce a new scope is through a new function, as far as I know.

Vanadium
Jan 8, 2005

EscapeHere posted:

So, anybody have any clue what is going on here?

You are invoking undefined behaviour in a way that is not immediately obvious from the lines of code you posted.

Vanadium
Jan 8, 2005

It should be relatively easy to transform that to a representation that excel will eat up. Can you run a regexp over it or something? What format would that last column ideally be in?

Edit: Maybe you can just have excel ignore the last column and use the line number instead to recalculate the time of each line if that is easier. :shobon:

Vanadium fucked around with this message at 00:06 on Sep 24, 2009

Vanadium
Jan 8, 2005

Using String#scan?

Vanadium
Jan 8, 2005

I want to throw my hands into the air and scream about the monomorphism restriction, but I am not entirely sure

Vanadium
Jan 8, 2005

Sweeper posted:

I am getting a strange error when I compile under linux (kubuntu in VM) with a project that works on Windows and Linux.

error: macro "max" requires 2 arguments, but only 1 given

The way I fixed this in the past is to go through and every time it says this for min or max I put "#undef min" or "#undef max". This makes it compile and it works, but I feel like there is something I am missing.

Here is my makefile, I'm not sure what info to add about the project to help. It uses the HL2SDK, it is a plugin for source dedicated server for the game counter strike source.

http://pastebin.com/mbd9554a

windows.h defines min and max as macros because it is retarded, maybe you are indirectly including that or something else that is as stupid.

You are apparently defining NOMINMAX to avoid that, but it loks like you are doing things in C++ and only setting that for C or something. Not sure. :shobon:

Vanadium fucked around with this message at 21:18 on Feb 16, 2010

Vanadium
Jan 8, 2005

Sweeper posted:

It compiles under windows without error or warning, but it fails under Linux, does Linux have a Windows.h somewhere that it includes? If so I will look to see if my project includes it and put an #ifndef or something around it.

Just guessing here, maybe the SDK headers include a copy or something. Can you search them for #define max or something?

Vanadium
Jan 8, 2005

Why are we not using seq here? seq --format=%010g 1 100000 or whatever number.

Vanadium
Jan 8, 2005

Guessing for i in range(len(list)): if list[i] < 0: list[i] += 180 but i know literally nothing about python

Vanadium
Jan 8, 2005

Look Around You posted:

Hey guys, I was wondering where I could find some programming exercises

http://code.google.com/codejam/contests.html and http://www.facebook.com/careers/puzzles.php have a bunch of not-so-trivial problems to solve, maybe they are fun!

quote:

Also, I'd like to learn some GUI frameworks if there's anything on those (Cocoa, GTK+, etc.).

I think the best you can do here is working through their non-reference documentation (like the free Gtk+ "book"), then imitating how other people do things in the framework.

Vanadium
Jan 8, 2005

Gtk+ is the only gui framework that does not make me tear my hair out five minutes into it. :rant:

It takes at least half an hour or so.

Vanadium
Jan 8, 2005

I honestly do not do much with it and can see how it is a great deal inconvenient, and no, I do not like glade either. I like the gtkmm API and most other language bindings a great deal more than other frameworks', and Gtk+ seems to do a bunch more plumbing for me like properly layouting poo poo or dealing with fonts and whatnot. :shobon:

Vanadium
Jan 8, 2005

Just use std:: everywhere, then you do not have to remember to put the using thing elsewhere. :colbert:

Vanadium
Jan 8, 2005

Well, Forms is a .net thing and C++/CLI is the extension that lets C++ talk to .net things directly. I guess you will have to tell visual studio you want to make a winapi project or something stupid instead.

Vanadium
Jan 8, 2005

Smugdog Millionaire posted:

Alright I'll take another swing at explaining myself.
Say I've got a bunch of iterative algorithms for graph scoring. They each take a graph and produce a score for each vertex. They all follow the same pattern:
1. Set the score of each node to some starting value or another
2. Perform one step of the process
3. Calculate the change in scores
4. If the change is too large and we haven't performed too many steps, GOTO #2.
Additionally, there's probably some stuff like maintaining a mapping from vertices to scores that is likely equivalent or identical across algorithms.

Now my goal is to build some construct that allows me to have one implementation of this loop and allow different algorithms to slot in their own ways of doing 1, 2, and 3.
In the example I gave, the first descendant fills #3. It chooses the value of the scores to be doubles, and enumerates each vertex and adds up the differences between old and new scores (and probably other stuff, I'm using my imagination to some degree starting now).
The grandchild (PageRankWithPriors) in the chain fills #2. It performs the PageRank update on the graph.
The great-grandchild in the chain, PageRank, fills #1. It sets the value of each vertex at the start equal to 1/N, where N is the number of vertices.

I claim that using inheritance is the best way to fulfill this goal (in Java or C# or similar). In these cases, it's very straghtforward: I create a base class with some DoIt() method that performs the above loop, calling abstract methods SetInitialScores() and CalculateOneUpdate() and CalculateDelta(). Each algorithm then can inherit from the base class and fill in those methods as appropriate.
The typical downsides to inheritance won't apply here. Algorithms are fixed: one doesn't typically decide that algorithm behavior needs to change. You could decide that you needed a different algorithm, certainly, but all my negative experiences regarding inheritance have been caused by needing to change the way certain derived objects function and being unable to make that happen in the restrictive world created by a fixed base class and a set-in-stone inheritance hierarchy. I just don't see that happening when it comes to this sort of development.

I see two ways of using object composition to meet the same goal. The first is to have your PageRank class hold a reference to a private PageRankWithPriors object. The reference would require you to pass in #1 as a parameter. Passing methods around in Java is real annoying as everyone knows. You'd wind up having to create interfaces for every(-ish) method you wanted to be able to plug into. C# has function pointers so it would not be as painful there. Even still, you'd wind up having to write loads of boilerplate methods just to pass the message down the chain: PageRank.DoIt() just calls WrappedMember.Doit() and so on.

The second way, which you alluded to, is to have a public IterativeAlgorithm base class as the one you call all the methods on. You'd have to instantiate it like new IterativeAlgorithm(new IterativeScorer(new PageRankWithPriors(new PageRank()))). Ugly. The benefit to using to this structure is that you can mix-and-match stuff at runtime. I cannot imagine how that could ever be useful. From a readability and discoverability, it's definitely the worst option. When you're checking for a PageRank implementation, you definitely aren't going to be thinking "I wonder what I can plug into this IterativeAlgorithm thing." When you want PageRank, you want PageRank. There's no reason to expose the implementation chain.

In summary: you'll write more code for no benefit by using composition. (imo)

Please don't think I actually like inheritance in Java.

yeah, and what if I have a square class and want to make a rectangle class, it makes more sense to just inherit from the square and add another diameter or whatever

Vanadium
Jan 8, 2005

.chr a number and it becomes a one-character string!!

Vanadium
Jan 8, 2005

If you do not release your thing under AGPL v3 you are literally Steve Ballmer

Vanadium
Jan 8, 2005

http://libsigc.sourceforge.net/


:colbert:

Vanadium
Jan 8, 2005

Aluminum Record posted:

It works perfectly fine.

Generally you post the code that does not.

Vanadium
Jan 8, 2005

At a guess, argv is a list, so you have to do [script, first, second, third] = argv so that there is a list on either side.

Vanadium
Jan 8, 2005

Rampager posted:

I'm going to ask a possibly really stupid question but my curiousity demands answers. I realise that this might not be the best place for it.

How does programming in another (real) language (ex German, Arabic, Japanese) work? I can understand strings and the like but if you put in say a hiragana あ as a variable name [ int あ = 5; ] would the compiler allow it? Are there specific additions to compilers made to handle this case, or is anyone who programs forced to use the English alphabet?

As a follow on, wouldn't being from a non-english speaking country immediately put you at a disadvantage? E.g. looking at standard library functions such as push() and pop() or malloc() and free() you'd pretty much need a English->Your Language dictionary by your side the whole time?

Don't hurt me, this is legitmate curiousity :(

I guess a bunch of programming languages explicitly allow unicode symbols, but, as a German, I get unreasonably annoyed when I have to read code with German comments in it, let alone German identifiers. Also my dictionary did not have "malloc" in it anyway so I did not feel disadvantaged there at all.

Vanadium
Jan 8, 2005

I bet it would be even faster and easier to understand if he rewrote it in C.

Vanadium
Jan 8, 2005

He doesn't have to. The license doesn't apply to the dude who wrote the code, it's about the terms under which he allows you to redistribute it.

Vanadium
Jan 8, 2005

I think this instead of "..." should do what you want? [A-Z]{2,3}

Vanadium
Jan 8, 2005

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

:colbert:

Vanadium
Jan 8, 2005

Guys, I can't get into #cobol, what's the deal with synirc?

Vanadium
Jan 8, 2005

Taking this here from the screenshots-of-your-projects thread.

Suspicious Dish posted:

Vanadium posted:

Now I just need to figure out how to make [a Gtk window] click-throughable. :smith:

Use the X Shape extension and shape the input region away. In C:

code:
cairo_region_t *input_region;
input_region = cairo_region_create ();
gdk_window_input_shape_combine_region (gtk_widget_get_window (widget),
                                       input_region, 0, 0);
cairo_region_destroy (input_region);

I and some dude in the #gtk+ channel found that this only prevents the window from receiving clicks and short of also making that part of the window invisible the clicks won't be passed to windows behind mine.

I know Gtk+ isn't too popular around these parts, but does anyon have any clue how to get a Gtk window to not be invisible but pass clicks through to the window of another process in the background that it covers? I don't even want this to run anywhere but a recent X on linux but doing the xlib stuff myself sounds like a bunch of stuff to learn without even knowing whether it'll get me anywhere.

Edit: Here's my sample that doesn't work. https://gist.github.com/1528915

Edit: My window manager was doing it wrong and I needed gdk_window_set_override_redirect() to tell it to step off. Thanks, Suspicious Dish!

Vanadium fucked around with this message at 22:25 on Dec 28, 2011

Vanadium
Jan 8, 2005

pokeyman posted:

I'm surprised I've never heard of an intro programming course doing stuff in the browser, maybe using something like Processing. It (anything in the browser) is shareable, it's the best REPL you can get, it can do graphics without dickery, and it should score high marks in co-op interviews.

It's not a real programming course but there was this:
http://cdsmith.wordpress.com/2011/08/16/haskell-for-kids-week-1/

Vanadium
Jan 8, 2005

oRenj9 posted:

I only really use ternary operators for conditional assignments to the same variable, only because they are more clear and concise.

code:
var output = (censor) ? "poop" : "poo poo";
Which is significantly less work to read and write than,

code:
var output = "poo poo";
if (censor) {
  output = "poop";
}

Dude in the OP could be using
Constant[home_team.score > away_team.score ? :HomeTeamWin : home_team.score < away_team.score ? :AwayTeamWin : :Tie],
that's about the same thing, right. Wouldn't want to have to type the Constant[ ] thing more than once.

Edit: How about the good old spaceship operator!!
code:
case home_team.score <=> away_team.score
  when  1 then Constant[:HomeTeamWin]
  when -1 then Constant[:AwayTeamWin]
  when  0 then Constant[:Tie]
end
or something of the sort. if/then/else is soooo pedestrian.

Vanadium fucked around with this message at 05:41 on Mar 7, 2012

Vanadium
Jan 8, 2005

yo, if I feel like I finally need to get in on all that sort of stuff, is the ~Dragon Book~ still the right place to start?

Vanadium
Jan 8, 2005

If you do something like (\d\d )+ depending on the regex library you'll be able to get multiple captures for a single grouped subexpression.

Vanadium
Jan 8, 2005

tef posted:

My email address has puny code in it :q:

We really need a new internet standard specifying a more limited grammar for valid email addresses so that we can finally explain the regexes to match valid emails in unironic tutorials!

Adbot
ADBOT LOVES YOU

Vanadium
Jan 8, 2005

Does this help?

http://en.wikibooks.org/wiki/Ada_Programming/Installing

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