Skip to content

Instantly share code, notes, and snippets.

View DimitryDushkin's full-sized avatar
😀
RxJS!

Dimitry DimitryDushkin

😀
RxJS!
View GitHub Profile
@DimitryDushkin
DimitryDushkin / gist:9020b6f5639fbbd46bc0746c5bfc2586
Created September 5, 2019 15:17 — forked from zeuxisoo/gist:980174
How to use git diff to patch file

Create patch file

git diff > patch.diff

Apply path file

patch -p1 < patch.diff

/**
* Graph respects explicit dependencies
* and implicit by resources (via positions)
*/
export const makeGraphFromTasks = (tasks: Array<Task>): Graph => {
// task and blockedBy
const graph: Graph = new Map();
const resourcesTasks = new Map<ID, Array<Task>>();
// Create graphs
export type Task = {
id: ID;
title: string;
start: Date;
end: Date;
duration: number;
/**
* Approximation of priority
*/
export const makeReverseGraph = (graph: Graph): Graph => {
const reverseGraph: Graph = new Map();
for (const [id, parentId] of dfs(graph, { withParentId: true })) {
const prerequesitions = reverseGraph.get(id) ?? new Set();
if (parentId) {
prerequesitions.add(parentId);
}
reverseGraph.set(id, prerequesitions);
}
export const scheduleTasks = (
inputTasks: Array<Task>,
today: Date = getNowDate()
): Array<Task> => {
const dayBeforeToday = subtractDays(today, 1);
const tasks: Array<Task> = inputTasks.map((t) => ({ ...t }));
const tasksById: TasksById = Object.fromEntries(tasks.map((t) => [t.id, t]));
const graph = makeGraphFromTasks(tasks);
let cyclesToFullyUpdateDates = 1;
@DimitryDushkin
DimitryDushkin / switch.js
Created August 17, 2021 10:23
JS assign a variable to switch result
const result = (function () {
switch (step) {
case Step.One:
return {one: 1};
case Step.Two:
return {two: 2};
case Step.Three:
return {three: 4};
}
})();
/**
* Main source of cyclic dependencies is previous step where graph is created
* Often top-level task has same owner as children tasks
* Since we create edge in graph also by same owner that's why there is cyclic deps
*
* IDEA: mitigate the issue by starting DFS walk from top-level (source) tasks!
*/
export const removeCyclicDependencies = (
graph: Graph,
tasks: Array<Task>
@DimitryDushkin
DimitryDushkin / server.ts
Created April 6, 2024 22:47
server.ts for bun + remix
import type { ServerBuild } from "@remix-run/node";
import { createRequestHandler } from "@remix-run/server-runtime";
import { serve } from "bun";
import { resolve } from "node:path";
process.env.REMIX_DEV_ORIGIN = "https://localhost";
// @see https://remix.run/docs/en/main/future/vite#migrating-a-custom-server
const viteDevServer =
process.env.NODE_ENV === "production"