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
ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Vanadium posted:

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

Good call.

Vanadium posted:

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.

The way I usually see it written is without using arguments, something like:

code:
for (var i = 0; i < 10; ++i) {
  (function(){
    var x = i;
    a.push( function ( ) { print( x ) } );
  })();
}
Which I suppose is just so that you can mentally map "(function(){" and "})()" to being incredibly verbose versions of "{" and "}" that open a new scope.

Adbot
ADBOT LOVES YOU

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Vanadium posted:

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.

Javascript 1.7 supports let, which gives you block-scope.

Lord Satan
Oct 15, 2004

Open wide the gates of Hell
And come forth from the abyss
By these names: Satan, Leviathan,
Belial, Lucifer.
Hello all maybe you can help me with something that should be easy. I am trying to create a windows command line batch file to rename image files to simply a number sequence(####.jpg). I want it to ask what number to start from then rename all the files in the directory from that number on. So far I have cobbled together this from searching around the web:

@Echo Off
setLocal EnableDelayedExpansion
set /p incr=Enter the starting number:
for %%f IN (*.jpg) do (
set incr=!incr!
ren "%%f" "!incr!.jpg"
set /A incr+=1
)

And it sorta works. The problem is it sometimes starts at the number specified and sometimes it starts at the next number. I need this to be precise since the numbers have to correspond with database entries. What is wrong? Or is there a better way to do this?

If I can figure this out I will be able to automate renaming, resizing, thumbnailing, watermarking, and uploading images with a single batch file and that would be awesome.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
I run the codebase for a lot of sites (we use one standard codebase for all of them) and I've always used HttpRuntime.AppDomainAppVirtualPath to get the base URL -- http://address.com or whatever, and then I slap a / on there. Very useful for linkbuilding. It's worked great for over two dozen sites, but for one site -- just one -- it keeps on coming back blank, but only when I try to insert it in an XML feed (I'm building the feed in the codebehind and then just Response.Writing it). Any ideas why it'd blank out then and only then? It's baffling me. This is all in c# .NET if that helps.

Kronikle
Jan 31, 2005

yeah well that's just like your opinion, man
I work for a company that is developing a web application that tests grade school students in preparation for standardized tests. One of the tasks in our program is basically a spelling test. You click on a picture of an ear, and the student hears the word said twice and used once in a sentence. When the sound file of the word is finished playing, a text box opens up, and the student can type in the word and press the Done button to submit their answer.

Our problem comes with web browsers using automatic spell checkers, particularly Safari. Our company works for the state, so this application is going to be distributed to thousands of schools. We cannot individually disable spell check on every computer, so I think the solution will have to be within our code.

We had what we thought was the solution by capitalizing every letter a student typed so Safari thought the word was an acronym, thus wouldn't spell check, but it only worked for words 6 characters or less. The application is being developed in ASP/.Net. Any possible suggestions I can pass onto the developers?

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
It sounds like you're making a regular website. If you are, then you can't prevent this. Maybe you want to develop a first class application that uses the webkit engine and points to a private website that can only be accessed by this user agent. While making the application, you could have the ability to turn off spell checking hooks.

That or look up an enterprise way to manage Macs and turn off spell check and the ability to toggle spell check.

Standish
May 21, 2001

Kronikle posted:

Any possible suggestions I can pass onto the developers?
Make your <input> 100% transparent and put a <div> behind it that you append the user's keystrokes to?

Kronikle
Jan 31, 2005

yeah well that's just like your opinion, man

Standish posted:

Make your <input> 100% transparent and put a <div> behind it that you append the user's keystrokes to?

This definitely sounds like the ideal solution. The way I think you're describing it is:

Basically, the student will be typing into a text box, but you're not actually seeing the contents of what the student is typing since it's 100% transparent. You're actually seeing the output of the <div> tag that is catching keystrokes and displaying them back.

Am I correct, or did you mean something else?

Standish
May 21, 2001

Kronikle posted:

This definitely sounds like the ideal solution. The way I think you're describing it is:

Basically, the student will be typing into a text box, but you're not actually seeing the contents of what the student is typing since it's 100% transparent. You're actually seeing the output of the <div> tag that is catching keystrokes and displaying them back.
yes, this article describes applying this trick to style <input type=file>s.

Eddie the Head
Jul 18, 2008
I'm writing a program in MIPS and I'm having a problem formatting output.

More specifically, I need to take an integer and put a decimal to the left of the the right-most character. (ie: the integer stored in the register is 2003 and I need it to print 200.3 ) How do I get the output to format like that?

Hopefully somebody can help me out with this.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Triple Tech posted:

It sounds like you're making a regular website. If you are, then you can't prevent this.

Yes you can, though it's browser-specific and I don't remember the details. But I've done it before.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

DRO posted:

I'm writing a program in MIPS and I'm having a problem formatting output.

More specifically, I need to take an integer and put a decimal to the left of the the right-most character. (ie: the integer stored in the register is 2003 and I need it to print 200.3 ) How do I get the output to format like that?

Hopefully somebody can help me out with this.
I assume you mean MIPS assembly? OK, here's a hint: if you perform integer division on 2003 by 10, what do you get? How can you use this to print the rest of "200.3"?

(Also this sounds suspiciously like part of a homework problem.)

Eddie the Head
Jul 18, 2008

Dijkstracula posted:

I assume you mean MIPS assembly? OK, here's a hint: if you perform integer division on 2003 by 10, what do you get? How can you use this to print the rest of "200.3"?

(Also this sounds suspiciously like part of a homework problem.)

Why the hell didn't I think of that?


Thanks for your help.

Eddie the Head fucked around with this message at 20:23 on Jul 23, 2009

Kronikle
Jan 31, 2005

yeah well that's just like your opinion, man

Standish posted:

yes, this article describes applying this trick to style <input type=file>s.

Thanks! The developers seemed happy with this solution.

yippee cahier
Mar 28, 2005

DRO posted:

Why the hell didn't I think of that?


Thanks for your help.

If you're thinking of doing a few more arithmetic operations, it looks like there's another way as well.

Eddie the Head
Jul 18, 2008

sund posted:

If you're thinking of doing a few more arithmetic operations, it looks like there's another way as well.

I've already got the code working, but I would love to hear other ways for the sake of learning.

yippee cahier
Mar 28, 2005

DRO posted:

I've already got the code working, but I would love to hear other ways for the sake of learning.

Just making sure that you didn't do x-((x/10)*10) to get the decimal place. I'm not familiar with MIPS assembly, but by a quick google search it looks like the divide instruction performs a modulo operation as well, so you only have to do a single math instruction.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

sund posted:

Just making sure that you didn't do x-((x/10)*10) to get the decimal place. I'm not familiar with MIPS assembly, but by a quick google search it looks like the divide instruction performs a modulo operation as well, so you only have to do a single math instruction.
Well, it's assembly, so you can't nest operations like that anyway. But yes, division also storing the remainder sounds right (it's been a few years since my assembly classes)

hrH
Jul 10, 2004

You are the unicorn to my elven wizard.
This is a mathematica question, so I hope it'll fly here...

I have a function F(X,Y,Z). I'm trying to find the value of X as a function of Y and Z that maximizes F(). I'm not having any success in mathematica, which I'm very inexperienced with. Can anyone give me a hand?

BigRedDot
Mar 6, 2008

hrH posted:

This is a mathematica question, so I hope it'll fly here...

I have a function F(X,Y,Z). I'm trying to find the value of X as a function of Y and Z that maximizes F(). I'm not having any success in mathematica, which I'm very inexperienced with. Can anyone give me a hand?

FindMinimum or NMinize might do what you want, with all the usual caveats about global optimizations. If F is really just a function of y and z then you should optimize it expressed in terms of only y and z and then compute x(y,z) afterward with the y_min and z_min result. Of course then it's not truly "f(x,y,z,)" so it might help if you were more specific.

hrH
Jul 10, 2004

You are the unicorn to my elven wizard.
I'm trying to find the value of s to maximize black scholes gamma, as follows
code:
Gamma = N(d1)/(s*v*sqrt(t))

where:
N() is the standard normal probability density function, and
d1 = [log(s/x)+(r+v^2/2)*t]/(v*sqrt(t))
Does that make it clearer? You can't really rewrite Gamma without s, but I know that there is a maximum where
code:
s=x*e^(-3v^2/2)*t
And I want to be able to find that on my own, as well as other maxima.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!
EDIT: Oops, in my defense, it's been at least 5 years since I've had to think about Calculus. Not that that is really much of a defense. I knew I should have thought a little harder.

hrH posted:

This is a mathematica question, so I hope it'll fly here...

I have a function F(X,Y,Z). I'm trying to find the value of X as a function of Y and Z that maximizes F(). I'm not having any success in mathematica, which I'm very inexperienced with. Can anyone give me a hand?
I don't know about mathematica, but in general, to find max/minima, solve for the second first derivative equal to zero, then do whatever else Avenging Dentist says to see if it is a maximum, minimum, or not interesting.

hrH posted:

I'm trying to find the value of s to maximize black scholes gamma, as follows
code:
Gamma = N(d1)/(s*v*sqrt(t))

where:
N() is the standard normal probability density function, and
d1 = [log(s/x)+(r+v^2/2)*t]/(v*sqrt(t))
Does that make it clearer? You can't really rewrite Gamma without s, but I know that there is a maximum where
code:
s=x*e^(-3v^2/2)*t
And I want to be able to find that on my own, as well as other maxima.
In this case you take the second first partial derivative with respect to s, set that equal to zero, and solve for s.

Jethro fucked around with this message at 17:35 on Jul 28, 2009

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Jethro posted:

I don't know about mathematica, but in general, to find max/minima, solve for the second derivative equal to zero.

This is so very wrong.

Edit to be helpful (I guess): Points where the second derivative is zero are called inflection points, and are generally unhelpful for determining the local extrema of a function. Using the second derivative test, you 1) find all points such that f'(x) = 0 (i.e. critical points in a differentiable function), and 2) observe the second derivative. If f''(x) > 0, the point is a minimum, else if f''(x) < 0, the point is a maximum, else you know nothing.

This is all beside the point though, since Mathematica has a Maximize function.

Avenging Dentist fucked around with this message at 16:59 on Jul 28, 2009

HiredGoon
Dec 30, 2005
Hey guys,

I'm sure this is a deathly simple question, but I really appreciate the advice!


I'm building a website on a Tumblr platform, and the last piece of the puzzle for me is truncating longer posts. Tumblr doesn't really allow you to add a 'jump' or a 'break' or a 'read more' kind of thing (as far as I have looked) and I wanted to find a way to include longer, wordier posts without disrupting the rest of the content. I figure CSS is the best way to do this.

I've found this code for truncating posts after a set amount of characters, but it's not doing anything after I paste it into the custom CSS:

code:
<script type="text/javascript">
function truncate() {
  var len = 10;
  var p = document.getElementById('truncateMe');
  if (p) {
    var trunc = p.innerHTML;
    if (trunc.length > len) {

     
      trunc = trunc.substring(0, len);
      trunc = trunc.replace(/w+$/, '');

     
      trunc += '<a href="#" ' +
        'onclick="this.parentNode.innerHTML=' +
        'unescape(''+escape(p.innerHTML)+'');return false;">' +
        '<span style="font-size: 10px;">[ more ... ]</span></a>';
      p.innerHTML = trunc;
    }
  }
}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  truncate();
});
</script>
I also found this guide to adding a 'read more' thing – http://groups.google.com/group/blogger-help-howdoi/browse_frm/thread/fae3eb826955e5a5 – is it Tumblr compatible?


