csos95's recent activity
-
Comment on Day 3: Mull It Over in ~comp.advent_of_code
-
Comment on Day 3: Mull It Over in ~comp.advent_of_code
csos95 (edited )LinkI'm pretty tired tonight (finally remembered to drag myself to the gym a few hours after dinner) so my initial solution is a bit less compact than it could be. I'll probably go back over it...I'm pretty tired tonight (finally remembered to drag myself to the gym a few hours after dinner) so my initial solution is a bit less compact than it could be.
I'll probably go back over it tomorrow and also write a few functions for my utils module.Rhai Solution
import "utils" as utils; let input = utils::get_input(3, false); // PART 1 let total = 0; for (section, i) in input.split("mul(").extract(1) { let possible_params = section.split(")"); if possible_params.len() < 2 { continue; } let possible_digits = possible_params[0].split(","); if possible_digits.len() != 2 || possible_digits[0].to_chars().some(|c| c < '0' || c > '9') || possible_digits[1].to_chars().some(|c| c < '0' || c > '9') { continue; } let x = possible_digits[0].parse_int(); let y = possible_digits[1].parse_int(); total += x * y; } print(`part 1: ${total}`); // PART 2 let total = 0; let enabled = true; for (section, i) in input.split("mul(") { if enabled && i != 0 { let possible_params = section.split(")"); if possible_params.len() < 2 { continue; } let possible_digits = possible_params[0].split(","); if possible_digits.len() != 2 || possible_digits[0].to_chars().some(|c| c < '0' || c > '9') || possible_digits[1].to_chars().some(|c| c < '0' || c > '9') { continue; } let x = possible_digits[0].parse_int(); let y = possible_digits[1].parse_int(); total += x * y; } if enabled && section.contains("don't()") { enabled = false; } if !enabled && section.contains("do()") { enabled = true; } } print(`part 2: ${total}`);
My current utils.rhai
fn get_input(day, example) { if example { let input = open_file(`day${day}_example.txt`) .read_string(); input.trim(); input } else { let input = open_file(`day${day}.txt`) .read_string(); input.trim(); input } } fn is_sorted(array) { for i in 0..array.len()-1 { if array[i] > array[i+1] { return false; } } true } fn is_rev_sorted(array) { for i in range(array.len()-1, 0, -1) { if array[i] > array[i-1] { return false; } } true } fn is_ordered(array) { let fails = 0; for i in 0..array.len()-1 { if array[i] > array[i+1] { fails += 1; break; } } for i in range(array.len()-1, 0, -1) { if array[i] > array[i-1] { fails += 1; break; } } fails < 2 }
-
Comment on Day 2: Red-Nosed Reports in ~comp.advent_of_code
csos95 (edited )LinkToday's took me a bit longer for the second part because I misunderstood the change and for some reason thought if there was a single bad level I could simply remove it without checking if the new...Today's took me a bit longer for the second part because I misunderstood the change and for some reason thought if there was a single bad level I could simply remove it without checking if the new report is safe.
Once I realized my mistake it was pretty straightforward.
My only real annoyance with Rhai so far is that there's no good mode for emacs for it.
I found an old one someone made, but the way it handles the indentations is really janky.
It seems like it's sort of trying to line the indentation up with the first letter of the second token on the line above and if that fails, it just does a massive amount of indentation.
So I've got anywhere from two to four spaces of indentation depending on the line.Rhai Code
fn get_input(day, example) { if example { let input = open_file(`day${day}_example.txt`) .read_string(); input.trim(); input } else { let input = open_file(`day${day}.txt`) .read_string(); input.trim(); input } } // INPUT let input = get_input(2, false); let reports = []; for line in input.split("\n") { let report = []; for level in line.split() { report.push(level.parse_int()); } reports.push(report); } // AUXILIARY fn is_decreasing(report) { if report.len() < 2 { true } else { report[0] > report[1] && is_decreasing(report.extract(1)) } } fn is_increasing(report) { if report.len() < 2 { true } else { report[0] < report[1] && is_increasing(report.extract(1)) } } fn is_gradual(report) { if report.len() < 2 { true } else { let diff = (report[0] - report[1]).abs(); diff > 0 && diff < 4 && is_gradual(report.extract(1)) } } // PART 1 let safe = 0; for report in reports { if (is_decreasing(report) || is_increasing(report)) && is_gradual(report) { safe += 1; } } print(`part 1: ${safe}`); // PART 2 let safe = 0; for report in reports { if (is_decreasing(report) || is_increasing(report)) && is_gradual(report) { safe += 1; } else { for i in 0..report.len() { let report_copy = report; report_copy.remove(i); if (is_decreasing(report_copy) || is_increasing(report_copy)) && is_gradual(report_copy) { safe += 1; break; } } } } print(`part 2: ${safe}`);
Edit: I made it more compact and moved the
get_input
function to a separate file since it'll be used every day.Rhai Code
import "utils" as utils; // INPUT let reports = utils::get_input(2, false) .split("\n") .map(|report| report .split() .map(|l| l.parse_int())); // AUXILIARY fn is_safe_inner(report, last_diff) { if report.len() < 2 { return true; } let diff = report[0] - report[1]; let diff_abs = diff.abs(); if last_diff != () && last_diff * diff < 0 { return false; } diff_abs > 0 && diff_abs < 4 && is_safe_inner(report.extract(1), diff) } fn is_safe(report) { is_safe_inner(report, ()) } // PART 1 let safe = reports.filter(is_safe).len(); print(`part 1: ${safe}`); // PART 2 let safe = reports.filter(|report| { if is_safe(report) { return true; } else { for i in 0..report.len() { let report = report; report.remove(i); if is_safe(report) { return true; } } } false }).len(); print(`part 2: ${safe}`);
-
Comment on Day 1: Historian Hysteria in ~comp.advent_of_code
csos95 This year I'm doing Advent of Code in rhai, an embedded scripting language for rust, because I've been meaning to try it out for a while. It's not amazing speed-wise because it's a treewalk...This year I'm doing Advent of Code in rhai, an embedded scripting language for rust, because I've been meaning to try it out for a while.
It's not amazing speed-wise because it's a treewalk interpreter, but it has a lot of nice features such as many safety options for when you need to run untrusted code, custom operators/syntax, and a decent api for making rust types and functions usable within it.
I initially did it using the built-in object map type, but it seems to only support string keys and I was annoyed that I had to convert the integer keys I had with every get and set.
I could've just re-processed the input to have the values as strings again and not need to do any conversion, but I'm almost certainly going to need to use integer keys more than once so I added anHashMap<INT, Dynamic>
type namedIntMap
to Rhai.It was very easy to get started with, I had no trouble finding the methods I needed in the docs to complete the initial challenge or for creating the
IntMap
type and methods.
I'm quite impressed with how easy it was to extend.Rhai Code
fn get_input(day) { let input = open_file(`day${day}.txt`) .read_string(); input.trim(); input } let input = get_input(1); // PART 1 let list1 = []; let list2 = []; for line in input.split("\n") { let items = line.split(); list1.push(items[0].parse_int()); list2.push(items[1].parse_int()); } list1.sort(); list2.sort(); let total = 0; for i in 0..list1.len() { total += (list1[i] - list2[i]).abs(); } print(`part1: ${total}`); // PART 2 let list2_occurrences = new_int_map(); for location in list2 { let prev = list2_occurrences[location] ?? 0; list2_occurrences[location] = prev + 1; } let total = 0; for location in list1 { let occurrences = list2_occurrences[location] ?? 0; total += location * occurrences; } print(`part2: ${total}`);
-
Comment on How do you build strong online communities? in ~talk
csos95 Every funeral I've been to (which isn't a ton, but it's more than a few) has had plenty of jokes told. Everyone grieves differently, but if I were at a funeral with zero jokes told I'd probably...I mean if you tell a joke at a funeral you cannot read the room.
Every funeral I've been to (which isn't a ton, but it's more than a few) has had plenty of jokes told.
Everyone grieves differently, but if I were at a funeral with zero jokes told I'd probably wonder if anyone around even liked the person or ever had any good times with them. -
Comment on Any recommendations for books, novellas and short story collections? in ~books
csos95 I recently read The Dispatcher by John Scalzi and enjoyed it.I recently read The Dispatcher by John Scalzi and enjoyed it.
In the wake of an unexplained phenomenon worldwide — when people are deliberately killed, they almost always disappear from their site of death and reappear, reset to several hours earlier, in a safe place — the profession of "Dispatcher" evolves. Dispatchers euthanize mortally-injured people before their natural deaths, enabling them to reset. Tony Valdez is a Dispatcher recruited by the police to assist in investigating the disappearance of another Dispatcher.
-
Comment on Tildes Book Club - Spring 2025 nomination thread - Books from minority or diverse or disadvantaged perspectives in ~books
csos95 (edited )LinkBorn a Crime: Stories from a South African Childhood by Trevor Noah.Born a Crime: Stories from a South African Childhood by Trevor Noah.
The book details Trevor Noah's experiences growing up in South Africa during the apartheid era. Noah's parents were a white Swiss-German father and a black Xhosa mother. At the time of Noah's birth in 1984, their interracial relationship was illegal under the Immorality Act, 1957. According to Noah, "for [him] to be born as a mixed-race baby" was to be "born a crime." Interracial relations were decriminalised when the Immorality Act was amended in 1985. As a mixed-race person, Noah was classified as a "Coloured" in accordance to the apartheid system of racial classification. Noah was raised primarily by his mother and maternal grandmother in Soweto.
-
Comment on A pregnant teenager died after trying to get care in three visits to Texas emergency rooms in ~society
csos95 It was Justice Thomas’ concurring opinion on the case. https://www.law.cornell.edu/supremecourt/text/19-1392#writing-19-1392_CONCUR_5 Relevant pragraph:I can't find a reference to it right now, but there was a whole list of decisions he was suggesting could be overturned, including gay and trans rights.
It was Justice Thomas’ concurring opinion on the case.
https://www.law.cornell.edu/supremecourt/text/19-1392#writing-19-1392_CONCUR_5Relevant pragraph:
For that reason, in future cases, we should reconsider all of this Court’s substantive due process precedents, including Griswold, Lawrence, and Obergefell. Because any substantive due process decision is “demonstrably erroneous,” Ramos v. Louisiana, 590 U. S. ___, ___ (2020) (Thomas, J., concurring in judgment) (slip op., at 7), we have a duty to “correct the error” established in those precedents, Gamble v. United States, 587 U. S. ___, ___ (2019) (Thomas, J., concurring) (slip op., at 9). After overruling these demonstrably erroneous decisions, the question would remain whether other constitutional provisions guarantee the myriad rights that our substantive due process cases have generated. For example, we could consider whether any of the rights announced in this Court’s substantive due process cases are “privileges or immunities of citizens of the United States” protected by the Fourteenth Amendment. Amdt. 14, §1; see McDonald, 561 U. S., at 806 (opinion of Thomas, J.). To answer that question, we would need to decide important antecedent questions, including whether the Privileges or Immunities Clause protects any rights that are not enumerated in the Constitution and, if so, how to identify those rights. See id., at 854. That said, even if the Clause does protect unenumerated rights, the Court conclusively demonstrates that abortion is not one of them under any plausible interpretive approach. See ante, at 15, n. 22.
-
Comment on Star Trek: Strange New Worlds | Season 3 NYCC exclusive clip in ~tv
csos95 They're from season 20 of South Park. They're talking fruit that look a bit like grapes that cause people to feel nostalgic about stuff with comments in the form of "Member X?". They start out...They're from season 20 of South Park.
They're talking fruit that look a bit like grapes that cause people to feel nostalgic about stuff with comments in the form of "Member X?".
They start out making comments about Star Wars, but as the season goes on they throw out more and more bigoted comments like "Member when there weren't so many Mexicans?"I can't remember specifically how the season ended, but I think it was something to do with the election, the memberberries being the big bad pulling the strings and creating a change in society that made Mr. Garrison (who acts as Trump stand-in in South Park) popular, and then they just sort of disappeared because the writers didn't plan for Trump actually winning.
I assume they just mean the "nostalgia bait" part and not the latter bit in their comment.
-
Comment on Intuit is shutting down the personal finance service Mint and shifting users to Credit Karma in ~finance
csos95 There was a new comment: https://tildes.net/~finance/1btc/intuit_is_shutting_down_the_personal_finance_service_mint_and_shifting_users_to_credit_karma#comment-cxn5 For future reference, the topic...There was a new comment: https://tildes.net/~finance/1btc/intuit_is_shutting_down_the_personal_finance_service_mint_and_shifting_users_to_credit_karma#comment-cxn5
For future reference, the topic log on the right sidebar (if you’re on mobile you can open it by clicking the “sidebar” link on the top right of the page) shows when the last comment was made and links to it.
So for me right now it shows
Last comment posted
7m ago -
Comment on Database schema for an upcoming comment hosting system in ~comp
csos95 Here is the documentation on strict tables. I haven't bothered to use them because I do all my stuff in rust (usually with diesel) and have strong type checking to prevent me from using the wrong...Here is the documentation on
strict
tables.
I haven't bothered to use them because I do all my stuff in rust (usually with diesel) and have strong type checking to prevent me from using the wrong type by accident.but not sure even referential integrity is maintained by Sqlite unless we use the strict mode?
Strict tables are unrelated to foreign key constraints.
The default for SQLite (another one of those "backwards compatibility" oddities) is to not enforce foreign key constraints.
You have to enable it with apragma
statement:pragma foreign_keys = on;
A full list of pragma statements is available here.I usually use
journal_mode = wal
,synchronous = normal
,foreign_keys = on
, andbusy_timeout = SOME_TIMEOUT_IN_MS
in my projects.
This will use a write ahead log for writes (much faster and makes it so readers and writers (still limited to one writer at a time though) do not block each other), make it do less syncing to the filesystem, enable foreign key checking, and automatically waits if a table is locked with a defaultbusy_handler
.Something to note for that last option is that it mostly will take care of
database is locked
errors that occur when you try to read/write when the needed table is locked.
The one case it doesn't cover is when adeferred
transaction (the default) is "upgraded" to a write transaction.
In this case, if a needed table is locked, it will immediately error instead of using thebusy_handler
.
So if you use transactions, you should make themimmediate
when you are going to be writing.
Ex:begin immediate transaction
Transactions documentation here -
Comment on Database schema for an upcoming comment hosting system in ~comp
csos95 Adding to what unkz said, php has built-in functions for secure password hashing and verification. password_hash and password_verify.Adding to what unkz said, php has built-in functions for secure password hashing and verification.
password_hash and password_verify. -
Comment on Database schema for an upcoming comment hosting system in ~comp
csos95 (edited )LinkSomething to be aware of is that in SQLite the types are more of a hint for how to store the data for a column rather than a constraint. You can store any type of data in any type of column...Something to be aware of is that in SQLite the types are more of a hint for how to store the data for a column rather than a constraint.
You can store any type of data in any type of column (unless you specifically usestrict
tables).
It will attempt to convert the data to the storage class indicated by the column type used, but if it fails it will store the data as is.
This page of the SQLite documentation explains this in detail.
I come back to it often to remind myself of what column types are associated with what affinities.Additionally, the numeric parameters on types are ignored.
So a column of typevarchar(255)
will store a 300 character string without complaint.
To add a constraint on the length you need to add acheck
constraint to the end.
So instead ofname varchar(255) not null
, you can doname text not null check(length(name) <= 255)
(I generally prefer using the five affinity type names so I don't have to remember the exact rules for affinity mapping).EDIT: I just noticed you have two primary keys set for the
comments
table.
That won't work.
Theid
column should probably be defined asid integer primary key autoincrement
and theuser_id
should be defined asuser_id integer not null references users(id)
.
Theautoincrement
preventsrowid
s from being reused in certain situations and isn't strictly necessary, but I always use it to be safe because it doesn't really affect performance for anything I've used SQLite for.
Additionally if you ever want to have a primary key that isn'tinteger
(which is a special case that maps to therowid
), you need to addnot null
to it.
Otherwise you could end up with every row having aNULL
id.
This is because of two issues:primary key
does not implynot null
in SQLite because there was a bug early on and changing it to follow the SQL standard would break programs that relied on that behavior (that's the general reason behind many weird behaviors/default values in SQLite).- In SQL null is not equal to anything, even null, so all of the null primary key values would be considered different.
Another thing is that you can put the
unique
constraints directly on the column they refer to when it's just a single column.
Ex:username text not null unique
-
Comment on Megathread: April Fools’ Day 2024 on the internet in ~talk
csos95 After years of it being requested, SpaceBattles has finally added a NSFW forum! Minecraft: Poisonous Potato Update -
Comment on Florida latest to restrict social media for kids as legal battle looms in ~tech
csos95 (edited )Link ParentSomething I've wanted a few times (usually after dealing with young children popping into a discord server that usually leans towards adult conversations) is a government run oauth service that...Something I've wanted a few times (usually after dealing with young children popping into a discord server that usually leans towards adult conversations) is a government run oauth service that provides a property with what age group the person is in.
If that were a thing, you wouldn't need to worry about each company's privacy/security policies around verifying IDs, you just need to login with that service and they'll have access to a few basic details about you that are listed before you approve the authorization.
-
Comment on Apple is turning William Gibson’s Neuromancer into a TV series in ~tv
csos95 I'm not familiar with this work, but I first heard about this adaptation yesterday in a discord server when someone posted this Twitter thread from the author and I thought it might be useful for...I'm not familiar with this work, but I first heard about this adaptation yesterday in a discord server when someone posted this Twitter thread from the author and I thought it might be useful for fans wondering how faithful it will be to the book.
text of the tweets
I’m not going to be answering many questions here, about Apple TV’s adaptation of Neuromancer. I’ll have to be answering too many elsewhere, and doing my part on the production. So I thought I’d try to describe that, my part.
I answer showrunner’s and director’s questions about the source material. I read drafts and make suggestions. And that’s it, really, though my previous experience has been that that winds up being quite a lot of work in itself.
I don’t have veto power. The showrunner and director do, because the adaptation’s their creation, not mine. A novel is a solitary creation. An adaptation is a fundamentally collaborative creation, so first of all isn’t going to “be the book”.
Particularly not the one you saw behind your forehead when you read the book, because that one is yours alone. So for now let’s leave it at that.
-
Comment on Collapse comments? in ~tildes
csos95 I pretty much always like seeing comments with <details> tags. It makes navigation much easier for me on both mobile and desktop.I pretty much always like seeing comments with
<details>
tags.
It makes navigation much easier for me on both mobile and desktop. -
Comment on Tildes Book Club - How is it going? Discussion of Cloud Atlas will begin the second full week in March. in ~books
csos95 I started the book yesterday, but have been having trouble getting through the first section. Maybe spoilers (it's the very start of the book though so not much) and negative feelings on the book...I started the book yesterday, but have been having trouble getting through the first section.
Maybe spoilers (it's the very start of the book though so not much) and negative feelings on the book
I get that the writing is supposed to make you feel like it was written by someone from the 1800s, that the racism is in your face as soon as possible to really hammer home it's a different time without "good old days" sugar coating, and maybe to make you not as sympathetic to the narrator.
My issue is that the end result of that is still reading about two wealthy white guys traipsing around the colonies while using as many obscure words (that almost all have no results on my kindle from the built-in dictionary or Wikipedia) and racist slurs as possible.
So I'm having a lot of trouble getting into it.For those who are further along/have finished: Do they cool it with the racism anytime soon?
I've heard the other sections are better, but I'm also aware that the sections are split so the second half of the first section is also the ending to the book.
I'm not sure I'm looking forward to getting to the end if it's going to be jumping back to more of this.If I can't get through this section tomorrow, I think I'll try just skipping it and seeing if the rest of the book interests me more.
-
Comment on Borderlands | Official trailer in ~movies
csos95 I've been a big fan of the Borderlands games (besides the third, haven't played it), but I somehow missed that there was a movie coming. I'm cautiously optimistic because Borderlands didn't really...I've been a big fan of the Borderlands games (besides the third, haven't played it), but I somehow missed that there was a movie coming.
I'm cautiously optimistic because Borderlands didn't really have a good or complex story that can be ruined in the translation to the movie.
There are vault hunters, they're looking for a vault, and there are other groups trying to find it first.The fun of it for me (beyond the gameplay) was the world, aesthetics, and short bits of funny dialogue.
And it seems to me like this has that from what the trailer showed. -
Comment on The carry-on-baggage bubble is about to pop in ~travel
csos95 Yes, they are free. A few people I know bring a backpack and a suitcase that is exactly the allowed carry-on size and board last with the knowledge that there's a very low chance there will be...When bags are checked at the gate, are those free? I wonder if that sets up some perverse incentive, where people, not wanting to pay the expensive fee for checked bags, hope that they can a free checked bag at the gate.
Yes, they are free.
A few people I know bring a backpack and a suitcase that is exactly the allowed carry-on size and board last with the knowledge that there's a very low chance there will be space available when they get on.
That way they'll be able to get on (the bins usually fill up and they're asked to check before they get to the boarding ramp) and off the plane without digging through overhead bins or paying for the bag check.
That was my first thought when I read the challenge and I'm looking forward to it!