Instantly share code, notes, and snippets.

@rauchg /README.md
Last active Nov 11, 2018

Embed
What would you like to do?
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

This comment has been minimized.

karan commented Mar 24, 2016

eval

¯_(ツ)_/¯

@rauchg

This comment has been minimized.

Owner

rauchg commented Mar 24, 2016

Mandatory disclaimer: this is not serious and not safe.

@knowbody

This comment has been minimized.

knowbody commented Mar 24, 2016

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

@joemccann

This comment has been minimized.

joemccann commented Mar 24, 2016

Brilliant.

@xero

This comment has been minimized.

xero commented Mar 24, 2016

you had me at eval

@sphvn

This comment has been minimized.

sphvn commented Mar 24, 2016

How do we solve deleted tweets?

@aroman

This comment has been minimized.

aroman commented Mar 24, 2016

i love the internet

@srcreigh

This comment has been minimized.

srcreigh commented Mar 24, 2016

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

@srcreigh

This comment has been minimized.

srcreigh commented Mar 24, 2016

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

requireFromTwitter(status, [context])

@imkarthikk

This comment has been minimized.

imkarthikk commented Mar 24, 2016

This is absolutely genius!

@insane0hflex

This comment has been minimized.

insane0hflex commented Mar 24, 2016

¯_(ツ)_/¯

ftfy

@NamPNQ

This comment has been minimized.

NamPNQ commented Mar 24, 2016

Awesome

@egoist

This comment has been minimized.

@eul721

This comment has been minimized.

eul721 commented Mar 24, 2016

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

@bigomega

This comment has been minimized.

bigomega commented Mar 24, 2016

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

@bleonard

This comment has been minimized.

bleonard commented Mar 24, 2016

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

@auchenberg

This comment has been minimized.

auchenberg commented Mar 24, 2016

wc4kbzvxqaf8lbunokx1

@jsonnull

This comment has been minimized.

jsonnull commented Mar 24, 2016

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

@daysv

This comment has been minimized.

daysv commented Mar 24, 2016

It doesn't work in China. 😂

@dwarandae

This comment has been minimized.

dwarandae commented Mar 24, 2016

😆

@luginbash

This comment has been minimized.

luginbash commented Mar 24, 2016

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

@autoclave

This comment has been minimized.

autoclave commented Mar 24, 2016

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

This comment has been minimized.

nurettin commented Mar 24, 2016

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

@eric-khoury

This comment has been minimized.

eric-khoury commented Mar 24, 2016

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

@thisizkp

This comment has been minimized.

thisizkp commented Mar 24, 2016

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

@Stephenitis

This comment has been minimized.

Stephenitis commented Mar 24, 2016

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

@Art4

This comment has been minimized.

Art4 commented Mar 24, 2016

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

@UncleBill

This comment has been minimized.

UncleBill commented Mar 24, 2016

It doesn't work in China. 😂

@daysv we can build a mirror 😂

@yasuhiro-okada-aktsk

This comment has been minimized.

yasuhiro-okada-aktsk commented Mar 24, 2016

🙏

@justim

This comment has been minimized.

justim commented Mar 24, 2016

Next level cloud hosting 💯

@l1x

This comment has been minimized.

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

This comment has been minimized.

madroneropaulo commented Mar 24, 2016

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

This comment has been minimized.

kuldeepdaftary commented Mar 24, 2016

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

@ferdbold

This comment has been minimized.

ferdbold commented Mar 24, 2016

Next-level social engineering

@pmuens

This comment has been minimized.

pmuens commented Mar 24, 2016

That's genius!

@ymschaap

This comment has been minimized.

ymschaap commented Mar 24, 2016

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

@MaxArt2501

This comment has been minimized.

MaxArt2501 commented Mar 24, 2016

Until someone removes a tweet and breaks the Internet.

@Ehekatl

This comment has been minimized.

Ehekatl commented Mar 24, 2016

🙏🙏🙏

@iqbalhasnan

This comment has been minimized.

iqbalhasnan commented Mar 24, 2016

:shipit:

@ileacristian

This comment has been minimized.

ileacristian commented Mar 24, 2016

genius!

@cu39

This comment has been minimized.

cu39 commented Mar 24, 2016

💯

@billythekid

This comment has been minimized.

billythekid commented Mar 24, 2016

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

@lukasz-madon

This comment has been minimized.

lukasz-madon commented Mar 24, 2016

it advice gopher

@pmolina

This comment has been minimized.

pmolina commented Mar 24, 2016

Absolutely brilliant!

@pluma

This comment has been minimized.

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-

This comment has been minimized.

birdy- commented Mar 24, 2016

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

@robotnoises

This comment has been minimized.

robotnoises commented Mar 24, 2016

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

This comment has been minimized.

dbergey commented Mar 24, 2016

I propose the nomenclature "twackages" for these modules

@BillyWM

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

maliqq commented Mar 24, 2016

brilliant

