Skip to content

Instantly share code, notes, and snippets.

View lukaszx0's full-sized avatar

Lukasz Strzalkowski lukaszx0

  • Column
View GitHub Profile
@lukaszx0
lukaszx0 / Makefile
Created February 24, 2021 14:02
tools.go makefile
TOOLS := $(shell cat tools.go | grep _ | awk -F'"' '{print $$2}')
.SECONDARY: bin/.tools
bin/.tools: bin/ tools.go
go install $(TOOLS)
@touch $@
.PHONY: tools
tools: bin/.tools
const maxStackLength = 10
const skipCallers = 5
func stacktrace() string {
stackBuf := make([]uintptr, maxStackLength)
length := runtime.Callers(skipCallers, stackBuf[:])
stack := stackBuf[:length]
trace := ""
frames := runtime.CallersFrames(stack)
@lukaszx0
lukaszx0 / Makefile
Last active February 7, 2021 15:39
proto + grpc + swagger makefile (golang)
PKG_PATH := pkg
PROTOC := protoc
PROTOS := $(sort $(shell find ./$(PKG_PATH) -type f -name '*.proto' -print))
GO_PROTO_SOURCES := $(PROTOS:%.proto=%.pb.go)
GW_PROTO_SOURCES := $(PROTOS:%.proto=%.pb.gw.go)
SWAGGER_SOURCES := $(PROTOS:%.proto=%.swagger.json)
PROTO_IMPORT_PATH := \
-I $(PKG_PATH) \
@lukaszx0
lukaszx0 / reset.css
Created December 4, 2019 06:31
Simple reset
*,
*::before,
*::after{box-sizing:border-box;}
a{text-decoration:none; color:inherit; cursor:pointer;}
button{background-color:transparent; color:inherit; border-width:0; padding:0; cursor:pointer;}
figure{margin:0;}
input::-moz-focus-inner {border:0; padding:0; margin:0;}
ul, li, ol, dd{margin:0; padding:0; list-style:none;}
h1, h2, h3, h4, h5, h6{margin:0; font-size:inherit; font-weight:inherit;}
p{margin:0;}
import Foundation
import Combine
protocol ActionType {}
protocol StateType {}
struct Command<Action: ActionType> {
let execute: (SendFunction<Action>) -> Void
}
@lukaszx0
lukaszx0 / optional.ts
Last active May 29, 2018 18:22
type script optionals
export declare type Optional<T> = T | undefined;
export function getOptional<T>(optional: Optional<T>, defaultVal?: T): T {
if (optional) {
return <T>optional;
}
if (defaultVal != undefined) {
return defaultVal;
}
throw new Error("the value of optional is undefined");
@lukaszx0
lukaszx0 / grpc-middleware.ts
Created May 21, 2018 05:32
gRPC Middleware for Redux
import { grpc } from "grpc-web-client";
// Use evn var if specified (used in development) or relative path to api otherwise.
export const API_URL = process.env.REACT_APP_API_URL ? process.env.REACT_APP_API_URL : "/api";
const GRPC_WEB_REQUEST = "GRPC_WEB_REQUEST";
// Descriptor of a grpc-web payload
// life-cycle methods mirror grpc-web but allow for an action to be dispatched when triggered
export type GrpcActionPayload<ReqT extends grpc.ProtobufMessage, RespT extends grpc.ProtobufMessage> = {
// The method descriptor to use for a gRPC request, equivalent to grpc.invoke(methodDescriptor, ...)
@lukaszx0
lukaszx0 / types.ts
Created May 21, 2018 05:29
Typescript Redux Action helpers
export interface Action<T extends string> {
type: T;
}
export interface ActionWithPayload<T extends string, P> extends Action<T> {
payload: P;
}
export function createAction<T extends string>(type: T): Action<T>;
export function createAction<T extends string, P>(type: T, payload: P): ActionWithPayload<T, P>;
@lukaszx0
lukaszx0 / proto-over-http.ts
Created May 13, 2018 20:16
proto-over-http
function doFetch<ReqT extends { serializeBinary(): Uint8Array }, RespT>
(method: string, req: ReqT, respClass: { new(): RespT, deserializeBinary(bytes: Uint8Array): RespT }): Promise<RespT> {
const params: RequestInit = {
headers: {
"Accept": PROTO_CONTENT_TYPE,
"Content-Type": PROTO_CONTENT_TYPE,
},
method: "POST",
body: toArrayBuffer(req.serializeBinary()),
};
import * as protos from "./protos";
import pb = protos.exemplar;
const HOST = "https://localhost:1234";
const PROTO_CONTENT_TYPE = "application/x-protobuf";
interface ResponseMessageBuilder<PropT, RespT> {
new(properties?: PropT): RespT;
encode(message: PropT, writer?: protobuf.Writer): protobuf.Writer;
decode(reader: (protobuf.Reader | Uint8Array), length?: number): RespT;