Skip to content

Instantly share code, notes, and snippets.

@arccoza
arccoza / callable-object-constructor.js
Last active March 6, 2023 21:38
Javascript Callable Object Class / Constructor created by arccoza - https://repl.it/EbN5/18
// This is my approach to creating callable objects
// that correctly reference their object members,
// without messing with prototypes.
// A Class that extends Function so we can create
// objects that also behave like functions, i.e. callable objects.
class ExFunc extends Function {
constructor() {
// Here we create a dynamic function with `super`,
// which calls the constructor of the parent class, `Function`.
@oinopion
oinopion / read-access.sql
Created October 5, 2016 13:00
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
# -*- coding:utf-8 -*-
def odd(n):
return True if n == 1 else even(n - 1)
def even(n):
return False if n == 1 else odd(n - 1)
def odd2(n):
@koorchik
koorchik / ast vs rpn.js
Last active July 6, 2023 09:27
Compare AST and RPN evaluation performance
/*
There is an AST (Abstract syntax tree) in JSON format.
AST represents Excel spreadsheet formula.
Is it possible in JavaScript to make RPN (Reverse Polish Notation) faster than AST?
AST evaluation is recusive and RPN evaluation is iterative.
But in any case, AST evaluation is faster despite recursion.
I guess that the main problem is in using dynamic js arrays to emulate stack.
Would RPN win if it was written in C/C++?