« first day (1827 days earlier)      last day (2322 days later) » 

9:58 AM
morning all
 
10:19 AM
ok, c# question really but anyways... I'm running a Stopwatch, is there anyway to stop stopwatch during debugger pause? like is there a event when the debugger pauses (where I can stop the stopwatch)?
 
10:54 AM
Hi all
 
hi you
 
Hey Markus
 
 
2 hours later…
12:51 PM
In a wpf app, I'm getting about 800 image names from a feed, then I fetch the images into an ObservableCollection that is bound to a ListView
Now I need to filter the images based on departments stored on a SQL db
Each image name is stored with an associated department on a table
What's the most efficient way to do the filtering? When I come in, I'm already doing a foreach on the images to add them to the OC
Should I look up each image on the db to get its dept in the loop or from a local collection that already has all the data?
Back in about 30 mins.
 
Show codez :)
 
Hey Maverik
That would help, wouldn't it? :)
Give me a little time and will do that and let you know
 
just need to see your loop bits.. from the point you get images to the point you filter them out (i'm assuming you have some form of implementation already and just need it optimised)
in general terms: do as much filtering on sql side as possible before loading anything
 
1:53 PM
Here's my plan... fetch all the image-dept data into a List; in loop, set each item's Dept code by doing an in-memory search against the List from db
Then when user selects dept from dropdown, filter OC on that
 
2:20 PM
Sorry Alex - just saw these replies.. checking now..
 
TotalImages = "Total images: " + ImageCount;
 
Crystal reports the bane of my life (one of many actually) are consuming time & energy right now (asking for login in an integrated security model)
 
i like using string format in xaml to do that kind of stuff
avoids needing a separate property
 
Hated Crystal Reports when I had to use it... awful stuff
 
Curious: why are you using ArrayOfString type?
 
2:23 PM
It's a type provided by that silly web service we're using
A lot of that code comes from another dev
 
ah ok - i know where its coming from then
that's an artifact of ancient serialization
 
Oh, didn't know where it came from. This is an ancient wcf web service
 
yup thats what i thought
this is part of soap serialization
i thought you actually went ahead and subclassed array somehow
what does IsValidUrl do?
 
Overkill, that's what it does...
private static bool IsValidUri(string uri)
{
	Uri uriResult;
	return Uri.TryCreate(uri, UriKind.Absolute, out uriResult) && uriResult != null
		&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
}
 
ah ok.. i expected something of this sort :) I was just trying to be sure you're not cooking something up yourself for validation
TryCreate is the way to go if you have to do validation
now I don't see any sql filtering here ?
And yes Julien is right about doing the trivial stuff directly in xaml - VMs get bloated as it is with properties.. try to avoid trivial ones like Images.Count
also if you have to do it.. don't use assignments .. use get only properties
 
2:41 PM
Not done the filtering piece yet. Wanted to ensure the approach was sound
 
well without a rough sketch of how you're doing it, it's hard to say
mainly because I don't know the exact inputs
would be enough to filter on name ?
if so, I'd filter before baseUrl (right after you get it from server)
 
Right now adding EF to project and getting models generated. There are just three tables.
 
no no - what do you use as input for filter from VM side
 
Oh, it'll be name
 
yea in that case as i said - do it straight after you get it from server - in my revised gist, that'd be just before baseUrl
 
2:44 PM
Well, I'll have dept in the dropdown, so actually filtering on that
 
ok don't know - does my revised gist make sense?
if so, take it and build a filter on top as you see it working
 
user6501892
For some reason, my GridControl is not updating on Drag and Drop. I have a PropertyChanged on the ObservableCollection and on the property within the Collection but when I drag and drop, the properties aren't changed
 
Think so... gotta code it and may have questions
 
user6501892
Rather my TableView
 
Thank you, guys :)
 
2:47 PM
Alex copy paste it :P
i just converted your code to linq - i feel its cleaner and easier to read (assuming folks are comfortable reading linq expressions which i think you are)
 
