Skip to content

Instantly share code, notes, and snippets.

@adisbladis
adisbladis / pkijs-decode-pem-node.js
Created May 10, 2018 03:04
Minimal example of loading a PEM certificate using pkijs (in nodejs)
#!/usr/bin/env node
// Minimal example of loading a PEM certificate using pkijs (in node)
// babel-polyfill needs to be loaded for pkijs
// It uses webcrypto which needs browser shims
require('babel-polyfill')
const Pkijs = require('pkijs')
const Asn1js = require('asn1js')
const FS = require('fs')
@adisbladis
adisbladis / .direnvrc
Created June 6, 2018 09:44
direnvrc nix cache
use_nix() {
local shell_file=$(test -f shell.nix && echo shell.nix || echo default.nix)
local cache_key=$(nix-instantiate "$shell_file" 2> /dev/null | shasum -a 1 | cut -d ' ' -f 1)
# Use ram as virtualenv storage
local tmpdir
case $(uname -s) in
Linux*) tmpdir=$XDG_RUNTIME_DIR;;
Darwin*) tmpdir_SDK=$TMPDIR;;
*) tmpdir=/tmp
@adisbladis
adisbladis / para.py
Created June 8, 2018 02:29
Paramiko example with proper stderr/stdout behaviour
import contextlib
import functools
import paramiko
import select
import sys
import os
if __name__ == '__main__':
@adisbladis
adisbladis / defer.py
Last active May 13, 2019 16:46
Go-style defer from python
#!/usr/bin/env python
# The MIT License
# Copyright (c) 2018 Adam Hose (adisbladis)
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@adisbladis
adisbladis / shell.nix
Created June 12, 2018 08:44
Build android applications from nix-shell without FHS env
with (import <nixpkgs> {});
let
# Extract license from a Linux box
# It's in ~/Android/Sdk/licenses/android-sdk-license
sdkLicense = "d56f5187479451eabf01fb78af6dfcb131a6481e";
in pkgs.mkShell {
buildInputs = with pkgs; [
@adisbladis
adisbladis / .envrc
Created June 18, 2018 08:14
Minimal example nix project with direnv
use nix
@adisbladis
adisbladis / default.nix
Created September 22, 2018 15:50
An example of how to set up a custom emacs with packages from nixpkgs
with import <nixpkgs> {};
let
# An example of how to get xwidgets rather than gtk
# overridenEmacs = emacs26.override { withXwidgets = true; };
overridenEmacs = emacs26;
emacsPkgs = pkgs.emacsPackagesNgGen overridenEmacs;
emacsWithPackages = emacsPkgs.emacsWithPackages;
in emacsWithPackages(epkgs: with epkgs; [
with import <nixpkgs> { };
let
cutPoints = builtins.map (drv: drv.outPath) [
nodejs
python2
python3
coreutils
openssl.out
glibc
@adisbladis
adisbladis / shell.nix
Created October 28, 2018 21:52
Dirty nixpkgs python
with import <nixpkgs> {};
mkShell {
buildInputs = [
(python3.withPackages(ps: [
ps.nixpkgs
]))
];
}
@adisbladis
adisbladis / nix-path.py
Created April 10, 2019 19:52
Add derivations to PATH at runtime from python
#!/usr/bin/env python
#
# Add binaries to PATH at runtime
import subprocess
import nix
import os
def realise_path(store_path: str):