Create a gist now

Instantly share code, notes, and snippets.

@rauchg /README.md
Last active Feb 24, 2017

require-from-twitter

require-from-twitter

Since Twitter doesn't have an edit button, it's a suitable host for JavaScript modules.

How to use

Source tweet: https://twitter.com/rauchg/status/712799807073419264

const leftPad = await requireFromTwitter('712799807073419264');
console.log(leftPad(1, 5));      // '00001'
console.log(leftPad(1234, 5));   // '01234'
console.log(leftPad(12345, 5));  // '12345'

Running this example

# populate `twitter-config.json` with your API tokens
$ npm install
$ npm test
import { babel } from './package';
import { transform } from 'babel-core';
import { decodeHTML as decode } from 'entities';
import Twit from 'twit';
// edit twitter-config.json first
const twit = new Twit(require('./twitter-config'));
export default async function requireFromTwitter (id) {
const tweet = await twit.get(`/statuses/show/:id`, { id });
if (tweet.errors) throw new Error(`Cannot find module '${id}'`);
const { text } = tweet.data;
const exports = {};
eval(transform(decode(text), babel).code);
return exports.default;
}
{
"name": "require-from-twitter",
"version": "0.0.1",
"description": "require(), but from a tweet",
"dependencies": {
"babel-preset-stage-0": "6.5.0",
"babel-preset-es2015": "6.6.0",
"babel-runtime": "6.6.1",
"babel-plugin-transform-runtime": "6.6.0",
"babel-cli": "6.6.5",
"babel-core": "6.7.4",
"twit": "2.2.3",
"entities": "1.1.1"
},
"babel": {
"presets": [
"es2015",
"stage-0"
],
"plugins": [
"transform-runtime"
]
},
"scripts": {
"test": "babel-node test"
}
}
import requireFromTwitter from './';
requireFromTwitter('712799807073419264')
.then((leftPad) => {
console.log(leftPad(1, 5));
console.log(leftPad(1234, 5));
console.log(leftPad(12345, 5));
}, (err) => console.error(err.stack));
{
"consumer_key": "",
"consumer_secret": "",
"access_token": "",
"access_token_secret": ""
}
@karan
karan commented Mar 24, 2016

eval

¯_(ツ)_/¯

@rauchg
Owner
rauchg commented Mar 24, 2016

Mandatory disclaimer: this is not serious and not safe.

@knowbody

@rauchg what?! I just updated all of my production apps to it... don't delete your tweet

@joemccann

Brilliant.

@xero
xero commented Mar 24, 2016

you had me at eval

@sphvn
sphvn commented Mar 24, 2016

How do we solve deleted tweets?

@aroman
aroman commented Mar 24, 2016

i love the internet

@srcreigh

@sphvn replicate via RTs + backend to walk the RT DAG for a non-deleted status

@srcreigh

also, safe-eval. https://www.npmjs.com/package/safe-eval

requireFromTwitter(status, [context])

@imkarthikk

This is absolutely genius!

@insane0hflex

¯_(ツ)_/¯

ftfy

@NamPNQ
NamPNQ commented Mar 24, 2016

Awesome

@eul721
eul721 commented Mar 24, 2016

Dude you're amazing. Will use 10/10.
Keep up the good work.

@bigomega

With twitter 140 char limit going away, it will be next platform for js libs 😆

@bleonard

quite often i click through on these kinds of things and it's you, sir.

@jsonnull

Man, with a webpack loader we could require from Twitter at build time!

@daysv
daysv commented Mar 24, 2016

It doesn't work in China. 😂

@dwarandae

😆

@methou
methou commented Mar 24, 2016

@daysv I believe their people can make most out of Weibo, which doesn't have 140 words limit.

@autoclave

Mandatory disclaimer: this is not serious and not safe.

This can be made somewhat serious and somewhat safe with a javascript transpiler for example github.com/dbpokorny/autoclave

@nurettin

