Skip to content

Instantly share code, notes, and snippets.

View roboncode's full-sized avatar

Rob Taylor roboncode

View GitHub Profile
@roboncode
roboncode / webworker.js
Created December 30, 2022 17:38
Dynamic web worker
function createWorker(fn) {
// Create a Blob object that contains the code for the worker
// create wrapper function that calls the function passed to createWorker
// and then posts the result back to the main thread
const fnStr = fn.toString()
// wrap the function in a function that calls the function and posts the result
const wrapper = `async function(evt) {
const fn = ${fnStr}
@roboncode
roboncode / forEach.ts
Last active December 15, 2022 20:13
forEach.ts
type Iteraterable = {
next: () => { value?: any; key?: any; hasNext: boolean; done: () => void }
hasNext: () => boolean
}
const clone = (obj: any) => JSON.parse(JSON.stringify(obj))
const makeArrayIterator = (array: any[]): Iteraterable => {
array = clone(array)
let nextIndex = 0
@roboncode
roboncode / vue-chat-layout.html
Created June 30, 2021 18:42
Vue Chat Layout
<!DOCTYPE html>
<html lang="en">
<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" />
<title>Test</title>
<script src="https://unpkg.com/vue@next"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" />
</head>
@roboncode
roboncode / client.js
Last active May 1, 2024 14:31
Lightweight Axios replacement using Fetch
class Client {
static _instance
static defaultHeaders = { 'Content-Type': 'application/json' }
config = {
baseUrl: '',
urlHandler: (baseUrl, uri, query) => {
var url = `${baseUrl}${uri}`
if (uri.includes('://')) {
url = uri
@roboncode
roboncode / firestore.go
Last active April 26, 2024 09:51
Firestore - GoLang Transform Struct To Map
package transform
import (
"reflect"
"strings"
"time"
)
const (
tagName = "firestore"
@roboncode
roboncode / cloudSettings
Last active March 8, 2021 22:25
vscode sync extensions
{"lastUpload":"2021-03-08T22:25:42.938Z","extensionVersion":"v3.4.3"}
@roboncode
roboncode / main.dart
Last active April 14, 2020 11:44
Dart - Bloc Auth Example
import 'dart:async';
class ServiceRespository {
Future<String> authenticate(String username, String password) {
if(username == "admin" && password == "admin") {
return Future<String>.delayed(Duration(milliseconds: 2000))
.then((_) => "abc");
}
return Future<String>.delayed(Duration(milliseconds: 1000))
.then((_) => throw "invalid credentials");
@roboncode
roboncode / main.dart
Created April 13, 2020 13:38
Dart - BlocCounter Example
import 'dart:async';
enum CounterEvent {increment, decrement}
class CounterBloc {
int _counter = 0;
get state => _counter;
final _counterStateController = StreamController<int>();
@roboncode
roboncode / orango.go
Created April 11, 2019 15:11
Orango Go Concept
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/arangodb/go-driver"
"github.com/arangodb/go-driver/http"
"log"
"strings"
@roboncode
roboncode / orango-complex-queries.js
Last active April 11, 2019 17:58
Orango - Complex Queries Concepts
const { append } = orango.funcs
orango.builder()
.add('numbers', append([1, 2, 3], [3, 4, 5], true))
.add('email', 'john@gmail.com')
.add('users', User.find().where({email: "@email"})
.return({
})