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.
 
  • Locked thread
~Coxy
Dec 9, 2003

R.I.P. Inter-OS Sass - b.2000AD d.2003AD
Yeah, SO has its issues but is pretty good overall and much better than the help sites it replaces.

(Why does MS even bother to keep pumping half-baked features into MSDN)

Adbot
ADBOT LOVES YOU

Mr SuperAwesome
Apr 6, 2011

im from the bad post police, and i'm afraid i have bad news
i find with SO you either get an answer from some nerdlord who refresehs it 24/7 but gives you a hella awesome complete answer or your question gets permanently negleted for ever


if its not answered in 20 mins then welp

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

Mr SuperAwesome posted:

i find with SO you either get an answer from some nerdlord who refresehs it 24/7 but gives you a hella awesome complete answer or your question gets permanently negleted for ever


if its not answered in 20 mins then welp

my homepage is the unanswered questions tab of my specialization for exactly this reason :shobon:

Usagi-Sauce
Dec 2, 2005

YAMOxNINJA
~otp~
i just took a programming test for a job w/ amazon and i could only find an O(N^2) solution for a problem that was supposed to be O(N log N) so I guess I belong in this thread

hi everyone I am not very good at algorithms I guess

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

Usagi-Sauce posted:

i just took a programming test for a job w/ amazon and i could only find an O(N^2) solution for a problem that was supposed to be O(N log N) so I guess I belong in this thread

hi everyone I am not very good at algorithms I guess

what was the problem

Usagi-Sauce
Dec 2, 2005

YAMOxNINJA
~otp~

coffeetable posted:

what was the problem

count all zero-sum slices in an array of ints

i was like "drat why didn't i listen when they tried to teach me about dijkstra in class"

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

Usagi-Sauce posted:

count all zero-sum slices in an array of ints

i was like "drat why didn't i listen when they tried to teach me about dijkstra in class"

aight, so the obvious solution is to find the sum S(i,j) every slice [i, j] in the array, and see which ones sum to zero. that's yr O(n^2) O(n^3).

next, look at the obvious solution and go "how is this wasteful?". well the obvious way is that it does a whole pile more summing than it needs to. instead, we could calculate the sum S(i) = S(0, i) once for each i, and calculate S(i, j) as S(j) - S(i).

oh cool. so S(i, j) == 0 exactly when S(i) == S(j). so now we have a different problem: in an array of integers, how many unordered matching pairs are there?

well that's easy. sort them and count!

e: something that threw me for a loop while thinking this through was going "am i sure there's a subquadratic solution?". looking for counterexamples, the obvious one is the array of all zeros, which has O(n^2) zero-sum slices. which meant any subquadratic algorithm couldn't just count each slice individually, and that pushed me away from "for each i, consider a lg(n)-sized subset of js" kinda algorithms.

coffeetable fucked around with this message at 14:52 on Nov 24, 2013

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY
it's kinda extraneous here, but i like this checklist from the Algorithm Design Manual:

1. Does brute force work?
2. Does it have an ordering?
3. Would sorting help?
4. Is approximation easier?
5. Does it have subproblems?
6. How does trivializing/ignoring parameters simplify things?
7. Have you followed Polya?

note: if you haven't read Polya's How to Solve It, welp

coffeetable fucked around with this message at 14:48 on Nov 24, 2013

Usagi-Sauce
Dec 2, 2005

YAMOxNINJA
~otp~
pretty sure the brute-force solution is O(N^3) but yeah I read that and screamed at myself just a little

my O(N^2) solution was already going in the right direction too ughhh

Usagi-Sauce
Dec 2, 2005

YAMOxNINJA
~otp~

coffeetable posted:

note: if you haven't read Polya's How to Solve It, welp

lookin dis up

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

Usagi-Sauce posted:

pretty sure the brute-force solution is O(N^3)

yup, whoops

rzeszowianin 44
Feb 21, 2006

