Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ndvo
ndvo / machine.js
Created June 25, 2021 17:17
Generated by XState Viz: https://xstate.js.org/viz
const type2scope = (type) => type.replace('SET', '').toLowerCase();
const setLocal = (ctx, ev) => {
const scope = type2scope(ev.type);
ctx.scope = scope;
ctx.country = ['country', 'region', 'local'].includes(scope);
ctx.region = ['region', 'local'].includes(scope);
ctx.city = ['local'].includes(scope);
};
@ndvo
ndvo / machine.js
Last active June 23, 2021 20:39
Generated by XState Viz: https://xstate.js.org/viz
interface TaxContext {
auto: boolean,
city: boolean,
country: boolean,
exemptShow: boolean,
originShow: boolean,
provider: boolean,
providerValues: {
avalara: boolean,
@ndvo
ndvo / index.js
Last active April 9, 2021 14:59
Example Foxy.io JSON webhook written in Node
const crypto = require('crypto');
const foxyEncryptionKey = 'YOUR_ENCRYPTION_KEY_HERE';
const foxyStoreId = 'YOUR_STORE_ID_HERE';
const foxyStoreDomain = 'YOUR_STORE_DOMAIN_HERE';
const http = require('http');
const server = http.createServer(handleRequest);
const routes = {
'transaction/created': handleTransactionCreated,
@ndvo
ndvo / watchmore.sh
Last active August 1, 2020 16:25
System limit for number of file watchers reached
sudo sysctl -w fs.inotify.max_user_watches=100000
@ndvo
ndvo / mymodule.module
Created July 30, 2020 13:57
Add a js to a specific page from a module in Drupal
function mymodule_preprocess_page(&$variables) {
if (isset($variables['node']) && $variables['node']->type == 'book') {
// Add js
drupal_add_js(drupal_get_path('module', 'mymodule') . '/mymodule.awesome.js');
$variables['scripts'] = drupal_get_js();
}
}
@ndvo
ndvo / contido.sh
Last active April 2, 2020 19:14
Verifica se um arquivo está contido em outro. A ordem não é importante.
#!/bin/bash
primeiro=$1;
segundo=$2;
for linha in $(cat $primeiro); do
if ! [[ $(grep "^$linha$" $segundo) ]]; then
echo "$primeiro não está contido em $segundo";
exit 1;
fi;
done;
exit 0;
@ndvo
ndvo / challengeTableFilter.js
Created August 8, 2019 20:03
A js filter manipulating DOM (answer to an exercise)
console.log("Initializing mySearch");
var filter=document.getElementById('myfilter')
buildForm(filter, filterTable)
function filterTable(){
this.table.setAttribute('id', 'deu-certo')
vim $(newbug)
@ndvo
ndvo / newbug
Created June 6, 2019 13:20
Create a text file for a bug using vim
#!/bin/bash
hoje=`date +%Y-%m-%d`
LAST=$(find . -maxdepth 1 -name $hoje-"*.bug" -type f -printf "%p\n" | sed -e s/.\\/$hoje-//g -e s/.bug//g | sort -g | tail -1)
echo $hoje-$(($LAST + 1)).bug
source ~/scripts/android.sh
nvm use node
sudo update-alternatives --config java
export JAVA_HOME=$(update-alternatives --query javac | sed -n -e 's/Best: *\(.*\)\/bin\/javac/\1/p')
export J2REDIR=''
export J2SDKDIR=''
source ~/scripts/fixjava.sh