HNHacker News
TopNewBestAskShowJobs

phiresky

3,459 karma · joined July 26, 2018

https://phiresky.github.io/blog/
submissionscomments
phiresky··on Have the Tables Turned on NoSQL?
Since Pg12, even adding a column with a default doesn't lock the table anymore - that only happens if you later change or remove the default
phiresky··on Zstandard v1.4.7
I'm actually working on a sqlite addon right now that allows to transparently compress tables in sqlite using zstd dictionaries and the preliminary results are really promising! One DB I have compresses down from 1GB to 80MB and random SELECTs are faster in the compressed DB when the cache is cold and only somewhat slower when it is hot :)

https://github.com/phiresky/sqlite-zstd

phiresky··on A case study on strict null checks
> As an aside, the Rust code could also be written like this

Sadly it can't really, because Rust doesn't have control-flow based type refinement like TypeScript.. In TS the type of `file` after the throw is File. In Rust it stays `Option<file>` so you would have to unsafely unwrap it below the if block.

phiresky··on How To Safely Store A Password (2010)
Yes, scrypt-kdf works great:

    const scryptParams = { logN: 15, r: 8, p: 1 };
    async function hashPassword(password: string): Promise<string> {
    const password_hash: Buffer = await scrypt.kdf(password, scryptParams);
    return password_hash.toString("base64");
    }
    async function verifyPassword(hash, password): Promise<boolean> {
        return await scrypt.verify(Buffer.from(hash, "base64"), password);
    }
phiresky··on Rga: Ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz
Yeah, In my opinion poppler should be a dependency of rga in homebrew (since it's kinda useless without having the default adapters), but I don't maintain that package.
phiresky··on Rga: Ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz
> If you file an issue against ripgrep proper with code links and some more details

Sorry, I don't think I explained my issue very well. In general it has nothing to do with the interaction with ripgrep, that works fine.

It's that each adapter (e.g. zip -> list of file streams) needs to have an interface of fn(Read) -> Iter<ReadWithMeta>

But then if there's a PDF within the zip, I have to give the returned ReadWithMeta to the PDF adapter - but it can't take ownership, because the Archive file iterators only give borrowed reads. I maybe worked around this by creating a wrapper type [3] and adding an unsafe here [2], but something deadlocks when adapting zip files currently.

Also, for external programs, I have to copy the data from the Read into a Write (stdin of the program) - which needs to happen in a separate thread, otherwise the stdout is never read [1], but some Reads I have aren't Send since they come from e.g. zip-rs, so they can't be passed to a thread.

[1] https://github.com/phiresky/ripgrep-all/blob/baca166fdab3d24...

[2] https://github.com/phiresky/ripgrep-all/blob/baca166fdab3d24...

[3] https://github.com/phiresky/ripgrep-all/blob/baca166fdab3d24...

phiresky··on Rga: Ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz
pdfgrep has a --cache option since a while ago :) Not sure why they don't enable it by default. Still, this is much faster.
phiresky··on Rga: Ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz
rga uses pdftotext (from poppler) internally for pdfs, except wraps it in parallelization and a very fast cache layer, since you usually want to do multiple queries per file :)
phiresky··on Rga: Ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz
Scanned PDFs only work well if they already have an OCR layer. There's some optional integration of rga with tesseract, but it's pretty slow and less good than external OCR tools.

ripgrep-all can do the same regexes as rg on any filetypes it supports. So you can could do something like --multiline and foo(\w+[\s\n]+){,20}bar

It won't work exactly like this, but something similar should do it:

--multiline enables multiline matching

* foo searches for foo

* \w+ searches for at least one word character

* [\W]+ searches for at least one space/nonword character like sentence marks

* {,20} searches for at most 20 iterations of the word-space combination bar searches for bar

phiresky··on Rga: Ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz
Developer of the tool here :) Glad to see it posted here, I still actively use it myself. Also check out the fzf integration in the README: https://github.com/phiresky/ripgrep-all/blob/master/doc/rga-...

Currently the main branch is undergoing a refactor to add support for having custom extractors (calling out to other tools), and more flexible chains of extractors.

Ripgrep itself has functionality integrated to call custom extractors with the `--pre` flag, but by adding it here we can retain the benefits of the rga wrapper (more accurate file type matchers, caching, recursion into archives, adapter chaining, no slow shell scripts in between, etc).

Sadly, during rewriting it to allow this, I kind of got hung up and couldn't manage to figure out how to cleanly design that in Rust. I'd be really glad if a Rust expert could help me out here:

In the currently stable version, the main interface of each "adapter" is `fn(Read, Write) -> ()`. To allow custom adapter chaining I have to change it to be `fn(Read) -> Read` where each chained adapter wraps the read stream and converts it while reading. But then I get issues with how to handle threading etc, as well as a random deadlock that I haven't figured out how to solve so far :/

phiresky··on Pandoc – A universal document converter
Yeah, filters are great. Writing filters is easy: Pandoc basically converts the input document into a universal AST (json), and a filter is just any program that takes this json as an input and outputs a modified json AST.