A lot of mandatory packages actually fit into the 140 character limit.

@eric-khoury

Deleted tweets? No problem: http://web.archive.org/web

@kp25
kp25 commented Mar 24, 2016

Kudos for the Brilliant idea.
Guess a lot of other mandatory packages will start doing this..

@Stephenitis

I had to pause for a second until i fully got it. bravo. hahah

@Art4
Art4 commented Mar 24, 2016

"If you have a bad idea there is always an idiot who implements it."
😁

@UncleBill

It doesn't work in China. 😂

@daysv we can build a mirror 😂

@justim
justim commented Mar 24, 2016

Next level cloud hosting 💯

@l1x
l1x commented Mar 24, 2016

Finally twitter gets a great use case, have you seen the impact on the price of the shares yet??

@madroneropaulo

Now we need a tweet package manager that will keep a record of all the tweet modules id's and assign them a module name :)

@kuldeepdaftary

🙏🙏🙏🙏🙏
I bow to you!
🙏🙏🙏🙏🙏

@ferdbold

Next-level social engineering

@pmuens
pmuens commented Mar 24, 2016

That's genius!

@ymschaap

Incredible, there is a complete tweet package manager: http://require-from-twitter.github.io/

@MaxArt2501

Until someone removes a tweet and breaks the Internet.

@Ehekatl
Ehekatl commented Mar 24, 2016

🙏🙏🙏

@ileacristian

genius!

@cu39
cu39 commented Mar 24, 2016

💯

@billythekid

Bye bye npm, there's a new big dog in town

@pmolina
pmolina commented Mar 24, 2016

Absolutely brilliant!

@pluma
pluma commented Mar 24, 2016

Can we have a require hook for this so we can just require('twitter:712799807073419264') pls?

I need this for a production app. Pls fix ASAP.

@birdy-
birdy- commented Mar 24, 2016

Leftpad INC. will ask twitter to delete your tweet. You'll break the Internet.

@robotnoises

Hi @rauchg, this is David from Rauchg Global Worldwide, LLC. I was wondering if you'd consider switching your Twitter handle so that we can use it for an upcoming marketing campaign.

Listen, I don’t mean to be a dick about it, but it’s a registered Trademark in most countries around the world and if you actually release any tweets from @rauchg, our trademark lawyers are going to be banging on your door and taking down your accounts and stuff like that — and we’d have no choice but to do all that because you have to enforce trademarks or you lose them.

@dbergey
dbergey commented Mar 24, 2016

I propose the nomenclature "twackages" for these modules

@BillyWM
BillyWM commented Mar 24, 2016

I'd love to use this but according to your example it depends on async/await, which needs Babel transpiling, which depends on line numbers, which depends on classic Leftpad (tm) (c) Kik Interactive.

Can you write me a self-hosting leftpad implementation? Thanks

@Pilfer
Pilfer commented Mar 24, 2016

This is old technology. I've been instagramming QR codes containing my JS libs for years now. It's secure, too. I just use the hashtag "#MyProjectName", and the code inside the QT code automagically gets included and evaluated on my prod box - 100% safe. Instagram has the best CDN, too, so you get maximum code availability in the cloud for free!

@maliqq
maliqq commented Mar 24, 2016

brilliant

@Xiphe
Xiphe commented Mar 24, 2016

How do we solve deleted tweets?

You should definitely bundle dependent tweets into yours before publishing a new version to twitter!

@fengmk2
fengmk2 commented Mar 24, 2016

require-from-weibo instead in China. :)

@drac
drac commented Mar 24, 2016

@daysv nothing works in China. 😄

@thebouv
thebouv commented Mar 24, 2016

I'm with dbergey here. twackages or gtfo.

@bcardarella

What happens when Twitter decides to reassign my tweet to someone else??

@Corbzilla

Brilliant. Also, twackages FTW.

@quantumpotato

Warning! http://require-from-twitter.github.io/'s link to "call function by name" links to /#.. did someone remove this? I can't call my functions!

