Last active
April 9, 2016 23:18
-
-
Save andreparames/c19f87fbe48ee8819f9ef098c8eeb5ee to your computer and use it in GitHub Desktop.
Store strings on the very useful https://booleans.io/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def frombits(s): | |
bts = (int(s[i:i+8], 2) for i in range(0, len(s), 8)) | |
return str(bytearray(bts)) | |
def tobits(s): | |
return ''.join(bin(b)[2:].zfill(8) for b in bytearray(s)) | |
def storebit(bit): | |
val = 'true' if bit == '1' else 'false' | |
res = requests.post('https://api.booleans.io', data={'val': val}).json() | |
return res['id'] | |
def storestr(valstr): | |
bits = tobits(valstr) | |
ids = ','.join(map(storebit, bits)) | |
return ids | |
def getbit(bit_id): | |
res = requests.get('https://api.booleans.io/'+bit_id).json() | |
return '1' if res['val'] else '0' | |
def getstr(bits_ids): | |
print frombits(''.join(map(getbit, bits_ids.split(',')))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment