Skip to content

Instantly share code, notes, and snippets.

import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import norm
# Data points
data_points = [2, 4, 6, 4, 2]
# Fit a normal distribution to the data
mu, std = np.mean(data_points), np.std(data_points)
xmin, xmax = min(data_points), max(data_points)
@legkvla
legkvla / OrderStatusDetails.java
Last active June 20, 2023 15:00
Example of domain object optimized for use with Map.compute()
package gateway.ibkr;
import com.ib.client.OrderStatus;
public class OrderStatusDetails {
public final int orderId;
public final OrderStatus orderStatus;
public final Integer errorCode;
public final String msg;
@legkvla
legkvla / OrderBridge.java
Created June 16, 2023 09:09
One file ibkr java integration
package samples.sandbox;
import com.ib.client.*;
import com.ib.contracts.StkContract;
import com.ib.controller.ApiConnection;
import com.ib.controller.ApiController;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@legkvla
legkvla / go.clj
Last active December 29, 2022 13:24
openai com based
(ns example.go
(:require [chesster.core :as go]
[chesster.uci :as uci]
[chesster.pgn :as pgn]))
(ns example.go
(:require [chesster.core :as go]
[chesster.uci :as uci]
[chesster.pgn :as pgn]))
@legkvla
legkvla / chatserver.clj
Created December 29, 2022 12:03
Some chat apps boilerplates
(ns example.chat-app
(:require [aleph.tcp :as tcp]
[clojure.core.async :refer [<! >! chan close!]]
[sente.client :as client]))
(defn chat-app
"Starts a chat server at the specified host and port and connects a chat client to it.
host: the hostname or IP address of the chat server
port: the port number of the chat server"
[host port]
@legkvla
legkvla / parsing.clj
Created October 9, 2020 18:13
Clj(s) parsing int
(defn parseInt [^String s]
#?(:clj (Integer/parseInt s)
:cljs (js/parseInt s)))
(defn try-parse-int [s]
(some->> s str (re-matches #"[-+]?\d+") parseInt))
@legkvla
legkvla / map_reduce.py
Created February 27, 2019 17:06
Spark from python example
data = [
("S1", [1, 2, 3, 4, 5], 1, 7),
("S2", [4, 2, 6, 4, 4], 5, 200),
("S3", [4, 2, 6, 4, 4], 2, 200),
("S4", [4, 2, 6, 4, 4], 5, 600),
]
distData = sc.parallelize(data)
def checkCriteriaForTag(t):
asset_id, ts, multiplier, criteria = t
(ns ds-sandbox.core
(:use clojure.tools.trace)
)
(def data [[0 1] [1 0] [1 1] [0 0] [1 0] [0 1] [0 1] [0 1]])
(defn txor [tuple]
(-> (first tuple)
(+ (second tuple))
(= 1)
@legkvla
legkvla / FileUtils.java
Last active July 24, 2018 11:14
Java file utils. Loading file from resource
public class FileUtils {
public static String loadFile(String name) throws IOException {
final ClassLoader classLoader = getClass().getClassLoader();
final URL resource = classLoader.getResource(name);
if (resource == null) throw new NullPointerException("Resource " + name + " not found");
final File file = new File(resource.getFile());
try (FileInputStream fis = new FileInputStream(file)) {
final byte[] data = new byte[(int) file.length()];
fis.read(data);
return new String(data, "UTF-8");
@legkvla
legkvla / filling.cljs
Created June 4, 2018 07:24
Vertical div filling in html (cljs)
[:div.col-md-offset-3.col-md-5
[:p {:style {:height "calc(100vh - 100px)"}} "Going to fill it in"]
[:p "This is footer"]
]