Hehehe!
 
for loops take a lot more effort for random strangers to understand since we have to dry run it in our heads
 
Yeah, I love linq, though still a noob in so many ways
 
while expressions - you can figure out at a glance and get the gist of code much quicker
only one way to not feel noob.. use it!
especially when you paste for loops and i give you linq back.. question if you don't get why something got translated in what it is
 
Yup, code, code, code... debug the heck out of stuff.
 
2:49 PM
but here's the simple recipe: if you feel like doing foreach -- use .Select instead
 
OK. Now to refactor this baby...
 
if there's an if in the loop - use .Where instead
 
Ahh. Didn't think of it that way
 
the assumption behind both of these statements being your loop creates some eventual result for rest of program to use
 
Is linq more efficient?
 
2:50 PM
it can be
for example in the conversion I've done - there's no extra processing involved and no extra assignments
 
BTW, on a new Win 10 box...
 
a foreach loop will often have slightly more allocations (because of programmers logic flow + eager evaluation of everything)
 
Xeon cpu, 32gb ram, 4gig video, + ssd
 
grats :)
was longgggg time over overdue
 
Thanks. Running multiple VS's
 
2:52 PM
Arrayoob: not ignoring you.. but have no answer for you
 
It's fastest PC here... boss really went all out
 
lol i didn't think you swung that way :P
 
HP Z440 workstation
Hehehe!
 
thats.. overkill
but as a gesture.. its pretty big too :)
 
512GB SSD + 3TB HD
Yup, he knew my pain.
 
2:54 PM
nah none of that matters: 256GB ECC RAM support <-- that's the overkill
ECC and then 256GB expansion on top.. overkill^2
 
This is 32GB RAM, and already using a fair amount
 
yea thats what you may have installed - but the workstation supports expansion upto 256gb
has 8 DDR4 ECC DIMM slots
 
O.O
Wow
 
thus: this shit is beyond overkill! -- if you didn't swing earlier.. you definitely should now!
 
Not bad, but it's overkill.
:)
I loaded a VM w/ no issues... it had 8GB assigned to it
 
2:56 PM
its pretty expensive kit - not sure I'd get it approved if i asked for it (i wouldn't - not my type but ignore for the sake of argument)
despite being as pampered an employee as I am
I know most folks don't generally do this - but i upgrade my office kit with my own stuff (meant just for my office equipment) - so ECC is an instant no go (since it's much more expensive than regular ram)
RAM is typically my only bottleneck but @ 32GB I've yet to exhaust it
 
W/ your skills, if they don't approve it, something wrong.
 
(of course i could just make a 32gb RAMDisk and i'll instantly run out of ram.. but that doesn't count)
Well nah they don't pamper me based on my skill.. they're just cool like that in routine
 
Nice
 
frankly they don't comprehend my skill level at all :)
 
Boss also wants to get R# licenses for us
 
3:00 PM
the only measuring sticks they've had were pretty ... small? to begin with.. so all they know is I can do more than what they could
well R# is a solid investment - you're still working for that Non-profit right?
 
user6501892
What is the link again to share code?
 
gist.github.com
 
Do you go for R# Ultimate or just R#?
 
I have both - I'd say go for simple R# unless you're heavy on unit testing
Once our current subscription runs out I'll cancel the ultimate one
its an overkill in most circumstances and I can't justify its price
frankly these days I can't even justify r# itself even :D
but that's more a praise to R# for teaching me so much through its tips than a real complaint
 
$300/yr
 
user6501892
 
user6501892
And my problem is that it's not updating the Position when I do a drag and drop. The position should always just be 1, 2, 3, 4....n
 
user6501892
as in the index of the instance in the collection
 
Alex: that's ultimate or regular?
 
Regular
 
Sorry Arrayoob - that's not something I've dealt with before ever - and Alex & I appear to be only ones around right now
may be ask SO question?
 
