Skip to content

Instantly share code, notes, and snippets.

Avatar

Jermaine Oppong graphicbeacon

View GitHub Profile
@graphicbeacon
graphicbeacon / chat-server.js
Last active Mar 24, 2021
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;
@graphicbeacon
graphicbeacon / main.dart
Created Feb 7, 2021
Convert map object to yaml in Dart
View main.dart
void main() {
final json = {
'name': 'package_name',
'version': '1.0.0',
'dependencies': {
'dep1': '^1.0.0',
'dep2': '^1.5.0',
'dep3': {
'git': 'https://github.com/graphicbeacon',
'home': {
@graphicbeacon
graphicbeacon / main.dart
Created Nov 27, 2020
Shelf_router server example with CORS enabled
View main.dart
import 'package:shelf_router/shelf_router.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
void start() async {
// Initiate server
const port = 8081;
final app = Router();
// CORS Settings
@graphicbeacon
graphicbeacon / server.dart
Created May 25, 2020
Shelf Dart Tutorial solution code
View server.dart
import 'dart:io';
import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as io;
// For Google Cloud Run, set _hostname to '0.0.0.0'.
const _hostname = 'localhost';
const _port = 8080;
void main(List<String> args) async {
@graphicbeacon
graphicbeacon / console.dart
Last active Sep 18, 2020
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 / index.html
Created Sep 7, 2020
Dispatching custom events example for Dart Web projects
View index.html
<input type="text" />
@graphicbeacon
graphicbeacon / async-gen.dart
Created Sep 3, 2020
Async Generators example
View async-gen.dart
import 'dart:async';
void main() {
// asynchronousNaturalsTo(10).listen(print);
final controller = asyncNaturalsTo(10);
controller.stream.listen((n) => print('YEss $n'),
onDone: () {
controller.close();
});
@graphicbeacon
graphicbeacon / main.dart
Last active Jun 26, 2020
Flutter Grid example with highlighted square
View main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false, home: Scaffold(body: BoxApp())));
}
class BoxApp extends StatefulWidget {
@override
BoxAppState createState() => BoxAppState();
@graphicbeacon
graphicbeacon / index.html
Created Jun 20, 2020
Centering card with Materialize example
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
@graphicbeacon
graphicbeacon / index.js
Last active Jun 4, 2020
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}`);
});
}