This file contains hidden or 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
// this is our possible base64-encoded byte array — serialized — flash cookie | |
val flashCookie: Option[String] = request.headers | |
.get[Cookie] | |
.flatMap(_.values.find(_.name == "flash")) | |
.map(_.content) | |
// aquí tienes, voilà | |
flashCookie.map(_.decode).sequence.fold( | |
_ => BadRequest("failed to deserialize cookie, this is very bad"), | |
cookie => Ok(renderPage(cookie)) // or do whatever we want with our freshly baked Option[Map[String, String]] |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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')({ |
NewerOlder