« first day (3660 days earlier)      last day (1281 days later) » 

10:07 AM
!~shiba
 
@nyconing naw
cute
28 mins ago, by Squirrel in training
Jack, funfriday
@CaptainSquirrel jack's bork again!
 
10:08 AM
tell me something i don't know
 
now im looking at the worst ladders lol
 
@CaptainSquirrel he isn't even reaction
 
welp
i'll stop him
sec
lmao
he wasn't even running
OOPS
Jack, tell SquirrelInTraining funfriday
 
@CaptainSquirrel lul he was in the memebr corner
Jack, funfriday
 
funfriday evry1
 
i turned him off yesterday i think
 
@mr5 Exposed is a code-first library
you write the classes representing the database and how you want to access it
when connecting, it updates the database's schema if necessary
 
mr5
oh. I'm not familiar with code-first jargon. does that means it's a server side library?
 
it doesnt matter where you use it
as long as the application has access to the database... so I assume that is a web server
if you still allow client's devices to directly access the database, you should be thoroughly beaten
code-first just means that you dont have to manage the database directly
the library knows how the database should look like and where it should be
if the database is not there, it makes it
if the database is out of date, it updates it
Exposed doesnt really have a nice way to updating though
not like EF with migrations
 
10:16 AM
Yeah code-first just means it generates the db from your models
 
mr5
eh, I'd rather build my schema in UI
 
db-first means you generate your models from the db schema
 
the advantage of code-first is that you have infrastructure as code
 
mr5
I see.
 
@hollystyles lel
 
10:17 AM
you could in theory clone Wietbot, run sls deploy and you have your own Wietbot
 
mr5
you can also easily migrate it to other rdbms
 
Code-first: You code the classes in your project and have no database, then you publish it and the witchcract creates the database from the info of your classes
 
the theory stops because I hardcoded my own AWS account id :D
 
    val munichId = Cities.insert {
        it[name] = "Munich"
    } get Cities.id
@Wietlol how does that work? What is Cities.id in this context?
 
im not sure I understand either...
 
10:19 AM
I mean clearly it's specifying to call id property of Cities instance
 
this is probably more reflection like than what I used
 
but I don't know what kind of value Cities.id might be.. function?
 
Column<Long> (assuming id is Long)
I think
 
kotlin converts val members into getters and setters doesn't it?
 
mr5
see how awful Kotlin is
 
10:20 AM
Cities.insert() returns an entity
on that entity, you do
entity get Cities.id
or
entity.get(Cities.id)
Cities.id is most probably a Column<Long>
 
maybe some proxy was used to return a column instance when called as a static reference?
 
so you get the value from the entity of the appropriate column
Cities.id is a property of type Column<Long>
 
@mr5 you have to admit that that's pretty elegant though
 
normally, you would do this tho
entity.id
@Neil in Exposed, you have 2 classes
 
in other words, Table class is doing something particular here to make that work
 
10:22 AM
the Table class (Cities) and the Entity class (City)
the Table class has a set of properties of type Column<T>
it represents the structure of the table
the Entity class has a subset of those properties of type T (respectively of each column)
it represents a single record
for example
 
yes but Table class presumably doesn't have an id property, it knows to return Column<Long> from using reflection on the derived class
 
Kotlin sounds lovely
 
mr5
so I have this code:
mapList.find { it.id == model.id }?.let {
    it.score = model.score.coerceAtLeast(newScore ?: 0)
} ?: run {
    mapList.add(model)
}
I wouldn't call that elegant though
it looks cryptic
 
object People {
    val id by biginteger()
    val name by varchar()
    val dateOfBirth by datetime()
}
those properties are inferred as
val id: Column<Long> by biginteger()
val name: Column<String> by varchar()
val dateOfBirth: Column<DateTime> by datetime()
the entity class would be
 
oh I get it
I just forgot what objects did
they're always static or something?
or single instance classes?
 
10:26 AM
class Person : Entity<People>() {
    val name by People.name
    val dateOfBirth by People.dateOfBirth
}
objects are singletons by code
 
