View s3-direct-javascript-upload.md

S3 Direct JavaScript Upload

TypeScript Code

S3 client module:

import * as AWS from 'aws-sdk'

export const REGION = 'eu-west-1'
View scala-vs-dynamic.md

Untyped Scala vs Properly Typed Scala vs Dynamic Typing

The point of comparison here is a simple function that looks up a string key in a nested map/dictionary (JSON data from the payload/claims of a JWT token) and returns the given key if it's there and None/nil otherwise.

Scala (Without Proper Types)

Original function:

def verifyPartner(partner: String, payload: Map[String, java.lang.Object]): Either[String, String] = {
View user.ts
export class User {
id: string
country: string
email: string
name: string
tags: string[]
verified: boolean
active: boolean
locale: string
openIds: any
View tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
View vs-code-user-settings.json
{
"editor.fontSize": 14,
"editor.tabSize": 2,
"editor.detectIndentation": false,
"editor.insertSpaces": true,
"files.trimTrailingWhitespace": true,
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
View diff.ts
const R = require('ramda')
function pathString(path: string[]): string {
return path.join('.')
}
function valueType(value: any): string {
if (value === undefined) {
return 'undefined'
} else if (value === null) {
View string_split_benchmark.md

Split Large String Benchmark

Results

String split 1 million line string from Heroku log file:

  • Elixir 166s
  • Clojure 8s
  • Ruby 1s
  • Python 0.5s
View s3-upload
#!/usr/bin/env node
// This script uploads a local file to S3
// Depends on the aws4 npm package for AWS signatures
// Usage:
// AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... s3-upload
const fs = require('fs')
const https = require('https')
const aws4 = require('aws4') // Handles complex AWS signatures: http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html
View server-side-handlebars-with-rails-4.rb
################################################################
# config/initializers/handlebars.rb:
################################################################
template_path = File.join(Rails.root.to_s, 'app/views')
helpers = {
t: lambda do |context, key|
I18n.t(key)
end,
path: lambda do |context, path_name|
View json-schema-in-plumatic-schema.clj
(require '[schema.core :as s])
(def StrOrKeyword (s/cond-pre s/Str s/Keyword))
(declare Schema)
(declare SchemaValue)
(def SchemaMap {s/Keyword (s/recursive #'SchemaValue)})
(def SchemaArray [(s/recursive #'SchemaValue)])
(def SchemaValue (s/cond-pre s/Str s/Num Nil s/Bool SchemaMap SchemaArray))
(def SchemaType (s/enum "string" "number" "integer" "null" "boolean" "array" "object"))