Skip to content

Instantly share code, notes, and snippets.

@damianobarbati
damianobarbati / Log.ts
Created November 11, 2024 12:13
Log decorator to log request/response
import ENV from '@api/env';
import { getUserFromAsyncStorage } from '@api/helpers';
import { dateToYMDHMS } from '@common/date';
type LoggerParams = {
input?: boolean;
output?: boolean;
hideKeys?: string[];
};
@damianobarbati
damianobarbati / pg.sql
Last active October 23, 2024 09:43
Postgres common queries / triggers / functions
-- sua (set updated at): set updated_at = now() when updating row
create or replace function sua() returns trigger language plpgsql as $$
begin
new.updated_at = now()::timestamptz(0);
return new;
end; $$;
-- asu (array sort unique): keep array values sorted and unique
create or replace function asu (anyarray) returns anyarray language sql as $$
select array(select distinct $1[s.i] from generate_series(array_lower($1,1), array_upper($1,1)) as s(i) order by 1);
Start testnet and deploy application smart contract:
```sh
pnpm -F bcm hh:node
pnpm -F bcm hh:deploy --network localhost
```
Hardhat JSON RPC is served at <http://127.0.0.1:8545>.
```json
{
"name": "bcm",
@damianobarbati
damianobarbati / Dockerfile
Created October 8, 2023 17:50
Dockerfile with squash
FROM node:20.6-alpine as build
ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
COPY ./ /opt
WORKDIR /opt
RUN apk --no-cache --update --upgrade add npm dumb-init
@damianobarbati
damianobarbati / index.ts
Last active January 24, 2023 14:39
SSE stream
import { PassThrough } from 'stream';
import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
// process spawned executing crawler to fetch subalterns
let subalterns_task: ChildProcessWithoutNullStreams | undefined;
router.all('/api/subalterns/stop', (ctx: Context) => {
if (!subalterns_task) {
ctx.body = 'Task is not running.';
} else {
@damianobarbati
damianobarbati / find-rm.sh
Created November 17, 2020 14:09
find + rm
find /var/log/ -maxdepth 1 -type f -iwholename '*[^a-z0-9\-\_\.\/]*' -print0 | xargs -r -0 rm
find /var/log/ -maxdepth 1 -type f -not -iname '*_*' -print0 | xargs -r -0 rm
find /var/log/ -maxdepth 1 -type f -not -name '*_*.log*' -delete
find /var/log/ -maxdepth 1 -type f -name '*.php*' -delete
find /var/log/ -maxdepth 1 -type f -name '*.html*' -delete
@damianobarbati
damianobarbati / apt-update.sh
Last active June 4, 2023 11:43
apt - update system
apt-get update -y
apt-get upgrade -y
apt dist-upgrade -y
apt autoremove --purge -y
apt clean
do-release-upgrade
# clean logs folder
find /var/log -type f -delete
@damianobarbati
damianobarbati / paypal.js
Last active March 31, 2020 19:37
paypal.js
window.paypal.Buttons({
// reference: https://developer.paypal.com/docs/checkout/integration-features/customize-button/
style: {
layout: 'horizontal',
shape: 'rect',
color: 'blue',
fundingicons: false,
tagline: false,
},
@damianobarbati
damianobarbati / droplet.sh
Last active May 22, 2020 19:59
Droplet setup
# remove LANG warning on ssh connection
printf "LANG=en_US.utf-8\nLC_ALL=en_US.utf-8" > /etc/environment
# if you have strong reasons disable selinux...
printf "SELINUX=disabled" > /etc/selinux/config
# update system
yum upgrade -y
yum clean all
yum makecache timer