Skip to content

Instantly share code, notes, and snippets.

@andreparames
Last active April 9, 2016 23:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreparames/c19f87fbe48ee8819f9ef098c8eeb5ee to your computer and use it in GitHub Desktop.
Save andreparames/c19f87fbe48ee8819f9ef098c8eeb5ee to your computer and use it in GitHub Desktop.
Store strings on the very useful https://booleans.io/
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