Skip to content

Instantly share code, notes, and snippets.

@forestgun
forestgun / upload.js
Created December 5, 2019 08:21 — forked from ibreathebsb/upload.js
file upload from dataUrl with axios
// Note: only for modern browser
import axios from 'axios'
// helper function: generate a new file from base64 String
const dataURLtoFile = (dataurl, filename) => {
const arr = dataurl.split(',')
const mime = arr[0].match(/:(.*?);/)[1]
const bstr = atob(arr[1])
let n = bstr.length
const u8arr = new Uint8Array(n)
@forestgun
forestgun / README.md
Created December 5, 2019 08:21 — forked from joyrexus/README.md
File upload POST with curl

Extracted from this excellent curl tutorial


Back in late 1995 they defined an additional way to post data over HTTP. It is documented in the RFC 1867, why this method sometimes is referred to as RFC1867-posting.

This method is mainly designed to better support file uploads. A form that allows a user to upload a file could be written like this in HTML:

@forestgun
forestgun / functions>index.js
Created December 3, 2019 10:05 — forked from kaleidawave/functions>index.js
Pass image files through firebase function arguments
exports.uploadImage = functions.https.onCall(async (data, context) => {
const mimeType = data.image.match(/data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,.*/)[1];
const base64EncodedImageString = data.image.replace(/^data:image\/\w+;base64,/, '');
const imageBuffer = new Buffer(base64EncodedImageString, 'base64');
const filename = `posts/${data.name}.${mimeTypes.detectExtension(mimeType)}`;
const file = admin.storage().bucket().file(filename);
await file.save(imageBuffer, { contentType: 'image/jpeg' });
const photoURL = await file.getSignedUrl({ action: 'read', expires: '03-09-2491' }).then(urls => urls[0]);
@forestgun
forestgun / handlers.js
Created June 19, 2019 16:14 — forked from monoceros-tech/handlers.js
Snippet de un handler de ejemplo de cómo dar al usuario tiempo a responder - juego (Veo Veo)
const LaunchRequest_Handler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'LaunchRequest';
},
handle(handlerInput) {
let response = handlerInput.responseBuilder;
let say = `Estamos en salón. `;
say += `Veo veo, ¿qué ves? una cosita, ¿qué cosita es? Empieza por la letra A `;
@forestgun
forestgun / V4: Ayudante de Santa
Created June 6, 2019 10:11 — forked from softwarechido/V4: Ayudante de Santa
Alexa, abre ayudante de santa y pide un mensaje - DialoManagement Enabled para Nombre + Comportamiento(bueno,malo,regular)
//lambda
const Alexa = require('ask-sdk');
const LaunchRequestHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'LaunchRequest'
},
handle(handlerInput) {
@forestgun
forestgun / index.js
Created January 23, 2019 23:01 — forked from memodoring/index.js
AD2 CDMX - Checkpoint 11
/* eslint-disable func-names */
/* eslint-disable no-console */
const Alexa = require('ask-sdk');
const GetNewFactHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'LaunchRequest'
|| (request.type === 'IntentRequest'
@forestgun
forestgun / importParseJson.js
Created June 28, 2017 16:33 — forked from pascalgiguere/importParseJson.js
Node.js script using the Parse REST API to import a JSON file to Parse. Useful when dropping an entire class then reloading it from a JSON backup (Parse export). Will also update pointers of a second Parse class pointing to the imported class so that pointers don't break despite the imported data having different objectIds.
var PARSE_APPLICATION_ID = '';
var PARSE_REST_API_KEY = '';
var JSON_FILE_PATH = ''; // Path to JSON file to import
var IMPORTED_CLASS_NAME = ''; // Class to import
var POINTING_CLASS_NAME = ''; // Class with pointers to imported class
var POINTING_CLASS_PROPERTY = ''; // Name of pointer property
var request = require('request');
var fs = require('fs');
@forestgun
forestgun / bot-send-message.js
Created June 28, 2017 07:11 — forked from DevWellington/bot-send-message.js
bot web.whatsapp.com - send message for a contacts list
var script = document.createElement('script');
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
// search contact
function searchContact(searchValue, interval_add)
{
var interval = interval_add;
var count = 1;
@forestgun
forestgun / whatsapp-web-text-formatting.user.js
Created June 28, 2017 07:09 — forked from giterlizzi/whatsapp-web-text-formatting.user.js
WhatsApp Web Text Formatting (for Greasemonkey / Tampermonkey)
// ==UserScript==
// @name WhatsApp Web Text Formatting
// @namespace https://github.com/LotarProject
// @version 0.1
// @description Convert formatting text syntax into HTML
// @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
// @match https://web.whatsapp.com/
// @grant none
// ==/UserScript==
@forestgun
forestgun / globalmods.js
Created June 28, 2017 07:09 — forked from WouterG/globalmods.js
Whatsapp fullscreen modification
// ==UserScript==
// @name GLOBAL MODS
// @namespace http://wouto.net/
// @version 2.0
// @description Some mods to the LocalStorage engine, an ImageLoader and a StyleUtil, which is effective on all sites that Tampermonkey is allowed to run on
// @author Wouter
// @match *://*/*
// @grant none
// ==/UserScript==