« first day (3917 days earlier)      last day (1254 days later) » 

00:43
@Squirrelkiller Thanks for the help. I solved it this morning with a fresh brain. The problem was it was waiting for the line-end "\n", nothing to do with task, or concurrency. But your help is much appreciated.
 
2 hours later…
02:53
What should I use C# for?
What difference is it from Java and Why should I Switch from Java to C#?
I have heard that Java is for android apps and C# is for WPF, web apps and games. Is this true?
 
4 hours later…
06:56
both are generic purpose languages
in essence, you could use C# for everything you could use Java for and vice versa
07:17
[Squirrel in Training] GoOoOoOoOoOoOoOoOoOoOoOd Mornin' pleberinos!
the major differences are
- what tools support only one and not the other (such as Unity only supporting C#)
- what libraries are already available to you (some libraries for specific tasks just dont yet exist for Java/C#, it is usually not the case of it being impossible, but just that no one wrote it yet for said language)
- the language syntax, developer tools and developer environments (one might be more favorable than the other)
morno SiT
07:34
Back again .. does anyone know of any C# namespaces/libraries that can trim segments from an audio file?
I've tried using NAudio but it was unsuccessful for me
again, I dont think that is NAudio's fault
But here's the thing
NAudio only works for integers
and?
I have intervals that are doubles
you want to remove half a byte?
you dont have intervals that are doubles
07:45
They are doubles though
that is your fault
An audio file I'm working with is 10 minutes
and I want to trim 9:55:43 to 10:00
How is it my fault? @wietlol
because you turn your double into an integer too early
you floor on a second level
and then multiply by 1000 to get your milliseconds
so your integers are like
from 595000 to 600000
you could easily do from 595430
Hm.. you have a point
I am Wietlol, having a point is what I do :D
07:50
But with what I'm given from NAudio, do you still think it's possible for me to remove MULTIPLE segments? Because what I noticed is does it lets say these are my intervals {[0,4], [11,34]} and the audio file is 50 seconds. If I were to first remove from [0,4] and tried to remove the next interval, it wouldn't be correct because it's off by 4 seconds. Do I just keep adding the difference every time I iterate it?
@Wietlol
yes, no
Happy about the first yes, but why no for the second one?
your source doesnt get altered
Ohh okay good
I'm going to get back to work, I really feel that I'm going to be able to achieve this ! But I have another quick question
1
Q: Naudio "TrimWavFile" function is not trimming wav correctly

user3620897I am stuck in trying to trim a wav file. My problem is that when I trim the file (of 32 kbps bit rate) to a 10-second clip, it is trimming it into 00:01:18. The full, original time is 1:37:13. I have tried specifying value of CutFromStart (00:0:0:0) and giving CutFromEnd (00:1:37:03), but as sta...

Here is a Stackoverflow post that I saw that the creator of NAudio even answered
I was confused with his answer because I thought the OP was write in his method
If you have an audio file of 1:37:13, and you want to only leave the last 10 seconds
then you start from 1:37:03 and an end time of 1:37:13
07:59
why wouldn't using Timespan.FromSeconds(00:0:0) and Timespan.FromSeconds(1:37:03) work?
ohh
Okayyyy
or the other way around
depending on what you do with the data
remove it
that's what I want to do
and the intervals that I have are the segments I want to remove
Okay so @Wietlol, just so I can explain what's happening
I have an input audio file -- 10:00 min
Intervals (in seconds) that I want to remove from it
95.2238 {start}
98.533 {end}
So I'm expecting about 3 seconds to be removed
After running this code, it produced an output file that is 06:39
If you want me to upload an image to imgur to prove so I can, but I found it unnecessary for now, but what do you think is the issue here? @Wietlol
you have to re-think what you are actually doing
your second TrimWavFile function is not trimming, it is copying
08:14
oh.. I just listened to the audio file output
So it started playing from 95.2238
But that doesn't explain why it was 6 minutes instead of 3 seconds then
what audio does it play after the 3 seconds?
also, you still need to get rid of this hideous int endPosition = (int)reader.Length - endBytes;
It plays the entire rest of the audio file @Wietlol
Do I need to get rid of it entirely or just change it up?
Because what end position am I going to pass in then
create the end position from the start
not from the end
you should never mix directions in indexing
Ahh, so int endPosition = startPosition - endBytes;
wait
no
your endPosition will use the exact same formula as your startPosition
just with a different input timespan
08:21
Oh, then it wouldn't even end up producing any audio
why?
because wouldn't it just be the same value ?
I may be wrong
> just with a different input timespan
Okay
Hmm..
Ah I just had it in reverse
endBytes - startPosition
08:26
Hmm .. that didn't seem to fix it
yeah smh
> your endPosition will use the exact same formula as your startPosition
you can just ignore what I say
but it wont help you
Ohhhh
You are a genius !
Ohh so now I see what I need to do
What the current program I've done literally just cuts out a segment of the audio
So that produces an audio file of 3 seconds
So there's two ways I can go about this
1. Create a while loop for until it reach of the end of the audio file, keep trimming out the parts that I DO NEED
2. Figure out how to change up the code to trim OUT parts from the full audio file that I DONT NEED
I feel like 2 would be the easiest route though, don't you think? @Wietlol
1. stop using the word "trim"
2. rewrite your 2 options
Okay
1. Create a while loop that begins from 0 until the duration of the audio file is met. Cut out every interval that is NOT in the list of intervals to create a new audio file
2. Adjust my program to cut out intervals and keep the remaining audio from the input file
@Wietlol this better?
ohhhhh
I think I see now
So like you were saying the second trimwavfile is a copier
1 and 2 are the same option
08:36
Yeah I just realized that !
there are 2 options
1, cut the parts you dont want
2, copy the parts you do want
I would go for 2
Yeah
I just need to change the second trimwavfile
invert your intervals to turn them into the parts you do want
(this effectively ends up with one more element to the list)
08:37
And only write the parts that are not in start to end
> And only write the parts that are not in start to end
pls no
invert your intervals, then copy those parts
So create intervals that only contain the parts that I do want?
So for example, if my audio file is 30 seconds and I dont want [4,7] and [12,17] , I would have to create a list that contains [0,4], [7,12], [17,30] ? @Wietlol
Okay so now I need to turn everything to doubles
@StriveForGreatness yes
@StriveForGreatness no
Well not everything but a couple things
I'll show you
This is what I've changed so far
@Wietlol
start and end position are still supposed to be ints though
08:51
in the first or second trimwavfile function?
mr5
mr5
Guess which server is this
both
well if I do that are you sure it will get the exact intervals that are doubles?
@Wietlol
08:53
again, there are no doubles
you are dealing with a byte-level data stream
your byte index therefor must be an integer as per Direct Mapping
okay bet
and my last question, I think you said it earlier but I still dont understand and hopefully this will help me for the future
mr5
mr5
@StriveForGreatness this looks inefficient. You should manipulate the stream in memory.
your precision and accuracy of those indices is on millisecond level, as per startPosition = start.TotalMilliseconds * segement;
Why do I need to invert the lists to only include the intervals that I NEED? @Wietlol
if this is an integer, it still is on millisecond precision
08:55
@mr5 explain?
@StriveForGreatness because it is repeatable
copying everything except what you do not need is not
@mr5 the probably most efficient approach is not far from the current approach
I bet the most efficient approach is to turn the intervals into a sequence of CopyUntil() and SkipUntil() operations
and going through the input stream without re-setting the position
mr5
mr5
@StriveForGreatness you were directly writing onto file system right? Writing in volatile memory is faster and will give you more flexibility.
or CopyNBytes() and SkipNBytes()
NAudio was just the only thing I saw that allowed me to convert a stream to a wav file in C#
@mr5 generally speaking, using the streams is faster
mr5
mr5
08:58
How about in low level languages?
keep in mind, you want to eventually write it to a file
mr5
mr5
@Wietlol yeah but MemoryStream > FileStream
nope
I tried doing it in C++ using FFMPEG API but it was a mess
if you want that, you'd need
1, read the entire file into memory
2, create a memory stream of the bytes
3, write the output of the memory stream into a file
mr5
mr5
09:00
@Wietlol yeah probably not in this case
it is better to
1, open a stream of a file
2, choose how many bytes you want to copy
3, stream the output to a file
but that is assuming you do not abuse the position of the reader
mr5
mr5
but he could stream the filestream and read it in chunk. I'm not sure though, depends on the data structure of the audio file.
That is the method that I'm currently using though, correct ? @Wietlol
you do, but you do abuse the reader position
09:02
@mr5 that is what the buffer array is for
although, a 1kb buffer might not be the most optimal
Appreciate the discussion as well, definitely learning a lot from both of you two
but I have not enough experience with that to know what is best
nor do I care
performance is something I care about when I need to
for example... now
:D
@mr5 remember my Java AWS Lambda applications started really slow?
mr5
mr5
Is it because it is written in Java?
09:04
nope
mr5
mr5
well, I'm not sure. Is it fast now?
I hate this C++
turns out, AWS Lambda unzips the code package on the hosted container before running it
and my code packages were a simple fat jar (a single file containing all the code)
the problem is that the code inside that jar is just all my class files and all class files of all dependencies
mr5
mr5
oic
so, imagine that every class in your project and all libraries you use are separate files on your disk
mr5
mr5
is that how serverless deployment works?
09:05
Java lazily loads those files on demand
so, on the first calls, it does tens if not hundreds of thousands of file-io calls
of miniscule files
mr5
mr5
iirc, that is how I deploy my tomcat server/servlets before.
I changed the packaging to be a zip containing the project jars instead
this would extract the zip in the runtime and load just the jars
this would be similar to how you see many .dll files in your bin folder in .net
that reduced the startup time by 90%
@mr5 deployment is the same, the generation of the package file is different
mr5
mr5
why is it not the default though?
the default is generating a transient jar
mr5
mr5
isn't the zip and jar file essentially the same?
09:12
the jar (a java archive) only contains the code from your own project
this is useful for publishing to an artifact repository for example
then you can choose to also copy all dependency jars
this would produce a folder containing all jars necessary for it to run
then you have the fat jar option
which is a single jar containing all the code
this is a single file that can be executed
it would be easy to distribute applications that way
I thought I had to use the fat jar approach
but that was a mistake
mr5
mr5
you probably chose the option for fast deployment
@mr5 a jar is essentially a zip
but the JRE (Java Runtime Environment) can assume jars are structured in a specific way
and you can associate jars with the JRE
the zip deployment package is just a folder containing all the jars
 
1 hour later…
10:16
I found an interesting thing, and it makes sense.
I changed the DbContext's ServiceLifetime to Singleton, and started the application and found out the same results are retrieved even I was changing the values of the database in SSMS while the app is running. now it's really Singleton DbContext (Database?), but does that mean that the database is loaded in memory in startup? because it keeps giving me the same values even after I changed them!
tracked entities are not reloaded
if an entity is tracked and deleted on the database, EF will still pretend it is still there
a DbContext is best suited for the smallest scope possible
imho, preferably without tracking at all
the problem then is, you cannot save changes... at all
That's a problem, I need to use the DbContext in a BackgroundService (Hosted service), but because the hosted services are registered as singletons, I had to change the lifetime of the repositories, down to the DbContext to Singleton
10:31
dont make it a singleton
either directly or indirectly
you could use a singleton pool
or a singleton factory
but not a singleton instance
I can't use scoped in a hosted service(singleton)
not the way the microsoft DI library works, no
 
2 hours later…
12:58
@mshwf Can't you register the dbcontext as pool and make every consumer get its own transient dbcontext, so the hosted service gets its own dbcontext too?
Or inject the service provider and make your own scope
13:30
[juanvan] ServiceLifetime.Transient in the AddDbContext on services.
I think AddDbContextPool automatically gives you transient instances
[juanvan] Unless they updated it, answer was 3yrs old
13:53
aw man one of the IT guys is leaving, which makes just two programmers left in the company 😩
14:05
Ryan Donovan on July 07, 2021
At some point in your career, you may well be advised to seek out a mentor. However, the benefits being a mentor are often overlooked.
Hi all
14:42
Is there a away to add a property to an existing class while iterating through the class in a foreach? for example I have my Car class and i can use car.Model, car.Miles but i want to add car.Price without adding it to the model class.
if it doesnt belong to the model, you dont get to add it
so, the question is, where does the price belong?
well the model is created with entities.edmx and i dont want to add another column to the table in the database to add the Price property
map the db model to your own class and use that
This use case is exactly why you don't use db models in the rest of the application
Also technically you could add an internal property, so EF won't be able to see it so it won't disturb the database.
My turn:
There's a service, basically a repository.
Calls lots of different things, gets lots of different DTOs.
DTOs usually convert to exactly one business model (because don't use your DB models in the rest of the application!)
~50 different DTOs, probably more.
Where to map them?
In the service? Service is convoluted.
In each DTO? DTO now has logic.
In a mapper class? Giant mapper class.
In multiple mapper classes? Now have multiple mapper classes and I can never be entirely sure which one has the mapping I need.
Let's pretend we don't use automapper for the time being
The mappings are currently in the service itself, so it literally has > 5k lines :/
@Harry Have fun at the game tonight
15:42
Alright look at my newest creation. I think I'm slowly going mad.
    public class DictWithDefault<TKey, TValue>
    {
        private readonly TValue defaultValue;
        private readonly Dictionary<TKey, TValue> values = new Dictionary<TKey, TValue>(60);

        public DictWithDefault(TValue defaultValue = default)
        {
            this.defaultValue = defaultValue;
        }

        public TValue this[TKey key]
        {
            get => this.values.TryGetValue(key, out var val) ? val : this.defaultValue;
            set => this.values[key] = value;
Let's you chose a property, replace it's type with this, but keep using it everywhere just as before. Except now you can also use it as a dictionary!
WHY
16:06
[milleniumbug] because operator== is static
[milleniumbug] as in, if someone defines the custom operator==, generics can't dispatch into calling it
[milleniumbug] accept a IEqualityComparer<TValue> in a constructor
[milleniumbug] and use EqualityComparer<TValue>.Default otherwise if the user does not provide a custom one
Yup using .Default now
I'm the user, I'm not gonna provide one
Hm still need to make a switch statement automatically get the default value now
[milleniumbug] the implicit conversion operators are super weird
Lot's of code using the property I'm changing with just ==
Don't wanna change lots of if(prop == SomeEnum.One) or whatever
16:44
@Squirrelkiller in the design I use, DTOs are the primary model used in the business logic
the repository, just like any other service, has the input/output of their methods primarily filled by those DTOs (plus standard types)
the repository therefor has to map from the database to the DTO
however, the mapping itself is not done by the repository
the repository uses a DtoMapper to convert the models
at work, we also have ApiModels, which are the models used for requests and responses
for my own projects, those models are the same as the DTO models
@LuDevGon the question still remains
what does the price belong to?
does the price belong to the car? or does it belong to a sale/purchase? or does it belong to a catalog? or to a market?
if it belongs to the car, add it to the car
but it probably doesnt
you could wrap the car and the price into a new model with composition
or use a dictionary with the cars as keys and the price as value
but it all depends on what you try to model
@Squirrelkiller is this... a dictionary? or is it a value?
Morning everyone
17:53
lolll steve wozniak is for right-to-repair....awesome
 
5 hours later…
22:39

« first day (3917 days earlier)      last day (1254 days later) »