Skip to content

Instantly share code, notes, and snippets.

View NthPortal's full-sized avatar

Marissa | April NthPortal

View GitHub Profile
@NthPortal
NthPortal / hats.py
Created March 11, 2016 08:35
Prisoners in Hats
import random
import itertools
def relative_complement(superset, subset):
return [elem for elem in superset if elem not in subset]
def simulate():
n = 1000
@NthPortal
NthPortal / proof.md
Created September 16, 2016 19:06
Keybase proof

Keybase proof

I hereby claim:

  • I am nthportal on github.
  • I am nthportal (https://keybase.io/nthportal) on keybase.
  • I have a public key whose fingerprint is BA6F F781 FFAD 1AE8 3DDF 735D C3FE 56CA 394F B05D

To claim this, I am signing this object:

@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)

@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
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
}
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
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)
@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() {
@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 / 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