Skip to content

Instantly share code, notes, and snippets.

View kesava's full-sized avatar

Kesava Mallela kesava

View GitHub Profile
@kesava
kesava / generators.js
Created December 15, 2022 21:08
Generators talk as part of UI Lunch and Learn 12/15/2022
// Generators
const obj = {
a: 1,
b: 2,
c: 3,
};
obj[Symbol.iterator] = function *() {
for(const k of Object.keys(obj)) {
@kesava
kesava / javascript-proxy-as-rest-client.js
Created February 18, 2022 20:36 — forked from DavidWells/javascript-proxy-as-rest-client.js
Using a javascript proxy as low code REST client
/* Using a JavaScript proxy for a super low code REST client */
// via https://dev.to/dipsaus9/javascript-lets-create-aproxy-19hg
// also see https://towardsdatascience.com/why-to-use-javascript-proxy-5cdc69d943e3
// also see https://github.com/fastify/manifetch
// also see https://github.com/flash-oss/allserver
// and https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const createApi = (url) => {
return new Proxy({}, {
get(target, key) {
const dict = ['computer', 'commuter', 'computation', 'computing', 'compute', 'computers'];
const letterDeletion = (word, index) => {
if (index === 0) return false;
let newWord = `${word.slice(0, index - 1)}${word.slice(index)}`;
if (dict.find(w => w === newWord)) {
return newWord;
} else {
return letterDeletion(word, index - 1);
}
}
function requireAll (fn) {
return function(...args) {
if (fn.length === args.length) {
return fn.apply(this, args);
} else {
console.error("All args are required")
// throw new Error("All the arguments are required.");
}
}
}
@kesava
kesava / example.js
Created September 1, 2021 04:27 — forked from heyimalex/example.js
Using mock-fs with jest
// __tests__/example.js
jest.mock('fs');
it('should serve as a nice example', () => {
const fs = require('fs')
// fs can be set up at any point by calling __configureFs.
fs.__configureFs({
'/test': {
@kesava
kesava / eopl-racket-help.md
Last active June 23, 2021 10:24
Need help porting macros from EOPL first edition

I am trying to work through EOPL first edition and I have made fairly good progress till chapter 5, working diligently through exercises[1]. I've been using Dr.Racket and #lang eopl[2] for the exercies.

Earlier in the the book, the authors define a couple of key macros define-record and variant-case which are used through out the book. Here is a brief usage of the macros.

(define-record leaf (number))

; that should define three methods
; a. make-leaf - constructor
; b. leaf? - predicate method
; c. leaf->number - a method to look up the members of the record
@kesava
kesava / define-record.rkt
Last active September 4, 2020 00:37
define-record in racket macros
#lang racket
(require racket/syntax)
(require (for-syntax racket/syntax))
(require macro-debugger/expand)
(require syntax/parse/define)
(require
racket/stxparam
(for-syntax syntax/parse))
(define-syntax (define-record stx)
#!/bin/bash
iatest=$(expr index "$-" i)
#######################################################
# SOURCED ALIAS'S AND SCRIPTS BY zachbrowne.me
#######################################################
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
@kesava
kesava / depth.js
Created February 17, 2019 18:37
Notate Depth in JS
var obj = {"isbn": "123-456-222",
"author":
{
"lastname": "Doe",
"firstname": "Jane"
},
"editor":
{
"lastname": "Smith",
"firstname": "Jane"
class LazySeq {
constructor(low, high) {
this.low = low;
this.high = high;
}
head() {
return this.low;
}