Thanks in advance for any help!

Contero
Mar 28, 2004

Has anyone tried making anything interesting in Rhino? I mean like a javascript-only app. I'm thinking of starting something simple but it seems a bit strange that package and inheritance rules are passed in as command line options and not parsed from the file in some way.

Is there some way to get around this aside from writing my own script that parses the first line for a comment containing package and inheritance info?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Contero posted:

Is there some way to get around this aside from writing my own script that parses the first line for a comment containing package and inheritance info?

I hope you aren't trying to use OO inheritance in Javascript, since that kinda defeats the point of using Javascript to begin with.

Contero
Mar 28, 2004

Avenging Dentist posted:

I hope you aren't trying to use OO inheritance in Javascript, since that kinda defeats the point of using Javascript to begin with.

Actually I forgot you can make objects that "inherit" from Java classes like t = new java.lang.Thread(r) (where r is some js object that has the appropriate methods).

So there's not much point to the command line options for inheritance then?

hrH
Jul 10, 2004

You are the unicorn to my elven wizard.

Avenging Dentist posted:

This is so very wrong.

Edit to be helpful (I guess): Points where the second derivative is zero are called inflection points, and are generally unhelpful for determining the local extrema of a function. Using the second derivative test, you 1) find all points such that f'(x) = 0 (i.e. critical points in a differentiable function), and 2) observe the second derivative. If f''(x) > 0, the point is a minimum, else if f''(x) < 0, the point is a maximum, else you know nothing.

