HNHacker News
TopNewBestAskShowJobs

rraval

421 karma · joined November 24, 2011

Blog: https://zeroindexed.com

[ my public key: https://keybase.io/rraval; my proof: https://keybase.io/rraval/sigs/Ax1_hUoT2TVxiPextem1Y8Vwi61TqJ2pIbE4E19eXqE ]

submissionscomments
rraval··on Do or undo – there is no VACUUM
The article has a link to a previous blog post that expands on how Oracle does it (as well as other DB's).

http://amitkapila16.blogspot.ca/2015/03/different-approaches...

> Oracle maintain old versions in rollback segments (also known as 'undo log').

rraval··on Chrome 61 UXSS (CVE-2017-5124)
This seems to be explained in better detail by https://bo0om.ru/chrome-and-safari-uxss. Working via Google Translate, the claim seems to be that using MHTML and XSLT allows you to bypass the sandboxing rules and inject JavaScript that bypasses the same-origin policy.

The linked blog credits a Chromium patch that led to the discovery of this exploit: https://chromium-review.googlesource.com/c/chromium/src/+/65...

rraval··on Select Transform: JSON template over JSON
Yeah, I personally find this sort of syntax convolution ugly and hard to read but I thought it relevant. Enough rope to hang yourself with and whatnot.
rraval··on Select Transform: JSON template over JSON
Since you're using Python for your example, it's worth mentioning that 3.5 extended the unpacking syntax [1] to sort of do what you want.

    foo = {
        'a': 1,
        'b': 2,
        **({
            'c': 3,
            'd': 4,
        } if bar else {}),
    }
This adds `c: 3` and `d: 4` into `foo` conditional on `bar`.

[1] https://docs.python.org/3/whatsnew/3.5.html#pep-448-addition...

rraval··on Transactionally Staged Job Drains in Postgres

    loop do
      DB.transaction do
        # pull jobs in large batches
        job_batch = StagedJobs.order('id').limit(1000)

        if job_batch.count > 0
          # insert each one into the real job queue
          job_batch.each do |job|
            Sidekiq.enqueue(job.job_name, *job.job_args)
          end

          # and in the same transaction remove these records
          StagedJobs.where('id <= ?', job_batch.last).delete
        end
      end
    end
Isn't this essentially a busy loop? You can achieve something much more performant by using `LISTEN` and `NOTIFY` to fire an event every time a row is inserted.

Then the enqueuer can do a preliminary scan of the table when it boots up and then just a `LISTEN` instead of polling the DB.

rraval··on HashiCorp and Google: easing secret and infrastructure management
We use StackExchange's blackbox [1] to check in GPG encrypted secrets into our monorepo (contains both ansible deployment playbooks and the code itself). This way, we can introduce secrets and the code that uses it in a single commit!

[1] https://github.com/StackExchange/blackbox

rraval··on Redesigning Python's named tuples
They are the "same" by equality, but that's not the only relevant comparison. Ordering is important if you want lexicographic less than.

Without ordering, you wouldn't be able to sanely run `sorted` on a iterable of namedtuples.

rraval··on Type Systems (2004) [pdf]
See https://codewords.recurse.com/issues/one/type-systems-and-lo... for a pretty elaborate response to this question.

tl;dr: types are propositions and values are proofs of those propositions. Constructive logic is not concerned with (true xor false), but rather "I can prove A" or "I can prove not-A". There's also the middle ground of "I don't know how to prove anything about A".

rraval··on Implementing Algebraic Effects in C
This is super interesting and I'm still going through the paper. For folks with a "Cool, but why" reaction, the introduction elaborates:

  For example, the P language [10] is a language for describing verifiable asyn-
  chronous state machines, and used for example to implement and verify the core
  of the USB device driver stack that ships with Microsoft Windows 8. Compiling
  to C involves a complex CPS-style transformation [19, 26] to enable async/await
  style programming [5] with a receive statement – using the effects library this
  transformation is no longer necessary and we can generate straightforward C
  code instead. Similarly, we hope to integrate this library with libuv [29] (the
  asynchronous C library underlying Node [43]) and improve programming with
  libuv directly from C or C++ using async/await style abstractions [12, 27]
Since the linked abstract doesn't actually mention this practical application, consider this comment as a goad to encourage more people to click through to the paper :)
rraval··on Ask HW: What is the state (for you) of CoffeeScript?
For background, my startup has been using CoffeeScript since August 2012. A quick check of our git monorepo says that we have 130k lines of code at HEAD, and have probably thrown out at least as many lines in rewrites over the years.

I have a love/hate relationship with CoffeeScript. I detest the implicit function call and object literal syntax. At various points in the language's history, it seemed like the language was essentially "done" and in maintenance mode. Especially when the eco-system stagnates around it and large parts of the community move on to things like ES6 and TypeScript. For example, the JSX tool was essentially a prototype [1], with tons of bugs [2] that were never fixed. And in the 6 months since its deprecation, there isn't a single tool to replace it.

Personally speaking, I consider the language dead and was considering alternatives so we could move off it. However, I still haven't been able to justify it because the alternatives don't make the same tradeoffs that make me love CoffeeScript:

- Minimal to zero runtime requirements. CoffeeScript generates a few things like `__extends` but that's it!

- One to one correspondence with generated JS. Source maps are nice but it's great to step through the JS debugger when looking at JS, and being able to convert the JS you're looking at with the CoffeeScript that generated it is not something I want to give up.

- Recognizes the warts, fixes what it can, and then gets the hell out of the way. `==` in JS is a mistake and IMO no language should carry that forward. Lexical `this` binding shouldn't require hoops to jump through. That sort of thing.

Ideally, if we are paying the cost of switching away from CoffeeScript, we'd move to a language with static type checking and solid support for sum types. I haven't been able to find any such language though, and the recent development spurt in CoffeeScript seems to have staved off that need for now.

PS: Yes, I'm aware of TypeScript. It's sum type support is rather weak. As part of my initial testing to see if it was a suitable language, I found a 5 line program that crashed at runtime. The bug report was closed as "Working as intended" [3]

[1] https://github.com/jsdf/coffee-react-transform [2] https://github.com/jsdf/coffee-react-transform/issues/62 [3] https://github.com/Microsoft/TypeScript/issues/13884

rraval··on Scrypt is Maximally Memory-Hard
I'm intrigued.

Do you have a link or something that I can read more about the "new approach" as you say?

rraval··on A Two Month Debugging Story
One advantage of the template approach is it allows for test level parallelism, which may address your primary goal of performance.

> Waterline queries are case insensitive; that is, Users.find().where(name: 'FOO') will turn into SELECT * FROM users WHERE name = LOWER('FOO');. There's no way to turn this off. If you ask Sails to generate an index for you, it will place the index on the uppercased column name, so your queries will miss it. If you generate the index yourself, you pretty much have to use the lowercased column value & force every other query against the database to use that as well.

What the actual fuck!

rraval··on A Two Month Debugging Story
> To ensure each test has a clean slate, we clear the database between each test.

The proposed solution to manually nuke the database state seems crazy to me. Some alternatives:

1. Run the entire test in a transaction, do flushes and assert as normal. At the end, ROLLBACK instead of COMMIT and now you have a pristine database again. [1]

2. Setup pristine DB state once and then use `CREATE DATABASE ... WITH TEMPLATE ...` to create a temporary database. Not sure what the perf hit is, but it's probably worth trying. [2]

[1] http://alextechrants.blogspot.ca/2013/08/unit-testing-sqlalc...

[2] https://www.postgresql.org/docs/9.4/static/manage-ag-templat... CREATE DATABASE actually works by copying an existing database. By default, it copies the standard system database named template1.

rraval··on A prog by any other name
That may just be because they are shell scripts instead of symlinks. On ArchLinux:

    $ ls -li /usr/bin/{grep,egrep,fgrep}
    1728040 -rwxr-xr-x 1 root root     28 Apr 23 12:12 /usr/bin/egrep*
    1728041 -rwxr-xr-x 1 root root     28 Apr 23 12:12 /usr/bin/fgrep*
    1728042 -rwxr-xr-x 1 root root 159024 Apr 23 12:12 /usr/bin/grep*

    $ cat /usr/bin/egrep
    #!/bin/sh
    exec grep -E "$@"

    $ cat /usr/bin/fgrep
    #!/bin/sh
    exec grep -F "$@"
The general point of them being implemented by the same executable still stands.
rraval··on Show HN: Libquiet – transmit data using sound
Wow, this looks like a much better version of something we attempted for a hackathon [1]. I'm probably going to spend the weekend spelunking through this!

Is there a more detailed write up of the inner workings floating around?

[1] https://github.com/rraval/pied-piper

rraval··on Performance of ES6 features relative to ES5
There is a recent v8-users mailing list thread on this exact topic. Here's one possible explanation on perf differences between `let` and `var`: https://groups.google.com/d/msg/v8-users/hsUrt4I2D98/ELsfO1e...
rraval··on Pandora to Buy Rdio Assets for $75M, Rdio Files Ch.11, Will Shutter Service
Not what you asked for, but I wrote an Rdio to Google Music exporter a while back: https://github.com/rraval/rdio-gmusic
rraval··on IBM is still making ThinkPad keyboards
I use vim and have caps lock bound to control. I use Ctrl-[ to switch to normal mode and ctrl is so much more useful outside of just vim.
rraval··on Tone: An experimental Chrome extension for instant sharing over audio
Oh hey, I actually built something extremely similar in a hacknight recently [1]. Except instead of just converting URLs to fixed size tokens (also how chirp.io works), I allowed arbitrary bit streams and forward error correction.

[1] https://github.com/rraval/pied-piper

rraval··on Ccat – syntax highlighting cat
Just a quick tip, you would want to use `less -R` (upper case R) instead. `less -r` allows all raw characters which makes it difficult for less to maintain screen appearance. From the man page:

    -R or --RAW-CONTROL-CHARS
        Like  -r,  but only ANSI "color" escape sequences are output in "raw" 
        form.  Unlike -r, the screen appearance is maintained correctly in most
        cases.
rraval··on Ruby-like string interpolation in Python
I called it funky because `x` is never local to `inner`, but gets an entry inside `locals()` if `inner` uses it implicitly or explicitly with `nonlocal`.

Non-funky behaviour would be to have an `enclosing()` that walks up the outer functions and returns the union of their `locals()`. Alternatively, a `vars()` which expands to all variables in scope (respecting LEGB) would be best given the context of variable interpolation.

rraval··on Ruby-like string interpolation in Python
Note that `locals()` actually does funky things around enclosing scopes.

Consider the following Python2/3 code:

    def outer():
        x = 1
        def inner():
            print(x)
            print("x = {x}".format(**locals()))
        inner()

    outer()
This actually prints the right thing when run:

    1
    x = 1
However, if you remove the `print(x)` line, both Python 2 and 3 don't hoist the enclosing `x` into `locals()` (since it can't see a single usage of that variable), resulting in a `KeyError`:

    Traceback (most recent call last):
      File "blah.py", line 7, in <module>
        outer()
      File "blah.py", line 5, in outer
        inner()
      File "blah.py", line 4, in inner
        print("x = {x}".format(**locals()))
    KeyError: 'x'
Python 3 has the `nonlocal` keyword that you can use to indicate that you're using a variable from an enclosing scope so that it's properly introduced into `locals()` but Python 2 doesn't have this facility.
rraval··on Qake: GNU Make-based build system with a different approach
In my case, I was entirely unaware of Shake's existence. The no-nonsense support for file oriented workflows is the most compelling feature of Makefiles for me.

In that regard, Shake seems really compelling. It supports the file oriented nature of my build system. It's backed by an actual programming language, with lexical scoping, functions, a module system... all the things that suck about Makefiles.

Most importantly, it solves the one thing that drives me up the wall with Makefiles: supporting custom command line arguments sanely. I detest typing `make web TARGET=prod` and `shakeArgsWith` seems like it provides the flexibility of specifying targets and flags from custom command line arguments.

Thanks for this, I'm going to try and convert a few non trivial Makefiles to Shake. Any cons I should be aware of?

rraval··on Leap Motion sets a course for VR
For a hacknight back in April, I tried mapping my arm into a 3D pointing device that recognized a recoil wrist gesture as firing a gun. Sound effects like "pew pew pew" were optional but heavily encouraged.

I initially tried the Leap Motion mounted on the Oculus Rift. As this blog notes, the top-down recognition was iffy at best but things really went to shit the moment the sensor was moved. I was unable to get even gun orientation working in the 6 hours or so that I tried, so maybe the new SDK + sensors can fix that.

I did end up building my demo, but with a alpha Thalmic Myo instead of the Leap. Video: https://www.youtube.com/watch?v=lihaqf3COw8

rraval··on MIT study finds that human subjects prefer when robots give the orders
I spent more time than I'd like to admit trying to find the actual paper (it's in the right corner under "Related", I blame banner blindness!)

Link for others like me [PDF]: http://interactive.mit.edu/sites/default/files/documents/Gom...

rraval··on High Performance Map Interactions Using HTML5 Canvas
Thanks for the thread. I figured mapping continuous input to discrete levels was more difficult than I was making it seem (especially with the fragmented way the web presents these devices).
rraval··on High Performance Map Interactions Using HTML5 Canvas
This is an awesome writeup!

I was playing with the demo linked elsewhere in this thread [demo], and noticed a bit of a hiccup when scrolling past multiple zoom levels. It seems like there'd be a bit of a pause as the tiles were rendered at each successive zoom level. It may be worthwhile to debounce the scroll event listeners with a small timeout, so you can catch multiple successive scroll events and zoom straight to the target zoom level without having to render each step along the way.

Quick video of the stuttering: http://gfycat.com/BrilliantActiveAfghanhound

[demo] https://seatgeek.com/senators-at-flyers-tickets/4-11-2015-ph...

rraval··on Color Runner
Context: https://news.ycombinator.com/item?id=8186972
rraval··on Faster AngularJS Rendering with ReactJS
The "Performance" section of the linked page claims that Mithril takes 9.44ms where React takes 79.65ms for their rendering benchmark [1] [2]. If true, it could be a good enough reason to pick over React.

[1] http://lhorie.github.io/mithril/comparisons/mithril.renderin... [2] http://lhorie.github.io/mithril/comparisons/react.rendering....

rraval··on 5 Months After Switching to Colemak
vim user here. I map mine to Control because ESC is a simple C-] away and Ctrl is so much more useful outside of just vim.
← PreviousPage 2 of 3Next →