Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: codeslinger/nooz
base: e14fc32262
...
head fork: codeslinger/nooz
compare: ca3c2b09c7
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
34 src/nooz/crypto.clj
@@ -9,7 +9,8 @@
java.security.SecureRandom
java.security.MessageDigest
java.math.BigInteger
- java.util.Random))
+ java.util.Random
+ java.nio.ByteBuffer))
(def ^{:private true
:doc "Algorithm to seed random numbers."}
@@ -19,18 +20,6 @@
(def ^{:private true} idkey "nextid")
(def ^{:private true} epochStart 1387263000)
-(defn gen-id
- "Generate a random unique ID."
- ([]
- (let [ms (- (nt/long-now) epochStart)
- r (.nextLong rando)
- id (mod (redis/with-server db/prod-redis (redis/incr idkey))
- 1024)]
- (bit-or
- (bit-or (bit-shift-left (bit-and ms 0x000001FFFFFFFFFF) 23)
- (bit-shift-left (bit-and r 0x0000000000001FFF) 10))
- (bit-and id 0x00000000000003FF)))))
-
(defn gen-salt
"Generate a salt for BCrypt's hashing routines."
([]
@@ -74,3 +63,22 @@
(defn gen-confirmation-token []
(let [hashbytes (gen-random-hash 16)]
(wrap-web-safe (codec/base64-encode hashbytes))))
+
+(defn long-to-web-safe [val]
+ (let [b (. ByteBuffer allocate 8)]
+ (.putLong b val)
+ (wrap-web-safe (codec/base64-encode (.array b)))))
+
+(defn gen-id
+ "Generate a random unique ID."
+ ([]
+ (let [ms (- (nt/long-now) epochStart)
+ r (.nextLong rando)
+ id (mod (redis/with-server db/prod-redis
+ (redis/incr idkey))
+ 1024)]
+ (long-to-web-safe
+ (bit-or
+ (bit-or (bit-shift-left (bit-and ms 0x000001FFFFFFFFFF) 23)
+ (bit-shift-left (bit-and r 0x0000000000001FFF) 10))
+ (bit-and id 0x00000000000003FF))))))
View
4 src/nooz/models/comment.clj
@@ -46,8 +46,8 @@
(redis/with-server db/prod-redis
(record-comment! post comment)
(update-comment-count! (get post "id"))
- (record-comment-for-user! comment (get post "id") user time)
- (get comment "id"))))
+ (record-comment-for-user! comment (get post "id") user time))
+ (get comment "id")))
(defn create-comment! [post user {:keys [parent comment] :as args}]
(if (valid-comment? args)
View
2  src/nooz/server.clj
@@ -38,4 +38,4 @@
(-main :dev)
server-config
(swap! server-config assoc :port 8081)
- )
+ )

No commit comments for this range

Something went wrong with that request. Please try again.