Skip to content

Instantly share code, notes, and snippets.

View longfellowone's full-sized avatar

Matt Wright longfellowone

  • Vancouver, Canada
View GitHub Profile
@longfellowone
longfellowone / .js
Last active April 29, 2019 05:05
replaceAtReducer
function replaceAt(indexArray, string) {
const func = (string, i) => {
string[i] = (
<span className="font-bold text-red" key={i}>
{string[i]}
</span>
);
return string;
};
@longfellowone
longfellowone / .js
Last active April 29, 2019 05:13
Group by date
import React from "react";
import ReactDOM from "react-dom";
function App() {
const orders = [
{ date: 1556396396, project: "Project 1" },
{ date: 1556396416, project: "Project 2" },
{ date: 1552186577, project: "Project 3" },
{ date: 1554064562, project: "Project 4" },
{ date: 1556396473, project: "Project 5" },
@longfellowone
longfellowone / group-objects-by-property.md
Created April 29, 2019 03:19 — forked from JamieMason/group-objects-by-property.md
Group Array of JavaScript Objects by Key or Property Value

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
@longfellowone
longfellowone / 0_main.dart
Created April 24, 2019 17:16 — forked from boformer/0_main.dart
Flutter Service Architecture
import 'package:architecture_playground/home_page.dart';
import 'package:architecture_playground/services.dart';
import 'package:flutter/material.dart';
void main() async {
// perform long-running tasks before "runApp" to display the native splash screen
final services = await Services.initialize();
runApp(ServicesProvider(
services: services,
WDIR := /go/src/github.com/Pisush/tensorflow-and-go
DIR := ${CURDIR}:${WDIR}
DOCKER_IMAGE := dahernan/tensorflow-and-go
login:
docker run -i -v $(DIR) -w $(WDIR) --entrypoint=/bin/bash -t $(DOCKER_IMAGE)
dockerbuild:
docker build -f Dockerfile -t $(DOCKER_IMAGE) .
@longfellowone
longfellowone / .js
Last active February 28, 2020 21:53
gRPC-web ReactJS Hook
import React, { useEffect, useState, useRef, useReducer } from "react";
import { Link } from "react-router-dom";
export const Test = () => {
const [input, setInput] = useState("world");
const [data, refetch] = useGrpcRequest(myRequest, { name: "init" }, []);
// useEffect(() => console.clear(), []);
const handleOnClick = () => {
const (
stmtCreateUser = iota
stmtGetUser
stmtUpdateUser
)
var stmtPairs = []struct {
id int
stmt string
}{
// https://play.golang.org/p/5p28UL4thc_r
package main
import "fmt"
func main() {
s := InitializeServices() // Inject *sql.DB here
s.CreateAuthor(0, "name", "[email protected]") // Example http/grpc/graphql endpoints
export const useGrpcRequest = (func, setState) => {
const [params, setParams] = useState(null);
useEffect(() => {
let unmounted = false;
(async () => {
try {
if (!params) return;
const result = await func(params);
if (unmounted) return;
@longfellowone
longfellowone / ObserverDesignPattern.go
Created December 21, 2018 00:36 — forked from sayden/ObserverDesignPattern.go
Observer Pattern in Golang
package main
import "fmt"
//Listener is a
type Listener struct {
ID int
}
//ListenerInterface is an