that makes sense then
 
the id property is special
above code is definitely incorrect :D
its a while since I wrote Exposed classes
object Permissions : IntIdTable("auth_permission")
{
	val name = varchar("name", 256).uniqueIndex()
}

class Permission(id: EntityID<Int>) : IntEntity(id)
{
	companion object : IntEntityClass<Permission>(Permissions)

	var name by Permissions.name
}
 
@mr5 I think that can be rewritten a little better
 
taken from Wietbot's source code
 
not criticizing the way you wrote your code, I just think that can be shortened somewhat
 
10:29 AM
let me help you
@mr5 that is trash
I am criticizing the way you wrote that code
btw, trusted sources say it can be shortened somewhat
 
is the ?. necessary after the find?
or only after the first to follow the find?
obviously find may or may not return a value, so the first ?. is necessary, but would it be necessary for everything that follows?
 
how is it not necessary after the find?
he only uses one tho
the other one is ?:
 
because if circumstantially you're calling let based on the fact that yes, there is a value, then isn't that like converting a nullable value into a non-nullable value?
true, but he could have done .? run I think right?
?. is like saying "if (retVal != null) { ... }", so from inside the if statement onwards, you know retVal isn't null
 
.?
^ what is that?
 
?. ..
 
10:34 AM
oh but that is the opposite of ?:
in this case
mapList.find() ?: run {}
it says "go find it, if it is not there, then run"
while
mapList.find()?.run {}
says "go find it, if it is there, then run"
 
oh, thought ?: meant something else
 
?: means "if left side is null, then invoke right side"
like ?? in C#
 
so the opposite of ?.
 
yep
basically, what he made is computeIfAbsent
mapList.computeIfAbsent(model.id) { model }
	.also {
		it.score = model.score.coerceAtLeast(newScore ?: 0)
	}
the only problem is that List<T> doesnt have a computeIfAbsent
 
computeIfAbsent is a nice function
 
10:37 AM
it is something special for a Map<K, V>
but looking at his code, he might be better off using a Map<K, V> instead
computeIfAbsent is so nice... it was one of the first functions added to my C# utils lib
public static V ComputeIfAbsent<K, V>(this IDictionary<K, V> dictionary, K key, Func<V> supplier) =>
    dictionary
        .Find(key)
        .OrGet(() =>
            supplier()
                .Also(it => dictionary.Add(key, it)));
^ yes, that is very kotliny
 
that's a good point, why search through a list when you could have a map with key by id
 
wait... is that even computeIfAbsent?
oh yes, it is
 
.OrGet()
 
IDictionary<K, V>.Find(K) returns IOptional<V> :D
which is also from that same library
just like that Also function
and ofcourse, we are in C# land so obviously
public static async Task<V> ComputeIfAbsentAsync<K, V>(this IDictionary<K, V> dictionary, K key, Func<Task<V>> supplier) =>
    await dictionary
        .Find(key)
        .OrGetAsync(async () => (await supplier())
            .Also(it => dictionary.Add(key, it)));
not sure if that first await is necessary
 
Mornign boys and girls
 
10:42 AM
I suppose I could remove the async from this function and remove the first await
 
Mornan
 
the first await is necessary if it is an async method I thought
you mean it shouldn't be necessary because await is used to the call to supplier()?
 
public static Task<V> ComputeIfAbsentAsync<K, V>(this IDictionary<K, V> dictionary, K key, Func<Task<V>> supplier) =>
    dictionary
        .Find(key)
        .OrGetAsync(() => (supplier())
            .AlsoAsync(it => dictionary.Add(key, it)));
it compiles...
 
I don't know, what happens if it's wrong?
 
0.0
if you omit async/awaits you might run into scoping issues
for example
 
10:44 AM
oh great, silent and unexpected bugs, the best kind
 
using (var x = new X()) {
    return GetStuffAsync(x);
}
x gets disposed before GetStuffAsync is awaited
 
GetStuffAsync can't reference x anyway, can it?
 
that is one example of a mandatory await
 
