top | item 21599546

Simple-twitter: A bare-bones Twitter clone implemented in a single file

423 points| revskill | 6 years ago |github.com | reply

164 comments

order
[+] apetresc|6 years ago|reply
A note to those who might dismiss this without looking at it carefully because you assume it's just some SPA that mocks the Twitter UI: it's actually a NixOps file (with everything inlined) that deploys the entire stack, including a full backend and database.
[+] cblum|6 years ago|reply
This is the first time I’m seeing that. It’s so beautiful. It’s elegant. I can understand it.

Why can’t the world move in that direction, instead of the insane Kubernetes hype that’s prevalent these days?

[+] MuffinFlavored|6 years ago|reply
Could the same not be done in a single Terraform file?
[+] OrgNet|6 years ago|reply
lol... a file that contains a bunch of files? is that an archive? or a set of instructions to download a bunch of files? what is the world coming to?
[+] joewrong|6 years ago|reply
" ORDER BY tweet.time DESC "

sign me up

[+] mc3|6 years ago|reply
Whether it is the lack of an ORM or lack of a "algorithm" that pleases you, this comment has made my day :-).
[+] jamroom|6 years ago|reply
I'm not an PG user but there does not appear to be an index on tweet.time - and even if there was wouldn't it better to do ORDER BY tweet.id DESC? I assume ordering by primary key is going to be the fastest, and would (ideally) prevent maintaining an index on tweet.time.
[+] WA|6 years ago|reply
Just create a private list on Twitter, put all people you follow in there. Bam, done. Reverse-chronological order, no ads.
[+] nkozyra|6 years ago|reply
I'll never understand why the stream cannot just default to logic like this or [my follows]+[non-rt/replies]+[desc by time]

Best I can come up with is it'd make promoted comment more apparent?

[+] mipmap04|6 years ago|reply
I was working on creating an rss reader with a reddit-like interface that allowed follows, voting, comments, etc. The computational expense of a fancy sort algorithm based on factors other than just one non-computed column is immense once you get to a decent number of users. I ended up removing the algo just to lower my hosting bills. Of course, there were other potential solutions, but for a side project, this was easiest.
[+] robobro|6 years ago|reply
Pleroma, part of the fediverse (3,500,000+ users) has exactly this.
[+] singron|6 years ago|reply
Is "Latest" sorting in the twitter UI not this?
[+] TheUndead96|6 years ago|reply
There are a lot of very strong opinions in this thread on whether this code would be "production ready". I don't think that is the point here. This is awesome because of its brevity, it is like writing a ray tracer in 100 lines of C. It demonstrates that a task which might be perceived to highly complicated can be reduced to a file, of which the size many of us would just define a single class in such a system.
[+] akersten|6 years ago|reply
It's a nice demo. But there seems to be a surprising lack of validation? Seems like anyone can delete any other user, or post as anyone else, etc. Then again, I can't read Haskell, so I don't know if there's something preventing that at a higher level than the endpoint logic.
[+] whateveracct|6 years ago|reply
Doesn't look like there is. I think the idea is for this to be a nontrivial example of a full-stack Haskell+Nix(Ops) project. The Twitter part is meant to be more familiar that robust.

It's fair to argue auth should be included in a nontrivial example though. I honestly don't think it would add that much clutter either. Although unlike the other components, I don't know if there's a simple off-the-shelf Haskell solution for auth.

[+] jpochtar|6 years ago|reply
Small, easy to write/maintain approaches are at an evolutionary disadvantage vs classically "enterprise" styles.

Easier to work with -> fewer people needed -> fewer people hired -> fewer people learn -> fewer people know.

Now there's fewer people in the market who know Simple, vs many people who've learned OverEngineered (TM). Leadership wants to pick a language/style they'll be able to hire for as-needed. OverEngineered has a much larger talent pool.

[+] kyllo|6 years ago|reply
Love the use of quasiquotation here:

    import Database.PostgreSQL.Simple.SqlQQ (sql)
    ...

    let index :: Handler Markup
        index = do
            tweets <- query_ [sql|
                SELECT "user".name, tweet.contents
                FROM           "user"
                    INNER JOIN user_tweet ON "user".name = user_tweet."user"
                    INNER JOIN tweet      ON user_tweet.tweet = tweet.id
                ORDER BY tweet.time DESC
            |]
[+] cocochanel|6 years ago|reply
This made me want to learn haskell. What a clean code. Pleasure to read.
[+] samcodes|6 years ago|reply
Yeah, another comment said this is “unreadable” if you don’t do FP... I have done a little lisp + Elixir, but 99% of my coding has been in C-descendant languages and this was definitely readable.
[+] xwdv|6 years ago|reply
I hope this is only the beginning of a series of popular web apps and social networks all recreated as pithy single file documents. Next should be Facebook.
[+] k__|6 years ago|reply
Haha, awesome.

It would be awesome if Nix, NixOS and NixOps replaced the current mess that is Docker and K8s.

[+] gulperxcx|6 years ago|reply
Are there any screenshots of what this looks like when in use?
[+] Gabriel439|6 years ago|reply
I just added one. Thanks for the suggestion!
[+] mark_l_watson|6 years ago|reply
I really like the code. Sometimes I have problems following other people’s Haskell code but I found this web app to be very readable. Good stuff.
[+] kgthegreat|6 years ago|reply
Slightly related - If you want a pre-categorised tweets feed with ability to add new categories, I have written one - http://trysensible.com/ (Open source https://github.com/kgthegreat/sensible). It comes with some standard categories such as politics, sports etc. but you can add whatever categories you want such as - music, academia and start adding your own curated list of keywords to support this category. This is written in golang and is open source https://github.com/kgthegreat/sensible
[+] cryptozeus|6 years ago|reply
Can someone explain more ? I am not familiar with haskell. So is this like a Twitter like functional demo ?
[+] cyborgx7|6 years ago|reply
A lot of people complaining that this wouldn't be able to hold the load of the original thing like that. I'd argue that all platforms attempting to be all-encompassing is a big problem right now. Maybe a single instance of a platform should really just accept as much load as this could handle in this form. They could federate with eachother to replicate the massive connected structure.
[+] beders|6 years ago|reply
Ok, CLJ/CLJS, your turn ;)
[+] zemnmez|6 years ago|reply
I learned more about haskell reading this than I ever have from anything else