Skip to content

Instantly share code, notes, and snippets.

@deejaygraham
deejaygraham / dinosaur-detector.py
Created September 24, 2018 20:57
Microbit detects vibration in case there are T-Rexs or other dinosaurs nearby
from microbit import *
sleep_time = 200
warning_time = 5000
class Pinger:
def __init__(self):
self.direction = 1
self.x = 2
@deejaygraham
deejaygraham / still-alive.py
Created April 17, 2018 11:47
rough draft of still-alive for the microbit
from microbit import *
import speech
note_name_to_value = {
"c3" : "58",
"cs3" : "55",
"d3" : "52",
"ds3" : "49",
"e3" : "46",
"f3" : "44",
@deejaygraham
deejaygraham / langtons-ant.py
Last active January 9, 2018 17:35
Microbit implementation of Langton's Ant cellular automata
# https://en.wikipedia.org/wiki/Langton's_ant
from microbit import *
import random
def create_new_ant():
return [random.randint(0, 4), random.randint(0, 4)] # start at a random place on the board
def pick_direction(compass_points):
return random.choice(compass_points)
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="SetTFSVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<Name ParameterType="System.String" Required="true" />
<Value ParameterType="System.String" Required="true" />
</ParameterGroup>
<!-- https://github.com/Microsoft/vsts-tasks/blob/master/docs/authoring/commands.md -->
<Task>
@deejaygraham
deejaygraham / environment.targets
Created November 27, 2017 14:30
Create an environment variable in inline msbuild task
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<Name ParameterType="System.String" Required="true" />
<Value ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
@deejaygraham
deejaygraham / score_passwords.py
Last active November 22, 2017 07:13
score a password plus unit tests
import unittest
def count_special_chars(password):
return sum(letter in "<>!&*" for letter in password)
def contains_special_chars(password):
return count_special_chars(password) > 0
def count_digits(password):
return sum(letter.isdigit() for letter in password)
@deejaygraham
deejaygraham / hearts.cpp
Last active September 6, 2017 14:37
microbit heart animation example
#include "MicroBit.h"
MicroBit micro_bit;
const uint8_t empty_heart_bitmap[] {
0, 1, 0, 1, 0,
1, 0, 1, 0, 1,
1, 0, 0, 0, 1,
0, 1, 0, 1, 0,
0, 0, 1, 0, 0, };
@deejaygraham
deejaygraham / hello-world.cpp
Created August 31, 2017 15:21
hello world for microbit in c++ as generated by mbed compiler
#include "MicroBit.h"
MicroBit uBit;
int main()
{
// Initialise the micro:bit runtime.
uBit.init();
// Insert your code here!
@deejaygraham
deejaygraham / blink-microbit.cpp
Created August 31, 2017 15:08
blinking light example in c++
@deejaygraham
deejaygraham / RomanNumeralTest.cs
Created August 31, 2017 12:44
Example Roman Numerals Kata in c#
using NUnit.Framework;
[TestFixture]
public class RomanNumeralTest
{
[Test]
public void Zero_Returns_Empty_String()
{
Assert.AreEqual(string.Empty, RomanNumerals.ToRoman(0));