Instantly share code, notes, and snippets.

View arrvsset.rb
# frozen_string_literal: true
require 'set'
require 'benchmark/ips'
ARRAY = 100_000.times.map(&:itself)
SET = Set.new(ARRAY)
def array_include?
ARRAY.include?(50_000)
View rails41_jsonb.rb
Rails.application.config.after_initialize do
ActiveSupport.on_load(:active_record) do
oid = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID
# https://github.com/rails/rails/blob/v4.2.3/activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
oid::Jsonb = Class.new(oid::Json) do
def type
:jsonb
end
View spyke.rb
class JSONParser < Faraday::Response::Middleware
def parse(body)
json = MultiJson.load(body, symbolize_keys: true)
{
data: json[:result],
metadata: json[:extra],
errors: json[:errors]
}
View doc.md
View transit vs json vs edn
Ξ transit/transit-cljs → node target/transit.bench.js
100 iters, JSON.parse seattle data
"Elapsed time: 81.000000 msecs"
100 iters, transit read seattle data
"Elapsed time: 105.000000 msecs"
100 iters, JSON.stringify seattle data
"Elapsed time: 44.000000 msecs"
100 iters, transit write seattle data
"Elapsed time: 1204.000000 msecs"
100 iters, transit write seattle data no-cache
View screenshots.clj
(defn make-screenshots-xf []
(fn [xf]
(let [_ (debug "Starting new browser")
browser (new-driver {:browser :chrome})]
(debug "New browser Maximize")
(maximize browser)
(fn
([]
(debug "Init")
(xf))
View relax.clj
(ns relaxfm.core
(:gen-class)
(:require [hickory.core :as hc]
[hickory.select :as hs]
[clj-http.client :as http]
[clojure.string :as s]
[clojure.java.shell :as sh]
[clj-time.core :as t]
[clj-time.format :as tf]
[clj-time.coerce :as tc]))
View comment.cljs
(ns nhchat.components.comment
(:require [om.core :as om]
[om-tools.core :refer-macros [defcomponent]]
[sablono.core :refer-macros (html)]))
(enable-console-print!)
(defcomponent wrapper [{:keys [comment]} owner]
(render [_]
(html [:div]))
View int_str.clj
(def i 343224324234)
(defn int->str-1
[]
(let [s (str i) p (mod (count s) 3)]
(->>
(reduce-kv
(fn [acc i c]
(if (and (> i 0) (zero? (mod (- i p) 3)))
(conj acc \, c)
View kittens.clj
(ns kittens.core
(:require [environ.core :refer (env)]
[clj-http.client :as http]
[clojure.java.io :as io]
[clojure.core.async :as async :refer (go go-loop <!)]))
(def api-key (-> env :dev :flickr :api-key))
(def rest-api-url "https://api.flickr.com/services/rest/")
(def folder "photos")