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 org.bouncycastle.crypto.generators.Argon2BytesGenerator) | |
(import org.bouncycastle.crypto.params.Argon2Parameters) | |
(import org.bouncycastle.crypto.params.Argon2Parameters$Builder) | |
(import org.bouncycastle.util.encoders.Hex) | |
(defn argon2-hash | |
[version iterations memory parallelism password salt output-length] | |
(let [builder (doto (Argon2Parameters$Builder. Argon2Parameters/ARGON2_i) | |
(.withVersion version) | |
(.withIterations iterations) |
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 key-generator.core | |
(:import (java.security KeyPairGenerator Key) | |
(java.util Base64))) | |
(def ^:private algorithm->key-type | |
{:RS256 "RSA" | |
:ES256 "EC"}) | |
(def ^:private algorithm->key-size | |
{:RS256 512 |
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 numpy as np | |
# Input image: 5x5 grayscale image | |
image = np.array([[10, 20, 30, 40, 50], | |
[60, 70, 80, 90, 100], | |
[110, 120, 130, 140, 150], | |
[160, 170, 180, 190, 200], | |
[210, 220, 230, 240, 250]]) | |
# Filter or Kernel: 3x3 |
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 cats._ | |
import cats.effect.{IO, IOApp, ExitCode} | |
import cats.syntax.all._ | |
object Main extends IOApp.Simple { | |
case class CustomState[A](value: A, remaining: Int) | |
implicit val customStateMonad: CommutativeMonad[CustomState] = new CommutativeMonad[CustomState] { | |
def pure[A](a: A): CustomState[A] = CustomState(a, 0) |
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 cats._ | |
import cats.effect.{IO, IOApp} | |
import cats.free.Free | |
sealed trait Calculation[A] | |
case class Add(value: Int) extends Calculation[Unit] | |
case class Subtract(value: Int) extends Calculation[Unit] | |
case class Multiply(value: Int) extends Calculation[Unit] | |
case class Divide(value: Int) extends Calculation[Unit] | |
case object Clear extends Calculation[Unit] |
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
// source: https://stackoverflow.com/questions/71608818/purely-functional-immutable-doubly-linked-list-in-javascript | |
var head = (function CircularList(previous, item, ...items) { | |
if (!items.length) return { item, next: () => head, previous }; | |
var rest = CircularList(() => current, ...items); // Recursion | |
var current = { ...rest, previous }; | |
return { ...rest, item, next: () => current }; | |
})(() => head, 1, 2, 3, 4); |
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
// is this possible with a purely-functional doubly-linked list in JavaScript? | |
function carousel(items) { | |
return { | |
_fastForward: function(n) { | |
if (n === 0) return carousel(items) | |
else return carousel([].concat(items.slice(1), items[0]))._fastForward(n - 1) | |
}, | |
_rewind: function (n) { | |
if (n === 0) return carousel(items); | |
else return carousel([].concat(items[items.length - 1], items.slice(0, items.length - 1)))._rewind(n - 1); |
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
'use strict'; | |
const _ = require('lodash'); | |
const Promise = require('bluebird'); | |
const data = require('./format.json') | |
const opts = require('./opts'); | |
const config = require('yaml').parse(require('fs').readFileSync('config.yaml', 'utf-8')); | |
const knex = require('knex')({ |
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
state | change_funding | change_tuition | net_hike | unaccountable_hike | |
---|---|---|---|---|---|
Colorado | -510 | 4425 | 4935 | 3915 | |
California | 250 | 3983 | 3733 | 3733 | |
Virginia | -1218 | 4587 | 5805 | 3369 | |
New Hampshire | -1342 | 4686 | 6028 | 3344 | |
Hawaii | 1532 | 4716 | 3184 | 3184 | |
Vermont | -755 | 3711 | 4466 | 2956 | |
Rhode Island | -881 | 3756 | 4637 | 2875 | |
Oregon | -693 | 3334 | 4027 | 2641 | |
Massachusetts | -1117 | 3524 | 4641 | 2407 |
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
// compress a string by counting its repeating characters | |
def compress(a: String): String = a.foldLeft("") { (acc, l) => | |
acc.lastOption match { | |
case Some(c) => | |
if (c == l) => { | |
acc.slice(acc.lastIndexOf(l) - 1, acc.lastIndexOf(l)).headOption match { | |
case Some(d) => c match { | |
case l => if (Character.isDigit(d)) { | |
s"${acc.slice(0, acc.lastIndexOf(l) - 1)}${Character.digit(d, 10) + 1}" :+ l // add 1 to repeating characters we have seen | |
} else { |
NewerOlder