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 / example_output.sql
Created March 23, 2015 13:13
SQL Server - Truncate all tables
-- COMING SOON
@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.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 / 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 / index.html
Last active January 18, 2019 15:08
Electron Fiddle Gist - test menu shortcuts/accelerators
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<!-- All of the Node.js APIs are available in this renderer process. -->
<pre>
<b>Node.js :</b> <script>document.write(process.versions.node)</script>
@danguilherme
danguilherme / git_configs.sh
Last active July 25, 2018 18:27 — forked from tacsio/Git Configs
My git config
git config --global user.name "Guilherme Ventura"
git config --global user.email "guilhermeventura2@gmail.com"
git config --global push.default simple
git config --global color.ui true
git config --global alias.s status
git config --global alias.c checkout
git config --global alias.co checkout
@danguilherme
danguilherme / symlink.bat
Last active November 14, 2017 00:42
Windows symlink

And the famous answer is: it depends. Depends on the use case.

Use case #1: Optional parameters

If the parameters are optional, you may use a single parameter (generally named options) to receive and conditionally Object.assign the default values (mostly used in pre-ES6 code, but still has its use).

jQuery uses this approach in lots of functions. Here's an example from Angular's $http.get:

// No params
$http.get('https://httpbin.org/get');

// Optional params

@danguilherme
danguilherme / snippets.sh
Created February 29, 2016 00:54
Command Line Magic
# Create a symbolic link to conveniently run $app from the terminal:
sudo ln -s /path/to/$app /usr/local/bin/$app
@danguilherme
danguilherme / aliases
Last active August 29, 2015 14:24
Alias file for Cmder
e.=explorer .
gl=git log --oneline --all --graph --decorate $*
ls=ls --color $*
pwd=cd
clear=cls
subl="C:\Program Files\Sublime Text 3\subl.exe" $*
atom="C:\Users\Guilherme\AppData\Local\atom\app-1.0.0\atom.exe" $*
eval=node -p $*