Skip to content

Instantly share code, notes, and snippets.

View GrandSchtroumpf's full-sized avatar
🏠
Working from home

François GrandSchtroumpf

🏠
Working from home
  • Dapps Nation
  • Nantes
View GitHub Profile
@GrandSchtroumpf
GrandSchtroumpf / Markdium-typescript.ts
Created May 7, 2020 14:29
Markdium-VSCode extension inside a nx workspace
const index = join(context.extensionPath, 'studio/index.html');
// Refresh the webview on update from the code
const updateWebview = async () => {
const html = await fs.readFile(index, 'utf-8');
panel.webview.html = html.replace(matchLinks, toUri);
}
// In dev mode listen on changes from index.html & update the view
if (!environment.production) {
@GrandSchtroumpf
GrandSchtroumpf / Markdium-typescript.ts
Created May 7, 2020 14:29
Markdium-VSCode extension inside a nx workspace
import { commands, ExtensionContext, window } from 'vscode';
// On activation
export function activate(context: ExtensionContext) {
// Register command "start"
commands.registerCommand('start', () => {
window.showInformationMessage('Hello World');
})
}
@GrandSchtroumpf
GrandSchtroumpf / Markdium-typescript.ts
Created May 7, 2020 14:29
Markdium-VSCode extension inside a nx workspace
import { promises as fs } from 'fs'; // Require @types/node@latest
import { join } from 'path';
// On activation
export function activate(context: ExtensionContext) {
// Register command "start"
commands.registerCommand('start', async () => {
...
const indexPath = join(context.extensionPath, 'studio/index.html');
const html = await fs.readFile(indexPath, 'utf-8');
@GrandSchtroumpf
GrandSchtroumpf / Markdium-JSON.json
Created May 7, 2020 14:29
Markdium-VSCode extension inside a nx workspace
{
"version": "0.2.0",
"configurations": [{
"name": "Run Extension In Dev Mode",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/dist/apps/vs-code"
],
@GrandSchtroumpf
GrandSchtroumpf / Markdium-typescript.ts
Created May 7, 2020 14:29
Markdium-VSCode extension inside a nx workspace
const html = await fs.readFile(join(context.extensionPath, 'studio/index.html'), 'utf-8');
// 1. Get all link prefixed by href or src
const matchLinks = /(href|src)="([^"]*)"/g;
// 2. Transform the result of the regex into a vscode's URI format
const toUri = (_, prefix: 'href' | 'src', link: string) => {
// For
if (link === '#') {
return `${prefix}="${link}"`;
}
class Client {
on(message) {
this.call(message)
}
// hooked by "connectClient"
call(message) {}
}
function connectClient(client) {
host.on((msg) => client.on(msg))
client['call'] = (msg) => host.send(`Modified by realm: ${msg}`)
@GrandSchtroumpf
GrandSchtroumpf / app.component.ts
Last active March 5, 2020 14:15
ng-form-factory simple example
import { Component } from '@angular/core';
import { FormGroupSchema, createForms } from 'ng-form-factory';
import { MatTextSchema } from './text-form/text-form.component';
interface Person {
firstName: string;
lastName: string;
}
const schema: FormGroupSchema<Person> = {
@GrandSchtroumpf
GrandSchtroumpf / world.json
Created January 18, 2020 18:41
map of the world
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@GrandSchtroumpf
GrandSchtroumpf / bottom-nav-bar.dart
Created December 13, 2019 08:11
Flutter Example - bottom nav bar
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
// Title
title: "Using Tabs",
// Home
home: MyHome()));
}
@GrandSchtroumpf
GrandSchtroumpf / nav-drawer.dart
Created December 13, 2019 08:09
Flutter nav drawer
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: HomeScreen(), // route for home is '/' implicitly
routes: <String, WidgetBuilder>{
SettingsScreen.routeName: (BuildContext context) => SettingsScreen(),
AccountScreen.routeName: (BuildContext context) => AccountScreen(),
},