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"))
View clojure-spec-plumatic-schema-comparison.clj
(ns versioned.crud-api-attributes
(:require [versioned.model-support :as model-support]
[versioned.model-spec :as model-spec :refer [Model]]
[versioned.json-api :as json-api]
[versioned.model-attributes :refer [api-writable-attributes api-readable-attributes]]
[versioned.crud-api-audit :refer [updated-by created-by save-changelog]]
[versioned.crud-api-types :refer [coerce-attribute-types]]
[clojure.spec :as s]
[schema.core :as schema]))
View java_vs_clojure_immutable.md

Java

We are using the Builder pattern here. Notice how each field is duplicated about five times and how we need to implement equals and hashCode manually (left as an exercise for the reader):

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

@JsonDeserialize(builder = User.Builder.class)
View clojure_vs_java_8.md

Java:

public Optional<String> getType() {
    return this.types.isEmpty() ?
        Optional.empty() :
        Optional.of(String.join(",", (Iterable)this.types.stream().map(Enum::name).collect(Collectors.toList())));
}