Skip to content

Instantly share code, notes, and snippets.

View florabtw's full-sized avatar

Flora Moon florabtw

View GitHub Profile
@florabtw
florabtw / Derangement
Created February 7, 2014 05:35
Iterative derangements / subfactorials using BigDecimals and BigIntegers in Java
public BigInteger derangement(int num) {
if (num == 0) {
return BigInteger.ONE;
}
BigDecimal sum = BigDecimal.ZERO;
for (int i = 0; i <= num; i++) {
BigDecimal fact = new BigDecimal(factorial(i));
BigDecimal toAdd = BigDecimal.valueOf(Math.pow(-1, i)).divide(fact, MathContext.DECIMAL128);
sum = sum.add(toAdd);
@florabtw
florabtw / TL.js
Last active December 17, 2015 06:55
Extracted from obfuscated Google Translate JavaScript. The result of TL(a) is REQUIRED to interact with Google Translate's TTS engine.
// TKK = hours since epoch
var window = {
TKK: parseInt(new Date().getTime() / 1000 / 60 / 60)
};
var t = "a";
var cb = "&";
var mf = "=";
var k = "";
var dd = ".";
@florabtw
florabtw / Translate.js
Last active August 6, 2021 22:23
Run with `node Translate.js hello`
// TKK = hours since epoch
var window = {
TKK: parseInt(new Date().getTime() / 1000 / 60 / 60)
};
var t = "a";
var dd = ".";
var Vb = "+-a^+6";
var Tb = "+";
var Ub = "+-3^+b+-f";

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)

@florabtw
florabtw / Client.scala
Created February 17, 2017 07:51
WebSocket Client and Server
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
@florabtw
florabtw / soundoftext.js
Last active February 9, 2021 18:21
Example Usage of Sound of Text API
/* 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
@florabtw
florabtw / soundoftext.sh
Created August 19, 2018 04:33
POST to Sound Of Text with curl
#! /bin/bash
curl \
-X POST \
-H "Content-Type: application/json" \
-d '{ "data": { "voice": "en-US", "text": "Hello, world!" } }' \
https://api.soundoftext.com/sounds
@florabtw
florabtw / youdontknowjs.md
Created December 14, 2018 16:14
Notes from You Don't Know Javascript

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,

@florabtw
florabtw / counter.rb
Last active December 21, 2018 22:01
Counter Game
module Actions
class Increment
def self.call(state)
{ count: state[:count] + 1 }
end
end
class Decrement
def self.call(state)
{ count: state[:count] - 1 }
@florabtw
florabtw / soundoftext.js
Created July 4, 2019 04:02
Sound of Text - Browser client
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 = {