This is all beside the point though, since Mathematica has a Maximize function.

With all due respect, none of what the two of you wrote is news to me. My question is more about Mathematica and how to use it. Taking dGamma/dS by hand is annoying, and I want to find local maxima for a variety of Greeks using the same method once I find what works in Mathematica. For some reason, entering Maximize[Gamma[(variables)], S] doesn't do the trick. Is there something I'm missing?

BigRedDot
Mar 6, 2008

hrH posted:

With all due respect, none of what the two of you wrote is news to me. My question is more about Mathematica and how to use it. Taking dGamma/dS by hand is annoying, and I want to find local maxima for a variety of Greeks using the same method once I find what works in Mathematica. For some reason, entering Maximize[Gamma[(variables)], S] doesn't do the trick. Is there something I'm missing?
Global optimization can difficult and subtle, even in the 1-D case? Also I doubt even Mathematica will be able to do much with that purely symbolically, will a numeric answer do? You'd probably have better success with NMaximize, though it may may only find a local extrema for you ("difficult and subtle"). Or you could try simulated annealing, there's a C library for that called ASA that's proved useful. Anyway... the greeks? I can't believe what you are looking for hasn't already been covered in a hundred different financial journal articles. Maybe a trip to the stacks would be the most efficient solution.

hrH
Jul 10, 2004

