Hacker Newsnew | past | comments | ask | show | jobs | submit | sevenproxies's commentslogin

Another example is Java's java.util.Map.of. It's a convenient method to construct a map in a single statement.

https://docs.oracle.com/en/java/javase/11/docs/api/java.base...


This kind of function overload is present everywhere in the Java collection framework (and probably other libraries). It is a performance optimization (variadic arguments in Java require creating an array), and variadiac overloads also exist (Map.of needs a list of Map.Entry for type safety) for creating collections of any size.

https://docs.oracle.com/en/java/javase/11/docs/api/java.base...


Do note that the created map is immutable. However, you could pass the created map to the constructor HashMap (or another type) to obtain a mutable copy of the Map created using Map.of


VLC doesn't have gapless audio playback.


A guide for reading this Twitter page.

1. Start at the bottom of the posts by the author (just above the "More Tweets" section).

2. Find the post that mentions q_rsqrt.

3. work you're way up the page, and though the "Show this thread" buttons to try and gleam some semi-chorological sense of context

Anyone got a better method?


The way twitter refuses to show you the actual tweet someone linked to in the middle of a thread is super-annoying. One thing that can help a little bit (on the desktop version at least) is to load the URL without the referer (i.e., highlight the URL bar and hit enter). It seems to use the presence of a referer as signal to hide the tweet you want to see (???).

But ThreadReaderApp is also a good alternative to just bypass the bad UI entirely.

Unfortunately I don't really have time for dedicated blogging any more, so I just post small bits to twitter as I go. Which is why putting together the full story required a bunch of QTs of threads from the past week...


Any hope of putting up a gist on pastebin?


A gist of what? The slur list? That's already on my website:

https://moyix.net/~moyix/copilot_slurs_rot13.txt


I assume they mean a more readable version of the content from the Twitter thread, rather than just the list. I could be wrong though.

Twitter's readability is really hit and miss, depending on client and logged in or not etc.


https://threadreaderapp.com/thread/1433254293352730628.html

The incessant quote-tweeting in a thread does make it unnecessarily complicated though.


Just read it on a Nitter instance. For example, https://nitter.net/moyix/status/1433261377125326851. (Hacker News: please pick another instance to avoid DOSing Nitter.)


Hint: Replace the instance name with "twiiit.com" and it automatically redirects to a random, online instance.

https://twiiit.com/


My approach, although incompatible, is to simply not use twitter for things it is really bad at. I'm happy with missing out.


Just click on the first post, and ignore the “More Tweets” section—it'll show the entire thread in order.


Not sure if I'm making any contribution but here's togetter aggregation[1]. Wondered why they don't have English counterpart and found it[2] had to shut down few years ago. I guess Twitter didn't like it at all.

1: https://togetter.com/li/1769757

2: https://chirpstory.com/


I've damaged two magsafe connectors in the last two years. The rubbery plastic protection near the charge point (with the orange/green LED) splits. Then it's super easy to make worse since the split ends catch on things. Like https://i.imgur.com/l2uS8pv.jpg.

I'm pretty sure it's from heat damage from the power. Not mechanical strain. The heat slowly weakens the rubber material to the point of failure.


>why can't "select A,B from foo" be served directly from the index

mysql supports that with covering indexes.

https://books.google.co.uk/books?id=IagfgRiKWd4C&lpg=PA178&v...


Wow, that's great news. Thanks for the correction!


From what I'm aware, authorization times are subject to the issuing banks. Some are valid for up to 30 days.


Further, MC and VISA regulations explicitly forbid charging a customer when a product is not sent within 30 days.


Device fingerprinting is a big boon to fraud prevention. The more data sources that can help uniquely identify a device the better. I know some fraud prevention companies require merchants to include an image (png), javascript and flash file on the checkout pages to profile a customer. Flash can access your microphone, camera and local storage (flash cookies).

Fraud is a big deal for Paypal, although I'm do not know if such permissions are needed in device fingerprinting on apps.

Interestingly from a privacy point of view, more granular permissions to device features might not necessary equate to greater anonymity. If most device users do not care or know about the privacy implications and accept the app's permission request, those who don't accept become the minority.


>A Hacker's Replacement for Gmail users

http://dbpmail.net/essays/2013-06-29-hackers-replacement-for...

    Show HN: I spent 2 years ago. I had no idea what that means.


In PHP

   array_sum([1, 2, 3, 4, 5]);


The GP's point is that Ruby doesn't require a built-in method that specifically sums an array to still get a clean, terse operation. You can use #inject to apply an arbitrary operation to (operator, last result, current element) and arrive at a result.

For example, given a list of numbers, you can generate a bitwise OR mask easily:

    [1,2,3,4,5].inject(:|)
What this does is iterate over the list and apply ($last_result | $current_element) and return the result, which is passed on as $last_result to the next iteration. $last_result is 0 by default. This is equivalent to (as of PHP 5.4):

    array_reduce([1,2,3,4,5], function($v, $e) { return $v | $e; }, 0);
Or prior to PHP 5.3:

    function or_mask($v, $e) { return $v | $e; }
    array_reduce(array(1,2,3,4,5), "or_mask", 0);
It's doable in both languages, but Ruby's functional language lineage and its object-oriented nature results in an exceptionally clean approach.


Prior to PHP 5.3 this could work as well:

    array_reduce(array(1,2,3,4,5), create_function('$v, $e', 'return $v | $e;'), 0);


I'm really glad that 5.3 got proper anonymous functions. Specifying function bodies as strings to be eval'd makes me twitch.


