Skip to content

Instantly share code, notes, and snippets.

@rauchg
Last active Jan 30, 2022
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": ""
}
@Flet
Copy link

Flet commented Mar 24, 2016

webpack loader plz :)

@Pyrolistical
Copy link

Pyrolistical commented Mar 24, 2016

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

@bhague1281
Copy link

bhague1281 commented Mar 24, 2016

😆

@rafaelrinaldi
Copy link

rafaelrinaldi commented Mar 24, 2016

whoa

@rauchg
Copy link
Author

rauchg commented Mar 24, 2016

@bleonard it was C.D. Cooney

@arabindadora
Copy link

arabindadora commented Mar 24, 2016

brilliant!! 😄 ❤️

@icodeforlove
Copy link

icodeforlove commented Mar 24, 2016

you guys are too much... lol

@collinanderson
Copy link

collinanderson commented Mar 24, 2016

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

@devmanhinton
Copy link

devmanhinton commented Mar 24, 2016

This is.... Amazing. WELL DONE

@miguelmc
Copy link

miguelmc commented Mar 24, 2016

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

@oreofeolurin
Copy link

oreofeolurin commented Mar 24, 2016

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

@pengx17
Copy link

pengx17 commented Mar 25, 2016

Time for a TPM (Twitter Package Manager)

@codemasher
Copy link

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
Copy link

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
Copy link

yisibl commented Mar 25, 2016

It doesn't work in China. 😂

@fordnox
Copy link

fordnox commented Mar 25, 2016

waiting for 'require from DNS TXT record'

@gavrochelegnou
Copy link

gavrochelegnou commented Mar 25, 2016

What about the simple :

atob('ZnVuY3Rpb24gbGVmdHBhZCh0LGUscil7dD1TdHJpbmcodCk7dmFyIG49LTE7Zm9yKHJ8fDA9PT1yfHwocj0iICIpLGUtPXQubGVuZ3RoOysrbjxlOyl0PXIrdDtyZXR1cm4gdH1tb2R1bGUuZXhwb3J0cz1sZWZ0cGFkOw==');

@andreabadesso
Copy link

andreabadesso commented Mar 25, 2016

Looks safe

@richardcpeterson
Copy link

richardcpeterson commented Mar 25, 2016

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

@rgaidot
Copy link

rgaidot commented Mar 26, 2016

👍

@chreestopher
Copy link

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
Copy link

gabmontes commented Mar 30, 2016

Awesome!!!

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

@justinoboyle
Copy link

justinoboyle commented Mar 30, 2016

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

@atilacamurca
Copy link

atilacamurca commented Mar 30, 2016

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

@tsia
Copy link

tsia commented Mar 31, 2016

how about a google cache fallback for deleted tweets?

@vrunoa
Copy link

vrunoa commented Apr 1, 2016

@calsioro
Copy link

calsioro commented Apr 7, 2016

Port it to rebmu!
Actually useful!
Youtube

@awnumar
Copy link

awnumar commented May 7, 2016

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

@eslachance
Copy link

eslachance commented Aug 29, 2016

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

@joaomilho
Copy link

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