3:15 PM
I'm around; but drag and drop isn't my specialty either
 
I don't see drag and drop in that code
 
there's that too indeed ^
but I'd rather not go down that rabbit hole :)
and to be blunt: I also prefer not to offer debugging service otherwise we quickly turn into a debugging channel
 
And it looks like you are using a 3rd party data grid anyways. I'd take it up with them
 
(exceptions made for channel residents of course)
 
total aside; indexes start at 0
 
3:20 PM
think that's why the +1 in his code :)
 
And he expects that to update on a drag and drop?
yeah... I don't think that's going to happen
 
I believe so
i suggested to open a question mainly because everything we've said would have been said in comments much more quickly anyway and would avoid me needing to be blunt about things :)
 
Arrayoob, for that to work you'd have to invoke that method (that iterates the whole collection :( ) every time a drag/drop completed.
 
a simple converter could have sorted it out I'd say
 
yeah, that's what I would have used
 
3:23 PM
but now we've started going down the rabbit hole.. STAHP Human
need a cat meme now
 
meow?
 
WpfFarmer.WaitForCatMeme();
 
Xamimax you know we have a script right? :D
 
@Maverik nope. What script?
 
we started doing it so frequently - i decided to write something for it
Alex has a fork of this that he uses to create his tumbleweeds I believe
 
3:28 PM
@Maverik Glorious! WpfFarmer.LetItSnow().Dump(); had me in tears LOL
 
:D
that was Christmas special :D
 
ha ha brilliant!
 
but i think the most fun i had was with creating random things by using ASCII art input
it needs a revision to be able to do more than one per line.. but i stopped at that point
 
Shame I didn't see those :-(
 
its a linqpad script - just run it in linqpad :)
.Dump() is an actual method to display things in linqpad
it's the greatest extension method .. ever.. nothing comes close
 
3:31 PM
ha ha I will try that at home. GTG now, have nice weekend all.
 
if you've never used linqpad - start using it now -- it works much better with autocomplete (paid feature) which converts it into mini-ide - it even includes debugger support now in its professional license
have a nice weekend :)
 
See ya @XAMlMAX
 
3:49 PM
See ya, XAMlMAX
 
Alex: I thought of a fun exercise for you (and anybody else who wants to have a go but please let alex have first chance of answering it):
using(var context = new DbContext())
{
    Func<string, string> RedactPostBody = x => x.Replace("Pa55word", "***");

    var postCharCounts = new List<int>();
    var redactedpostBodies = new List<string>();
    var postBodies = new List<string>();

    //pretend expensive sql query
    var posts = context.Posts.Select(x => x.Body ?? string.Empty);

    //Do one operation
    foreach(post in posts)
        postCharCounts.Add(post.Count());

    //Do another
    foreach(post in posts)
        postBodies.Add(post);
^ compilable code of a hypthetical DbContext with a Posts table - but how could we optimise it?
 
4:05 PM
Looking at it ^ now...
 
is this more complicated than I think it is
because otherwise it looks too simple
 
it's meant to provoke thought - the kinda thing i'd ask in an interview question.. here's a piece of code.. what do you think kinda thing :)
 
You can combine all those loops into one linq, I think
 
that'd be the first answer I'd get typically and if i'm feeling good about candidate.. i'd tell them to be sure about it :)
want me to paste it in a gist for color coding?
(no there's no spelling mistake or at least you can pretend all identifiers are fine and like i said you can pretend this will compile fine)
since we're not in an interview - i can give you a hint: how will RedactPostBody work in last loop?
(this is one of the two things that need fixing)
^ that's 2 hints :)
hmm no scratch my hints - i've jumped ahead to how I would fix it and that'll just confuse you
but evaluation is the key thing here - you've sorted this sort of thing before
 
Just curious,why are you call Count() on string?
 
4:13 PM
good point foggy :D
cos i typed this on notepad? :D
 
that would explain the typo too
 
i'll leave it for folks to fix up :)
sure tell me the typo and i'll fix it.. i'm gonna make a gist
 
redactedpostBodies vs redactedPostBodies
 
aha - thanks
 
user6501892
Are ObervableCollections not propertychanged eligible for modifying the structure of the observable collection? i.e. moving elements and reassigning indexes
 
4:16 PM
no
 
user6501892
How do people work around that?
 
they don't - you don't reassign OC
it should be get-only property
 
user6501892
What do you think is best to use for displaying data then?
 
and for collection it has INotifyCollectionChanged implemented
thanks foggy / millennium for casting your eye on the notepad written sample :D
 
46 mins ago, by Maverik
if you've never used linqpad - start using it now -- it works much better with autocomplete (paid feature) which converts it into mini-ide - it even includes debugger support now in its professional license
:P
 
4:19 PM
yes yes - i thought about it.. but that'd require more effort
I'd have to flesh out the DbContext :P
I've posted the gist here LinqFun.cs
@Alex: may want to use that gist instead when you're checking ^
ok I'm gonna write the answer for it - and then we can talk about it :) Alex is probably busy
 
first, foreach(post in posts) postBodies.Add(post); materializes every entry in a collection so you may as well materialize it first and do the rest on that collection instead of issuing a query 3 times
 
that was indeed what i wanted to point to Alex :)
the first and foremost thing that any linq developer should realise is when we have multiple enumerations of collection
 
