Simplify nested if/else with repeated results?

You could check with the result of the first check. This is an exclusive OR check. // typeof inverse === ‘boolean’ function handleDirection(src) { if (src === ‘left’ === inverse) { tracker–; } else { tracker++; } } The check evaluates the expression in this order (src === ‘left’) === inverse: src === ‘left’ === … Read more

Replace conditional with polymorphism – nice in theory but not practical

You’re right – “the conditionals are getting pushed up to the top of the chain” – but there’s no “just” about it. It’s very powerful. As @thkala says, you just make the choice once; from there on out, the object knows how to go about its business. The approach you describe – BaseAction, ViewAction, and … Read more

Using conditional statements inside ‘expect’

Have to recomment the Exploring Expect book for all expect programmers — invaluable. I’ve rewritten your code: (untested) proc login {user pass} { expect “login:” send “$user\r” expect “password:” send “$pass\r” } set username spongebob set passwords {squarepants rhombuspants} set index 0 spawn telnet 192.168.40.100 login $username [lindex $passwords $index] expect { “login incorrect” { … Read more

Greater Than Condition in Linq Join

You can’t do that with a LINQ joins – LINQ only supports equijoins. However, you can do this: var query = from e in entity.M_Employee from p in entity.M_Position where e.PostionId >= p.PositionId select p; Or a slightly alternative but equivalent approach: var query = entity.M_Employee .SelectMany(e => entity.M_Position .Where(p => e.PostionId >= p.PositionId));

replace zeroes in numpy array with the median value

This solution takes advantage of numpy.median: import numpy as np foo_array = [38,26,14,55,31,0,15,8,0,0,0,18,40,27,3,19,0,49,29,21,5,38,29,17,16] foo = np.array(foo_array) # Compute the median of the non-zero elements m = np.median(foo[foo > 0]) # Assign the median to the zero elements foo[foo == 0] = m Just a note of caution, the median for your array (with no zeroes) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)