Skip to content

Instantly share code, notes, and snippets.

View jasonblanchard's full-sized avatar

Jason jasonblanchard

View GitHub Profile
@jasonblanchard
jasonblanchard / reult.ts
Last active April 30, 2023 17:22
typescript result types
type Result<T, E = Error> =
| { ok: true; value: T }
| { ok: false; error: E };
function wrap<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => Result<ReturnType<T>> {
return function(...args: Parameters<T>): Result<ReturnType<T>> {
try {
const value = fn(...args);
return {
@jasonblanchard
jasonblanchard / connect-nextjs13-adapter.ts
Last active March 29, 2023 16:21
buf connect with next 13 route handlers
import {
ConnectRouter,
ConnectRouterOptions,
createConnectRouter,
} from "@bufbuild/connect";
import type { UniversalHandler } from "@bufbuild/connect/protocol";
import { createFetchHandler, FetchHandler } from "./fetch-universal-handler"; // https://gist.github.com/timostamm/5ca423155a0ddf03678ddc61f08cf4bd
interface NextJs13ApiRouterOptions extends ConnectRouterOptions {
/**

App Structure

root
├── core - core application logic. Things in here have no knowledge of stores nor interaction ingress/egress
│   ├── entities.ts -- domain entities shared throughout the core logic
│   └── someFn.ts -- some (probably pure) function that does some business logic.
├── store
│   ├── SqlStore.ts -- given a DB connection, issues queries and returns plain 'old objects. You could also go nuts and define these as interfaces alongside concrete instances to allow for mocked instances in tests or pre-prod envs.
│ └── ObjectStore.ts -- given object store client, issues requests to CRUD files, returns plain 'old objects
ch := make(chan *nats.Msg, 64)
_, err = nc.ChanSubscribe("insights.get.velocity", ch)
if err != nil {
panic(err)
}
go func() {
for {
msg := <-ch
fmt.Print("Receiving in channel: ")
import tkinter
def main():
root = tkinter.Tk()
canvas = tkinter.Canvas(root, width=200, height=100)
canvas.pack()
button = tkinter.Button(root, text="test")
button.bind("<Button-1>", lambda e: print("left clicked"))
button.bind("<Button-2>", lambda e: print("right clicked")) # Should print "right clicked" to the console. Change it to <Button-3> and it won't work
button.pack()
@jasonblanchard
jasonblanchard / README.md
Last active July 1, 2022 00:19 — forked from int128/README.md
Watching build mode on Create React App

Create React App does not provide watching build mode oficially (#1070).

This script provides watching build mode for an external tool such as Chrome Extensions or Firebase app.

How to Use

Create a React app.

Put the script into scripts/watch.js.

Keybase proof

I hereby claim:

  • I am jasonblanchard on github.
  • I am aboutblank (https://keybase.io/aboutblank) on keybase.
  • I have a public key ASDzal-YgJh2hplpuC2K_pBpr8gEczosOfkUyEfO-f6wIAo

To claim this, I am signing this object:

@jasonblanchard
jasonblanchard / createPerson.js
Last active July 6, 2016 13:24
Functional example jawn
function createPerson(attribute) {
var attributes = [attribute];
return function inner(attribute) {
if (!attribute) {
return attributes;
}
attributes.push(attribute);

Getting Oriented

JS Resources

Front-End Frameworks

Most complex Web applications use a front-end JavaScript framework to help manage the complexity of rich UIs. As you get more comfortable with JS, definitely check out these:

function createRunOnce() {
var hasRun = false;
return function() {
if (hasRun === false) {
console.log('I have run');
hasRun = true;
}
};
}