Skip to content

Instantly share code, notes, and snippets.

View kenreilly's full-sized avatar
💻
asdf

Ken Reilly kenreilly

💻
asdf
View GitHub Profile
@kenreilly
kenreilly / arraysquasher.ts
Last active June 1, 2016 17:21
TypeScript example class for array flattener
// Flatten nested arrays of numbers into a single-dimension array of numbers
// e.g. [0, 1, [2, 3, [4, 5]]] => [0, 1, 2, 3, 4, 5]
class ArraySquasher {
// Private method - Recursively flatten array
private static recurse(arr: Array<any>): Array<number> {
// Initialize result and process array
var result = [];
for (var i = 0, ii = arr.length; i != ii; ++i) {
@kenreilly
kenreilly / bt_demo.cpp
Last active June 1, 2019 18:27
Arduino C++ source file with bluetooth interface example
#include <SoftwareSerial.h>
#include <CapacitiveSensor.h>
SoftwareSerial BTserial(2, 3); // Digital pins 2 and 3 for bluetooth RX and TX
CapacitiveSensor cap_sensor = CapacitiveSensor(4,8); // Digital pins 4 and 8
// Holds the current available character on the BT serial stream
char bt_char = ' ';
// Initialization
@kenreilly
kenreilly / pubspec.yaml
Last active May 31, 2019 17:38
Arduino bluetooth demo - flutter project
name: arduino_bluetooth_mobile
description: Arduino bluetooth control demo app
version: 1.0.0+1
environment:
sdk: ">=2.2.0 <3.0.0"
dependencies:
flutter:
@kenreilly
kenreilly / main.dart
Last active June 1, 2019 07:23
Arduino bluetooth demo - Flutter app entry point
import 'package:flutter/material.dart';
import 'dart:async';
import 'bt-controller.dart';
void main() => runApp(ArduinoBT());
class ArduinoBT extends StatelessWidget {
@override
Widget build(BuildContext context) {
@kenreilly
kenreilly / bt-controller.dart
Created June 1, 2019 07:50
Arduino bluetooth demo - Flutter client-side bluetooth bridge
import 'package:flutter/services.dart';
import 'dart:async';
class BTController {
static const platform = const MethodChannel('flutter.native/helper');
static Function _onData = (String string) => { };
static init(Function onData) {
@kenreilly
kenreilly / MainActivity.java
Last active June 1, 2019 17:40
Arduino bluetooth demo - native Android code
package com.example.bt_demo;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@kenreilly
kenreilly / main.dart
Last active July 5, 2019 19:40
Main app entry file for Flutter custom scroll demo
import 'package:flutter/material.dart';
import 'demo-card.dart';
import 'items.dart';
import 'animated-bg.dart';
void main() => runApp(AnimationDemo());
class AnimationDemo extends StatelessWidget {
@override
@kenreilly
kenreilly / items.dart
Last active July 5, 2019 20:14
Item class and items definition in Flutter custom scroll project
import 'package:flutter/material.dart';
class Item {
String name;
String description;
MaterialColor color;
IconData icon;
Item(this.name, this.description, this.color, this.icon);
}
@kenreilly
kenreilly / demo-card.dart
Last active July 5, 2019 23:43
DemoCard class for rendering content in the Flutter scroll demo project
import 'package:flutter/material.dart';
import 'items.dart';
class DemoCard extends StatelessWidget {
DemoCard(this.item);
final Item item;
static final Shadow _shadow = Shadow(offset: Offset(2.0, 2.0), color: Colors.black26);
final TextStyle _style = TextStyle(color: Colors.white70, shadows: [_shadow]);
@kenreilly
kenreilly / animated-bg.dart
Last active July 6, 2019 00:58
AnimatedBackground class for the Flutter scrolling animation demo
import 'package:flutter/material.dart';
import 'dart:math' as math;
class AnimatedBackground extends StatefulWidget {
AnimatedBackground({Key key, this.controller}) : super(key: key);
final ScrollController controller;
@override