You are the unicorn to my elven wizard.

BigRedDot posted:

Global optimization can difficult and subtle, even in the 1-D case? Also I doubt even Mathematica will be able to do much with that purely symbolically, will a numeric answer do? You'd probably have better success with NMaximize, though it may may only find a local extrema for you ("difficult and subtle"). Or you could try simulated annealing, there's a C library for that called ASA that's proved useful. Anyway... the greeks? I can't believe what you are looking for hasn't already been covered in a hundred different financial journal articles. Maybe a trip to the stacks would be the most efficient solution.

You're right, of course it's been covered by people who can partially differentiate circles around me. The reason I'm doing this is because of the formula for maximum gamma described by Haug here on page 5, where he mentions deriving it via mathematica. Believe me, trying to set speed (dgamma/dspot) equal to zero is a pain, and I figure that if he can do it in a couple of minutes using mathematica for this problem it would be useful to know how to do it for other similar ones.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
A graph layout / graphics type problem: I've written some code to draw phylogenetic trees, but I developed it from first principles, it's subpar and I'd like some pointers to decent prior art or algorithms.

In more detail: so a phylogeny is a evolutionary family tree. And I need to draw them, lots of them. In theory this should be easy. A phylogeny is a tree, which is a connected, directed, acyclic graph and there are oodles of packages and algorithms for doing layout and drawing of those, right? But:

1. A branch on a phylogeny represents time between events and so "longer" branches have to be drawn as longer. Almost all graph layout and drawing algorithms treat all branches as being of the same length and draw them accordingly.

2. What prior art / code out there seems to be of very poor quality. It works but extracting the general algorithm is near impossible. I haven't been able to find a general descriptions of drawing graphs with fixed relative branch lengths.

