Skip to content

Instantly share code, notes, and snippets.

View adisbladis's full-sized avatar
:shipit:
^ This guy

adisbladis

:shipit:
^ This guy
View GitHub Profile
@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 / 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 / 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 / .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 / 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 / envrc.bash
Created May 7, 2018 05:20
Better python dev experience with direnv + nix + pipenv
use nix
layout_nix_pipenv() {
if [[ ! -f Pipfile ]]; then
log_error 'No Pipfile found. Use `pipenv` to create a Pipfile first.'
exit 2
fi
# Use ram as virtualenv storage
@adisbladis
adisbladis / findprocs.js
Created April 30, 2018 09:56
Finding child processes recursive in nodejs without external dependencies
#!/usr/bin/env node
const ChildProcess = require('child_process')
function findChildren(pid) {
const pgrep = ChildProcess.spawnSync('pgrep', ['-P', pid])
// Probably segfault..
// Happens on linux at least when there is no child
if(pgrep.status === null) {
In this moment of year NixPkgs already close to half of the umber of commits from previous year.
commits=12747/26374=0.483
velocity_last_year=26374/365=72.258 commits/day
velocity_this_time=12747/109=116.945 commits/day
velocity_times=velocity_this_year/velocity_last_year=1.618 times
accel=(velocity_this_time-velocity_last_year)/current_day=0.410 commits/day^2
velocity_end_of_year_extrapolated=velocity_last_year+365*accel=221.899 commits/day
# Teclast X98 Pro nixos install iso
# nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=iso.nix --no-out-link --show-trace
{ config, lib, pkgs, modulesPath, ... }:
{
imports = [
<nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-graphical-kde.nix>
];
# Hardware is only well-supported on very recent kernels
{
"name": "example-nix-project",
"version": "0.1.0",
"dependencies": {
"imagemagick-native": "^1.9.3"
},
"devDependencies": {}
}