Skip to content

Instantly share code, notes, and snippets.

@patbeagan1
patbeagan1 / MACD.kt
Last active June 29, 2021 03:10
Calculating EMA and MACD - could be used to parse stock data via csv.
fun main(args: Array<String>) = main2(args)
/**
* Simple Moving Average
*/
fun sma(p: Int): (Double) -> Double {
if (p < 1) throw IllegalArgumentException("Period must be a positive integer")
val list = mutableListOf<Double>()
return {
list.add(it)
fun <A, B, R> ((A, B)->R).curry(a: A): (B)->R = { b: B -> this(a, b) }
fun <A, R> ((A)->R).curry(t: A): ()->R = { this(t) }
//----------------------------------------------------------------------
fun f(i: Int, s: String) {
print(i)
println(s)
}
fun main() {
@patbeagan1
patbeagan1 / hashcode_kotlin.kt
Last active April 30, 2021 21:12
Hashcode generation
/**
* You can edit, run, and share this code.
* play.kotlinlang.org
*/
val test1 = "test1"
val test2 = "test2"
val test3 = "test3"
val test4 = null
/**
* You can edit, run, and share this code.
* play.kotlinlang.org
*/
// --- implementation of a union in kotlin
abstract class UnionBase<T>(s: Set<T?>) {
init {
val c = s.count { it != null }
@patbeagan1
patbeagan1 / plasmid.py
Last active April 30, 2021 21:19
Generates a set of chunks for a given file. The chunks are named in such a way that each chunk is able to find the hash of the next one. This means that the file is circular - given any chunk, the rest of the file will be attainable
#!python3
from hashlib import sha256
import sys
import os
import random
import difflib
prefix = "out/"
suffix = ".plasmid"
@patbeagan1
patbeagan1 / nodeCocktailRequest.js
Last active August 2, 2018 03:50
Grabbing a drink and image from thecocktaildb
/**
* https://www.thecocktaildb.com/api.php
* Note, this is for educational purposes only, request an api key for other uses.
*/
var https = require('https');
var express = require('express')
function slurpJson(optionInfo) {
return new Promise(function(resolve, reject) {
var reqGet = https.request(optionInfo,
#!/usr/bin/env python
"""
Matplotlib based photo ranking system using the Elo rating system.
Reference: http://en.wikipedia.org/wiki/Elo_rating_system
by Nick Hilton
modified by Patrick Beagan
This file is in the public domain.