oh, but the compiler doesn't correct you on that one?
 
it can reference it, but it would be a closed resource, probably resulting in an exception at runtime
 
10:46 AM
@mr5 you're right, C# is far more graceful ಠ_ಠ
in the off chance that it doesn't leave scope by the time GetStuffAsync gets called without await?
 
the compiler doesnt give me a warning or anything on that, no
 
like say, if you did thread sleep after the call before exiting the scope
 
@Neil what is the question?
 
You said references to x result in a runtime exception
 
usage of x probably does
for example reading from a closed stream
 
10:48 AM
Is this because of it being called without await or is this because the caller left the scope already containing x reference?
 
it is because of the using
the variable scope is perfectly fine
 
in other words, if you call an async method and then forcibly make the thread wait so that x doesn't go out of scope.. (horrible I know), what happens?
when x is referenced inside the async method, it hasn't gone out of scope yet
 
it never runs "out of scope" incorrectly
it just gets disposed
if the disposing is delayed, it might still work
 
it gets disposed the moment x is no longer needed
if you don't exit the using scope, then technically x doesn't get disposed
 
it would work if the disposing is delayed until after the loading of the result of GetStuffAsync
 
10:51 AM
that makes sense, being a runtime exception and all
 
nvm
 
removed
removed
REMOVED
 
ComputeIfAbsent completely without async/await keywords appears to be perfectly fine
 
WIETRL0L IS ON FIAAAA
 
R E M O V E D
 
10:54 AM
E
M
O
 
I performed some serious heresy to make the apis of the tools in that library work nicely with Task<T>
 
V
nooooooooooooo
ugh
BAD LION
;)
 
He be lion
 
lol
 
cD
@Wietlol reeeeeeeee
hereeeeeeeeeseeeeeeeeeeeeeee
 
10:56 AM
for example
public static IOptional<T> Flatten<T>(this IOptional<IOptional<T>> self) =>
    self.FlatMap(it => it);

public static async Task<IOptional<T>> Flatten<T>(this Task<IOptional<IOptional<T>>> self) =>
    (await self).Flatten();
there are tons of extension methods for Task<T>
so that I can do
await GetNestedOptionalAsync().Flatten()
instead of
(await GetNestedOptionalAsync()).Flatten()
 
mr5
anyone willing to be put in my internal testing for my game?
 
sorry wörk
 
mr5
@Neil C# izz way better. I'm more of a guy that writes readable code than clever code.
@Wietlol Kotlin is trash
 
@mr5 What type of game?
 
mr5
2D puzzle/arcade game in Android
oh I forgot, tis only available for Android users atm
 
11:02 AM
@mr5 then write readable code, dang it
 
Sure providing you dont try to read my contacts lol
 
Kotlin is Kot
 
obviously cant do anything during office hours
 
I'll never use it
 
mr5
I would be needing your email though 😅
 
11:03 AM
no worries, will give you a shout later on
 
mr5
the Open Testing takes time so
 
there is no reason why you cant do
val entry = mapList.find { it.id == model.id }
if (entry != null)
	entry.score = model.score.coerceAtLeast(newScore ?: 0)
else
	mapList.add(model)
 
mr5
there's a way to deliver it without requiring email but it takes hours.
 
no worries, ill give it a go but my phone is about 2-3 years old now
min Adroid Version required?
 
mr5
@Wietlol yeah I actually rewritten it that way after posting it.
@DAustin marshmallow
 
11:05 AM
still, if you convert it to a MutableMap<Id, Model>, you have access to computeIfAbsent
 
posted on October 23, 2020 by jonskeet

Note: all the code in this blog post is available in my DemoCode GitHub repo, under Functions. For most of 2020, one of the projects I’ve been working on is the .NET Functions Framework. This is the .NET implementation of the Functions Framework Contract… but more importantly to most readers, it’s “the way to run … Continue reading A Tour of the .NET Functions Fram

 
in fact... just compute
 
Should be alright, will double check what version im on tonight
 