In case this was a serious entry... which I honestly can't tell.

The problem with array_sum is not that it's too long but instead that it's combined two rather specific bits of functionality into a fixed (if common) form, while the Ruby code separates the ideas of "folding" and "addition" allowing for many orthogonal creations.

To pick another favorite, in Haskell you could write

    Foldable.foldl1 (+)
which sums any foldable thing—anything which has elements which can be combined together one-by-one. So it'll apply to Trees or Sets or Dictionaries (well, Maps) just as easily while also allowing things like (+) to be replaced by other binary operators.


PHP does have array_reduce, however operators like '+' can't be used as callables so you'd have to make your own wrapper functions.

Edit: Screw it, haven't self promoted on a while. In Pharen (https://github.com/scriptor/pharen), which compiles to PHP, you could do:

    (reduce (+) 0 [1 2 3 4 5])


That's really cool, but the syntax is strange to me. How do you distinguish between operator sectioning (+) and a side-effecting function call (f)?


It works (superficially) similarly to how Haskell does things and treats (+) as a partial function call by recognizing that + isn't getting at least 2 arguments. You could also do stuff like:

    ((+ 1) 2) ; => 3

    (map (* 2) [1 2 3]) ; => [2 4 6]
If a function f takes any arguments and Pharen knows this, it'll convert (f) into a partial function call as well. Unfortunately I haven't figured out a way to check if a function has any side effects. Otherwise in this case at least operators are treated like functions.


So it's tracking the arity of functions and turning anything which has been applied to fewer than ARITY arguments to a partial application?

I suppose that comes at the cost of (+ 1 2 3 4)?


It does track the arity of functions, but remember that this happens at compile time. Regular addition in Pharen is still just regular addition in PHP:

    (def a (+ 1 2 3 4)) ; => $a = (1 + 2 + 3 + 4);
Of course, there are situations where partial application won't always happen because the compiler is unable to detect it:

    (fn add (x y)
      (+ x y))

    (map #add [1 2 3])
Pharen won't be able to realize that `add` here is being partially applied inside `map`. It's not smart enough for that yet. If you try to run this you'll end up with 'Missing argument 2' and 'Undefined variable: y' all over the place.

However, I'm not putting a whole lot of emphasis on partials. They're there as a convenience, but they're not really a core part of the language.

But yes, back to the original point, all the tracking is done at compile time so that for addition with two or more arguments the resulting PHP will look like regular addition in PHP.


Gotcha, very interesting!


Surprisingly, not really.

    {-# OPTIONS -fglasgow-exts #-}
    
    class BuildList a r  | r-> a where
      build' :: [a] -> a -> r
    
    instance BuildList a [a] where
      build' l x = reverse$ x:l
    
    instance BuildList a r => BuildList a (a->r) where
      build' l x y = build'(x:l) y
    
    varargs x = build' [] x
    
    main = print $ ( sum $ varargs 1 2 3 4 5 6 100)


    $ ./Test
    121

    
http://okmij.org/ftp/Haskell/vararg-fn.lhs


I love that example, but it does depend upon some pretty arcane features in Haskell's type inference engine.


Why would it?


My hypothesis was that the compiler was tracking the arities of each function in order to open up opportunities for partial application. That means there's some ambiguity when you write something like (+ 1) which, in Scheme is a complete application equal to 1 but may also be interpreted as a partial application equal to (lambda (x) (+ 1 x)).

There are many ways to mitigate that ambiguity statically and dynamically, but I feel there's always going to be a tradeoff between favoring partial application, favoring variadic functions, and the complexity/sophistication of your static checking or runtime environment.

I just made a stab at where the solution might lie in that design space. Turns out I was wrong.


Well how about this then.

    foreach(array(1,2,3,4,5) as $x) $i=$i+$x; echo $i;


The array_reduce answers get closer to what I was looking for. This might be a "one line" answer, but it requires two special forms, assignment, sequencing operators (;), and two fresh variables.


This works, is fast enough and readable. Perfectly fine solution to me.


1. Separate folding and addition.

2. ?

3. Profit.


Orthogonality and composability dramatically increase abstraction, code reuse, testability, and likelihood of writing correct code, both for library maintainers and library users.

Step 2 is actually extremely well known.


array_sum_of_1_2_3_4_5();

(Added in PHP 6)


the funny thing is, with proper abuse of __call you can almost get that to work: https://gist.github.com/kennethrapp/328b6bd1bda8a8f94092


That's not funny. Horrifying, maybe, but not funny.

Edit: Strike 'maybe'. I looked at it again and it's definitely horrifying. I saved it anyway, though; Halloween's only a few weeks off, and I think I shall print it out and stick it on the wall of my cube next to the PHP hammer and the "periodic" table of Perl 6 operators.


kudos. almost as cool as the cpp template hack to compute area based on part of the source code 'ascii art' size. (which I can't find anymore. googlefu--)


Made me laugh :)


    irb(main):001:0> x = [1,2,3,4,5]
    => [1, 2, 3, 4, 5]
    irb(main):002:0> x.inject &:*
    => 120


The colours just look to iterate through Red, Yellow, Green, Blue for each search term per box.


If this is the same thing I remember, then yes, it's just cycling through the colors.


I think it's iterating through queries as well. I can't imagine Hebrew is such a "hot" language and that is used so heavily, so that I see the same query repeated over and over (population of Israel has about 7 million people, where only 5-6 would probably use Hebrew as their main language...).


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: