Skip to content

Instantly share code, notes, and snippets.

View terribleplan's full-sized avatar

terribleplan terribleplan

View GitHub Profile
@terribleplan
terribleplan / prettyjsonandp.php
Last active December 25, 2015 17:59
This /should/ parse json(p) into a nice readable format
#!/usr/bin/env php
<?php
print("\n");
//read from stdin
$rawdata = fgets(STDIN);
//pull out the callback from a jsonp request
$temp = explode('(', $rawdata, 2);
//check if the response is jsonp or not
$callback = false;
@terribleplan
terribleplan / gist:10478411
Last active August 29, 2015 13:59
XDR workaround
<?
//Check that the request is a POST, sent by ie8/9 and DOESN'T have a content-type with the request
if ($_SERVER['REQUEST_METHOD'] == "POST" && (bool)preg_match('/msie (8|9)./i', $_SERVER['HTTP_USER_AGENT']) && !isset($_SERVER['CONTENT_TYPE'])) {
//And parse it into the $_POST superglobal
parse_str(file_get_contents('php://input'), $_POST);
}
?>
@terribleplan
terribleplan / gist:c9033e963b0019cf81f7
Created June 23, 2014 02:43
Grunt render-handlebars
//I'll probably turn this into an actual plugin at some point, but for now this is a simple way to compile handlebars templates statically
grunt.registerMultiTask('render-handlebars', function () {
var done = this.async();
var inputFile = this.data["inputFile"],
outputFile = this.data["outputFile"],
removeInput = !!(this.data["removeTemplate"] || false),
templateName = this.data["templateName"] || "index";
try {
@terribleplan
terribleplan / crc64.c
Created September 9, 2014 22:13
crc64-adler
/* crc64.c -- compute CRC-64
* Copyright (C) 2013 Mark Adler
* Version 1.4 16 Dec 2013 Mark Adler
*/
/*
This software is provided 'as-is', without any express or implied
warranty. In no event will the author be held liable for any damages
arising from the use of this software.
@terribleplan
terribleplan / gist:d398921d575b6c21ad11
Last active September 21, 2015 15:32
Figgy Fresh
#!/bin/bash
docker rm $(docker ps -a -q) && docker rmi $(docker images -q) && docker-compose build
@terribleplan
terribleplan / ABOUT.md
Last active August 29, 2015 14:22
/r/dailyprogrammer [217]

Here is a near-ideal, overly complex, ECMA6 solution to #217. This solution is less than ideal in 3 ways:

  1. There are 2 instances when the input is looped over entirely due to the separation of parsing logic and the logic that builds the initial index. This could be fixed, but shouldn't really since the concerns are wholly separate. Theoretically this also allows for pluggable inputs (who knows, maybe in one you don't need to loop to parse the input). I don't consider the parsing in the complexity for my solution.
  2. My solution does not follow l->r t->b insertion order, except at the very beginning. To fix this there could be a binary search for an insertion position within the index the node is moving to, creating some sort of meta order to the index contents. (I may fix this if I get bored). This is potentially weird because once pile size parity is reached the increase pattern is always going to be th
@terribleplan
terribleplan / stripe.js
Created August 1, 2016 17:40
CC/Paypal Fee Calculator
const FIXED_FEE = 30; //The number of cents you are charged per transaction
const PERCENTAGE_FEE = .029; //The percentage of the transaction your processor will take in addition to the fixed fee
/**
* This function calculates how much you need to charge your customer to recoup the cost of transaction fees
*
* @param targetPrice The target number of cents you want to earn
* @return The number of cents that you want to actually charge the customer, including fractions of a cent
*/
const calculateFee = (targetPrice) => (targetPrice + FIXED_FEE) / (1 - PERCENTAGE_FEE;
@terribleplan
terribleplan / osx-for-hackers.sh
Last active September 30, 2016 01:23 — forked from brandonb927/osx-for-hackers.sh
OSX for Hackers: Yosemite/El Capitan Edition. This script tries not to be *too* opinionated and any major changes to your system require a prompt. You've been warned. Also, please don't email me about this script, my poor inbox...
#!/bin/sh
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
//Constant helpers
const octave = (hz, octave) => Math.pow(2, octave) * hz;
//Constants
const NOTES = (() => {
const NOTES = {
C: 16.35,
"C#": 17.32,
D: 18.35,
"D#": 19.45,