Skip to content

Instantly share code, notes, and snippets.

@luqmaan
luqmaan / README.md
Last active October 25, 2024 14:40
create postgres db schema from swagger schema

janky way to generate db schema from swagger

run node schema.js

this will create output.sql

you will need to massage a few things:

  • there are duplicate tables like rsv_address and rsv_revenue_and_balances
  • address needs to be named to two separate things

tictactoe

  • What is tic tac toe?
  • Build a data structure to represent the game board.
  • Write a function that updates the board with somebody's chosen position. Don't worry about detecting if somebody has won.
  • Write a function to detect that somebody has won.
  • What should the UI look like? Use excalidraw to mock up the layout of the page
  • Set up codesandbox.io with React and draw the board using the data structure we built earlier. Don't make it interactive, just draw the board.
  • Add a feature so that clicking on the board fills the spot.
  • Show a message when the game is over.
@luqmaan
luqmaan / algorithm_interview_study_notes.md
Last active October 2, 2020 02:10
I reviewed these notes before every interview

Algorithms notes

  • Implement binary search in js without recursion
  • implement quick sort in py and js
  • implement merge sort in js

for queues, you dequeue from 0 and enqueue at -1

function curry(func, ...argv) {
let prevArgs = argv;
function innerCurry(...args) {
prevArgs.push(...args)
if (prevArgs.length === func.length) {
return func(...prevArgs);
}
@luqmaan
luqmaan / generate-systemd-schedule.js
Last active May 26, 2020 08:10
Script from my blog post "Using systemd as a better cron." https://medium.com/horrible-hacks/using-systemd-as-a-better-cron-a4023eea996d. ⚠️ It may not actually work. 🤷‍♂️
const fs = require("fs");
const getTimerTemplate = (platform, importType, interval) => `
[Unit]
Description=Run ${platform}-${importType} every 15 minutes
Requires=${platform}-${importType}.service
[Timer]
Unit=${platform}-${importType}.service
OnUnitInactiveSec=${interval}
const StatsD = require("hot-shots");
const statsdclient = new StatsD();
const properties = Object.getOwnPropertyNames(
Object.getPrototypeOf(statsdclient)
);
const client = properties.reduce((prev, property) => {
if (property === "constructor") {
gulpTask = (name, fn) => {
done = (err) => {
if (err) {
console.log(`Completed task "${name}" with error`);
console.error(err)
}
else {
console.log(`Completed task "${name}" successfully`);
}
}
@luqmaan
luqmaan / string_to_dom.js
Last active April 12, 2017 18:38
Slightly interactive UI + templating with ES6. No handlebars, no react.
const stringToDom = (string) => document.createRange().createContextualFragment(string);
function viewTest(test) {
window.location.hash = test.id;
document.querySelector('#viewer').innerHTML = `
<iframe src="${test.link}"></iframe>
`;
}
fetch('/tests')
export function* getMissingRates(orderNumbers, labelType) {
const ratesDeltaByOrderNumber = {};
const orderNumbersMissingRates = yield select(orderNumbersMissingRatesSelector, {orderNumbers, labelType});
if (!orderNumbersMissingRates.length) {
return;
}
yield put(startUpdatingRates(orderNumbersMissingRates, labelType));

Redux Action Registry

Create an object with all your action creators. This makes it easier to debug your application, since now you can dispatch actions from the console or from the Redux Devtools Extension.

Usage

ActionRegistry['data/accountBalance'].SET_ACCOUNT_BALANCE // "ordoro/data/accountBalance/SET_ACCOUNT_BALANCE"
ActionRegistry['data/accountBalance'].setAccountBalance(3) // {type: "ordoro/data/accountBalance/SET_ACCOUNT_BALANCE", payload: 3}