Skip to content

Instantly share code, notes, and snippets.

@rmorlok
rmorlok / bytesToSize.js
Last active July 8, 2022 17:32 — forked from lanqy/bytesToSize.js
JavaScript To Convert Bytes To MB, KB, Etc
export function bytesToSize(bytes: number): string {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes === 0) return 'n/a';
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), sizes.length - 1);
if (i === 0) return `${bytes} ${sizes[i]}`;
return `${(bytes / (1024 ** i)).toFixed(1)} ${sizes[i]}`;
}
// Jest spec
describe('bytesToSize', () => {
@rmorlok
rmorlok / gist:7177882
Created October 27, 2013 04:07
Connecting to the Marketo SOAP API using Python and suds
Marketo has a [SOAP-based API](http://developers.marketo.com/documentation/soap) that allows you to interact with a lot of their data, and while there is a [Python library that supports it](https://github.com/segmentio/marketo-python), the library doesn't cover nearly all the methods supported in the API.
[suds](https://fedorahosted.org/suds/) is a Python SOAP library that will read WSDL and provide methods for calling into the service.
Here is an example of making a call to the getLead(...):
import hmac
import hashlib
import datetime
import time