Skip to content

Instantly share code, notes, and snippets.

View graphicbeacon's full-sized avatar
🏠
Working from home

Jermaine Oppong graphicbeacon

🏠
Working from home
View GitHub Profile
@graphicbeacon
graphicbeacon / index.html
Created May 4, 2019 10:12
Sample code for Star Wars API search with delayed timeout.
<!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 May 20, 2020 14:13
WebAssembly in Dart for web example
<!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 April 6, 2019 10:49
Snippet examples from wtfjs.com
// 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 April 6, 2019 10:50
Snippet comparing Dart conventions to JS
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 March 17, 2019 19:47
Sample snippet demonstrating Chart.js in an AngularDart application
/* 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 February 28, 2019 20:30
Code snippet for "How to use Streams in Dart (Part 3)" article
<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 February 28, 2019 12:08
Code snippet for "How to use Streams in Dart (Part 2)" series
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 February 22, 2019 16:07
Solution for "How to use Streams in Dart (Part 1)" blog post series
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,
@graphicbeacon
graphicbeacon / generics_example_1.dart
Created December 19, 2018 11:56
Sample code for "Ever been stumped by <E>..." Medium post
class CacheItem<A> { // Using the letter A
CacheItem(A this.itemToCache);
final itemToCache;
String get detail => '''
Cached item: $itemToCache
The item type is $A
''';
}
@graphicbeacon
graphicbeacon / hacker_news_scraper_test.dart
Created December 17, 2018 12:30
Code snipper for "Write your first Web Scraper in Dart" Medium post
void main() {
MockClient client = null;
test('calling initiate(client) returns a list of storylinks', () async {
// Arrange
client = MockClient((req) => Future(() => Response('''
<body>
<table><tbody><tr>
<td class="title">
<a class="storylink" href="https://dartlang.org">Get started with Dart</a>