This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# syntax=docker/dockerfile:1 | |
# The Oso Local Development binary will be available at http://localhost:8080 | |
# Test it out with the following curl command: | |
# | |
# Simple Dockerfile to run the Oso Local Development binary in a container. | |
# | |
# To build the image, run: | |
# docker build -t oso-local . | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.math.absoluteValue | |
fun diagonalDifference(arr: Array<Array<Int>>) = arr | |
.mapIndexed { index, ints -> Pair(ints[index], ints[arr.size - index - 1]) } | |
.reduce { pair, acc -> Pair(pair.first + acc.first, pair.second + acc.second) } | |
.let { pair -> pair.first - pair.second } | |
.absoluteValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def input [[1 2 3] [4 5 6] [9 8 9]]) | |
(defn diag-diff2 | |
[arr] | |
(->> arr | |
(map-indexed (fn [i e] [(nth e i) (nth e (- (count arr) i 1))])) | |
(reduce (fn [acc [x y]] [(+ (first acc) x) (+ (second acc) y)])) | |
(reduce -) | |
Math/abs)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.SSERouter do | |
use Plug.Router | |
@event_delay 2000 | |
plug(:match) | |
plug(:dispatch) | |
defp send_chunk(conn) do | |
:timer.sleep(@event_delay) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"github.com/gin-gonic/gin" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.reflect.full.declaredMemberProperties | |
import kotlin.reflect.full.primaryConstructor | |
/** | |
* Merge two data classes | |
* The resulting data class will contain | |
* - all fields of `other` which are non null | |
* - the fields of `this` for the fields which are null in `other` | |
*/ | |
infix inline fun <reified T : Any> T.merge(other: T): T { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmacro is_loaded_module(module) do | |
quote do | |
case Code.ensure_loaded(unquote(module)) do | |
{:module, module_name} -> true | |
_ -> false | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns com.fire.kingdom.flambit | |
(:require [flambo.api :as f] | |
[flambo.tuple :as ft] | |
[clojure.string :as s]) | |
(:import [com.datastax.spark.connector.japi CassandraJavaUtil])) | |
; in Cassandra ... | |
; CREATE KEYSPACE test WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1 }; | |
; CREATE TABLE test.words (word text PRIMARY KEY, count int); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn opposite? | |
"Returns true if x and y are opposite numbers, false otherwise." | |
[x y] | |
(and (zero? (+ x y)) | |
(every? (complement zero?) [x y]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns stuff.file-cache | |
(:require [clj-time.core :as t]) | |
(:require [clojure.java.io :as io]) | |
(:require [taoensso.nippy :as nippy]) | |
(:import [java.io DataInputStream DataOutputStream])) | |
;; This was just a quick experiment. I wanted to cache some lookup tables from a database. Rather than memoize each one individually, | |
;; though, I just wanted the whole chunk at once, the use case being a big table in Oracle that only changed periodically. I would use this | |
;; to cache on disk, and then also cache each one in memory, so even if the app restarted it wouldn't have to hit the database more than | |
;; once per 24 hour period. Worked ok in development, never quite made it to production. |
NewerOlder