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 / main.dart
Last active February 28, 2024 20:22
Flutter GestureDetector example - draggable square
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Padding(
// padding: const EdgeInsets.only(top: 20, left: 20, right: 20),
padding: const EdgeInsets.all(0),
child: Page()
)
@graphicbeacon
graphicbeacon / index.js
Last active February 20, 2024 22:45
How to handle the POST request body without using a framework
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 / main.dart
Created November 27, 2020 15:41
Shelf_router server example with CORS enabled
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 09:20
Shelf Dart Tutorial solution code
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 October 27, 2023 21:16
Final snippets for "How to use JavaScript libraries in your Dart applications" article
// web/console.dart
@JS('console')
library console;
import 'package:js/js.dart';
external void log(dynamic str);
@graphicbeacon
graphicbeacon / chat-server.js
Last active October 10, 2023 16:37
A simple TCP chat server with NodeJS, based on the example provided by creationix.
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
Last active April 3, 2023 09:29
"Dart File Upload Server Tutorial" solution for YouTube video tutorial
// bin/main.dart
import 'dart:io';
import 'package:mime/mime.dart';
main() async {
var server = await HttpServer.bind('localhost', 8085);
server.listen((request) async {
@graphicbeacon
graphicbeacon / main.dart
Last active September 20, 2022 12:48
Solution for "Understanding Reflection in Dart" video tutorial on YouTube
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 April 21, 2022 10:09
How to create an application using the Monzo Bank API (Full solution)
const express = require('express');
const request = require('request');
const app = express();
const oauthDetails = {
client_id: '[your client id]',
client_secret: '[your client secret]',
redirect_uri: 'http://localhost:3000/oauth/callback'
};
@graphicbeacon
graphicbeacon / main.dart
Last active September 17, 2021 01:46
Solution code on "Flutter for React developers" YouTube tutorial
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:math' as math;
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {