Use type inference where possible, but put clarity first, and favour explicitness in public APIs.
Almost never annotate the type of a private field or a local variable
All public methods should have explicit type annotations.
| (defn flattener | |
| [input flattened?] | |
| (((fn [f] (f f)) | |
| (fn [f] | |
| (fn [x xs] | |
| (if (flattened? x) | |
| (cons x ((f f) (first xs) (rest xs))) | |
| (if (empty? x) | |
| xs |
| (defn invoke-private-method [obj fn-name-string & args] | |
| (let [m (first (filter (fn [x] (.. x getName (equals fn-name-string))) | |
| (.. obj getClass getDeclaredMethods)))] | |
| (. m (setAccessible true)) | |
| (. m (invoke obj args)))) | |
| (defn private-field [obj fn-name-string] | |
| (let [m (.. obj getClass (getDeclaredField fn-name-string))] | |
| (. m (setAccessible true)) | |
| (. m (get obj)))) |
| (defn new-instance | |
| " creates a new Instance of a Class | |
| Passing a Class will result in Class.newInstance | |
| (new-instance String) | |
| Passing a Class and vector of args will attempt to match the Constructor | |
| by creating a Class[] by calling `class` on each arg |
| ;;; https://clojure.org/reference/repl_and_main#_launching_a_socket_server | |
| ;;; -Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}" | |
| (defmacro send-forms [host port form & forms] | |
| `(with-open [socket# (java.net.Socket. ~host ~port)] | |
| (let [pw# (java.io.PrintWriter. (.getOutputStream socket#) true) | |
| in# (java.io.BufferedReader. (java.io.InputStreamReader. (.getInputStream socket#))) | |
| forms# (list ~(str form) ~@(map str forms))] | |
| (reduce |
| (defn fizzbuzz | |
| " | |
| rules - map of number and string ex. {3 \"fizz\" 5 \"buzz\"} | |
| limit - number to count too | |
| " | |
| [rules limit] | |
| (((fn [f] (f f)) | |
| (fn [f] | |
| (fn [x] |
| # /usr/libexec/java_home -X | |
| $ sudo opensnoop -n java_home | |
| UID PID COMM FD PATH | |
| 501 79809 java_home 3 /System/Library/PrivateFrameworks/JavaLaunching.framework/Versions/A/JavaLaunching | |
| 501 79809 java_home 3 /dev/dtracehelper | |
| 501 79809 java_home 4 /System/Library/CoreServices/SystemVersion.bundle//English.lproj | |
| 501 79809 java_home -1 /System/Library/CoreServices/SystemVersion.bundle//Base.lproj | |
| 501 79809 java_home 4 /System/Library/CoreServices/SystemVersion.bundle/English.lproj/SystemVersion.strings | |
| 501 79809 java_home -1 /System/Library/CoreServices/SystemVersion.bundle/English.lproj/SystemVersion.stringsdict | |
| 501 79809 java_home 3 /usr/share/icu/icudt51l.dat |
Use type inference where possible, but put clarity first, and favour explicitness in public APIs.
Almost never annotate the type of a private field or a local variable
All public methods should have explicit type annotations.
| #! /usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import sys, os, argparse | |
| import logging | |
| import csv | |
| import json | |
| from functools import partial |
| # Adjust Docker Machine Memory+CPU | |
| # http://stackoverflow.com/questions/32834082/how-to-increase-docker-machine-memory-mac | |
| docker-machine stop | |
| VBoxManage modifyvm default --cpus 2 | |
| VBoxManage modifyvm default --memory 4096 | |
| docker-machine start |
| (defn ns-qualified-keys | |
| " | |
| takes a namespace and map of kv and converts it to namespace qualified keys | |
| (ns-qualified-keys 'foo.bar {:port 80}) | |
| ;;=> {:foo.bar/port 80} | |
| " | |
| [ns m] | |
| (into {} | |
| (for [[k v] m] |