Skip to content

Instantly share code, notes, and snippets.

View noahlz's full-sized avatar
🕵️‍♂️
Secret Stuff for SEI Novus. I might take 1 - 3 days to respond.

Noah Zucker noahlz

🕵️‍♂️
Secret Stuff for SEI Novus. I might take 1 - 3 days to respond.
View GitHub Profile
@noahlz
noahlz / chars-in-common.clj
Created July 10, 2012 20:41
Find the set of characters two strings have in common
;; Solve the problem "find the set of characters two strings have in common"
;; Approach #1 BitSets
;; - use a bitsets for each string,
;; - flip the bit for each character in each string
;; - then "and" the two bitsets. Theoretically O(N + M) performance
(defn string-to-charbits [s]
(loop [[f & rest] s
bits (java.util.BitSet.)]
@noahlz
noahlz / eval.sh
Created July 13, 2012 20:10
Attempt to code eval loop in sh
#!/bin/sh
# Futile attempts keep BUG below to not potentially exit the script.
set +e +E
trap '' ERR
# displays the prompt in light cyan.
# TODO: http://stackoverflow.com/q/6788777/7507
echo -e "\e[00;36mEnter expressions, [Ctrl-C] to exit\e[00m"
@noahlz
noahlz / datomic-first-steps.clj
Created July 17, 2012 21:24
First steps with Datomic
;; adopted from http://www.datomic.com/company/resources/getting-started
;; Clojure 1.4.0
;; user=>
(use '[datomic.api :only [q db] :as d])
;;=> nil
;; user=>
(doc d/q)
;; -------------------------
;; Robot from Joy of Clojure, Ch 7
(def bearings [{:x 0 :y 1} ; move north
{:x 1 :y 0} ; move east
{:x 0 :y -1} ; move south
{:x -1 :y 0}]) ; move west
(defn bot [x y bearing-num]
{:coords [x y]
:bearing ([:north :east :south :west] bearing-num)
:forward (fn [] (bot (+ x (:x (bearings bearing-num)))
@noahlz
noahlz / clojure-nyc-meetup-notes-20120718.md
Created July 20, 2012 17:28
Rough Notes from the July 18 Clojure NYC Meetup

Organizing Clojure Projects

Presented by @stuartsierra

Stuart presented using a deck created with org-html-slideshow, a Clojure library for formatting org-mode notes as HTML slides.

General Code Structure / Organization
  1. Be careful not to make function calls across component boundaries.
  2. Protocols should be minimalistic. They should have the fundamental operations of your component.
@noahlz
noahlz / doc-vs-meta.clj
Created August 22, 2012 06:21
Exploration of Clojure doc and meta functions
;; See http://stackoverflow.com/questions/12066020/in-clojure-why-i-need-to-write-doc-str-but-meta-str
;; Define a var foo that points to a function
(def foo (with-meta (fn [] (println "bar")) {:doc "prints bar"} ))
;=> #'user/foo
(foo)
;=> bar
;=> nil
;; We see the :doc in our foo metadata...but where's our REPL documentation?
@noahlz
noahlz / GetLatestBuildNumber.java
Created September 7, 2012 18:48
Answer to a StackOverflow problem. 1000 rep points or bust!
import java.io.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
* http://stackoverflow.com/q/12321837/7507
*/
public class GetLatestBuildNumber {
private static final AtomicInteger number = new AtomicInteger();
;; See https://twitter.com/stevelosh/status/269269366992936960
(defn multi-update [m updates]
(reduce (fn [m [k f & args]]
(update-in m k #(apply f % args)))
m updates))
;; user=> (multi-update {:a 1 :b 2 :c 3} [[[:a] 1 1 1][[:b] 1 1][[:c] 3 1 -2]])
;; {:a 4, :c 5, :b 4}
@noahlz
noahlz / wtf.java
Created March 6, 2013 00:06
What did I do in a prior life to have to look at code like this?
public Result processCommand(Data data) {
try {
return doStuff();
// fuck it, just catch everything
} catch (Exception ex) {
String message = ex.getMessage() != null ? message : "LOL OOPS!";
return new Result(message);
}
}
@noahlz
noahlz / BushLeagueJava.md
Last active December 14, 2015 14:29
Something I wrote back in 2008 when I was dealing with a codebase that was driving me nuts.

Bush league is a general term used to describe an action or thing as being amateur, inferior or crude. In a literal sense, it refers to a low quality minor-league in baseball not associated with any of the major league teams. The term originated from the state of minor-league fields that often were ringed with shrubs and bushes.

- Wikipedia

Secretly using StringBuffer to convert a number to a String

int value = getValue();
String valStr = value + "";