map.compute(model.id) { _, old ->
	old?.score = model.score.coerceAtLeast(newScore ?: 0)
	old ?: model
}
compute adds or replaces with the result of the lambda
the lambda will update the score of the old value (if present)
then it returns the old or new model
 
11:14 AM
At the risk of being shunned, i love EF
It's not the most elegant, it's not the most efficient, but my word does it remove a lot of the boilerplate code
And i can just concentrate on writing the actual app
 
Sep 17 at 16:06, by mr5
CupOfKotlin
 
brb coffee time
 
ohyeah so I looked into the powermac g4 as a server (literally) and found out one of the memory sticks burned out or something, so I only got 1gb to run Minecraft lmao
 
I'm all about chaining the calls, but only if it is still perfectly leggible
 
oh hey, jack is back
 
11:21 AM
I agree with Wiet that your code could use a nice clean separate with an if condition
but a Map would still be better here
 
I do sometimes chain too much :D
but I try to keep SLA mostly so it usually is perfectly fine
just adding some test code now and then requires splitting it up a bit
 
I try to avoid .orGet and .also
because that can be contrived as just chaining for the sake of chaining
 
also is quite nice imho
because it can be used as just chaining for the sake of chaining
val x = getX()
    .also { log(it) }
 
see, I don't like that
they're related operations, but you could simply put log(x) on the next line just as easily
 
in this example, sure
 
11:30 AM
I won't say in all examples, but in a good many, I would argue it's unnecessary
 
but not if you are using it as argument for something else
val point = Point(
    getX().also { log(it) },
    getY(),
)
 
mr5
@Wietlol what is the main difference of .apply and .let aside from the closure?
 
with this argument, I assume you see my point
 
@Freerey Still needing assistance with the minecraft server?
 
.apply uses an extension lambda, .let uses a normal lambda
.apply returns the input, .let returns the result of the lambda
 
11:32 AM
@DAustin really the only thing I wanna know for now is....is 550mhz enough to run the damn thing?
 
.apply is closer to .also
because both return the input
 
@Freerey Probably not, the main bottlenecks are cpu speed and disk I/O
 
@Wietlol ba dum tss
 
.apply is also closer to .run
because both use an extension lambda
 
11:33 AM
ffuuuu
 
all i can say is give it a try and see, i was able to run a server off a raspberry pi but it wasnt great
 
oh dam
did you at least put heatsinks on the chips?
 
was ok for like 3 people
 
vr goggles werent sent today
guess what that means
:/
 
oh...well I don't plan on more than 3 people being here at a time lol
 
11:34 AM
Yeh, ran hot though i ended up sticking a fan nearby to help out, but chunk loading unloading was the real killer
 
well next week then
 
damn...and the big problem I have is that the fan in my powermac is broken and Apple decided it'd be cool to make the fan the MOST PAIN IN THE ASS PART TO TAKE OUT
 
mr5
@Wietlol just stumbled with this weird behavior: gist.github.com/mr5z/bbd76500c887b29acc8dd8a0d4c5a1c4
 
so if you're all together in the same area, you can get way with it, if someone goes off exploring, itll start to lag a bit, not a massive issue unless you end up in combat
 
what does it throw?
 
11:36 AM
We're currently running ours off an Odyssey SBC, goes for around $200
but it works a treat and only uses a max of 15Watts
 
mr5
@Wietlol somehow, it sees one of the object as null.
 
you sure it is related to apply vs let?
 
though i did need to use PaperMC and a SATAIII ssd to get it to run super smooth
 
(also, let should prolly be replaced by also)
 
mr5
lemme try again
@Wietlol it's just a matter of semantics right?
 
11:38 AM
also returns your color picker, let returns the result of show()
so probably a Unit or Boolean
 
@Freerey also remember that your old rig there is gonna be eating a lot of power being on 24/7, it might be more cost effective in the long term to get something new thats more power efficient
 
mr5
it's consistent. If I use .apply, it sees one of the object as null
 
which object?
 
mr5
the mapView
 
@DAustin yeah I'm only gonna have this thing on when my friends wanna play lol
 
