Skip to content

Instantly share code, notes, and snippets.

@aputilouski
aputilouski / pg-proxy.ts
Last active April 22, 2026 18:33
postgresql proxy(nodejs typescript)
import net from 'net';
import tls from 'tls';
import { URL } from 'url';
import { config } from 'dotenv';
config();
const DATABASE_URL = process.env.DATABASE_URL;
if (!DATABASE_URL) {
@aputilouski
aputilouski / requestAnimationFrame.ts
Created May 24, 2024 18:46
requestAnimationFrame
/*const boxRef = React.useRef<HTMLDivElement>(null);
React.useEffect(() => {
if (!boxRef.current) return;
runAnimation(boxRef.current, isOpen);
}, [isOpen]);*/
export const runAnimation = (box: HTMLDivElement, isOpen: boolean) => {
@aputilouski
aputilouski / stripe-checkout-session.js
Created March 14, 2023 17:09
Stripe checkout session (buying a subscription, adding new payment methods)
// buy a subscription
const session = await stripe.checkout.sessions.create({
customer: customerID,
success_url: '/settings/subscription',
cancel_url: '/settings/subscription',
line_items: [{ price: somePrice, quantity }],
subscription_data: { trial_period_days: 60 },
mode: 'subscription',
});
@aputilouski
aputilouski / sequelize-count.js
Last active March 4, 2023 11:07
Sequelize count submodel with limit
const requests = await RequestModel.findAll({
include: {
model: UserModel,
where: { user_id: ids },
as: 'users',
attributes: [],
through: { model: UserRequestModel, attributes: [] },
},
attributes: [],
group: ['request.id'],
@aputilouski
aputilouski / saga.js
Last active August 6, 2022 10:29
redux-saga examples (uploading files (channel explanation)
const handleProgressChange = (fileUploadingChannel, progressValue) => {
fileUploadingChannel.put({ value: progressValue })
}
function* handleFilesUploadingEvents(fileUploadingChannel) {
while(true) {
const payload = yield take(fileUploadingChannel);
yield put({
type: FILES_UPLOADING_PROGRESS,
payload
@aputilouski
aputilouski / saga.js
Last active August 6, 2022 10:29
redux-saga examples (login flow)
function* authorize(user, password) {
try {
const token = yield call(Api.authorize, user, password);
yield put({ type: 'LOGIN_SUCCESS', token });
yield call(Api.saveToken, token);
} catch(error) {
yield put({ type: 'LOGIN_ERROR', error });
} finally {
if (yield cancelled()) yield put({type: 'STOP_LOADING'});
}