uG posted:

perl 5 has copied lots of ruby poo poo but better (its not ruby for one). it will also have a mop in a year or two. for hipsters who use ruby because its a fad there will be perl 6

I would like to know more what perl 5 has borged from ruby.

rzeszowianin 44 fucked around with this message at 19:13 on Nov 29, 2013

Elder Postsman
Aug 30, 2000


i used hot bot to search for "teens"

hey was it in this thread that a yosposter used beautifulsoup to scrape the music thread for youtubes. (hubris.height maybe????)

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
yes

qntm
Jun 17, 2009

coffeetable posted:

it's kinda extraneous here, but i like this checklist from the Algorithm Design Manual:

1. Does brute force work?

does brute force ever not work? and by "not work" i mean "never finds the solution" not "runs in O(n^^n) time"

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

qntm posted:

does brute force ever not work? and by "not work" i mean "never finds the solution" not "runs in O(n^^n) time"

find the minimum of (x-pi)^2 :v:

the obvious application of brute force - try all values of x - wouldn't work, but if you picked your search space correctly it would. that's what the "does brute force work?" thing is meant to get you to think about

e: missed the obvious one: "does this program halt?"

coffeetable fucked around with this message at 13:59 on Nov 28, 2013

Elder Postsman
Aug 30, 2000


i used hot bot to search for "teens"


cool, thanks

Impromptu Flip
Aug 30, 2008
how do you override the behaviour of the window's top right x button in wpf/mvvm? i need to nicely close some things down before the window closes.

i've tried using an interaction trigger and some other stuff, but i can't seem to get it doing what i want. i don't want to override OnClosing and do the validation in the view code-behind as in example code I've read because while im not a sperg about Design Pattern Compliance, the validation involves cleaning up domain stuff in the model and id rather keep that in the viewmodel. i have gotten my existing OnRequestClose event to fire in the view model from pressing the x but i get an exception in my window close code saying it can't do it while the window is closing. so it seems it's just firing the original closing event even though im intercepting it and cancelling it?

i don't know how to approach this. help me yospos.

(paging shaggar)

bobbilljim
May 29, 2013

this christmas feels like the very first christmas to me
:shittydog::shittydog::shittydog:
pity me for I am bitbanging in Java

Shaggar
Apr 26, 2006

Impromptu Flip posted:

how do you override the behaviour of the window's top right x button in wpf/mvvm? i need to nicely close some things down before the window closes.

i've tried using an interaction trigger and some other stuff, but i can't seem to get it doing what i want. i don't want to override OnClosing and do the validation in the view code-behind as in example code I've read because while im not a sperg about Design Pattern Compliance, the validation involves cleaning up domain stuff in the model and id rather keep that in the viewmodel. i have gotten my existing OnRequestClose event to fire in the view model from pressing the x but i get an exception in my window close code saying it can't do it while the window is closing. so it seems it's just firing the original closing event even though im intercepting it and cancelling it?

i don't know how to approach this. help me yospos.

(paging shaggar)

It depends on a few things like what you're trying to clean up and if you're trying to clean it up cause the application is closing or cause the window is closing.

If you are worried about database connections, you may be overthinking something or maybe doing it wrong. with ADO.net it will manage connections in a pool based on connection strings behind the scenes so you can just grab a connection w/ the using syntax and let it be disposed automatically. depending on your pool configuration when Dispose() is called it will either close the connection immediately or leave it around until its needed again. Either way your code doesn't care. It will automatically clean itself up and close all open connections in the pool upon termination of the application.

if you have other stuff, like maybe a running thread that you want to wait to terminate, then you have a few options.
The first and easiest is to just add a destructor to your viewmodel with the cleanup code. If your application is a single window application the viewmodel is gonna get destroyed on close so its safe to do cleanup in the destructor. There are edge cases where this might not be what you want, but w/e.

