Skip to content

Instantly share code, notes, and snippets.

View montyr75's full-sized avatar

Monty Rasmussen montyr75

View GitHub Profile
@montyr75
montyr75 / grid.dart
Created April 6, 2020 18:59
Calculate grid position in 1D model
// If you have an array or string containing cell data for a "grid",
// you can calculate x and y coords using division and the row length.
// define the row length in the virtual grid
const rowLength = 8;
// create a 1D model representing the "grid"
final onScreenKeyboard = 'abcde123fghij456klmno789pqrst.@0uvwxyz_/^ ';
// this function will return the grid position of the given content (content must be unique)
@montyr75
montyr75 / meeting.dart
Last active August 14, 2020 19:48
Sort by multiple factors.
String meeting(String s) {
final people = s.split(';').map((String name) => Person.fromData(name)).toList();
people.sort();
return people.join();
}
class Person implements Comparable<Person> {
final firstName;
final lastName;
@montyr75
montyr75 / main.dart
Created September 12, 2019 19:16
static object builder
void main() async {
final cache = await Cache.createCache();
}
class Cache {
static Db myDb;
static createCache() async {
if (myDb == null) {
myDb = await Future.delayed(Duration(seconds: 1));;
@montyr75
montyr75 / obj-search.ts
Last active May 31, 2018 23:13
Searching for all instances of "key" in an object with TypeScript.
class Utils {
static search(name: String, obj: any, results: Array<any>) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
const value = obj[key];
if (key == name) {
results.push(value);
}
else if (typeof value === 'object') {
@montyr75
montyr75 / hangman_assets.dart
Created April 16, 2018 16:02
Words and images for a Dart Hangman game.
const List<String> wordList = const ["PLENTY","ACHIEVE","CLASS","STARE","AFFECT","THICK","CARRIER","BILL","SAY","ARGUE","OFTEN","GROW","VOTING","SHUT","PUSH","FANTASY","PLAN","LAST","ATTACK","COIN","ONE","STEM","SCAN","ENHANCE","PILL","OPPOSED","FLAG","RACE","SPEED","BIAS","HERSELF","DOUGH","RELEASE","SUBJECT","BRICK","SURVIVE","LEADING","STAKE","NERVE","INTENSE","SUSPECT","WHEN","LIE","PLUNGE","HOLD","TONGUE","ROLLING","STAY","RESPECT","SAFELY"];
const List<String> imageList = const [
"https://i.imgur.com/kReMv94.png",
"https://i.imgur.com/UFP8RM4.png",
"https://i.imgur.com/9McnEXg.png",
"https://i.imgur.com/vNAW0pa.png",
"https://i.imgur.com/8UFWc9q.png",
"https://i.imgur.com/rHCgIvU.png",
"https://i.imgur.com/CtvIEMS.png",
@montyr75
montyr75 / big_o.dart
Created January 4, 2018 17:54
Big O notation, with Dart examples.
// O(1)
// constant
bool isFirstElementNull(List<String> elements) {
return elements.first == null;
}
// O(n)
// growth is linear in direct proportion to the size of the data set
bool containsValue(List<String> elements, String value) {
for (String element in elements) {
@montyr75
montyr75 / empty.dart
Last active September 27, 2016 15:57
An empty place to start.
We couldn’t find that file to show.
@montyr75
montyr75 / safe_inner_html.dart
Last active May 31, 2018 18:46
Angular 2 directive to safely inject HTML.
import 'dart:html' show Element, NodeTreeSanitizer;
import 'package:angular2/core.dart'
show Directive, Input, OnChanges, SimpleChange;
@Directive(selector: '[safeInnerHtml]')
class SafeInnerHtml implements OnChanges {
Element _el;
SafeInnerHtml(this._el);
@montyr75
montyr75 / wait_for_config.dart
Last active June 9, 2016 16:13
Angular service that acquires information asynchronously, but has dependents waiting for that info. (Pattern)
class ConfigService {
var _config;
Completer _waitForConfig = new Completer();
ConfigService() {
doHttpCall().then((result) {
_config = result;
_waitForConfig.complete(_config);
}
@montyr75
montyr75 / download_string.dart
Last active June 17, 2016 17:05
Automatically send a string in the form of a downloaded file to a browser client using new HTML5 anchor attributes.
void downloadFileToClient(String filename, String text) {
AnchorElement tempLink = document.createElement('a');
tempLink
..attributes['href'] = 'data:text/plain;charset=utf-8,${Uri.encodeComponent(text)}'
..attributes['download'] = filename
..click();
}