Skip to content

Instantly share code, notes, and snippets.

webapp/OAuth2/REST API stack security checklist

OAuth2 (implicit flow)

  • response_type is a constant set for particular app on server (1)
  • redirect_uri, too (1)
  • "state" parameter is echoed by server and checked by client (1)
  • hash of "state" parameters is stored in LocalStorage and destroyed on receiving redirect (1)
  • "client_id" parameter is checked (after obtaining token, make a request to server to get "token_id" for this token and compare to existing one) (2, 3)
  • IP is saved for particular token on grant and checked on access
@si14
si14 / tmp.erl
Created November 13, 2013 12:44
-module(tmp).
-behaviour(gen_server).
%% API
-export([start_link/0]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
-module(foobar_tests).
-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").
prop_delete() ->
?FORALL({X,L}, {integer(),list(integer())},
not lists:member(X, lists:delete(X, L))).
proper_test() ->
?assertEqual(
(defrecord GHCache [^TTLCache ttl-cache etagged cleaner-c])
(defn init-cache []
(let [control-c (chan)
old-killer (fn [etagged]
(let [now (System/currentTimeMillis)]
(->> etagged
(filter #(> (- now (-> % value :created-at))
(* 6 60 60 1000)))
(into {}))))
curl -XPOST -d "source=`git config user.name`&from_address=`git config user.email`&subject=pushed to production&content=`git log --pretty=format:'%s %H' -n 1`" https://api.flowdock.com/v1/messages/team_inbox/YOUR_TOKEN_GOES_HERE
@si14
si14 / code.clj
Created September 23, 2013 20:38
(defn gaussian [m mu gamma]
(let [m (mp/clone m)
t (/ 1 (* gamma (Math/sqrt (* 2 Math/PI))))]
(magic/specialize :double
(loop-over [m]
(let [x (aget m-data m-idx)
exparg (* -0.5 (Math/pow (/ (- x mu) gamma) 2))
g (* t (Math/exp exparg))]
(aset m-data m-idx g))))))
(defn tags-types [form]
(clojure.walk/prewalk
(fn [form]
(when-let [m (meta form)]
(when-let [t (:tag m)]
(prn m t (type t))))
form)
form))
;; enable printing of meta in repl with (set! *print-meta* true)
(def test-form1
'(let [^String a "a"]
:ok))
(def test-form2
`(let [^String ~'a "a"]
:ok))
(def test-form3
`(let [^String a# "a"]
@si14
si14 / examples.md
Last active December 20, 2015 12:29

NDArray examples

An obvious stuff:

> (identity-matrix :ndarray 3)
#<NDArray [[1.0 0.0 0.0] [0.0 1.0 0.0] [0.0 0.0 1.0]]>
> (identity-matrix :ndarray-long 3)
#<NDArrayLong [[1 0 0] [0 1 0] [0 0 1]]>
> (identity-matrix :ndarray-double 3)