Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
Hardly Working

Nick Pierson ncpierson

👨‍💻
Hardly Working
View GitHub Profile
@ncpierson
ncpierson / fizzbuzz-aaa.js
Last active Dec 19, 2019
Web-Scale FizzBuzz
View fizzbuzz-aaa.js
const operations = [
number => number % 3 === 0 && number % 5 === 0 && 'FizzBuzz',
number => number % 3 === 0 && 'Fizz',
number => number % 5 === 0 && 'Buzz',
number => number
];
const toFizzBuzz = number =>
operations.reduce((out, fn) => out || fn(number), false);
@ncpierson
ncpierson / soundoftext.py
Created Sep 28, 2019
Using Sound of Text API in Python 3
View soundoftext.py
import time
import requests
data = { 'engine': 'Google', 'data': { 'voice': 'en-US', 'text': 'Hello, world!' } }
response = requests.post(
'https://api.soundoftext.com/sounds',
headers={'Content-Type':'application/json'},
json=data
)
View Sound of Text Demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
</head>
<body>
<script
src="https://gist.githack.com/ncpierson/4d94970859c679a3884bfe7d00709f52/raw/3452fd99f67414be49d11689ae10055c45afd477/soundoftext.js"
type="text/javascript"
@ncpierson
ncpierson / soundoftext.js
Created Jul 4, 2019
Sound of Text - Browser client
View soundoftext.js
const soundoftext = (() => {
const API_URL = 'https://api.soundoftext.com';
const urls = {
base: 'https://api.soundoftext.com',
request: () => `${urls.base}/sounds`,
status: id => `${urls.base}/sounds/${id}`,
};
const bodies = {
@ncpierson
ncpierson / counter.rb
Last active Dec 21, 2018
Counter Game
View counter.rb
module Actions
class Increment
def self.call(state)
{ count: state[:count] + 1 }
end
end
class Decrement
def self.call(state)
{ count: state[:count] - 1 }
@ncpierson
ncpierson / youdontknowjs.md
Created Dec 14, 2018
Notes from You Don't Know Javascript
View youdontknowjs.md

ALL of the falsy values:

  • ""
  • 0, -0, NaN
  • null, undefined
  • false

The empty array is truthy. However, when loosely compared, it is coerced into an empty string, which is falsy. So,

@ncpierson
ncpierson / soundoftext.sh
Created Aug 19, 2018
POST to Sound Of Text with curl
View soundoftext.sh
#! /bin/bash
curl \
-X POST \
-H "Content-Type: application/json" \
-d '{ "data": { "voice": "en-US", "text": "Hello, world!" } }' \
https://api.soundoftext.com/sounds
@ncpierson
ncpierson / soundoftext.js
Last active Feb 9, 2021
Example Usage of Sound of Text API
View soundoftext.js
/* Downloads 'Hello, World', spoken in English, to ./hello.mp3 */
const http = require('https');
const fs = require('fs');
/* Set up handler for response from initial POST request */
function handlePostResponse(data) {
const response = JSON.parse(data); // parse response body from POST
@ncpierson
ncpierson / Client.scala
Created Feb 17, 2017
WebSocket Client and Server
View Client.scala
import akka.Done
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.ws.TextMessage.Strict
import akka.http.scaladsl.model.ws.{Message, TextMessage, WebSocketRequest}
import akka.stream.scaladsl.{Flow, Keep, Sink, Source, SourceQueue}
import akka.stream.{ActorMaterializer, OverflowStrategy}
import scala.concurrent.ExecutionContext.Implicits.global
View Nick's Scala Notes.md

Nick's Scala Notes

Basics

This section should be most of the things you need to get going. The goal is that you can read most scala code and write your own simple applications. (Also check out Intermediate and Advanced)

The REPL (Scala playground)