Skip to content

Instantly share code, notes, and snippets.

View witnessmenow's full-sized avatar

Brian Lough witnessmenow

View GitHub Profile
@witnessmenow
witnessmenow / .babelrc
Created May 5, 2016 12:58
Babel configuration for compiling a react component
{
"presets": ["es2015", "stage-1", "stage-2", "react"]
}
@witnessmenow
witnessmenow / wrapper.js
Created May 5, 2016 12:53
Node React wrapper
import { Conversation } from 'chat-template';
import ReactDOM from 'react-dom';
import React from 'react';
const showChatTemplate = (messages, element, delay = 1, height = 300) => {
ReactDOM.render(<Conversation delay={delay} height={height} messages={messages} />,
element);
};
module.exports = showChatTemplate;
@witnessmenow
witnessmenow / DelayAndUploadQueue.js
Created April 16, 2016 13:01
A queue of promises that for the given url will wait for 3 seconds and then upload it to gfycat
var uploadQueue
var addGifToUploadQueueWithDelay = (url) => {
var delayAndUpload = () => {
return delay().then(uploadGifToGfycat.bind(null, url));
}
//Queue is either empty or finished
if(!uploadQueue || uploadQueue.isFulfilled()){
uploadQueue = delayAndUpload();
@witnessmenow
witnessmenow / ConvertKeenEntryToGfycatMRW.js
Created April 16, 2016 12:25
mrwgame.com specific. Takes a list of our keen objects and gets back the gfycat details. getGifycatLinkDetails goes to gfycat and checks does the link exist and uploads if it doesn't. Returns a promise that resolves when all keen objects have been converted.
var getGfycatUrlsForKeenList = (keenEntries) => {
var promises = keenEntries.map((entry) => {
return new Promise((resolve, reject) => {
GfycatClient.getGifycatLinkDetails(entry.reaction)
.then((gfycatDetails) => {
if(!gfycatDetails.mp4Url){
}
resolve({
title : entry.question,
documentId : entry.reaction,
@witnessmenow
witnessmenow / TelegramDocumentProxy.js
Last active October 10, 2024 23:35
Example of a getting a file from Telegram without exposing your Bot Token using nodeJS and express. TelegramClient.getFileDetails is a call to the Telegram getFile api. The file is then requested and the response is pipped into response sent back to the user
router.get('/:documentId/*', (req, res) => {
var documentId = req.params.documentId;
if(documentId){
TelegramClient.getFileDetails(documentId).then((fileDetails) => {
var fileUrl = TelegramClient.getTelegramFileUrl(fileDetails.result.file_path);
request(fileUrl)
.on('response', (response) => {
if (response.statusCode === 200) {
res.writeHead(200, {
'Content-Type': response.headers['content-type']