The second is to do what you're currently trying and attach to an event on the window. Window has 2 events related to closing that you can bind delegates to. Closing and Closed. Closing happens when the window is closing for whatever reason and gives you the opportunity to cancel the close. This is useful for cases where the window is a form with data thats been changed by the user but not saved. You can use Closing to test to see if the data needs to be saved and ask the user if they want to save/cancel/quit. Closed is for after the window is closed and gives to the opportunity to clean up any mess within the window object (like ur viewmodel). Create a cleanup method in your view model and call it from a delegate thats attached to closed on your window.

Create a method like this in ur window
C# code:
private void Window_Closed(object sender, EventArgs e)
{
	var viewModel = ...;
	viewModel.cleanup();
}
Then add the event handling method to the Closed event either in code like this:
C# code:
public MainWindow()
{
	InitializeComponent();
	//blah blah whatever other dumb crap
	Closed += Window_Closed;

}
or bind it in xaml
XML code:
<Window x:Class="BonerTown.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:src="clr-namespace:BonerTown"
        Title="Where the boners live" Height="350" Width="600" 
        Closed="Window_Closed">
Then when the window closes, the Window_Closed method in the window codebehind will be called which will call your viewmodel.cleanup() method;

Tho really make sure you aren't just making this harder than it should be.

zokie
Feb 13, 2006

Out of many, Sweden
I've had problems with stuff like that, in the end I made my own custom window were I had better control over the closing... but that occasionally semi-breaks the adorner layer :-(

~Coxy
Dec 9, 2003

R.I.P. Inter-OS Sass - b.2000AD d.2003AD
shaggar was right

X-BUM-RAIDER-X
May 7, 2008

~Coxy posted:

shaggar was right

Shaggar
Apr 26, 2006
for reals tho make sure you're just wrapping you're idisposables in using and if its a thread that doesnt matter just let it die w/ the application. I don't have anything too complex but i have a wpf app for doing some word automation and the word/com processes/handles are the only thing i have to clean up manually and that's the edgiest of edge cases.

X-BUM-RAIDER-X
May 7, 2008
a corner case, if you will

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Shaggar posted:

for reals tho make sure you're just wrapping you're idisposables in using and if its a thread that doesnt matter just let it die w/ the application.

yeah this should usually be your strategy

if you need to free up a resource on another machine when your gui app is closed, what are you doing with the gui app loses a network conncetion or power?

if you're dealing with hardware and moving parts, glhf glad i'm not part of it

Impromptu Flip
Aug 30, 2008

Shaggar posted:

wpf words

i might have been able to get away with using a destructor but i did it binding to the window closing event. actually that was my original approach but somehow it didn't work, i used a dependency property bound to the closing event (if that makes sense - i can't remember now) and that did the trick.

i could probably have just left it and not cleaned up but I'm not familiar enough w/ the system to do that at this stage, and it'll get used on production servers where losing data is a Big Deal and I'm being overly cautious with it being my first prog

thanks for your comprehensive answers tho. shagger was right, wpf+xaml owns so far, writing xaml is so easy and bindings and commands are awesome

Shaggar
Apr 26, 2006
hey so Im doing some web "development" with knocked out js and I have some questions. I am trying to make what are essentially some standalone pages that get content from a rest. I want to be able to host the pages as static content instead of needing an application server.

The first page is basically a search page w/ options populated from the REST service. What I'm trying to figure out is whats the best way to handle the actual query for the results. Normally I'd just do a post to an application page which would generate the content based on the post variables, but since this is all in js I cant really do that. I could do a get and then use javascript to parse out the paramters and then use those to get the page model (search results) from the REST service. That seems kind of dumb but it is javascript so is that the right way?


Is there another way to pass data from one page to another without using a server to store it? (also this has to work on ie8 so i think that means html5 local storage is out)

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
i dont really understand what you mean by "Is there another way to pass data from one page to another without using a server to store it?" but that's probably my fault

anyhow the way you usually pass data in web javascript is the X in ajax (ie xml ie json)