So, any pointers? Obviously literature would be best, as well as anything that directly refers to phylogenies, but if there is are algorithms or decent code for the right sort of graph, that would be great too.

Daedleh
Aug 25, 2008

What shall we do with a catnipped kitty?
I don't have search so I don't know if this has come up, but I've read a few comments in threads that Select...Case statements are bad. Why? If I have a variable and I need to test if it's a range of different values then why is it so much better to use a bunch of continuous If...Else statements when I find Select Case statements so much easier to read?

To give an example, I have a treeview control in VB.net. Each node has a different tag which says what type of node it is. Each type of node requires a different set of controls to be shown so in my trvStructure_AfterSelect I have this:
code:
ClearPanels 'Sub which hides all control panels
Select Case trvStructure.SelectedNode.Tag
     Case "NodeType1"
          pnlNodeType1.Show()
          pnlNodeType1.BringToFront()
     Case "NodeType2"
          pnlNodeType2.Show()
          pnlNodeType2.BringToFront()
End Select
I have 9 different node types to get through.

Daedleh fucked around with this message at 20:13 on Jul 31, 2009

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
I think they're bad in that in larger programs they're often indicative of poor, unscalable design. If you're just writing some small program for class or a one-off, it doesn't matter.

Scaevolus
Apr 16, 2007

outlier posted:

So, any pointers? Obviously literature would be best, as well as anything that directly refers to phylogenies, but if there is are algorithms or decent code for the right sort of graph, that would be great too.

You've already considered graphviz, right? This is based on it and seems to do what you want.

1337JiveTurkey
Feb 17, 2005

Daedleh posted:

I don't have search so I don't know if this has come up, but I've read a few comments in threads that Select...Case statements are bad. Why? If I have a variable and I need to test if it's a range of different values then why is it so much better to use a bunch of continuous If...Else statements when I find Select Case statements so much easier to read?

Chained if statements aren't that much different from case statements, you're correct. From an OOP perspective though, what you're doing is basically polymorphism the hard way. Each tag corresponds to a different subclass of the base Node object. The different switch blocks each correspond to a different method/function, the default case would be the base Node's implementation and the rest of the cases are different overriding implementations.

This keeps all of the individual nodes' behaviors together, so adding a new node type or changing the behavior of BringToFront() or Show() for an individual node type doesn't require hunting throughout the code for every switch block.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

Scaevolus posted:

You've already considered graphviz, right? This is based on it and seems to do what you want.

Doesn't do different edge lengths for different branch lengths, which is the critical property I'm looking for.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

outlier posted:

A graph layout / graphics type problem: I've written some code to draw phylogenetic trees, but I developed it from first principles, it's subpar and I'd like some pointers to decent prior art or algorithms.

Here are two programs for phylogeny viz I've seen others using.

http://www.phylowidget.org/
http://loco.biosci.arizona.edu/paloverde/paloverde.html

nbv4
Aug 21, 2002

by Duchess Gummybuns
A long time ago I read about this method where you can store many boolean values as an integer value by multiplying a bunch of prime numbers together. Does anyone know what this method is called? For instance if you want to store

a=true
b=false
c=false
d=true
e=true

you go:

a=2
b=3
c=5
d=7
e=11

a * d * e = 2 * 7 * 11 = 154

then to go back to booleans, you factor the number and get:

2*7*11 which correlates to a=true, d=true, e=true

Whats this method called?

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

I don't know the name of such a thing, but why on earth would you want to use that instead of a bit field? Suddenly extracting values becomes Hard-With-A-Capitol-H rather than a simple mask and shift.

Dijkstracula fucked around with this message at 18:50 on Aug 1, 2009

Adbot
ADBOT LOVES YOU

baquerd
Jul 2, 2007

by FactsAreUseless

Dijkstracula posted:

I don't know the name of such a thing, but why on earth would you want to use that instead of a bit field? Suddenly extracting values becomes Hard-With-A-Capitol-H rather than a simple mask and shift.

If you make the prime numbers large enough, you could have a new crypto algorithm to play with.

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