Skip to content

Instantly share code, notes, and snippets.

Jermaine Oppong graphicbeacon

Block or report user

Report or block graphicbeacon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@graphicbeacon
graphicbeacon / main.dart
Created Nov 8, 2019
Code sample for 'Use Extension Methods in Dart' lesson on Egghead.io
View main.dart
import 'dart:async';
getDuration(int seconds) {
return Duration(seconds: seconds);
}
extension MyInt on int {
Duration get seconds => Duration(seconds: this);
DateTime monthsAgo() => DateTime.now().subtract(Duration(hours: 24 * 30 * this));
}
@graphicbeacon
graphicbeacon / main.dart
Last active Jul 8, 2019
Solution for "Understanding Reflection in Dart" video tutorial on YouTube
View main.dart
import 'dart:io';
import 'dart:mirrors';
main() async {
var server = await HttpServer.bind('localhost', 8085);
await for (HttpRequest req in server) {
// Create InstanceMirror type from which
// we retrieve metadata information
var ref = reflect(Endpoint(req));
@graphicbeacon
graphicbeacon / index.html
Created May 4, 2019
Sample code for Star Wars API search with delayed timeout.
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>API Search</title>
</head>
<body>
<input id="search" type="search" />
<div id="results"></div>
@graphicbeacon
graphicbeacon / index.html
Last active Oct 31, 2019
WebAssembly in Dart for web example
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="scaffolded-by" content="https://github.com/google/stagehand" />
<title>webassembly_example</title>
<link rel="stylesheet" href="styles.css" />
@graphicbeacon
graphicbeacon / index.js
Last active Apr 6, 2019
Snippet examples from wtfjs.com
View index.js
// https://wtfjs.com/wtfs/2015-04-08-array-sort
console.log([1, 2, 3, 15, 30, 7, 5, 45, 60].sort());
// https://wtfjs.com/wtfs/2015-03-23-adding-arrays
console.log([1, 2, 3] + [4, 5, 6]);
// https://wtfjs.com/wtfs/2014-02-22-wtf_document.all
console.log(document.all);
console.log(document.all[0]);
console.log(typeof document.all);
@graphicbeacon
graphicbeacon / main.dart
Last active Apr 6, 2019
Snippet comparing Dart conventions to JS
View main.dart
import 'dart:html';
import 'dart:math' as Math;
main() {
// 1 - Sorting arrays
var arr = [1, 2, 3, 15, 30, 7, 5, 45, 60];
arr.sort();
print(arr);
// 2 - Adding lists/arrays
@graphicbeacon
graphicbeacon / chart_display_component.css
Created Mar 17, 2019
Sample snippet demonstrating Chart.js in an AngularDart application
View chart_display_component.css
/* Master Styles */
h1 {
color: #369;
font-family: Arial, Helvetica, sans-serif;
font-size: 250%;
}
h2,
h3 {
color: #444;
font-family: Arial, Helvetica, sans-serif;
@graphicbeacon
graphicbeacon / index.html
Created Feb 28, 2019
Code snippet for "How to use Streams in Dart (Part 3)" article
View index.html
<h2>Subscribe to our Newsletter</h2>
<form novalidate>
<span id="result"></span>
<input type="email" name="email" id="email" placeholder="Enter your email" />
<span id="validation-message"></span>
<button>Subscribe</button>
</form>
@graphicbeacon
graphicbeacon / main.dart
Created Feb 28, 2019
Code snippet for "How to use Streams in Dart (Part 2)" series
View main.dart
import 'dart:async';
void main() {
var controller = StreamController<num>();
// Create StreamTransformer with transformer closure
var streamTransformer = StreamTransformer<num, num>.fromHandlers(
handleData: (num data, EventSink sink) {
sink.add(data * 2);
},
@graphicbeacon
graphicbeacon / main.dart
Created Feb 22, 2019
Solution for "How to use Streams in Dart (Part 1)" blog post series
View main.dart
import 'dart:async';
void main() {
var streamController = StreamController();
streamController.stream.listen(
(data) => print('Got eem! $data'),
onError: (err) => print('Got an error! $err'),
onDone: () => print('Mission complete!'),
cancelOnError: false,
You can’t perform that action at this time.