Skip to content

Instantly share code, notes, and snippets.

View danguilherme's full-sized avatar
👨‍💻
npx danguilherme

Guilherme Ventura danguilherme

👨‍💻
npx danguilherme
View GitHub Profile
@danguilherme
danguilherme / imperative.ts
Created May 21, 2019 08:55
Imperative vs Declarative
function waitSingleWidgetInVirtualTree(
options: MacroApiOptions,
scope: ScopeItem[] = [],
callback: (
(error: Error | null, virtualTreeNode: VirtualTreeNode | null) => void
)
) {
let unsubscribeFromStore: (() => void) | null = null;
function stopWaitingSingleWidgetInVirtualTree() {
if (unsubscribeFromStore) {
@danguilherme
danguilherme / _example.ts
Created August 5, 2019 14:48
Send messages from Electron Renderer to Main processes, with an RxJS observable to communicate progress and completion
// In Renderer
export function makeHttpRequest(url: string; method: string) {
return createIpcSender<{ url: string; method: string }, void>(
'http-request',
{ url, method },
);
}
// ... in browser window code ...
makeHttpRequest('https://httpbin.org', 'GET').subscribe({
@danguilherme
danguilherme / replaceVars.ts
Created July 5, 2021 21:01
Function to replace variables in a string
export function replaceVars(
content: string,
variables: { [key: string]: string }
) {
const varRegex = /\$([a-z0-9_]*)/gi;
let match: RegExpExecArray;
while ((match = varRegex.exec(content)!)) {
let [wholeVar, varName] = match;
@danguilherme
danguilherme / example_output.sql
Created March 23, 2015 13:13
SQL Server - Truncate all tables
-- COMING SOON