Skip to content

Instantly share code, notes, and snippets.

@ayal
ayal / updateproduct__schema.js
Last active July 31, 2023 18:35
update product schema
export const updateProduct__schema = {
name: 'updateProduct',
description: 'Updates specified fields in a product.',
parameters: {
type: 'object',
properties: {
_id: {
type: 'string',
},
product: {
@ayal
ayal / server.js
Created March 5, 2023 08:03
simple node server with cors allow all
const http = require('http');
const hostname = '127.0.0.1';
const port = 3300;
const server = http.createServer((req, res) => {
console.log('got request', req.method);
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', '*');
res.setHeader('Access-Control-Allow-Headers', '*');
@ayal
ayal / date_match.js
Last active February 2, 2022 19:46
hebrew date match
import { HDate } from '@hebcal/core';
const month = 1; // feb, zero based (so 0=jan, 1=feb etc..)
const day = 2;
const time = 13;
const year = 1984;
for (let i = 0; i < 120; i++) {
const loazi_date = new Date(year+i, month, day, time) // 02/02/198X 13:00
const hebrew_date = new HDate(loazi_date);
@ayal
ayal / test.ts
Last active January 17, 2022 09:44
image loaded hook
Object.defineProperty(Image.prototype, 'onload', {
set: function (fn) {
fn();
},
configurable: true,
});
@ayal
ayal / presence.md
Last active October 22, 2021 14:32
velo presence package readme

Site Members Presence

Use this package to add a widget showing the site members that are currently on your site.

Setup

Add a repeater with id onlineUsers inside the repeater you can set: image with id profilePic text with id userName How to Use the Package in your Site In your home page paste the following code:

@ayal
ayal / spotify.md
Created October 22, 2021 14:28
velo spotify integration markdown

Spotify Integration

Setup

Configuration

1 - spotify_client_secret stored in Velo secret manager value should be the Client Secret generated after registering your application

@ayal
ayal / shortcodes_inverse.json
Last active October 17, 2021 13:24
shortcodes inverse
{\"0⃣\":[\"0\",\"keycap\",\"number\",\"zero\"],\"1⃣\":[\"1\",\"number\",\"one\"],\"🕐\":[\"1\",\"00\",\"1:00\",\"clock\",\"one\",\"one o’clock\",\"o’clock\",\"time\"],\"🕜\":[\"1\",\"30\",\"1:30\",\"clock\",\"one\",\"one-thirty\",\"thirty\",\"time\"],\"🕑\":[\"2\",\"00\",\"2:00\",\"clock\",\"o’clock\",\"time\",\"two\",\"two o’clock\"],\"2⃣\":[\"2\",\"number\",\"two\"],\"🕝\":[\"2\",\"30\",\"2:30\",\"clock\",\"thirty\",\"time\",\"two\",\"two-thirty\"],\"🕒\":[\"3\",\"00\",\"3:00\",\"clock\",\"o’clock\",\"three\",\"three o’clock\",\"time\"],\"🕞\":[\"3\",\"30\",\"3:30\",\"clock\",\"thirty\",\"three\",\"three-thirty\",\"time\"],\"3⃣\":[\"3\",\"keycap\",\"number\",\"three\"],\"🕓\":[\"4\",\"00\",\"4:00\",\"clock\",\"four\",\"four o’clock\",\"o’clock\",\"time\"],\"🍀\":[\"4\",\"clover\",\"four\",\"four leaf clover\",\"irish\",\"leaf\",\"lucky\",\"plant\"],\"🕟\":[\"4\",\"30\",\"4:30\",\"clock\",\"four\",\"four-thirty\",\"thirty\",\"time\"],\"4⃣\":[\"4\",\"four\",\"number\"],\"🕠\":[\"5\",\"30\",\"5:30\",\"clock\",\"five\",\
@ayal
ayal / child.js
Last active November 3, 2020 16:38
killing forked children after setrawmode(true -> false)
var cp = require("child_process");
console.log('hi from child', process.stdin.isRaw)
setInterval(() => {
console.log('hi from child', process.stdin.isRaw);
}, 1000);
var child2 = cp.fork('child2.js', []);
console.log('child 2 pid', child2.pid);
@ayal
ayal / balance.js
Created February 14, 2020 12:07
balance
var userSums = [{name: 'ayal', sum: 400}, {name: 'tomer', sum: 300}, {name: 'guy', sum: 250}, {name: 'ronni', sum: 0}, {name: 'max', sum: 0}];
var sum = userSums.reduce((acc,u)=>acc+u.sum,0);
var usum = sum / userSums.length;
userSums.map(x=>(x.balance = x.sum - usum) && (x.gotgave = 0));
var balanceUsers = (u1,u2)=> {
if (u1.balance < 0 && u2.balance > 0) {
// u1 pays u2
@ayal
ayal / app.js
Created October 28, 2019 09:38
oren split airbnb bills
var amount = 1000;
var billDays = 1000 ;
var yesGuestDays = 1000;
///
var noGuestDays = billDays - yesGuestDays;
var amountPerDay = amount / billDays;
var orenPay = (amountPerDay / 2) * noGuestDays + (amountPerDay / 3) * yesGuestDays;
var ayalPay = amount - orenPay;
console.log(`Oren: ${orenPay.toFixed(0)}, (${((orenPay / amount)*100).toFixed(0)}%)
Ayal: ${ayalPay.toFixed(0)}, (${((ayalPay / amount)*100).toFixed(0)}%)`);