Skip to content

Instantly share code, notes, and snippets.

View carbonphyber's full-sized avatar

David Wortham carbonphyber

View GitHub Profile
@carbonphyber
carbonphyber / coinbase-transactions-export-to-cost-basis.js
Created March 6, 2021 04:19
Convert Coinbase transactions export to a cost basis CSV almost compatible with TurboTax import. No Warranties.
/**
* Read a Coinbase transaction export and print out a Cost Basis CSV (useful for tax calculation
* of cryptocurrency profits). The output is near the format that TurboTax expects, but not perfect
* (likely headers/columns are slightly deformed). This script was written with an export file
* which had only a single Coinbase account / wallet, only two currencies, and all transactions were
* USD <-> BTC (no conversions/transactions of one crypto for another).
*
* This script is meant to be run as CLI from Node (probably compatible with 12+ because of use of fs.promises).
* Needs an npm repo around this source file, then run `npm install` / `yarn`.
* Example commands:
@carbonphyber
carbonphyber / read_county_xml.py
Created February 16, 2021 10:58
OpenElection XML->CSV converter for Santa Clara County, California
# File for reading a county XML and exporting to OpenElections CSV format
# The expected input file was
# - downloaded from: https://results.enr.clarityelections.com//CA/Santa_Clara/106043/272625/reports/detailxml.zip
# - linked from: https://results.enr.clarityelections.com/CA/Santa_Clara/106043/web.264614/#/summary
# Some Python code borrowed from:
# - https://www.geeksforgeeks.org/xml-parsing-python/
import csv
import json
import sys
alert('xss!');
@carbonphyber
carbonphyber / index.ios.js
Last active October 13, 2015 20:08
Modified Sample1 of React-Native-Webview-Bridge to reproduce exception thrown when unloaded via a React Native Navigator
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var WebViewBridgeNative = require('react-native-webview-bridge');
var {
@carbonphyber
carbonphyber / currency_to_float.js
Last active August 29, 2015 14:26
A function to parse a USD currency
"use strict";
var tests = {
"$0.41": 0.41,
"$12,345.67": 12345.67,
"$1m": 1000000,
"$32b": 32000000000,
"$0.2t": 200000000000
};
package main
import (
"net/http"
"./muxtester" // this is our router library. the "muxtester" dir should be in the same directory as this "main.go"
)
func main() {
http.HandleFunc("/", muxtester.HandleCatchall)
http.ListenAndServe("localhost:8080", nil)
@carbonphyber
carbonphyber / all_tests.php
Last active March 31, 2021 05:35
Unit tests for new BBCode Parser
<?php
/**
* Unit Tests for BBCode parser
* Uses OWASP cheatsheet to prevent XSS
* @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
*
* @author CarbonPhyber
*/
require dirname(dirname(dirname(__FILE__))) . '/private/common.php';
@carbonphyber
carbonphyber / bbcode.php
Last active March 31, 2021 05:36
BBCode parser replacement candidate for GaiaOnline
<?php
/**
* \DJW\BBCode
* A BBCode translation class
* Uses OWASP cheatsheet to prevent XSS
* @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
*
* @author CarbonPhyber
*/
namespace DJW;
@carbonphyber
carbonphyber / pre-commit
Created June 6, 2011 21:53
Git pre-commit hook for PHP+JS+CSS (Gaia version)
#!/usr/bin/env php
<?php
$output = array();
$errorOutput = array();
$return = 0;
$pathToErrorFile = 'temp/minify_errors.txt';
file_put_contents($pathToErrorFile, '');
exec('git rev-parse --verify HEAD 2> /dev/null', $output, $return);
$against = $return == 0 ? 'HEAD' : '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
@carbonphyber
carbonphyber / isPrime.rb
Created April 30, 2011 20:19
Ruby function to detect if a Fixednum is a prime number
# @author David Wortham <djwortham+programming@gmail.com>
# @date 2011-04-30
# @license MIT License: http://www.opensource.org/licenses/mit-license.php
# isPrime
# Function to detect if the input (asserted Fixednum) is a prime number
# uses an optional cache (asserted Hash) to speed up subsequent calls
def isPrime(number, cache)
return false if number < 1
return true if number == 1