Greed is eternal
Jun 8, 2008
I'm not sure exactly what you mean, but I think you want AJAX.

Doing it with jQuery is extremely easy.

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

Shaggar posted:

Is there another way to pass data from one page to another without using a server to store it? (also this has to work on ie8 so i think that means html5 local storage is out)

hidden form fields?

Zaxxon
Feb 14, 2004

Wir Tanzen Mekanik

Shaggar posted:

Normally I'd just do a post to an application page which would generate the content based on the post variables, but since this is all in js I cant really do that.

you can do posts in js

Greed is eternal
Jun 8, 2008
I did a simple AJAX search site when applying for a job. (I didn't get it)
It might be something you can salvage https://github.com/neural99/searchapp

Shaggar
Apr 26, 2006

USSMICHELLEBACHMAN posted:

i dont really understand what you mean by "Is there another way to pass data from one page to another without using a server to store it?" but that's probably my fault

anyhow the way you usually pass data in web javascript is the X in ajax (ie xml ie json)

index.html has a form where the user enters some data.

I want results.html to display the items matching the data they entered in the form.

The way i'd like to do it is somehow when results.html loads the data is json coming from a rest service where the url contains the parameters from the form on the first page.

Basically how do i make the parameters from the form on the first page available to the second page?

Traditionally you would post the form to a jsp or a asp or whatever and it would build the REST url for the results data, but I want to do it w/out the server.

I guess one way would be to stay on the same page and use ajax to pull in the new data and display it below the search form, but that's not what I really want.

Nomnom Cookie
Aug 30, 2009



Shaggar posted:

I guess one way would be to stay on the same page and use ajax to pull in the new data and display it below the search form, but that's not what I really want.

this is what you should do, stop :spergin: and git-r-done

Shaggar
Apr 26, 2006

Greed is eternal posted:

I did a simple AJAX search site when applying for a job. (I didn't get it)
It might be something you can salvage https://github.com/neural99/searchapp

yeah that's all one page and i think that might be the way i suggest we do it. This is really supposed to be for a demo for how other people can use this rest api and i wanted to do the non-REST stuff in pure html/js that they could just straight up steal and rebrand if they wanted to without needing a specific application server.

Shaggar
Apr 26, 2006

Nomnom Cookie posted:

this is what you should do, stop :spergin: and git-r-done

well one thing is that it would be nice if the resulting query is shareable by url. that would really be the only thing i'd lose by doing it all in one page.

Tiny Bug Child
Sep 11, 2004

Avoid Symmetry, Allow Complexity, Introduce Terror
you can use history.pushState() to manipulate the url and put your query in it. then when you do a fresh page load you can also check to see if the url says you should do a query

Nomnom Cookie
Aug 30, 2009



Tiny Bug Child posted:

you can use history.pushState() to manipulate the url and put your query in it. then when you do a fresh page load you can also check to see if the url says you should do a query

or if you need to support ie8 or smth do the old-timey way and use the fragment identifier

Adbot
ADBOT LOVES YOU

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal

Shaggar posted:

hey so Im doing some web "development" with knocked out js and I have some questions. I am trying to make what are essentially some standalone pages that get content from a rest. I want to be able to host the pages as static content instead of needing an application server.

The first page is basically a search page w/ options populated from the REST service. What I'm trying to figure out is whats the best way to handle the actual query for the results. Normally I'd just do a post to an application page which would generate the content based on the post variables, but since this is all in js I cant really do that. I could do a get and then use javascript to parse out the paramters and then use those to get the page model (search results) from the REST service. That seems kind of dumb but it is javascript so is that the right way?


Is there another way to pass data from one page to another without using a server to store it? (also this has to work on ie8 so i think that means html5 local storage is out)

http://www.jstorage.info/
That's for jquery but it apparently works back to IE6 so maybe you could look and see if how it uses userData will work for you?

  • Locked thread