Skip to content

Instantly share code, notes, and snippets.

@luqmaan
luqmaan / write_to_clipboard.py
Last active April 5, 2023 16:35
Write a python string to the clipboard via pbcopy (OS X)
def write_to_clipboard(output):
import subprocess
process = subprocess.Popen('pbcopy', env={'LANG': 'en_US.UTF-8'}, stdin=subprocess.PIPE)
process.communicate(output.encode())

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

@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}
@luqmaan
luqmaan / alterColor.js
Created November 29, 2012 14:38
Darkens or lightens a CSS RGB color.
/**
* Darkens or lightens a CSS RGB color. Derived from http://www.sitekickr.com/coda/jquery/darken-background-color-element.html
* @param {string} rgb "rgb(26,26,26)""
* @param {string} type "darken" or "lighten"
* @param {int} percent
* @return {string} returns the altered RGB color
*/
function alterColor(rgb, type, percent) {
rgb = rgb.replace('rgb(', '').replace(')', '').split(',');
function curry(func, ...argv) {
let prevArgs = argv;
function innerCurry(...args) {
prevArgs.push(...args)
if (prevArgs.length === func.length) {
return func(...prevArgs);
}
@luqmaan
luqmaan / CapMetro_API_Wishlist.md
Last active February 13, 2018 04:22
CapMetro API Wishlist

Support CORS. Allow the API to be accessed through webapps without having to setup a proxy server in between.

Add documentation! Sneaking around the API and looking at the the trip planner code is not optimal.

Build an API the right way. Provide API keys so you can throttle requests and make sure things aren't getting slow.

More frequent polling of the bus locations. Right now it takes 30-90 seconds for bus locations to update. This sucks for users.

When will the 803 info be added to the GTFS database?

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") {
@luqmaan
luqmaan / debugging reselect performance.md
Last active July 17, 2017 23:32
debug reselect performance

Debugging reselect performance

Some steps I'm taking to debug bad performance with reselect.

My performance problems are coming from the fact that I am not using reselect properly. I wrote a bunch of selectors that use props but don't do anything to make sure they can be shared across multiple components.

The fix for this is: https://github.com/reactjs/reselect/blob/fec65b63b9a2ffa570348271138d20cf831e0185/README.md#sharing-selectors-with-props-across-multiple-components.

But before rewriting tons of code, I'd like to see which selectors are recomputed the most.

gulpTask = (name, fn) => {
done = (err) => {
if (err) {
console.log(`Completed task "${name}" with error`);
console.error(err)
}
else {
console.log(`Completed task "${name}" successfully`);
}
}