Skip to content

Instantly share code, notes, and snippets.

@michelle
michelle / JSONtoCSV.js
Last active October 13, 2015 00:58
Converts an array of JSON objects to a CSV string, with a header (assuming complete objects as from a database). Does not use Object.keys.
// Converts an array of JSON objects a CSV string.
function JSONtoCSV(jsonArray) {
var csv = '';
var header = '';
for (var i = 0; i < jsonArray.length; i += 1) {
var entry = '';
var obj = jsonArray[i];
for (var property in obj) {
function strip_ends(str, ends) {
var special = { '[' : ']',
'(' : ')',
'<' : '>',
'{' : '}' };
if (str.charAt(0) == ends &&
(str.charAt(str.length - 1) == ends ||
str.charAt(str.length - 1) == special[ends])) {
str = str.slice(1, str.length - 1);
@michelle
michelle / oddities.coffee
Created March 2, 2013 05:05
CoffeeScript oddities.
foo: (str) ->
str
'he' + foo('llo ') +'world'
# compiled:
({
@michelle
michelle / oddities2.coffee
Created March 2, 2013 05:12
More CoffeeScript oddities.
window.Michelle =
username: 'michellebu'
Hobbies:
daytime: 'biking'
evening: 'walks'
Friends: {}
class Michelle.Friends.Michelle
username: 'othermichelle'
morningCompatible: ->
# returns false. I'm expecting true, because undefined !== 0.
undefined is not 0
# Becomes...
void 0 === !0
@michelle
michelle / dispute_close.md
Last active December 23, 2015 09:19
Close dispute endpoint

Closing the dispute for a charge indicates that you do not have any evidence to submit and are essentially 'dismissing' the dispute, acknowledging it as lost.

The status of the dispute will change from under_review to lost. Closing a dispute is irreversible.

Request:

POST https://api.stripe.com/v1/charges/ch_XXX/dispute/close

curl https://api.stripe.com/v1/charges/ch_XXX/dispute/close \
 -u sk_XXX: \
# This doesn't even compile:
email = ' michelle@stripe.com '.replace(/ /g, '')
function saveFile(blob) {
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = 'Filename';
link.click();
};
@michelle
michelle / debittransfers.md
Last active September 29, 2015 04:53
Debit card transfers beta API
@michelle
michelle / rgbcmyk.js
Created April 28, 2014 06:46
RGB to CMYK (rough)
function rgbtocmyk(r, g, b) {
if (!r && !g && !b) {
return [0, 0, 0, 1]
}
var c = m = y = k = 0;
c = 1 - (r/255);
m = 1 - (g/255);