Skip to content

Instantly share code, notes, and snippets.

@Yinnon-Haviv
Yinnon-Haviv / check_encoding.py
Last active May 29, 2016 21:25 — forked from anonymous/check_encoding.py
Checks that the encoding described in in the following link is resilient to rotations. https://github.com/polyvision/EasyRaceLapTimer/blob/master/docs/ir_pulses.md
def encode(n):
if (n > 63) | (n < 0):
raise Exception('Out of range {0}'.format(n))
ret = bin(n)[2:] # [2:] to chop off the "0b" part # creating initial bit encoding (for bits 3-8)
ret += reduce(lambda a,b: '1' if (a != b) else '0', ret) # adding checksum as bit 9
pad = ''.join(['0'] * (9 - len(ret)))
return pad + ret # padding with leading zeros by spec (for bits 1-2 and maybe more for lower ids)
def decode(arr):
if (len(arr) != 9):
@Yinnon-Haviv
Yinnon-Haviv / background.html
Created October 30, 2011 08:53 — forked from battlehorse/background.html
Attempt to draw Google Charts in Chrome extension popups, while loading the API in the background page
<!DOCTYPE html>
<html>
<head>
// Autoload the 'corechart' visualization library, as described in:
// http://code.google.com/apis/chart/interactive/docs/library_loading_enhancements.html#enhancedloading
//
// the 'autoload' parameter is URI encoded.
<script type="text/javascript" src="https://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22visualization%22%2C%22version%22%3A%221%22%2C%22packages%22%3A%5B%22corechart%22%5D%7D%5D%7D"></script>
</head>
<body>