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 / console.dart
Last active Nov 9, 2019
Final snippets for "How to use JavaScript libraries in your Dart applications" article
View console.dart
// web/console.dart
@JS('console')
library console;
import 'package:js/js.dart';
external void log(dynamic str);
@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 / 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 / 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.js
Last active Jun 17, 2019
How to handle the POST request body without using a framework
View index.js
const http = require('http');
const { parse } = require('querystring');
const server = http.createServer((req, res) => {
if (req.method === 'POST') {
collectRequestData(req, result => {
console.log(result);
res.end(`Parsed data belonging to ${result.fname}`);
});
}
@graphicbeacon
graphicbeacon / index.html
Last active May 13, 2019
Create a countdown timer in Dart
View index.html
<div>
<strong id="days"></strong>
<strong id="hours"></strong>
<strong id="minutes"></strong>
<strong id="seconds"></strong>
</div>
@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 / 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 / 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 / chat-server.js
Last active Mar 17, 2019
A simple TCP chat server with NodeJS, based on the example provided by creationix.
View chat-server.js
var net = require('net');
var sockets = [];
var port = 8000;
var guestId = 0;
var server = net.createServer(function(socket) {
// Increment
guestId++;
socket.nickname = "Guest" + guestId;
You can’t perform that action at this time.