Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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);
};