Skip to content

Instantly share code, notes, and snippets.

@barbietunnie
barbietunnie / download-file.js
Created June 23, 2017 10:30
Downloading files in Node.js
var http = require('http');
var fs = require('fs');
var download = function(url, dest, cb) {
var file = fs.createWriteStream(dest);
var request = http.get(url, function(response) {
response.pipe(file);
file.on('finish', function() {
file.close(cb); // close() is async, call cb after close completes.
});
const someReallyUsefullFunction = async (text) => {
// Break in parts small enough to be handle by Polly API
const parts = divideTextEnoughToBeHandleByPolly(text)
// Concat AudioStreams in one Buffer
const audioStreams = audios.map(a => a.AudioStream)
const buffer = Buffer.concat(audioStreams, audioStreams.reduce((len, a) => len + a.length, 0))
...
}
@anaptfox
anaptfox / amazon-polly-file.js
Created December 13, 2016 13:54
Node.js Amazon Polly to file example.
// Load the SDK
const AWS = require('aws-sdk')
const Fs = require('fs')
// Create an Polly client
const Polly = new AWS.Polly({
signatureVersion: 'v4',
region: 'us-east-1'
})
@pixelbreaker
pixelbreaker / example.js
Last active March 2, 2017 16:13
PouchDB image cache
import ImageCache from './image-cache.js'
var imageCache = new ImageCache();
var img = $(el).find('img');
imageCache.loadImage(img[0], img.attr('src'));
var count = function(txt, rank) {
var wordFreq = {};
var words = txt.split(' ');
for (i = 0; i < words.length; i++) {
var current = words[i];
var last = current.length - 1;
current = noPunc(current);
if (notInArray(current, particle) && !wordFreq[current]) {
wordFreq[current] = 1;
}
Import-Module -Name D:\Temp\ACME-posh\ACMEPowerShell.psd1
$domain = "mydomain.com"
$certificiatePassword = "abcd1234"
$email = "letsencrypt@mydomain.com"
$vault = "D:\Vault\{0}\{1}" -f $domain, [guid]::NewGuid()
mkdir $vault
cd $vault
Initialize-ACMEVault -BaseURI https://acme-v01.api.letsencrypt.org/
New-ACMERegistration -Contacts mailto:$email
@adactio
adactio / basicServiceWorker.js
Last active March 27, 2023 09:30
A basic Service Worker, for use on, say, a blog.
'use strict';
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function() {
// Update 'version' if you need to refresh the cache
var staticCacheName = 'static';
var version = 'v1::';
@lukehoban
lukehoban / speech.js
Last active December 28, 2023 15:14
Project Oxford Speech APIs Node.js Sample
var fs = require('fs');
var util = require('util');
var request = require('request');
var clientId = 'test-app'; // Can be anything
var clientSecret = 'f6f0bfec08274b8790520a9079b808af'; // API key from Azure marketplace
var str = 'This is a cool demo to call Microsoft text to speach service in Node.js.';
console.log('Converting from text -> speech -> text.');
@JamesMessinger
JamesMessinger / IndexedDB101.js
Last active April 4, 2024 02:00
Very Simple IndexedDB Example
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
// Open (or create) the database
var open = indexedDB.open("MyDatabase", 1);
// Create the schema
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore("MyObjectStore", {keyPath: "id"});
@jshbrntt
jshbrntt / pan-zoom-image.js
Last active October 16, 2018 11:10
A simple way of panning and zooming an image using Hammer.js.
// <img id="myimage" src="http://placecage/1280/720">
var image = document.getElementById('myimage');
var mc = new Hammer.Manager(image);
var pinch = new Hammer.Pinch();
var pan = new Hammer.Pan();
pinch.recognizeWith(pan);