Skip to content

Instantly share code, notes, and snippets.

View NthPortal's full-sized avatar

Marissa | April NthPortal

View GitHub Profile
@NthPortal
NthPortal / proof.md
Created March 7, 2024 01:37
Keyoxide proof

aspe:keyoxide.org:O6EPBCN4MXZQBGKHCP5QA3S53Q

@NthPortal
NthPortal / git-bt
Created January 4, 2022 19:50
git scripts
#!/bin/bash
[ $# != 1 ] && echo "expects exactly one arg" && exit 1
if branch_name=$(git symbolic-ref --short -q HEAD) ; then
new_end="$1"
branch_name="${branch_name%/*}/$new_end"
git checkout -b "$branch_name"
else
echo "not on any branch" && exit 1
@NthPortal
NthPortal / merge.sc
Last active September 2, 2021 02:21
Ammonite script to merge JMH outputs for comparison
#!/usr/bin/env amm
import $ivy.`com.lihaoyi::ammonite-ops:2.4.0`
import ammonite.ops._
import scala.collection.immutable.ArraySeq
import scala.util.control.NoStackTrace
object Abort extends Throwable("unable to process inputs") with NoStackTrace
@NthPortal
NthPortal / wconf.scala
Last active April 9, 2021 07:40
WConf sample API [WIP]
import scala.util.matching.Regex
object Impl {
sealed trait WConfAnyFilterable {
type Result = WConfFilterable with WConfCompletable
@annotation.inline
private[this] def quote(literal: String): String = Regex.quote(literal)
@NthPortal
NthPortal / whiches.bash
Last active October 9, 2019 03:24
Recursively resolving `which` utilities
_rwhich_1() {
readlink -e "$(command -v "$1")"
}
_rwhich_comp() {
mapfile -t COMPREPLY < <(compgen -c "${COMP_WORDS[COMP_CWORD]}")
return 0
}
# recursively resolve commands ("recursive `which`")
rwhich() {
private final class SingleUse[R](resource: => R) {
private val used = new AtomicBoolean(false)
def useWith[A](f: R => A)(implicit r: Using.Resource[R]): A =
if (used.getAndSet(true)) throw new IllegalStateException("resource has already been used")
else Using.resource(resource)(f)
}
final class Using[R, A] private[Using](resource: SingleUse[R], op: R => A) {
private def use0()(implicit r: Resource[R]): A = resource.useWith(op)
scala> class Foo {
| def p1[A, B](t: (A, B)): (Option[A], Option[B]) = {
| val (e1, e2) = t
| (Some(e1), Some(e2))
| }
| def p2[A, B](t: (A, B)): (Option[A], Option[B]) = {
| (Some(t._1), Some(t._2))
| }
| }
defined class Foo
case class User(id: User.Id, firstName: User.FirstName, lastName: User.LastName, email: User.Email)
object User {
opaque type Id = Long
object Id {
def apply(value: Long): Id = value
implicit class Ops(val self: Id) extends AnyVal {
def value: Long = self
}
@NthPortal
NthPortal / proxy.conf
Last active June 15, 2021 19:35
Example proxy config (for Sonatype Nexus) for Apache2
ProxyRequests Off
ProxyPreserveHost On
<VirtualHost *:80>
ServerName example.com
RedirectPermanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
@NthPortal
NthPortal / project-euler-59.md
Last active February 7, 2017 08:15
Project Euler problem 59

Regarding Project Euler problem 59

The problem contains one correct statement, which is that

For unbreakable encryption, the key is the same length as the plain text message, and the key is made up of random bytes.

Assuming that the bytes are actually random, there is said to be 'perfect secrecy' - the ciphertext reveals no information (other than length, obviously) about the plaintext. However, this approach has several problems, which will be covered below.

The problem goes on to say that, "[u]nfortunately, this method is impractical for most users," (yup) "so the modified method is to use a password as a key." (NO. BAD. VERY BAD. NONONONO)