Skip to content

Instantly share code, notes, and snippets.

View maxp's full-sized avatar

Maxim Penzin maxp

View GitHub Profile
function isObject(obj) {
return obj !== null && typeof obj === 'object';
}
const isArray = Array.isArray;
function isPlainObject(obj) {
return isObject(obj) && (
obj.constructor === Object // obj = {}
|| obj.constructor === undefined // obj = Object.create(null)

Keybase proof

I hereby claim:

  • I am maxp on github.
  • I am mpenzin (https://keybase.io/mpenzin) on keybase.
  • I have a public key whose fingerprint is C086 D0BB A73A 97D5 B486 C516 F5F1 67A9 3283 443B

To claim this, I am signing this object:

### Keybase proof
I hereby claim:
* I am maxp on github.
* I am mpenzin (https://keybase.io/mpenzin) on keybase.
* I have a public key ASD1POnkRCRj1eeXHbXfjJM0RuzZhy_JQjWmrkQpwo0Nogo
To claim this, I am signing this object:
(import [java.util UUID])
(defn timebased-uuid []
(let [uuid (UUID/randomUUID)
time (int (/ (System/currentTimeMillis) 1000))
high (.getMostSignificantBits uuid)]
(UUID.
(bit-or
(bit-and high 0x00000000FFFFFFFF)
(bit-shift-left time 32))
@maxp
maxp / haversine.clj
Created August 27, 2017 04:59
distance between two points on Earth, #geo
defn haversine
[{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}]
(let [R 6372.8 ; kilometers
dlat (Math/toRadians (- lat2 lat1))
dlon (Math/toRadians (- lon2 lon1))
lat1 (Math/toRadians lat1)
lat2 (Math/toRadians lat2)
a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2))) (* (Math/sin (/ dlon 2)) (Math/sin (/ dlon 2)) (Math/cos lat1) (Math/cos lat2)))]
(* R 2 (Math/asin (Math/sqrt a)))))
;; https://github.com/samfoo/mercator/blob/master/src/mercator/gpx.clj
(ns mercator.gpx
(:use [clojure.core.match :only [match]])
(:require [clojure.zip :as zip]
[clj-time.format :as time]
[clojure.data.zip.xml :as xzip]
[clojure.data.xml :as xml]))
;; https://github.com/samfoo/mercator/blob/master/src/mercator/kml.clj
(ns mercator.kml
(:use [clojure.core.match :only [match]])
(:require [clojure.zip :as zip]
[clj-time.format :as time]
[clojure.data.zip.xml :as xzip]
[clojure.data.xml :as xml]))
;; https://raw.githubusercontent.com/honza/clj-gpx/master/src/gpx/core.clj
(ns gpx.core
(:require [clojure.xml :refer :all]
[clojure.algo.generic.math-functions :refer :all]
[clj-time.format :as tf]
[clj-time.core :as tc]
[clojure.pprint :refer [pprint]])
(:gen-class))
;; 1
(defn resend-code [email on-success on-error]
(let [cognito_user (new CognitoUser #js {:Username email :Pool config/user_pool})]
(.resendConfirmationCode cognito_user
(fn [err result]
(info! "cognito.resend-code:" err result
(if err
(on-error err)
(on-success result)))))))
(ns cron.meteo
(:require
[clj-time.core :as t]
[clj-time.periodic :as tp]
[chime :refer [chime-at]]
[mount.core :refer [defstate]]
[monger.collection :as mc]
[monger.query :as mq]
;