Skip to content

Instantly share code, notes, and snippets.

@imacg
imacg / fake-hostname-shell.nix
Last active October 7, 2020 15:35
Use of resolv_wrapper and nss_wrapper to fake DNS resolution without modifying host system
with import <nixpkgs> {};
let
hosts = { "trow.test" = "127.0.0.1"; };
resolv_hosts = writeTextFile { name = "resolv"; text = lib.concatStringsSep "," (lib.mapAttrsToList (h: a: "A ${h} ${a}") hosts); };
nss_hosts = writeTextFile { name = "nss"; text = lib.concatStringsSep "," (lib.mapAttrsToList (h: a: "${a} ${h}") hosts); };
in
mkShell {
shellHook = ''
export RESOLV_WRAPPER_HOSTS=${resolv_hosts}
export NSS_WRAPPER_HOSTS=${nss_hosts}

Keybase proof

I hereby claim:

  • I am imacg on github.
  • I am imacg (https://keybase.io/imacg) on keybase.
  • I have a public key ASB-guKysYLjYWlTY5bzYx438Uh0oYJd_YzNUC9ffKwRHAo

To claim this, I am signing this object:

@imacg
imacg / Deadlocker.hs
Last active May 27, 2018 15:31
GHC killing deadlocked thread
module Main where
import Control.Monad
import Control.Concurrent
import Control.Concurrent.MVar
import System.Mem
deadlocker :: IO ()
deadlocker = void $ forkFinally deadlock exit
where deadlock = newEmptyMVar >>= takeMVar
@imacg
imacg / Managed.scala
Created March 17, 2017 13:00
Simple Scala Resource managing monad
package ca.imacg.managed
import Managed._
object Managed {
def resource[A](create: () => A, destroy: A => Unit = (_: A) => ()): Managed[A] = Pure(create, destroy)
def pure[A](v: A): Managed[A] = resource(() => v)
}
sealed trait Managed[A] {