I wrote a filter that automatically converts URL citstions in markdown to "real" citations in any style you want - very useful for writing papers without fighting with bibtex and managing bibliographies manually: https://github.com/phiresky/pandoc-url2cite

phiresky··on Cloudflare One
Yes, by default all websites hosted with cloudflare are completely insecure. Even if both the client connects via https, AND the server supports https, cloudflare uses an unencrypted http connection.

Even the encryption: "full" setting is useless, since it doesn't verify certificates in any way, so an MITM attacker can just sign their own cert in your name.

I suspect CF does this so they can have their "one-click" on boarding for panicking under-attack companies. It really shows that despite all the blog posts about lava lamps and how important security is for them, in the end sales and the shareholder's interest (profit) is king. The very least they should do is have huge warnings about switching to "full (strict)" asap, but really the other two shouldn't be an option at all.

I'm reminded of this whenever I add a new site to CF, since when port 80 is not open, CF just does not work at all, it just shows "backend server down", even when TLS/443 is set up correctly.

And arguing that "it's fine because it protects the connection between the user and the CF server which is the most vulnerable point" is ridiculous. Your nearest CF server is probably in a neighboring city, so the whole path between that city and the other side of the world is readable and modifiable by whoever.

phiresky··on Loading CSV File at the Speed Limit of the NVMe Storage
Yeah, I meant both the ByteRecord/read_byte_record API, as well as using Serde with a struct containing &str or &[u8] references.
phiresky··on Loading CSV File at the Speed Limit of the NVMe Storage
It would be great if a comparison to the rust csv library or xsv [1] could be added - it's single threaded, but it has a zero copy option as far as I know. I've used it to parse / filter large PostgreSQL log files (20GB+) with great success.

[1] https://github.com/BurntSushi/xsv

phiresky··on Beware of Async/Await
This is not true, since in JS promises are dispatched as soon as they are created. So as long as you call the fetch function, it doesn't matter that you are calling `await` sequentially.
phiresky··on Worrying about the NPM Ecosystem
You could have found a better example. The package you referenced literally just does `Number.isInteger` unless you are on decade old versions of nodejs
phiresky··on Show HN: Zapatos, a Postgres Library for TypeScript
Looks pretty good. Looks like a good compromise between Prisma [1] and pure pg.

Also the way you show examples is one of the best I've seen so far, with the output right below, optionally showing imports imports and the option to show it in a monaco editor with types.

Could you also compare it to Prisma and Mammoth [2]?

[1]: https://www.prisma.io/ [2]: https://github.com/Ff00ff/mammoth

phiresky··on Windows Package Manager Preview
... this thing literally just downloads .exe files and then executes them. There's no dependency management.

Look at the firefox "package": https://github.com/microsoft/winget-pkgs/blob/master/manifes...

There isn't even any uninstall functionality.

This is a package manager as much as a piece of cardboard is a swiss army knife.

Even if you say "but it's a preview", there's just no where to go when your starting point is "execute some arbitrary binary". The point of packages is to be declarative as much as possible.

phiresky··on WorldBrain's Memex: Bookmarking for the power users of the web
> Yeah, my computer is fast enough that I can just do "find . -name '*.pdf' -exec pdftotext {} \; | grep -i someSearchTerm" and come back later.

You may be interested in my ripgrep-all [1] tool, it should allow you to search those tens of thousands of PDFs in under a second (with hot cache)

[1] https://phiresky.github.io/blog/2019/rga--ripgrep-for-zip-ta...

phiresky··on No cookie consent walls, scrolling isn’t consent, says EU data protection body
You're really misunderstanding the GDPR. Cookies are not mentioned anywhere in the law and it's actually really simple to understand:

1. You can do whatever you need to do to provide the service you're providing. (login cookies, sessions, store their email address, whatever).

2. If you want to process, store, and sell any other user data, you need to ask them first.

So for example if you want to send 100 advertising companies personal data about your users, you need to ask for consent and allow them to decline without restricting their access to you service.

What technology you use to track users is irrelevant, it can be fingerprinting or cookies or anything else.

The only reason why you think the law is bad is because companies are frantically trying to work around it, trying to interpret it in unintended ways to not impact their data tracking ways, and trying to make users hate the law instead of them.

phiresky··on Khronos Announces OpenCL 3.0
Alternative take: An Open API is good, but Microsoft and Nvidia are too powerful to allow it

http://blog.wolfire.com/2010/01/Why-you-should-use-OpenGL-an...

phiresky··on Possible dinosaur DNA has been found
> DNA has a half life of ~500 years

but:

Researchers in 2016 measured chloroplast DNA in marine sediment cores, and found diatom DNA dating back to 1.4 million years.[62] This DNA had a half-life significantly longer than previous research, of up to 15,000 years. Kirkpatrick's team also found that DNA only decayed along a half-life rate until about 100 thousand years, at which point it followed a slower, power-law decay rate.

