Skip to content

Instantly share code, notes, and snippets.

@rauchg

rauchg/README.md

Last active Sep 29, 2020
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.

Copy link

@karan karan commented Mar 24, 2016

eval

¯_(ツ)_/¯

@rauchg

This comment has been minimized.

Copy link
Owner Author

@rauchg rauchg commented Mar 24, 2016

Mandatory disclaimer: this is not serious and not safe.

@knowbody

This comment has been minimized.

Copy link

@knowbody 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.

Copy link

@joemccann joemccann commented Mar 24, 2016

Brilliant.

@xero

This comment has been minimized.

Copy link

@xero xero commented Mar 24, 2016

you had me at eval

@sphvn

This comment has been minimized.

Copy link

@sphvn sphvn commented Mar 24, 2016

How do we solve deleted tweets?

@aroman

This comment has been minimized.

Copy link

@aroman aroman commented Mar 24, 2016

i love the internet

@srcreigh

This comment has been minimized.

Copy link

@srcreigh 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.

Copy link

@srcreigh srcreigh commented Mar 24, 2016

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

requireFromTwitter(status, [context])

@imkarthikk

This comment has been minimized.

Copy link

@imkarthikk imkarthikk commented Mar 24, 2016

This is absolutely genius!

@insane0hflex

This comment has been minimized.

Copy link

@insane0hflex insane0hflex commented Mar 24, 2016

¯_(ツ)_/¯

ftfy

@NamPNQ

This comment has been minimized.

Copy link

@NamPNQ NamPNQ commented Mar 24, 2016

Awesome

@egoist

This comment has been minimized.

@eul721

This comment has been minimized.

Copy link

@eul721 eul721 commented Mar 24, 2016

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

@bigomega

This comment has been minimized.

Copy link

@bigomega 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.

Copy link

@bleonard 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.

Copy link

@auchenberg auchenberg commented Mar 24, 2016

wc4kbzvxqaf8lbunokx1

@jsonnull

This comment has been minimized.

Copy link

@jsonnull jsonnull commented Mar 24, 2016

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

@daysv

This comment has been minimized.

Copy link

@daysv daysv commented Mar 24, 2016

It doesn't work in China. 😂

@dwarandae

This comment has been minimized.

Copy link

@dwarandae dwarandae commented Mar 24, 2016

😆

@luginbash

This comment has been minimized.

Copy link

@luginbash 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.

Copy link

@autoclave 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.

Copy link

@nurettin nurettin commented Mar 24, 2016

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

@eric-khoury

This comment has been minimized.

Copy link

@eric-khoury eric-khoury commented Mar 24, 2016

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

@thisizkp

This comment has been minimized.

Copy link

@thisizkp 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.

Copy link

@Stephenitis 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.

Copy link

@Art4 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.

Copy link

@UncleBill 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.

Copy link

@yasuhiro-okada-aktsk yasuhiro-okada-aktsk commented Mar 24, 2016

🙏

@justim

This comment has been minimized.

Copy link

@justim justim commented Mar 24, 2016

Next level cloud hosting 💯

@l1x

This comment has been minimized.

Copy link

@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

This comment has been minimized.

Copy link

@madroneropaulo 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.

Copy link

@kuldeepdaftary kuldeepdaftary commented Mar 24, 2016

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

@ferdbold

This comment has been minimized.

Copy link

@ferdbold ferdbold commented Mar 24, 2016

Next-level social engineering

@pmuens

This comment has been minimized.

Copy link

@pmuens pmuens commented Mar 24, 2016

That's genius!

@ymschaap

This comment has been minimized.

Copy link

@ymschaap 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.

Copy link

@MaxArt2501 MaxArt2501 commented Mar 24, 2016

Until someone removes a tweet and breaks the Internet.

@Ehekatl

This comment has been minimized.

Copy link

@Ehekatl Ehekatl commented Mar 24, 2016

🙏🙏🙏

@iqbalhasnan

This comment has been minimized.

Copy link

@iqbalhasnan iqbalhasnan commented Mar 24, 2016

:shipit:

@ileacristian

This comment has been minimized.

Copy link

@ileacristian ileacristian commented Mar 24, 2016

genius!

@cu39

This comment has been minimized.

Copy link

@cu39 cu39 commented Mar 24, 2016

💯

@billythekid

This comment has been minimized.

Copy link

@billythekid billythekid commented Mar 24, 2016

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

@lukasz-madon

This comment has been minimized.

Copy link

@lukasz-madon lukasz-madon commented Mar 24, 2016

it advice gopher

@pmolina

This comment has been minimized.

Copy link

@pmolina pmolina commented Mar 24, 2016

Absolutely brilliant!

@pluma

This comment has been minimized.

Copy link

@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.

@immortal-tofu

This comment has been minimized.

Copy link

@immortal-tofu immortal-tofu commented Mar 24, 2016

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

@robotnoises

This comment has been minimized.

Copy link

@robotnoises 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.

Copy link

@dbergey dbergey commented Mar 24, 2016

I propose the nomenclature "twackages" for these modules

@BillyWM

This comment has been minimized.

Copy link

@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

This comment has been minimized.

Copy link

@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

This comment has been minimized.

Copy link

@maliqq maliqq commented Mar 24, 2016

brilliant

@Xiphe

This comment has been minimized.

Copy link

@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

This comment has been minimized.

