file_path
stringlengths
3
280
file_language
stringclasses
66 values
content
stringlengths
1
1.04M
repo_name
stringlengths
5
92
repo_stars
int64
0
154k
repo_description
stringlengths
0
402
repo_primary_language
stringclasses
108 values
developer_username
stringlengths
1
25
developer_name
stringlengths
0
30
developer_company
stringlengths
0
82
rollup.config.js
JavaScript
import json from '@rollup/plugin-json'; import babel from 'rollup-plugin-babel'; import commonjs from 'rollup-plugin-commonjs'; import nodeResolve from 'rollup-plugin-node-resolve'; import serve from 'rollup-plugin-serve'; import { terser } from 'rollup-plugin-terser'; import typescript from 'rollup-plugin-typescript2'...
zsarnett/Custom-Grid-View
109
Custom Drag and Drop Grid for Home Assistant
TypeScript
zsarnett
Zack Barett
src/functions.ts
TypeScript
/* eslint-disable @typescript-eslint/ban-ts-ignore */ /* eslint-disable @typescript-eslint/no-explicit-any */ import { LovelaceConfig } from 'custom-card-helpers/dist/types'; export const replaceView = (config: LovelaceConfig, viewIndex: number, viewConfig: any): LovelaceConfig => ({ ...config, views: config.views...
zsarnett/Custom-Grid-View
109
Custom Drag and Drop Grid for Home Assistant
TypeScript
zsarnett
Zack Barett
src/grid-view.ts
TypeScript
/* eslint-disable @typescript-eslint/ban-ts-ignore */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ /* eslint-disable @typescript-eslint/no-explicit-any */ import { mdiPlus, mdiResizeBottomRight } from '@mdi/js'; import { computeCardSize, computeRTL, fireEvent, HomeAssistant, LovelaceCard, L...
zsarnett/Custom-Grid-View
109
Custom Drag and Drop Grid for Home Assistant
TypeScript
zsarnett
Zack Barett
src/hui-grid-card-options.ts
TypeScript
/* eslint-disable @typescript-eslint/no-non-null-assertion */ /* eslint-disable @typescript-eslint/no-explicit-any */ import { mdiDelete, mdiPencil } from '@mdi/js'; import { computeCardSize, fireEvent, HomeAssistant, LovelaceCard } from 'custom-card-helpers'; import { css, CSSResult, customElement, LitElement, propert...
zsarnett/Custom-Grid-View
109
Custom Drag and Drop Grid for Home Assistant
TypeScript
zsarnett
Zack Barett
index.html
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Lit Grid Layout</title> <!-- <script src="https://unpkg.com/lit-grid-layout@1.1.10/dist/lit-grid-layout.js?module" crossorigin="anonymous" ...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/lit-draggable-wrapper.ts
TypeScript
import { css, CSSResult, customElement, html, LitElement, property, TemplateResult, } from "lit-element"; import "./lit-draggable"; import type { DraggingEvent, LGLDomEvent } from "./types"; import { fireEvent } from "./util/fire-event"; @customElement("lit-draggable-wrapper") export class LitDraggableWr...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/lit-draggable.ts
TypeScript
import { customElement, html, LitElement, property, TemplateResult, } from "lit-element"; import { fireEvent } from "./util/fire-event"; import { getMouseTouchLocation } from "./util/get-mouse-touch-location"; import { getTouchIdentifier } from "./util/get-touch-identifier"; import { matchesSelectorAndParents...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/lit-grid-item.ts
TypeScript
import { css, CSSResult, customElement, html, internalProperty, LitElement, property, PropertyValues, query, TemplateResult, } from "lit-element"; import { classMap } from "lit-html/directives/class-map"; import "./lit-draggable"; import "./lit-resizable"; import type { DraggingEvent, LGLDomEvent, R...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/lit-grid-layout.ts
TypeScript
import deepClone from "deep-clone-simple"; import { css, CSSResult, customElement, html, internalProperty, LitElement, property, PropertyValues, TemplateResult, } from "lit-element"; import { nothing } from "lit-html"; import { repeat } from "lit-html/directives/repeat"; import "./lit-grid-item"; impo...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/lit-resizable-wrapper.ts
TypeScript
import { customElement, html, LitElement, TemplateResult, CSSResult, css, } from "lit-element"; import type { LGLDomEvent, ResizingEvent } from "./types"; import { fireEvent } from "./util/fire-event"; import "./lit-resizable"; @customElement("lit-resizable-wrapper") export class LitResizableWrapper exte...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/lit-resizable.ts
TypeScript
import { css, CSSResult, customElement, html, LitElement, property, svg, TemplateResult, } from "lit-element"; import "./lit-draggable"; import type { DraggingEvent, LGLDomEvent } from "./types"; import { fireEvent } from "./util/fire-event"; @customElement("lit-resizable") export class LitResizable ex...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/types.ts
TypeScript
import type { TemplateResult } from "lit-html"; export interface LayoutItem { width: number; height: number; posX: number; posY: number; key: string; hasMoved?: boolean; minWidth?: number; maxWidth?: number; minHeight?: number; maxHeight?: number; } export type Layout = Array<LayoutItem>; export i...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/are-layouts-different.ts
TypeScript
import type { Layout } from "../types"; export const areLayoutsDifferent = (a: Layout, b: Layout): boolean => { if (a === b) { return false; } return ( a.length !== b.length || a.some((aItem, itemIndex) => { const bItem = b[itemIndex]; const aItemKeys = Object.keys(aItem); return ( ...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/condense-layout.ts
TypeScript
// Fill in any gaps in the LayoutItem array import type { Layout, LayoutItem } from "../types"; import { getItemItersect } from "./get-item-intersect"; import { resolveIntersection } from "./resolve-intersection"; import { sortLayout } from "./sort-layout"; // Return LayoutItem Array export const condenseLayout = (la...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/debounce.ts
TypeScript
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/ban-ts-comment */ // From: https://davidwalsh.name/javascript-debounce-function // Returns a function, that, as long as it continues to be invoked, will not // be triggered. The function will be called after it ...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/find-layout-bottom.ts
TypeScript
import type { LayoutItem } from "../types"; // Return the bottom y value export const findLayoutBottom = (layout: LayoutItem[]): number => { let layoutYMax = 0; for (const item of layout) { const itemBottom = item.posY + item.height; layoutYMax = itemBottom > layoutYMax ? itemBottom : layoutYMax; } r...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/fire-event.ts
TypeScript
export const fireEvent = ( target: EventTarget, event: string, detail: Record<string, any> = {} ): void => { target.dispatchEvent(new CustomEvent(event, { detail })); };
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/fix-layout-bounds.ts
TypeScript
import type { LayoutItem } from "../types"; // Make sure all layout items are within the bounds of the cols provided export const fixLayoutBounds = ( layout: LayoutItem[], cols: number ): LayoutItem[] => { for (const item of layout) { // Width is greater than amount of columns // set the width to be numb...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/get-all-intersects.ts
TypeScript
import type { Layout, LayoutItem } from "../types"; import { intersects } from "./intersects"; export const getAllIntersects = ( layout: Layout, layoutItem: LayoutItem ): Array<LayoutItem> => { return layout.filter((l) => intersects(l, layoutItem)); };
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/get-item-intersect.ts
TypeScript
import type { LayoutItem } from "../types"; import { intersects } from "./intersects"; export const getItemItersect = ( layout: LayoutItem[], layoutItem: LayoutItem ): LayoutItem | undefined => { for (const item of layout) { if (intersects(item, layoutItem)) { return item; } } return undefined;...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/get-masonry-layout.ts
TypeScript
import type { Layout, LayoutItem } from "../types"; import { sortLayout } from "./sort-layout"; export const getMasonryLayout = (layout: Layout, columns: number): Layout => { const masonryLayout: Layout = []; const sortedLayout: Layout = sortLayout(layout); const columnHeights: number[] = new Array(columns).fill...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/get-mouse-touch-location.ts
TypeScript
import type { MouseTouchLocation } from "../types"; export const getMouseTouchLocation = ( ev: MouseEvent | TouchEvent, touchIdentifier: number | undefined ): MouseTouchLocation | undefined => { if (ev.type.startsWith("touch")) { if (touchIdentifier === undefined) { return; } const touchEvent ...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/get-touch-identifier.ts
TypeScript
export const getTouchIdentifier = (e: TouchEvent): number => { if (e.targetTouches && e.targetTouches[0]) return e.targetTouches[0].identifier; if (e.changedTouches && e.changedTouches[0]) return e.changedTouches[0].identifier; return 0; };
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/install-resize-observer.ts
TypeScript
export const installResizeObserver = async (): Promise<void> => { if (typeof ResizeObserver !== "function") { window.ResizeObserver = (await import("resize-observer-polyfill")).default; } };
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/intersects.ts
TypeScript
import type { LayoutItem } from "../types"; export const intersects = (item1: LayoutItem, item2: LayoutItem): boolean => { // same element if (item1.key === item2.key) { return false; } // item1 is left of item2 if (item1.posX + item1.width <= item2.posX) { return false; } // item1 is right of ...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/match-selector.ts
TypeScript
// Credit to react-draggable [https://github.com/STRML/react-draggable] let matchesSelectorFunc: string | undefined = ""; const matchesSelector = (el: Node, selector: string): boolean => { if (!matchesSelectorFunc) { matchesSelectorFunc = [ "matches", "webkitMatchesSelector", "mozMatchesSelector...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/move-item-away-from-intersect.ts
TypeScript
import type { Layout, LayoutItem } from "../types"; import { moveItem } from "./move-item"; import { getItemItersect } from "./get-item-intersect"; export const moveItemAwayFromIntersect = ( layout: Layout, intersectItem: LayoutItem, itemToMove: LayoutItem, cols: number, isUserMove: boolean ): Layout => { ...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/move-item.ts
TypeScript
import type { Layout, LayoutItem } from "../types"; import { sortLayout } from "./sort-layout"; import { getAllIntersects } from "./get-all-intersects"; import { moveItemAwayFromIntersect } from "./move-item-away-from-intersect"; export const moveItem = ( layout: Layout, item: LayoutItem, newPosX: number | undef...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/resolve-intersection.ts
TypeScript
import type { LayoutItem } from "../types"; import { intersects } from "./intersects"; export const resolveIntersection = ( layout: LayoutItem[], item: LayoutItem, newYPos: number ): void => { item.posY += 1; const itemIndex = layout .map((layoutItem: LayoutItem) => { return layoutItem.key; }) ...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
src/util/sort-layout.ts
TypeScript
import type { Layout } from "../types"; export const sortLayout = (layout: Layout): Layout => { return layout.slice(0).sort(function (a, b) { if (a.posY > b.posY || (a.posY === b.posY && a.posX > b.posX)) { return 1; } else if (a.posY === b.posY && a.posX === b.posX) { return 0; } return ...
zsarnett/Lit-Grid-Layout
31
Grid Layout using Lit Element
TypeScript
zsarnett
Zack Barett
index.html
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <script src="dist/lit-resizable-wrapper.js" type="module"></script> <title>Lit Resizable</title> </head> <body> <div style=" width: 100%; ...
zsarnett/Lit-Resizable
0
Resizable Lit Element
TypeScript
zsarnett
Zack Barett
rollup.config.js
JavaScript
import { nodeResolve } from "@rollup/plugin-node-resolve"; import typescript from "@rollup/plugin-typescript"; import { terser } from "rollup-plugin-terser"; import filesize from "rollup-plugin-filesize"; export default [ { input: "src/lit-resizable.ts", output: { file: "dist/lit-resizable.js", f...
zsarnett/Lit-Resizable
0
Resizable Lit Element
TypeScript
zsarnett
Zack Barett
src/lit-resizable-wrapper.ts
TypeScript
import { customElement, html, LitElement, TemplateResult, CSSResult, css, } from "lit-element"; import type { LGLDomEvent, ResizingEvent } from "./types"; import { fireEvent } from "./util/fire-event"; import "./lit-resizable"; @customElement("lit-resizable-wrapper") export class LitResizableWrapper exte...
zsarnett/Lit-Resizable
0
Resizable Lit Element
TypeScript
zsarnett
Zack Barett
src/lit-resizable.ts
TypeScript
import { customElement, html, LitElement, TemplateResult, CSSResult, css, property, svg, } from "lit-element"; import "lit-draggable"; import type { LGLDomEvent, DraggingEvent } from "./types"; import { fireEvent } from "./util/fire-event"; @customElement("lit-resizable") export class LitResizable ex...
zsarnett/Lit-Resizable
0
Resizable Lit Element
TypeScript
zsarnett
Zack Barett
src/types.ts
TypeScript
export interface LGLDomEvent<T> extends Event { detail: T; } export interface DraggingEvent { deltaX: number; deltaY: number; } export interface ResizingEvent { width: number; height: number; }
zsarnett/Lit-Resizable
0
Resizable Lit Element
TypeScript
zsarnett
Zack Barett
src/util/fire-event.ts
TypeScript
export const fireEvent = ( target: EventTarget, event: string, detail: Record<string, any> = {} ): void => { target.dispatchEvent(new CustomEvent(event, { detail })); };
zsarnett/Lit-Resizable
0
Resizable Lit Element
TypeScript
zsarnett
Zack Barett
README.sh
Shell
#!/bin/sh cat << EOF # Awfice - the world smallest office suite Awfice is a collection of tiny office suite apps: * a word processor, a spreadsheet, a drawing app and a presentation maker * each less than 1KB of plain JavaScript * each is literally just one line of code * packaged as data URLs, so you can use them ri...
zserge/awfice
3,645
The world smallest office suite
HTML
zserge
Serge Zaitsev
beam.html
HTML
<body><script>d=document;for(i=0;i<50;i++)d.body.innerHTML+='<div style="position:relative;width:90%;padding-top:60%;margin:5%;border:1px solid silver;page-break-after:always"><div contenteditable style=outline:none;position:absolute;right:10%;bottom:10%;left:10%;top:10%;font-size:5vmin>';d.querySelectorAll("div>div")....
zserge/awfice
3,645
The world smallest office suite
HTML
zserge
Serge Zaitsev
calc.html
HTML
<table id=t><script>z=Object.defineProperty,p=parseFloat;for(I=[],D={},C={},q=_=>I.forEach(e=>{try{e.value=D[e.id]}catch(e){}}),i=0;i<101;i++)for(r=t.insertRow(-1),j=0;j<27;j++)c=String.fromCharCode(65+j-1),d=r.insertCell(-1),d.innerHTML=i?j?"":i:c,i*j&&I.push(d.appendChild((f=>(f.id=c+i,f.onfocus=e=>f.value=C[f.id]||"...
zserge/awfice
3,645
The world smallest office suite
HTML
zserge
Serge Zaitsev
calculator.html
HTML
<table style="text-align: center;width:80vw;margin: 0 auto;"><tbody><tr><td colspan="4"><textarea></textarea></td></tr></tbody><script>let d=document;let tbl=d.querySelector('tbody');let z=d.querySelector('textarea');let oc=(x)=>z.value+=x;let cl=()=>z.value='';let re=()=>{try{z.value=eval(z.value);}catch(error){cl();}...
zserge/awfice
3,645
The world smallest office suite
HTML
zserge
Serge Zaitsev
code.html
HTML
<body oninput="i.srcdoc=h.value+'<style>'+c.value+'</style><script>'+j.value+'</script>'"><style>textarea,iframe{width:100%;height:50%;}body{margin:0;}textarea{width: 33.33%;font-size:18px;padding:0.5em}</style><textarea placeholder="HTML" id="h"></textarea><textarea placeholder="CSS" id="c"></textarea><textarea placeh...
zserge/awfice
3,645
The world smallest office suite
HTML
zserge
Serge Zaitsev
draw.html
HTML
<canvas id=v><script>d=document,d.body.style.margin=0,P="onpointer",c=v.getContext`2d`,v.width=innerWidth,v.height=innerHeight,c.lineWidth=2,f=0,d[P+"down"]=e=>{f=e.pointerId+1;e.preventDefault();c.beginPath();c.moveTo(e.x,e.y)};d[P+"move"]=e=>{f==e.pointerId+1&&c.lineTo(e.x,e.y);c.stroke()},d[P+"up"]=_=>f=0</script></...
zserge/awfice
3,645
The world smallest office suite
HTML
zserge
Serge Zaitsev
edit.html
HTML
<body contenteditable style=line-height:1.5;font-size:20px onload=document.body.focus()>
zserge/awfice
3,645
The world smallest office suite
HTML
zserge
Serge Zaitsev
examples/nanomagick/frontalface.h
C/C++ Header
#ifndef FRONTALFACE_H #define FRONTALFACE_H /* LBP Cascade for grayskull * Window: 24x24 * Features: 136 * Stages: 20 * Auto-generated from OpenCV XML */ #include <stdint.h> #define FRONTALFACE_NFEATURES 136 #define FRONTALFACE_NWEAKS 139 #define FRONTALFACE_NSTAGES 20 static const int8_t frontalface_features[...
zserge/grayskull
680
A tiny, dependency-free computer vision library in C for embedded systems, drones, and robotics.
C
zserge
Serge Zaitsev
examples/nanomagick/nanomagick.c
C
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <unistd.h> #include "grayskull.h" // face detection data from opencv lbpcascade_frontalface.xml cascade #include "frontalface.h" static void identify(struct gs_image img, struct gs_image *out, char *argv[]) { (void)out, (voi...
zserge/grayskull
680
A tiny, dependency-free computer vision library in C for embedded systems, drones, and robotics.
C
zserge
Serge Zaitsev
examples/wasm/grayskull.c
C
#include <stddef.h> // A simple bump allocator for our WASM module since we don't have stdlib. #define MEMORY_HEAP_SIZE (1024 * 1024 * 8) // 8MB heap for a few buffers static unsigned char memory_heap[MEMORY_HEAP_SIZE]; static size_t heap_ptr = 0; void* gs_alloc(size_t size) { size_t aligned_size = (size + 7) & ~7;...
zserge/grayskull
680
A tiny, dependency-free computer vision library in C for embedded systems, drones, and robotics.
C
zserge
Serge Zaitsev
examples/wasm/grayskull.js
JavaScript
const video = document.getElementById('video'); const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); const startButton = document.getElementById('start'); const stopButton = document.getElementById('stop'); const cameraSelect = document.getElementById('cameraSelect'); const addStepButt...
zserge/grayskull
680
A tiny, dependency-free computer vision library in C for embedded systems, drones, and robotics.
C
zserge
Serge Zaitsev
examples/wasm/index.html
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Grayskull WASM Demo</title> <style> body { font-family: sans-serif; display: flex; flex-direction: column; align-items: center; } .controls, .container { ...
zserge/grayskull
680
A tiny, dependency-free computer vision library in C for embedded systems, drones, and robotics.
C
zserge
Serge Zaitsev
grayskull.h
C/C++ Header
#ifndef GRAYSKULL_H #define GRAYSKULL_H #include <limits.h> #include <stdint.h> #ifndef GS_API #define GS_API static inline #endif #define GS_MIN(a, b) ((a) < (b) ? (a) : (b)) #define GS_MAX(a, b) ((a) > (b) ? (a) : (b)) struct gs_image { unsigned w, h; uint8_t *data; }; struct gs_rect { unsigned x, y, w, h;...
zserge/grayskull
680
A tiny, dependency-free computer vision library in C for embedded systems, drones, and robotics.
C
zserge
Serge Zaitsev
test.c
C
#include <assert.h> #include "grayskull.h" static void test_crop(void) { uint8_t data[4 * 4] = { 0, 0, 0, 0, // 0, 1, 0, 0, // 0, 1, 1, 0, // 0, 0, 0, 0 // }; struct gs_image img = {4, 4, data}; struct gs_rect rect = {1, 1, 3, 2}; uint8_t cropped_data[3 * 2]; struct gs_image c...
zserge/grayskull
680
A tiny, dependency-free computer vision library in C for embedded systems, drones, and robotics.
C
zserge
Serge Zaitsev
h/index.html
HTML
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Nokia Composer - Help</title> <style> @font-face { font-family: 'N'; src: url('../N.ttf'); } * { margin: 0; padding: 0; font-family: 'N...
zserge/nokia-composer
143
Nokia Composer in 512 bytes
HTML
zserge
Serge Zaitsev
index.html
HTML
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Nokia Composer</title> <style> @font-face { font-family: 'N'; src: url('N.ttf'); } * { margin: 0; padding: 0; f...
zserge/nokia-composer
143
Nokia Composer in 512 bytes
HTML
zserge
Serge Zaitsev
n.js
JavaScript
C = 0; // Initial value for audio context is zero stop = _ => C && C.close((C = 0)); // interrupt the playback, if any c = (x = 0, a, b) => (x < a && (x = a), x > b ? b : x); // clamping function (a<=x<=b) play = (s, bpm) => { // Create audio context, square oscillator and gain to mute/unmute it C = new AudioContex...
zserge/nokia-composer
143
Nokia Composer in 512 bytes
HTML
zserge
Serge Zaitsev
n.min.js
JavaScript
C=0;stop=t=>C&&C.close(C=0);c=(t=0,e,a)=>(t<e&&(t=e),t>a?a:t);play=(e,a)=>{C=new AudioContext;(z=C.createOscillator()).connect(g=C.createGain()).connect(C.destination);z.type="square";z.start();t=0;v=(e,a)=>e.setValueAtTime(a,t);for(m of e.matchAll(/(\d*)?(\.?)(#?)([a-g-])(\d*)/g)){k=m[4].charCodeAt();n=0|((k&7)*1.6+8)...
zserge/nokia-composer
143
Nokia Composer in 512 bytes
HTML
zserge
Serge Zaitsev
api_test.go
Go
package pennybase import ( "bytes" "encoding/json" "io" "net/http" "net/http/httptest" "net/url" "path/filepath" "strings" "testing" ) func TestServerREST(t *testing.T) { testDir := testData(t, filepath.Join("testdata", "rest")) s := must(NewServer( testDir, filepath.Join(testDir, "templates"), filep...
zserge/pennybase
818
Poor man's Backend-as-a-Service (BaaS), similar to Firebase/Supabase/Pocketbase
Go
zserge
Serge Zaitsev
authz_test.go
Go
package pennybase import ( "errors" "path/filepath" "testing" ) func TestAuthorization(t *testing.T) { tests := []struct { name string resource string id string action string username string password string wantErr bool expectedErr error }{ { name: "Publ...
zserge/pennybase
818
Poor man's Backend-as-a-Service (BaaS), similar to Firebase/Supabase/Pocketbase
Go
zserge
Serge Zaitsev
cmd/pennybase/main.go
Go
package main import ( "log" "net/http" "os" "github.com/zserge/pennybase" ) func main() { server, err := pennybase.NewServer("data", "templates", "static") if err != nil { log.Fatal(err) } logger := func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request...
zserge/pennybase
818
Poor man's Backend-as-a-Service (BaaS), similar to Firebase/Supabase/Pocketbase
Go
zserge
Serge Zaitsev
csvdb_test.go
Go
package pennybase import ( "crypto/rand" "path/filepath" "slices" "strconv" "sync" "testing" ) var _ DB = (*csvDB)(nil) func TestDBBasicOperations(t *testing.T) { db := must(NewCSVDB(filepath.Join(t.TempDir(), "test.csv"))).T(t) defer db.Close() id := rand.Text() if rec, err := db.Get(id); err == nil { ...
zserge/pennybase
818
Poor man's Backend-as-a-Service (BaaS), similar to Firebase/Supabase/Pocketbase
Go
zserge
Serge Zaitsev
examples/chat/templates/index.html
HTML
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/htmx.org@latest"></script> <script src="https://unpkg.com/htmx.org/dist/ext/json-enc.js"></script> <script src="https://unpkg.com/htmx.org/dist/ext/sse.js"></script> </head> <body> {{if not .User}} <form hx-post="/api/login"> <i...
zserge/pennybase
818
Poor man's Backend-as-a-Service (BaaS), similar to Firebase/Supabase/Pocketbase
Go
zserge
Serge Zaitsev
examples/login/templates/index.html
HTML
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/htmx.org@latest"></script> <script src="https://unpkg.com/htmx.org/dist/ext/json-enc.js"></script> </head> <body> {{if not .User}} <form hx-post="/api/login"> <input name="username" placeholder="Username" required> <input name="password" type="passw...
zserge/pennybase
818
Poor man's Backend-as-a-Service (BaaS), similar to Firebase/Supabase/Pocketbase
Go
zserge
Serge Zaitsev
examples/todo/templates/index.html
HTML
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/htmx.org@latest"></script> <script src="https://unpkg.com/htmx.org/dist/ext/json-enc.js"></script> </head> <body> <div hx-get="/todo-list" hx-trigger="load" hx-target="this"> </div> </body> </html> {{define "todo-list"}} <div id="todo-list" hx-get...
zserge/pennybase
818
Poor man's Backend-as-a-Service (BaaS), similar to Firebase/Supabase/Pocketbase
Go
zserge
Serge Zaitsev
pennybase.go
Go
package pennybase import ( "context" "crypto/rand" "crypto/sha256" "encoding/base32" "encoding/csv" "encoding/json" "errors" "fmt" "html/template" "io" "log" "net/http" "os" "path/filepath" "regexp" "slices" "sort" "strconv" "strings" "sync" "time" ) type Record []string type Resource map[string]...
zserge/pennybase
818
Poor man's Backend-as-a-Service (BaaS), similar to Firebase/Supabase/Pocketbase
Go
zserge
Serge Zaitsev
schema_test.go
Go
package pennybase import ( "fmt" "math" "reflect" "slices" "testing" ) const testID = "test0001" func TestFieldSchema(t *testing.T) { tests := []struct { name string field FieldSchema value any expected bool }{ // Number validation { name: "valid number within range", field: ...
zserge/pennybase
818
Poor man's Backend-as-a-Service (BaaS), similar to Firebase/Supabase/Pocketbase
Go
zserge
Serge Zaitsev
store_test.go
Go
package pennybase import ( "errors" "testing" ) func TestStoreCRUD(t *testing.T) { originalID := ID defer func() { ID = originalID }() tests := []struct { name string operation func(*Store) error wantErr bool postCheck func(*Store) error }{ { name: "Create valid book", operation: func(s ...
zserge/pennybase
818
Poor man's Backend-as-a-Service (BaaS), similar to Firebase/Supabase/Pocketbase
Go
zserge
Serge Zaitsev
testdata/rest/templates/books.html
HTML
{{define "books.html"}} {{range .Store.List "books" ""}} <div class="book">{{.title}} ({{.year}})</div> {{end}} {{end}}
zserge/pennybase
818
Poor man's Backend-as-a-Service (BaaS), similar to Firebase/Supabase/Pocketbase
Go
zserge
Serge Zaitsev
util_test.go
Go
package pennybase import ( "os" "testing" ) type mustResult[T any] struct { Val T Err error } func (m mustResult[T]) T(t *testing.T) T { t.Helper() must0(t, m.Err) return m.Val } func must[T any](v T, err error) mustResult[T] { return mustResult[T]{v, err} } func must0(t *testing.T, err error) { t.Helper()...
zserge/pennybase
818
Poor man's Backend-as-a-Service (BaaS), similar to Firebase/Supabase/Pocketbase
Go
zserge
Serge Zaitsev
.eslintrc.js
JavaScript
module.exports = { "env": { "browser": true, "es6": true }, "extends": "eslint:recommended", "globals": { "Atomics": "readonly", "SharedArrayBuffer": "readonly" }, "parserOptions": { "ecmaVersion": 2018 }, "rules": { } };
zserge/q
48
Tiny and simple VueJS clone
JavaScript
zserge
Serge Zaitsev
counter.html
HTML
<html> <style> ul, li { list-style: none; display: inline; } .active { text-decoration: underline; } </style> <body> <div id="counter"> <button q-on:click="clicks++" q-bind:disabled="clicks >= 5">Click me</button> <button q-on:click="clicks=0">Reset</button> <p q-text="`Clicked ${cli...
zserge/q
48
Tiny and simple VueJS clone
JavaScript
zserge
Serge Zaitsev
q.js
JavaScript
const call = (expr, ctx) => new Function(`with(this){${`return ${expr}`}}`).bind(ctx)(); const directives = { html: (el, _, val, ctx) => (el.innerHTML = call(val, ctx)), text: (el, _, val, ctx) => (el.innerText = call(val, ctx)), if: (el, _, val, ctx) => (el.hidden = !call(val, ctx)), on: (el, name, val, ctx...
zserge/q
48
Tiny and simple VueJS clone
JavaScript
zserge
Serge Zaitsev
q.min.js
JavaScript
let call=(t,e)=>new Function(`with(this){${"return "+t}}`).bind(e)(),directives={html:(t,e,n,o)=>t.innerHTML=call(n,o),text:(t,e,n,o)=>t.innerText=call(n,o),if:(t,e,n,o)=>t.hidden=!call(n,o),on:(t,e,n,o)=>t["on"+e]=()=>call(n,o),model:(t,e,n,o)=>{t.value=o[n],t.oninput=()=>o[n]=t.value},bind:(t,e,n,o)=>{let i=call(n,o)...
zserge/q
48
Tiny and simple VueJS clone
JavaScript
zserge
Serge Zaitsev
test.js
JavaScript
const assert = require('assert'); const jsdom = require('jsdom'); const fs = require('fs'); // Global map of tests const $ = {}; $['call'] = () => { assert.equal(call('2+3', null), 5); assert.equal(call('a', {a:42}), 42); assert.equal(call('a+b', {a:1, b: 2}), 3); assert.equal(call('Math.pow(2, a)', {a: 3}), ...
zserge/q
48
Tiny and simple VueJS clone
JavaScript
zserge
Serge Zaitsev
todo.html
HTML
<html> <style> ul, li { list-style: none; } .done { text-decoration: line-through; } </style> <body> <div id="app"> <input q-model="draft" /> <button q-on:click="addTask(draft)" q-bind:disabled="!draft.length">Add task</button> <button q-on:click="deleteCompleted()" q-bind:disabled="...
zserge/q
48
Tiny and simple VueJS clone
JavaScript
zserge
Serge Zaitsev
tab.c
C
#include <ctype.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #define C4 60 /* Tabs support a range C3..B6, C4 is a middle C reference */ static char *RST = "\x1b[0m"; /* Normal style */ static char *TXT = "\x1b[37m"; /* Text: white */ static char *DIM =...
zserge/tab
41
🎼 A tiny CLI tool to render tabs for music instruments (🎹🎷🎺🎸🪕🪈 and many others!)
C
zserge
Serge Zaitsev
apl.py
Python
#!/usr/bin/env python3 # # This is an implementation of k/simple language (https://github.com/kparc/ksimple/) in Python # K/simple is a subset of K langauge, which belongs to the APL family, together with J and Q. # This program illustrates how array languages work. # import sys, re, functools, itertools G = {} # g...
zserge/tinylangs
350
Real programming languages in 50 lines of code
Python
zserge
Serge Zaitsev
asm.py
Python
#!/usr/bin/env python3 import types,dis,sys # A minimal two-pass assembler for CPythin VM bytecode. It can handle assembly # instructions (simple and extended BINARY_OPs), constants, variables and # labels. Assembly source file is read from stdin until EOF. Resulting # function is compiled and executed immediately a...
zserge/tinylangs
350
Real programming languages in 50 lines of code
Python
zserge
Serge Zaitsev
basic.py
Python
#!/usr/bin/env python3 import sys code, vars = {}, {"#": 0} def num(s): n = 0 while s and s[0].isdigit(): n, s = n * 10 + int(s[0]), s[1:] return n, s.strip() def expr(s): res, s = term(s); op = "" while s and s[0] in "+-": op = s[0]; n, s = term(s[1:]) res += n if op == "+" else ...
zserge/tinylangs
350
Real programming languages in 50 lines of code
Python
zserge
Serge Zaitsev
factorial/fac.asm
Assembly
CONST 1 CONST 10 VAR n VAR result LOAD_CONST 0 # result = 1 STORE_FAST 0 # store in result LOAD_CONST 1 # n = CONST[1] (change this to calculate factorial of different numbers) STORE_FAST 1 # store in n loop: LOAD_FAST 1 # load n POP_JUMP_IF_FALSE end # if n == 0, jump to end ...
zserge/tinylangs
350
Real programming languages in 50 lines of code
Python
zserge
Serge Zaitsev
factorial/fac.lsp
Common Lisp
(label fac (lambda (x) (cond ((eq x 0) 1) (1 (* x (fac (- x 1))))))) (fac 1) (fac 2) (fac 3) (fac 4) (fac 5) (fac 6) (fac 7) (fac 8) (fac 9) (fac 10)
zserge/tinylangs
350
Real programming languages in 50 lines of code
Python
zserge
Serge Zaitsev
factorial/fac.pas
Pascal
var n, f; begin n := 10; f := 1; while n > 0 do begin f := f * n; n := n - 1; end; ! f end.
zserge/tinylangs
350
Real programming languages in 50 lines of code
Python
zserge
Serge Zaitsev
lisp.py
Python
#!/usr/bin/env python3 import sys # Very simple lexer, split by parens and whitespace def lex(code): return code.replace("(", " ( ").replace(")", " ) ").split() # A simple parser: build nested lists from nested parenthesis def parse(tokens): t = tokens.pop(0) if t == "(": sexp = [] while toke...
zserge/tinylangs
350
Real programming languages in 50 lines of code
Python
zserge
Serge Zaitsev
mouse.py
Python
#!/usr/bin/env python3 import sys # Returns a position in string "s" of the unmatched delimiter "r" (skipping nested l+r pairs) # # skip("2+(3+(4+5)))+6", "(", ")") -> 12 ("+6") # skip("a [ b [] [] c]] d []", "[", "]") -> 16 (" d []") # def skip(s, l, r): return next(i + 1 for i, c in enumerate(s) if (c == r...
zserge/tinylangs
350
Real programming languages in 50 lines of code
Python
zserge
Serge Zaitsev
pl0.py
Python
#!/usr/bin/env python3 import re, sys, operator def parse(code): tok = ""; kind = ""; code = code + ";" # force terminate code to trick look-ahead lexer # A simple regex-based lexer for PL/0, cuts one token from the string def lex(expected=None, when=None): nonlocal code, tok, kind if wh...
zserge/tinylangs
350
Real programming languages in 50 lines of code
Python
zserge
Serge Zaitsev
tcl.py
Python
#!/usr/bin/env python3 import sys, re, operator G = {} def tcl_m(op): return lambda a: str(int(op(int(a[0]), int(a[1])))) def tcl_puts(a): s = " ".join(a); print(s); return s def tcl_set(a): G.update({a[0]: a[1]}) if len(a) > 1 else ""; return G.get(a[0], "") def tcl_while(a): while int(tcl_eval(a[0])): tcl_eval(...
zserge/tinylangs
350
Real programming languages in 50 lines of code
Python
zserge
Serge Zaitsev
test/test.lsp
Common Lisp
nil ; [] 42 ; 42 (quote 42) ; 42 (quote (a b)) ; ['a', 'b'] (quote ()) ; [] (+ 2 3) ; 5 (+ 2 (* 5 7)) ; 37 (atom 42) ; t (atom (quote t)) ; t (atom (quote foo)) ; t (atom (quote (foo bar))...
zserge/tinylangs
350
Real programming languages in 50 lines of code
Python
zserge
Serge Zaitsev
test/test.pas
Pascal
var max, arg, ret; var foo; procedure isprime; var i; begin ret := 1; i := 2; while i < arg do begin if arg / i * i = arg then begin ret := 0; i := arg; end; i := i + 1; end; end; procedure primes; begin arg := 2; while arg < max do begin call isprime; if ret = 1 th...
zserge/tinylangs
350
Real programming languages in 50 lines of code
Python
zserge
Serge Zaitsev
c/tinysh.c
C
#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <sys/wait.h> #include <unistd.h> /* Display prompt */ static void prompt() { write(2, "$ ", 2); } /* Display error message, optionally - exit */ static void err(int retval, int fatal) { if (retval < 0) { ...
zserge/tinysh
98
Tiny UNIX shell, de-obfuscated, modernized, and "rewritten in Rust".
C
zserge
Serge Zaitsev
orig/tbr.c
C
#define D ,close( char *c,q [512 ],m[ 256 ],*v[ 99], **u, *i[3];int f[2],p;main (){for (m[m [60]= m[62 ]=32 ]=m[* m=124 [m]= 9]=6; e(-8) ,gets (1+( c=q) )|| exit (0); r(0,0)...
zserge/tinysh
98
Tiny UNIX shell, de-obfuscated, modernized, and "rewritten in Rust".
C
zserge
Serge Zaitsev
src/main.rs
Rust
use std::fs::File; use std::io::Write; use std::io::{Error, ErrorKind}; use std::process::{Command, Stdio}; use std::{env, io}; #[derive(Debug, Clone)] enum Token { Blank, Redir(i32), Delim(bool), Normal(char), } fn token(x: Option<&char>) -> Token { match x { Some(&c) => match c { ...
zserge/tinysh
98
Tiny UNIX shell, de-obfuscated, modernized, and "rewritten in Rust".
C
zserge
Serge Zaitsev
example.html
HTML
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="zine.css" rel="stylesheet"> </head> <body> <main class="zine"> <article> <h1>Header</h1> </article> <article> <p>First page</p> ...
zserge/zine
79
Tiny CSS template to produce micro-zines (folded 8-page magazines)
HTML
zserge
Serge Zaitsev
hollow-men/index.html
HTML
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="../zine.css" rel="stylesheet"> <style> @import url('https://fonts.googleapis.com/css2?family=Comforter+Brush&display=swap'); @font-face { font-family: poem-fo...
zserge/zine
79
Tiny CSS template to produce micro-zines (folded 8-page magazines)
HTML
zserge
Serge Zaitsev
mandolin/frets.py
Python
FRETS = [ ["G", "G#", "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G"], ["D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "C", "C#", "D"], ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A"], ["E", "F", "F#", "G", "G#", "A", "A#", "B", "C", "C#", "D", "D...
zserge/zine
79
Tiny CSS template to produce micro-zines (folded 8-page magazines)
HTML
zserge
Serge Zaitsev
mandolin/index.html
HTML
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="../zine.css" rel="stylesheet"> <style> @import url('https://fonts.googleapis.com/css2?family=Zeyada&display=swap'); @import url('https://fonts.googleapis.com/css2?family=Payt...
zserge/zine
79
Tiny CSS template to produce micro-zines (folded 8-page magazines)
HTML
zserge
Serge Zaitsev
mandolin/uchord.py
Python
# The MIT License (MIT) # # Copyright (c) 2017 G. Völkl # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, ...
zserge/zine
79
Tiny CSS template to produce micro-zines (folded 8-page magazines)
HTML
zserge
Serge Zaitsev
tinwhistle/index.html
HTML
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="../zine.css" rel="stylesheet"> <style> @import url('https://fonts.googleapis.com/css2?family=Eagle+Lake&family=Amiri&display=swap'); img { width: 100%; height: 100%; object-...
zserge/zine
79
Tiny CSS template to produce micro-zines (folded 8-page magazines)
HTML
zserge
Serge Zaitsev
tokipona/index.html
HTML
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="../zine.css" rel="stylesheet"> <style> /*@import url('https://fonts.googleapis.com/css2?family=Comforter+Brush&display=swap');*/ @import url('https://fonts.goog...
zserge/zine
79
Tiny CSS template to produce micro-zines (folded 8-page magazines)
HTML
zserge
Serge Zaitsev
ukulele/index.html
HTML
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="../zine.css" rel="stylesheet"> <style> @import url('https://fonts.googleapis.com/css2?family=Zeyada&display=swap'); @import url('https://fonts.googleapis.com/css2?family=Payt...
zserge/zine
79
Tiny CSS template to produce micro-zines (folded 8-page magazines)
HTML
zserge
Serge Zaitsev
ukulele/uchord.py
Python
# The MIT License (MIT) # # Copyright (c) 2017 G. Völkl # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, ...
zserge/zine
79
Tiny CSS template to produce micro-zines (folded 8-page magazines)
HTML
zserge
Serge Zaitsev
zine.css
CSS
/* Minimal CSS reset */ * { margin: 0; padding: 0; box-sizing: border-box; } /* Common styles: zine is a grid with some gap between pages */ .zine { display: grid; padding: 1mm; gap: 2mm; } /* Pages are also 21x15 grids to roughly fit A4/Letter aspect ratio */ .zine > * { display: grid; grid-template-columns: repeat...
zserge/zine
79
Tiny CSS template to produce micro-zines (folded 8-page magazines)
HTML
zserge
Serge Zaitsev
eslint.config.js
JavaScript
const tsParser = require('@typescript-eslint/parser'); const tsPlugin = require('@typescript-eslint/eslint-plugin'); module.exports = [ { files: ['**/*.ts'], languageOptions: { parser: tsParser, }, plugins: { '@typescript-eslint': tsPlugin, }, rules: { '@typescript-eslint/no...
zsviczian/KPlex
11
A knowledge graph project inspired by TheBrain and ExcaliBrain aiming to create an Obsidian.md plugin that will serve as a graph based user interface to link and navigate notes
TypeScript
zsviczian
rollup.config.js
JavaScript
import babel from "@rollup/plugin-babel"; import commonjs from "@rollup/plugin-commonjs"; import replace from "@rollup/plugin-replace"; import resolve from "@rollup/plugin-node-resolve"; import { terser } from "rollup-plugin-terser"; import typescript from "@rollup/plugin-typescript"; import copy from "rollup-plugin-co...
zsviczian/KPlex
11
A knowledge graph project inspired by TheBrain and ExcaliBrain aiming to create an Obsidian.md plugin that will serve as a graph based user interface to link and navigate notes
TypeScript
zsviczian