also resharper warns on that
 
hehe.. that's cheating :D but yes it does - sadly it can't know if you're working off a local collection or remote so it warns indiscriminately
so caching it the first time we materialize it is indeed the first step to get it a bit optimised - with hint being there: "Expensive query" :)
The other thing I'd do is push as much of processing as I can to server side.. and that's something Alex needs practice with
 
@Arrayoob Could you rephrase that?
 
4:33 PM
in this trivial case of course we have stuff that doesn't need much from sql translation but if we can figure what can be pushed to sql and what can't - then we're golden with linq and don't need to feel noob :D
Bradley: he asked if you can't use an OC to display modified data - then what would be better
the problem isn't with OC - the problem is with the way he's using it
 
@milleniumbug I thought that Alex said the same just without details
 
hence my question
29 mins ago, by milleniumbug
is this more complicated than I think it is
 
using(var context = new DbContext())
{
    Func<string, string> RedactPostBody = x => x.Replace("Pa55word", "***");

    var postCharCounts = new List<int>();
    var redactedPostBodies = new List<string>();
    var postBodies = new List<string>();

    //pretend expensive sql query
    var posts = context.Posts
        .Select(x => x.Body ?? string.Empty)
        //Push the bits of things that can be translated
        //To SQL to server side and pull only the processed result
        //Trivial sample that would normally just be used directly from
^ that's hwo i'd do it - with notepad anyway :)
and yea its more complicated that it shuold be - because a lot of pretend is happening and its meant to be a bit confusing to trap people :)
if you two feel it's ok (& agree with how i've done it) i'll push it gist as answer for alex to review when he's free
I wish SO would apply syntax highlighting on code blocks /sigh
 
indeed, it's hilarious that a chat "for gamers" (Discord) has better support for syntax highlighting than a chat "for programmers" which is also a part of the most popular Q&A site for programmers
 
and has syntax highlights on its main site!
 
4:44 PM
var postCharCounts = posts.Select(x => x.PostBodyLength).ToList(); instead of that declaration way above there and .AddRange below down there
 
umm no then you'd have only post body length and lose post body ?
 
AFAICS it's not used in the query
 
oh wait .. i see what you mean - you mean just declaration move?
yea its a good optimisation - no need to allocate a list before this
 
also I like to pretend built-in arrays don't exist and use List<T> exclusively, but that's mostly me
 
