Skip to content

Instantly share code, notes, and snippets.

View adnelson's full-sized avatar

Allen Nelson adnelson

View GitHub Profile
-- | Optionally set up a reverse HTTP proxy to a ghcjsi server.
--
-- The idea here is that you are working on an application which has a
-- GHCJS frontend and a GHC backend. The backend delivers the front-end
-- JavaScript to the browser, and also provides some kind of REST API
-- which the frontend uses. The API server is assumed to be the same
-- server which serves the frontend code, so that you don't need to set
-- up CORS.
--
-- When developing on your front-end code, you want to be able to rapidly
use std::{cmp};
type ParseResult<T> = Result<T, String>;
// Parse a string containing any number of balanced parentheses
// groups. For example these are valid:
//
// () => 1 group, max depth 1
// (())() => 2 groups, max depth 2
// (()()()(())()) => 1 group, max depth 3
@adnelson
adnelson / default.nix
Last active October 11, 2016 22:20
generate cabal file with nix
{
pkgs ? import <nixpkgs> {},
compiler ? "ghc7102"
}:
import ./project.nix {
inherit pkgs;
haskellPackages = pkgs.pkgs.haskell.packages."${compiler}";
}
import sys
import json
import requests
import re
def get_license(package_name):
"""Find the license of an NPM package, come hell or high water."""
url = "https://registry.npmjs.org/{}".format(package_name)
resp = requests.get(url).json()
def read_license(license_):

Building nix with a repo over SSH

It's pretty simple to use a repo to aid the building of nix packages. You need:

  • Two machines, let's call them Builder and Repo.
  • Each machine has nix installed. Let's say that Repo has a nix installation owned by the user nix-repo, and Builder has one owned by nix-builder.
  • nix-builder is able to SSH into Repo as nix-repo.

Once you have this, to build a package on Builder using Repo:

git clone https://github.com/adnelson/nixfromnpm
cd nixfromnpm
git checkout -b fetch_dev_dependencies
git pull origin fetch_dev_dependencies
nix-shell --pure
# In nix-shell:
cabal configure
cabal build
cabal run -- -p grunt -o results
{pkgs}:
{
# Fetches a tag from a github repo.
fetchRepo = {owner, repo, tag, sha256, requireToken ? false}:
let
url = "https://api.github.com/repos/${owner}/${repo}/tarball/${tag}";
in
pkgs.stdenv.mkDerivation {
inherit requireToken;
name = "${repo}-${tag}-snapshot.tar.gz";
nan = float('nan')
def convert_nans(obj):
if isinstance(obj, list):
return [convert_nans(x) for x in obj]
elif isinstance(obj, dict):
return {k: convert_nans(v) for k, v in obj.iter()}
elif obj is nan or obj is None:
return None
elif isinstance(obj, (str, float, int)):
return obj
source $stdenv/setup
echo test1 > $out
export FOO=BAR
echo "FOO from d1 is: $FOO"
@adnelson
adnelson / uses_pv.nix
Created September 8, 2015 17:39
This should output something with PV, but it doesn't.
with import <pkgs>;
stdenv.mkDerivation {
name = "test_of_stuff";
buildInputs = [python pv];
buildCommand = ''
echo "doing some random stuff..."
cat <<EOF | python
import random, string, os
letters = string.letters + ' '