https://en.wikipedia.org/wiki/Ancient_DNA#Non-human_aDNA

phiresky··on Prisma 2.0 Beta: Type-safe Database Access
This seems to be solving mostly the same problem as the following libraries:

[1] https://github.com/phiresky/ts-typed-sql [2] https://github.com/Ff00ff/mammoth [3] https://github.com/AnyhowStep/tsql [4] https://github.com/travigd/vulcyn

A query in one of those looks like the following:

    const rows = await select(list.id, list.createdAt)
      .from(list)
      .where(list.createdAt.gt(now().minus(`2 days`)).or(list.value.eq(0)))
      .limit(10);
The resulting type of `rows` is inferred by TypeScript to the corresponding correct type (`{id: string, createdAt: Date}`)

Prisma solves the problem by generating code, while all of these do it completely in type-level within typescript. Prisma also seems to introduce its own query language, while the above linked libraries stay closer to SQL.

[1] was written by a friend of mine and I'm using it in production to great success. I wouldn't recommend it though because it has repeatedly broken with new TypeScript updates since it uses very complex type structures and the dev has basically given up on it due to the complexity.

[2] is probably the most production-ready, though it has some design choices I'm not sure about.

[3] is the most well-designed, and can handle complex scenarios (including differentiating between join types etc). But it's incomplete so far.

[4] I have not used.

Pure type-level has the advantage of not adding a compile-step and keeping everything in a tool you already know. But all of the above have the disadvantage that the resulting type structures are very complex - most TS devs would have a hard time understanding the internals of the libraries and the resulting type errors can be unreadable. They can also cause the TS compiler to slow down significantly (in the past [1] had exponential compile time when adding a new column, though this has been fixed).

Also, since the TS compiler uses heuristics in multiple places and the type system is not sound, Microsoft has introduced regressions that have broken [1] in every other release.

phiresky··on Blake3 is 10 times faster than SHA-2
> They are computationally slow, no tricks

They have to and do use tricks, they aren't just slow. You could trivially make sha256 slow by just applying it a million times (that's not even parallelizable as well), but scrypt et al improve on that by making the algorithm also require a lot of RAM, use complex instructions (hard to recreate on a GPU or FPGA) and so on.

It's really hard to do very well, look at cryptocurrencies trying to be ASIC resistant: They want every normal person to be able to mine it, and don't want companies to be able to build a machine that can eclipse the mining power of everyone which means centralization.

phiresky··on Show HN: Url2cite: Transparently convert links to citations in markdown papers
That's one problem with relying on automatically extracted information - sometimes it's not really what you want. In this case that's just what GitHub puts in the og:description tag for large? repos, probably to make it appear that way on Google. Of course I could fix it for this instance but then it wouldn't really accurately represent what you can expect...

The relevant code to extract that is a Zotero Translator [1] so that's what would have to be changed for this.

[1]: https://github.com/zotero/translators/blob/master/GitHub.js

phiresky··on Show HN: Url2cite: Transparently convert links to citations in markdown papers
Well, you can use the same json file for multiple documents.

By default it will be stored in the directory from which pandoc is invoked, but you can also change that by setting `url2cite-cache: filename` in the markdown frontmatter or in the pandoc invocation: `pandoc -M url2cite-cache=../bla.json --filter ...`.

phiresky··on Show HN: Url2cite: Transparently convert links to citations in markdown papers
I don't really see the issue, but I've increased the opacity anyways :)
phiresky··on Show HN: Url2cite: Transparently convert links to citations in markdown papers
Each citation is added to a formatted JSON file when it is first seen. After this it stays the same. This means you can fix the citation data by hand by just editing the JSON file. You should include the JSON file in your version control. An example is here [1]

Of course this might not be as comfortable as a GUI editor like Zotero, but I think I still prefer doing some small tweaks to a JSON file vs. the problems I've had in the past with Zotero exporting. The auto-export didn't always work consistently, and Zotero has many features that I don't need at all that make the whole thing more complex and fragile. Even collections are somewhat confusing to work with - I've often added citations to the wrong collection because it always adds to the currently open one, and then had to spend time to find it again. You also can't know which references are actually used and which aren't.

And I pretty much always gave up as soon as someone else needs to work on the same paper, which then leads to managing the .bib file by hand anyways.

[1]: https://github.com/phiresky/pandoc-url2cite/blob/master/exam...

phiresky··on An open-source browser extension to auto-skip sponsored segments on YouTube
Currently yes, though there's discussion of adding k-anonymity: hashing the video id and querying by a prefix of the hash short enough so each request will return on average data for maybe ~16 videos

https://github.com/ajayyy/SponsorBlockServer/issues/25

phiresky··on Frink
I wrote a similar tool that uses the same unit database (from GNU units) but is open source, has a somewhat better online interface [1] and a crappier app [2]

[1]: https://phiresky.github.io/qalc-react/ [2]: https://play.google.com/store/apps/details?id=io.github.phir...

← PreviousPage 4 of 7Next →