yea i've made the argument for that in the past: for me when I see lists - i expect modifications to collection and will code accordingly
when i see arrays - i expect no collection change on them and thus code reflects that
Why did i create lists in here then? Well no real reason other than it being the norm of most folks
.ToArray() came later out of habit
ok i've changed everything to ToList and incorporated your optimisation
 
4:51 PM
Hey all. I have a problem with mouse focus that Mouse.Capture(...) does not seem to be helping with. I have two windows in two separate app domains. I am doing a DragDrop between them. When the item is dragged over the second window form the first, I need to set mouse focus on that second window. However, it seems no matter what I do, the second window will not receive messages until I release the mouse button. Is there another way to force this?
 
posted answer as the last gist revision :)
Branden I'd imagine no but i've never dealt with such a thing so could be completely wrong
and I have to jet
 
@Maverik I like to think this as a mental optimization: the narrower the scope of a variable is, the less statements are likely to access it
 
5:10 PM
Back from lunch w/ bosses
 
try to avoid looking at the transcript :D to avoid getting spoiled
 
:)
 
here's the original if you're still in the mood and you want to take a look gist.github.com/Venomed/ad087f55300259f493a43ef1181bb62f/…
 
5:38 PM
I think drag drop between windows isn't supposed to need that kind of focus, but I haven't done it myself
 
Yeah, @BrandenBoucher try it with Windows Explorer windows... they don't get focused either. at least not with win7
you might not have control over that
 
I should probably report back here when I find something out. Sry for the delay. I found a WinApi call, AttachThreadInput, which solved my issue.
It's not perfect as it doesn't release the first window until the mouse button is released, but it does work.
 
yeah, kinda take it back... chrome does it with tabs
 
could maybe search chromium source for that function to see how they handle it, but that's probably much more labor intensive lol
 
5:51 PM
I think at some point I will try to understand the chromium source, but today is not that day :)
 
6:12 PM
@Alex Good lunch?
 
Yes, and haven't forgotten about the challenge :)
 
I'd create a Select to bring in at a minimum the 3 loops, all into the one select
That would eliminate the need for the lists... one list to rule them all :)
In Linq, can you create a variable and use it further along in the same query?
Example....
var vms = imageNames
	.OrderBy(x => x)
	.Select(x => new { Filename = x, Url = baseUrl + x.Replace("(", "").Replace(")", "") })
	.Where(x => IsValidUri(x.Url))
	.Select(x => new TimsImageVm { Filename = x.Filename, Url = new Uri(x.Url) })
This needs the same x.Replace("(", "").Replace(")", "") on the Filename and Url
Hate to perform it twice
How do I store that and reference it elsewhere in the query?
 
.Where(x => IsValidUrl((baseUrl + x).Replace(...).Replace(...)).Select(...)?
 
Think I just saw an answer in the above. One minute please....
 
6:28 PM
ah, would have to get url again though... yeah, gotta do something else
 
var vms = imageNames
	.OrderBy(x => x)
	.Select(x => x.Replace("(", "").Replace(")", ""))
	.Select(x => new { Filename = x, Url = baseUrl + x })
	.Where(x => IsValidUri(x.Url))
	.Select(x => new TimsImageVm { Filename = x.Filename, Url = new Uri(x.Url) })
^ maybe
 
var vms = new List<TimsImageVm>();
foreach (var imageName in ImageNames)
    vms.Add(new TimsImageVm(imageName);
less code lol
 
You can also create an anonymous object to store values for use w/in query... .Select(x => new {...})
I like it :)
 
ah i suppose mine is creating vms of invalid uris :(
i surrender
 
Did that years ago
 
 
1 hour later…
7:40 PM
wonder if andre is alive
 
I saw him on facebook the other day
did not chat with him
but he was green
 
Last seen Oct 10 at 20:15
too cool for us. boss is watching too
hi @JoBiesta
 
7:59 PM
@Kcvin :)
 
 
4 hours later…
11:52 PM
Helpme please
in jmap
 

« first day (1827 days earlier)      last day (2322 days later) »