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
#include <iostream> | |
#include <math.h> | |
const int HEART_SIZE = 20; | |
const int HALF_SIZE = HEART_SIZE / 2; | |
bool is_in_love(int x, int y); | |
int main(void) | |
{ |
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
# this method will return a pair of prime numbers which, when multiplied, equal the argument | |
def find_factors(num): | |
if num == 0: return (0,0) | |
# if not prime ... | |
for i in [2]+range(3, num/2+2, 2): | |
if num % i == 0: | |
return (i, num/i) | |
return (1, num) | |
def sieve_primes(SIEVE_SIZE): |
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
while not stop: | |
start = time.time() | |
plt.cla() # clear axis, get rid of old lines | |
print "Clear:\t", time.time()-start | |
start = time.time() | |
slicedata = data[:,-1*DATA_SIZE:] # use only the last n data points, where n is DATA_SIZE | |
print "Slice:\t", time.time()-start | |
start = time.time() | |
# plot a spline (smooth line) for each axis | |
for i in range(3): plt.plot(smooth_x, spline(np.arange(len(slicedata[i])), slicedata[i], smooth_x)) |
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
from PiStorms import PiStorms | |
import time | |
psm = PiStorms() | |
s = psm.screen | |
for _ in range(4): | |
for align in ["left", "center", "right"]: | |
s.clearScreen(display = False) | |
s.drawAutoText(align+", rotation: "+str(s.currentRotation), 10 if align!="center" else 9999, 20, align=align) |
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
LegoDevices.py:298: Compound LegoDevices::EV3ColorSensor | |
swarmclient.py:60: Compound swarmclient::SwarmClient | |
LegoDevices.py:347: Compound LegoDevices::EV3InfraredSensor | |
LegoDevices.py:311: Compound LegoDevices::EV3GyroSensor | |
LegoDevices.py:257: Compound LegoDevices::NXTLightSensor | |
PiStormsCom.py:33: Compound PiStormsCom::PSSensor | |
MS_ILI9341.py:31: Compound MS_ILI9341::ILI9341 | |
LegoDevices.py:199: Compound LegoDevices::EV3TouchSensor | |
scratch.py:9: Compound scratch::Scratch | |
LegoDevices.py:330: Compound LegoDevices::EV3UltrasonicSensor |
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
from PiStorms import PiStorms | |
from TouchScreenInput import TouchScreenInput | |
from functools import partial | |
psm = PiStorms() | |
textbox = TouchScreenInput(psm.screen) | |
textbox.bind_led_on_func(partial(psm.led, 1, 255, 0, 0)) | |
textbox.bind_led_off_func(partial(psm.led, 1, *[0]*3)) | |
result = textbox.getInput() | |
psm.screen.showMessage(['Your answer', result['response']]) |
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
with open("/usr/share/dict/words") as f: | |
dict = [word.rstrip('\n') for word in f] | |
import random | |
print random.choice(dict) | |
# or, a one-liner | |
random.choice(open("/usr/share/dict/words").readlines())[:-1] | |
# in an isolated environment: |
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
+-1 | |
--1 | |
-----1 | |
+++++1 | |
++++++++--------1 | |
1*-+-+-+-+-+-+-+-+-+-+-+-1*-+1/+-+-+-+-+-1 |
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
b=`grep homefolder /usr/local/mindsensors/conf/msdev.cfg | cut -d"=" -f2 | cut -c 2-` | |
for f in 'MSDriver.py' 'MSBrowser.py' 'psm_shutdown' 'swarmserver' 'pistorms-diag.sh'; do sudo ln -f $b/sys/$f /usr/local/bin/$f; done | |
chmod +x $b/sys/swarmserver $b/sys/pistorms-diag.sh $b/programs/addresschange | |
for f in 'rmap.py' 'rmapcfg.py' 'scratch.py' 'PiStorms.py' 'PiStormsCom.py' 'TouchScreenInput.py' 'mindsensorsUI.py' 'MS_ILI9341.py' 'mindsensors.py' 'MsDevices.py' 'LegoDevices.py' 'swarmclient.py'; do sudo ln -f $b/sys/$f /usr/local/lib/python2.7/dist-packages/$f; done | |
sudo rm -rf /var/www | |
sudo ln -s $b/www /var/www | |
sudo ln -f $b/sys/msdev.cfg /usr/local/mindsensors/conf/msdev.cfg | |
# skipping images, art, scratch, changing ownerships... programs are still only in /home/pi/PiStorms | |
for f in 'MSDriver.sh' 'MSBrowser.sh' 'MSWeb.sh' 'SwarmServer.sh'; do sudo ln -f $b/setup/$f /etc/init.d/$f; done | |
for f in 'MSDriver.sh' 'MSBrowser.sh' 'MSWeb.sh' 'SwarmServer.sh'; do chmod +x $b/setup/$f; done |
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
from PiStorms import PiStorms | |
from TouchScreenInput import TouchScreenInput | |
from functools import partial | |
psm = PiStorms() | |
textbox = TouchScreenInput(psm.screen) | |
textbox.bind_led_on_func(partial(psm.led, 1, 255, 0, 0)) | |
textbox.bind_led_off_func(partial(psm.led, 1, *[0]*3)) | |
result = textbox.getInput() | |
psm.screen.showMessage(['Your answer', result['response']]) |