Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / rtlsdr-to-gqrx.c
Last active March 25, 2024 05:12
rtlsdr-to-gqrx SDR file format converter
#include <complex.h>
#include <stdio.h>
#include <stdlib.h>
// rtlsdr-to-gqrx Copyright 2014 Paul Brewer KI6CQ
// License: GNU GPL 3.0
//
// IQ file converter for Software Defined Radio Programs rtl_sdr, gqrx
// from rtl_sdr recording format -- interleaved unsigned char
// to gqrx/gnuradio .cfile playback format -- complex64
@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 / HamGridSquare.js
Last active December 12, 2020 17:18
find Maidenhead grid square from latitude and longitude
// HamGridSquare.js
// Copyright 2014 Paul Brewer KI6CQ
// License: MIT License http://opensource.org/licenses/MIT
//
// Javascript routines to convert from lat-lon to Maidenhead Grid Squares
// typically used in Ham Radio Satellite operations and VHF Contests
//
// Inspired in part by K6WRU Walter Underwood's python answer
// http://ham.stackexchange.com/a/244
// to this stack overflow question:
@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 / 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))