11:40 AM
what if you do
wait...
does ColorPicker have a property mapView ?
 
@Freerey Fair enough, you could potentially just run it off your main rig then, unless youre gonna have it on without joining in
 
HMM
 
We went with always on so we could make an Iron farm in the spawn chunks, plus it meant whenever someone fancied playing they could
 
oh yeah I forgot about one message I keep getting when I do run a server (which I haven't been able eto connect to yet)
"can't keep up! is the server overloaded"
 
Yeh that's basically saying the cpu is hitting a bottleneck
 
11:43 AM
I'm running this from OS X Tiger...I wanna install BSD or something and run from that
fug
 
not an issue if you only get it every once in a while
 
hmmm
 
mr5
@Wietlol no. it belongs to the class that code is executed.
 
ah
that also works
 
use DietPi on a base linux distro, it'll remove every package that isnt required to boot up, reduces load quite a lot
 
11:45 AM
ooh okay thx!
 
what if you do
this@apply.setCallback { color ->
    model.map.color = color
    mapView.invalidate()
}
 
Also, use OpenJDK 11 (instead of 8)
aaaaand let me find the link
 
also, what is the signature of setCallback ?
 
mr5
izz Jaba
 
use this flags when starting up the server: aikar.co/2018/07/02/…
 
mr5
11:46 AM
public void setCallback(ColorPickerCallback listener) {
    callback = listener;
}
 
and ColorPickerCallback is?
 
those flags are very useful in reducing the load from the actual java instance running the server
 
mr5
public interface ColorPickerCallback {
    void onColorChosen(@ColorInt int color);
}
tis
 
hmm
if you do "go to declaration" on mapView, where do you end up?
 
mr5
also, the mapView was produced from Kotlin Synthetic library. It's basically an auto generated code from xml
 
11:49 AM
ah
that is probably your issue
 
mr5
@Wietlol it only points to the xml. I can't see the auto generated code.
 
btw I did something super ballsy with my mac last night....it couldn't detect one of the ram sticks, so I pulled the thing out while the system was still running without knowing for sure if it was the one causing problems....and it was!! 😂
 
try
val mapView = mapView
buildColorPicker().apply {
	enableAutoClose()
	setCallback { color ->
		model.map.color = color
		mapView.invalidate()
	}
	show()
}
 
@Freerey lol ballsy indeed, speaking of which how much RAm you got in the rig?
 
if the above works, then this probably also works
buildColorPicker().apply {
	enableAutoClose()
	setCallback { color ->
		model.map.color = color
		this@apply.mapView.invalidate()
	}
	show()
}
 
11:51 AM
I think i give our server 4GB out of the 8 available on the system but i cant actually remember lol
 
which means that ColorPicker does have a mapView
 
mr5
@Wietlol it indeed work.
dfuq is wrong with that?
I'm running this in the same thread.
 
you have multiple this variables
 
mr5
@Wietlol why would it? It's a color picker library. Why would it need a mapView?
 
this@YourClass and this@apply
 
mr5
11:54 AM
oh the pitfalls
 
when the this. is omitted, the compiler will iterate over all the thisses in it's stack
it would first find the ColorPicker and see that it has a mapView
so it uses that one
if it didnt, it would fall back further to the YourClass
 
@DAustin 1gb...ther'es supposed to be 1.5
 
it is one of the problems of abusing extension lambdas
usually, this isnt a problem, but when you have properties/functions that are auto generated, you probably do have a collision
I usually use apply when I am sure that name clashes cannot happen
 
mr5
@Wietlol it seems to be not the case. I searched for it in its repo: github.com/Pes8/android-material-color-picker-dialog/…
 
source code my ass
it has a mapView
this@apply.mapView also compiles, right?
 
mr5
11:59 AM
 
what to name a lambda that puts new entry in DDB on invocation?
say the service is XYZ
 
mr5
@Wietlol yes
 
XYZDynamoPutLambda?
 
so?
 

« first day (3660 days earlier)      last day (1281 days later) »