Copy link

@fengmk2 fengmk2 commented Mar 24, 2016

require-from-weibo instead in China. :)

@drac

This comment has been minimized.

Copy link

@drac drac commented Mar 24, 2016

@daysv nothing works in China. 😄

@thebouv

This comment has been minimized.

Copy link

@thebouv thebouv commented Mar 24, 2016

I'm with dbergey here. twackages or gtfo.

@bcardarella

This comment has been minimized.

Copy link

@bcardarella bcardarella commented Mar 24, 2016

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

@Corbzilla

This comment has been minimized.

Copy link

@Corbzilla Corbzilla commented Mar 24, 2016

Brilliant. Also, twackages FTW.

@quantumpotato

This comment has been minimized.

Copy link

@quantumpotato 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.

Copy link

@spotlightishere 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.

Copy link

@adizam adizam commented Mar 24, 2016

+1 twackages.

And the next major outage will be labeled The Twacalpyse

@ReedJessen

This comment has been minimized.

Copy link

@ReedJessen 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.

Copy link

@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

This comment has been minimized.

Copy link

@josser josser commented Mar 24, 2016

What about splitting bigger modules into 140-char chunks?

@pavanandhukuri

This comment has been minimized.

Copy link

@pavanandhukuri pavanandhukuri commented Mar 24, 2016

Lol..

@Cameri

This comment has been minimized.

Copy link

@Cameri Cameri commented Mar 24, 2016

RT is the new fork?

@jsen-

This comment has been minimized.

Copy link

@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

This comment has been minimized.

Copy link

@Flet Flet commented Mar 24, 2016

webpack loader plz :)

@Pyrolistical

This comment has been minimized.

Copy link

@Pyrolistical Pyrolistical commented Mar 24, 2016

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

@bhague1281

This comment has been minimized.

Copy link

@bhague1281 bhague1281 commented Mar 24, 2016

😆

@rafaelrinaldi

This comment has been minimized.

Copy link

@rafaelrinaldi rafaelrinaldi commented Mar 24, 2016

whoa

@rauchg

This comment has been minimized.

Copy link
Owner Author

@rauchg rauchg commented Mar 24, 2016

@bleonard it was C.D. Cooney

@nullv01d

This comment has been minimized.

Copy link

@nullv01d nullv01d commented Mar 24, 2016

brilliant!! 😄 ❤️

@icodeforlove

This comment has been minimized.

Copy link

@icodeforlove icodeforlove commented Mar 24, 2016

you guys are too much... lol

@collinanderson

This comment has been minimized.

Copy link

@collinanderson 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.

Copy link

@devmanhinton devmanhinton commented Mar 24, 2016

This is.... Amazing. WELL DONE

@miguelmc

This comment has been minimized.

Copy link

@miguelmc miguelmc commented Mar 24, 2016

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

@oreofeolurin

This comment has been minimized.

Copy link

@oreofeolurin oreofeolurin commented Mar 24, 2016

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

@pengx17

This comment has been minimized.

Copy link

@pengx17 pengx17 commented Mar 25, 2016

Time for a TPM (Twitter Package Manager)

@codemasher

This comment has been minimized.

Copy link

@codemasher 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.

Copy link

@thefotios 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.

Copy link

@yisibl yisibl commented Mar 25, 2016

It doesn't work in China. 😂

@fordnox

This comment has been minimized.

Copy link

@fordnox fordnox commented Mar 25, 2016

waiting for 'require from DNS TXT record'

@gavrochelegnou

This comment has been minimized.

Copy link

@gavrochelegnou gavrochelegnou commented Mar 25, 2016

What about the simple :

atob('ZnVuY3Rpb24gbGVmdHBhZCh0LGUscil7dD1TdHJpbmcodCk7dmFyIG49LTE7Zm9yKHJ8fDA9PT1yfHwocj0iICIpLGUtPXQubGVuZ3RoOysrbjxlOyl0PXIrdDtyZXR1cm4gdH1tb2R1bGUuZXhwb3J0cz1sZWZ0cGFkOw==');

@andreabadesso

This comment has been minimized.

Copy link

@andreabadesso andreabadesso commented Mar 25, 2016

Looks safe

@richardcpeterson

This comment has been minimized.

Copy link

@richardcpeterson 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.

Copy link

@rgaidot rgaidot commented Mar 26, 2016

👍

@chreestopher

This comment has been minimized.

Copy link

@chreestopher 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.

Copy link

@gabmontes 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.

Copy link

@justinoboyle justinoboyle commented Mar 30, 2016

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

@atilacamurca

This comment has been minimized.

Copy link

@atilacamurca 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.

Copy link

@tsia tsia commented Mar 31, 2016

how about a google cache fallback for deleted tweets?

@vrunoa

This comment has been minimized.

Copy link

@vrunoa vrunoa commented Apr 1, 2016

@calsioro

This comment has been minimized.

Copy link

@calsioro calsioro commented Apr 7, 2016

Port it to rebmu!
Actually useful!
Youtube

@awnumar

This comment has been minimized.

Copy link

@awnumar 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.

Copy link

@eslachance eslachance commented Aug 29, 2016

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

@joaomilho

This comment has been minimized.

Copy link

@joaomilho joaomilho commented Apr 24, 2019

This will never make it in Enterprise™! We'll have import-all-from-linkedin instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.