@Xiphe

This comment has been minimized.

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

This comment has been minimized.

fengmk2 commented Mar 24, 2016

require-from-weibo instead in China. :)

@drac

This comment has been minimized.

drac commented Mar 24, 2016

@daysv nothing works in China. 😄

@thebouv

This comment has been minimized.

thebouv commented Mar 24, 2016

I'm with dbergey here. twackages or gtfo.

@bcardarella

This comment has been minimized.

bcardarella commented Mar 24, 2016

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

@Corbzilla

This comment has been minimized.

Corbzilla commented Mar 24, 2016

Brilliant. Also, twackages FTW.

@quantumpotato

This comment has been minimized.

quantumpotato commented Mar 24, 2016

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!

@spotlightishere

This comment has been minimized.

spotlightishere commented Mar 24, 2016

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

@adizam

This comment has been minimized.

adizam commented Mar 24, 2016

+1 twackages.

And the next major outage will be labeled The Twacalpyse

@ReedJessen

This comment has been minimized.

ReedJessen commented Mar 24, 2016

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

This comment has been minimized.

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

This comment has been minimized.

josser commented Mar 24, 2016

What about splitting bigger modules into 140-char chunks?

@pavanandhukuri

This comment has been minimized.

pavanandhukuri commented Mar 24, 2016

Lol..

@Cameri

This comment has been minimized.

Cameri commented Mar 24, 2016

RT is the new fork?

@jsen-

This comment has been minimized.

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

This comment has been minimized.

Flet commented Mar 24, 2016

webpack loader plz :)

@Pyrolistical

This comment has been minimized.

Pyrolistical commented Mar 24, 2016

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

@bhague1281

This comment has been minimized.

bhague1281 commented Mar 24, 2016

😆

@rafaelrinaldi

This comment has been minimized.

rafaelrinaldi commented Mar 24, 2016

whoa

@rauchg

This comment has been minimized.

Owner

rauchg commented Mar 24, 2016

@bleonard it was C.D. Cooney

@nullv01d

This comment has been minimized.

nullv01d commented Mar 24, 2016

brilliant!! 😄 ❤️

@icodeforlove

This comment has been minimized.

icodeforlove commented Mar 24, 2016

you guys are too much... lol

@collinanderson

This comment has been minimized.

collinanderson commented Mar 24, 2016

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

@devmanhinton

This comment has been minimized.

devmanhinton commented Mar 24, 2016

This is.... Amazing. WELL DONE

@miguelmc

This comment has been minimized.

miguelmc commented Mar 24, 2016

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

@oreofeolurin

This comment has been minimized.

oreofeolurin commented Mar 24, 2016

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

@pengx17

This comment has been minimized.

pengx17 commented Mar 25, 2016

Time for a TPM (Twitter Package Manager)

@codemasher

This comment has been minimized.

codemasher commented Mar 25, 2016

You, Sir, have won the internet!

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

@thefotios

This comment has been minimized.

thefotios commented Mar 25, 2016

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

This comment has been minimized.

yisibl commented Mar 25, 2016

It doesn't work in China. 😂

@fordnox

This comment has been minimized.

fordnox commented Mar 25, 2016

waiting for 'require from DNS TXT record'

@gavrochelegnou

This comment has been minimized.

gavrochelegnou commented Mar 25, 2016

What about the simple :

atob('ZnVuY3Rpb24gbGVmdHBhZCh0LGUscil7dD1TdHJpbmcodCk7dmFyIG49LTE7Zm9yKHJ8fDA9PT1yfHwocj0iICIpLGUtPXQubGVuZ3RoOysrbjxlOyl0PXIrdDtyZXR1cm4gdH1tb2R1bGUuZXhwb3J0cz1sZWZ0cGFkOw==');

@andreabadesso

This comment has been minimized.

andreabadesso commented Mar 25, 2016

Looks safe

@richardcpeterson

This comment has been minimized.

richardcpeterson commented Mar 25, 2016

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

@rgaidot

This comment has been minimized.

rgaidot commented Mar 26, 2016

👍

@chreestopher

This comment has been minimized.

chreestopher commented Mar 27, 2016

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

This comment has been minimized.

gabmontes commented Mar 30, 2016

Awesome!!!

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

@justinoboyle

This comment has been minimized.

justinoboyle commented Mar 30, 2016

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

@atilacamurca

This comment has been minimized.

atilacamurca commented Mar 30, 2016

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

@tsia

This comment has been minimized.

tsia commented Mar 31, 2016

how about a google cache fallback for deleted tweets?

@vrunoa

This comment has been minimized.

vrunoa commented Apr 1, 2016

@calsioro

This comment has been minimized.

calsioro commented Apr 7, 2016

Port it to rebmu!
Actually useful!
Youtube

@awnumar

This comment has been minimized.

awnumar commented May 7, 2016

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

@eslachance

This comment has been minimized.

eslachance commented Aug 29, 2016

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