Skip to content

Instantly share code, notes, and snippets.

View witnessmenow's full-sized avatar

Brian Lough witnessmenow

View GitHub Profile
@witnessmenow
witnessmenow / TelegramDocumentProxy.js
Last active April 16, 2016 12:00
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']
@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 / 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 / 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 / .babelrc
Created May 5, 2016 12:58
Babel configuration for compiling a react component
{
"presets": ["es2015", "stage-1", "stage-2", "react"]
}
@witnessmenow
witnessmenow / webpack.dev.config.js
Created May 5, 2016 13:04
Example dev webpack configuration for wrapping react modules
module.exports = {
entry: './wrapper.js',
output: {
libraryTarget: 'var',
library: 'showChatTemplate',
path: 'builds',
filename: 'chat-template.js',
},
module: {
@witnessmenow
witnessmenow / example.html
Created May 5, 2016 13:06
Example of using chat-template.js
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/">
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>react-webpack-wrapper-example</title>
@witnessmenow
witnessmenow / webpack.prod.config.js
Created May 5, 2016 13:15
Example production webpack configuration for wrapping a react component using webpack
const webpack = require('webpack');
module.exports = {
entry: './wrapper.js',
output: {
libraryTarget: 'var',
library: 'showChatTemplate',
path: 'builds',
filename: 'chat-template-min.js',
},
@witnessmenow
witnessmenow / Instructions
Created September 22, 2017 10:58
Backup a file using telegram, backup runs every day at 2:30
Create the backup.sh file and paste in contents of the file
Edit the crontab: crontab -e
30 2 * * * /root/backup.sh
@witnessmenow
witnessmenow / BTMakeyMakey
Created October 9, 2017 23:51
Arduino code for a bluetooth Makey Makey running on an ESP8266
#include <Wire.h>
#define ttp229 (0xAF>>1)
uint16_t data_out = 0;
uint16_t data1, data2;
int count = 0;
boolean count2 = false;
// https://github.com/witnessmenow/BPLib
#include <BPLib.h>
#include <SoftwareSerial.h>