Posts

Showing posts from March 17, 2019

Having a decrement (-=) function stop at 0 in Ruby

Image
1 I have the following line of code which very simply decrements a Shareholders number of stocks (integer in the DB) when they sell them to someone else. This works well and as expected. @selling_shareholder.update_attribute(:number_of_stocks, @selling_shareholder.number_of_stocks -= @transaction.number_of_stocks) Very simply what I'd like to do is have the decrement function stop when the number_of_stocks hits 0 i.e. having a negative number should not be possible. I guess I could use a simple unless @selling_shareholder.number_of_stocks > 0 at the end of the line, but I'm wondering if that will actually work without using a loop? ruby-on-rails ruby share | improve this question asked Nov 14 '18 at 18:09 JP89 JP89 104 1 8 2 Riddle me this. How can one have a transaction with a number_of_stocks in excess of their number_of_stocks ? This seems like a simple validation validates :number_of_stocks, numericality: gre

Program escalates itself from admin to system

Image
0 I wrote a program that needs to be running as SYSTEM. I add the linker option 'UAC Execution Level' to 'requireAdministrator' and it pops the UAC like it should but now I need to escalate from admin to SYSTEM how can I do that? I thought about opening the program's token and inject it the SYSTEM token but it is not legit way. How can I do it neatly because I know once you admin you can be SYSTEM. c windows winapi elevated-privileges share | improve this question asked Nov 14 '18 at 18:09 user3725519 user3725519 20 5 1 Run it as a service under the local system account. Of course, one wonders why you feel the need to do this at all. – David Heffernan Nov 14 '18 at 18:18 you can get token from system process or impersonate system thread, if you have debug privileges. and impersonate some your thread(s) with this system token, when you need do some task as LocalSystem . and anyway - what co