@awesomebing1

@ymschaap That is the best thing I have ever seen today. Better start updating production code ASAP.

@adizam
adizam commented Mar 24, 2016

+1 twackages.

And the next major outage will be labeled The Twacalpyse

@ReedJessen

So... I like this a lot. I think I would only use it for user password storage, however. Don't see any other good uses... ;)

@emonti
emonti commented Mar 24, 2016

why stop with code? boasting an impressive 140 character limit, twitter is also an excellent option for key storage up to 1024-bit keys!!!

Correction: I mean 1120-bit keys. That's a thing right?

@josser
josser commented Mar 24, 2016

What about splitting bigger modules into 140-char chunks?

@pavan496

Lol..

@Cameri
Cameri commented Mar 24, 2016

RT is the new fork?

@jsen-
jsen- commented Mar 24, 2016

We should ask Pirate Bay to host npm stuff. I can imagine the reply to the Kik's lawyer ... 😂

@Flet
Flet commented Mar 24, 2016

webpack loader plz :)

@Pyrolistical

Please implement requireFromGist so I can require this gist to require left-pad

@bhague1281

😆

@rauchg
Owner
rauchg commented Mar 24, 2016

@bleonard it was C.D. Cooney

@nullv01d

brilliant!! 😄 ❤️

@icodeforlove

you guys are too much... lol

@collinanderson

I'm surprised no one has mentioned IPFS as a solution to it getting deleted.

@devmanhinton

This is.... Amazing. WELL DONE

@miguelmc

<3
Who needs testing in 140 character piece of code anyway?

@oreofeolurin

wow.....this changes how we see the cloud.

@pengx17
pengx17 commented Mar 25, 2016

Time for a TPM (Twitter Package Manager)

@codemasher

You, Sir, have won the internet!

Reminds me of https://gist.github.com/140bytes/962807/forks (who needs NPM anyway?)

@thefotios

I took this a little more seriously, I think this might actually help out: https://www.npmjs.com/package/jhi

Create a file with a list of one-liners from anywhere (gist, github raw file, etc). It will pull them once into a directory and expose them via an index.js.

@yisibl
yisibl commented Mar 25, 2016

It doesn't work in China. 😂

@fordnox
fordnox commented Mar 25, 2016

waiting for 'require from DNS TXT record'

@gavrochelegnou

What about the simple :

atob('ZnVuY3Rpb24gbGVmdHBhZCh0LGUscil7dD1TdHJpbmcodCk7dmFyIG49LTE7Zm9yKHJ8fDA9PT1yfHwocj0iICIpLGUtPXQubGVuZ3RoOysrbjxlOyl0PXIrdDtyZXR1cm4gdH1tb2R1bGUuZXhwb3J0cz1sZWZ0cGFkOw==');

@andreabadesso

Looks safe

@richardcpeterson

Excellent. I just hosted all my shell scripts on Twitter and now hashtag "!" is trending

@rgaidot
rgaidot commented Mar 26, 2016

👍

@chreestopher

this relies on centralized infrastructure operated by a corporation!
The only safe way to do this is to use my package ... require-from-torrent.

lol

@gabmontes

Awesome!!!

What about require-from-blockchain? That cannot be deleted or taken down. Never ever!

@justinoboyle

This is great. Just pushed to production, thanks! Never using NPM again.

@atilacamurca

is it possible to use inside the tweet and then require functions from other tweets?

@tsia
tsia commented Mar 31, 2016

how about a google cache fallback for deleted tweets?

@vrunoa
vrunoa commented Apr 1, 2016

@calsioro
calsioro commented Apr 7, 2016

Port it to rebmu!
Actually useful!
Youtube

@libeclipse
libeclipse commented May 7, 2016 edited

This is actually pretty clever. Inspired me to make a python version: http://github.com/libeclipse/import-from/

@eslachance

So.... basically like 25-50% of sindresorhus' modules can use this, no problem. Right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment