Skip to content

Instantly share code, notes, and snippets.

@DrPaulBrewer
DrPaulBrewer / splitTemplates
Last active August 29, 2015 13:56
splitTemplates templates.html dirname -- refactoring tool to split out each <template name="xxx">contents</template> to its own file
#!/usr/bin/python
# Copyright 2014 Dr Paul Brewer -- Economic and Financial Technology Consulting LLC
# This script is made available under the terms of the MIT LICENSE
# Intended as a helper for refactoring template-enhanced html
# warning: overwrites existing files.
# Does not delete or modify original file templates.html
# Thanks to Stack Overflow users for these helpful hints:
# use of htmlparser to unescape entities
# http://stackoverflow.com/a/21894821/103081
# http://stackoverflow.com/a/663128/103081
#!/usr/bin/python
# Copyright 2014 Dr Paul Brewer
# This python file is licensed to the public under the terms of the MIT License
# -----
# When redirecting from name.com to www.name.com or from www.name.com to name.com
# it is easy to write the NGINX response incorrectly as
# return 301 http://name.com/$request_uri
# when it should be
# return 301 http://name.com$request_uri
# For more info see http://stackoverflow.com/a/7958540/103081
@DrPaulBrewer
DrPaulBrewer / csv_to_mongodb.py
Last active August 29, 2015 14:09
csv_to_mongodb.py
# Copyright 2014 Dr Paul Brewer
# Economic and Financial Technology Consulting LLC -- www.eaftc.com
#
# python script to import CSV to mongoDB via csv.DictReader, pymongo
#
# You may copy or reuse this script under the terms of the standard MIT License:
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@DrPaulBrewer
DrPaulBrewer / replace.c
Last active August 29, 2015 14:21 — forked from anonymous/replace.c
/* replace.c code snippet
* Copyright 2015 Dr Paul Brewer Economic and Financial Technology Consulting LLC
* License: MIT
* http://opensource.org/licenses/MIT
*/
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@DrPaulBrewer
DrPaulBrewer / code_count.py
Created June 26, 2015 04:09
count expressions in python code, not including comment lines
#!/usr/bin/env python
# Copyright 2015 Paul Brewer
# This file is open source software
# License: The MIT License
import re
import sys
if len(sys.argv)!=3:
print 'Usage: '
@DrPaulBrewer
DrPaulBrewer / env2json.py
Created January 8, 2016 15:25
environment vars to JSON
#!/usr/bin/env python
import json
import os
print json.dumps(dict(os.environ))
@DrPaulBrewer
DrPaulBrewer / unfubarcsv.py
Last active February 2, 2016 09:09
Attempts rational removal of inner commas and inner quotes from csv file fields
# Copyright 2015 Paul Brewer Economic and Financial Technology Consulting LLC
# Released under the MIT Public License
# LICENSE: http://opensource.org/licenses/MIT
# Purpose: rationally removes inner commas and inner quotes from csv file fields
# Useful for Google BigQuery as of 2015-03 does not support quoted commas in CSV fields
# python ./unf
@DrPaulBrewer
DrPaulBrewer / gcloud-discounted-VM-with-disk-and-startup-script.sh
Last active March 9, 2016 08:06
gcloud-discounted-VM-with-disk-and-startup-script.sh
!/bin/bash
# Do NOT use this as-is
# you probably need to change a few lines (disk, subnet, script)
# The google compute engine web UI may provide you
# with an equivalent command line for a specific configuration built in the web UI
gcloud compute instances create "my-spark-notebook" \
--description "docker spark jupyter-notebook analysis platform" \
--zone "us-east1-c" \
--machine-type "n1-highcpu-32" \
--subnet "default-754f8fec2c9e9fe2" \
@DrPaulBrewer
DrPaulBrewer / stringifyToStream.js
Last active April 13, 2016 20:10
node,js asyncronous JSON.stringify stringifyToStream ----- Intended for saving JSON of a large object out to a file without using up memory or choking out other activity on the node ----- Caveat: do not modify the object as it is being written out
// Copyright 2013 Paul Brewer
// License: You may copy this file under the same terms as the MIT License
// located at http://opensource.org/licenses/MIT
// This file is provided AS IS WITH NO WARRANTY OF ANY KIND. All use is at your own risk.
//
// Status: July 13, 2013, Paul Brewer: First version. Simple test case passed. It needs to be more extensively tested.
// It lacks escaping for odd characters in strings, though a workaround is possible as described in the comments.
//
// July 14, 2013, Paul Brewer: JSON.stringify() used to stringify basic
// types such as string, number, null/undefined. This provides string
@DrPaulBrewer
DrPaulBrewer / zcash-miner-Dockerfile
Last active July 8, 2017 04:29
Dockerfile and run script to mine zcash with EWBF and Dwarfpool. Pre-requisite: download and unzip EWBF into ./zec/miner
# Working as of Dec 2016
FROM ubuntu:14.04
MAINTAINER drpaulbrewer@eaftc.com
RUN apt-get update && apt-get --yes upgrade && apt-get --yes install iputils-ping less emacs24-nox git curl wget build-essential screen python-pip software-properties-common
RUN echo deb http://us.archive.ubuntu.com/ubuntu/ xenial multiverse >>/etc/apt/sources.list && \
echo deb-src http://us.archive.ubuntu.com/ubuntu/ xenial multiverse >>/etc/apt/sources.list && \
echo deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates multiverse >>/etc/apt/sources.list && \
echo deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates multiverse >>/etc/apt/sources.list
RUN apt-get update && apt-get --yes --no-install-recommends install nvidia-cuda-dev nvidia-cuda-doc
RUN apt-get --no-install-recommends --yes install nvidia-367; exit 0