Skip to content

Instantly share code, notes, and snippets.

@bdadam
bdadam / example.html
Created January 30, 2014 22:44
Adding tabs to simple textareas
<!doctype html>
<html>
<head>
<meta name="charset" content="utf-8"/>
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="author" content="Adam Beres-Deak"/>
<meta name="viewport" content="width=device-width"/>
<style>
body {
@bdadam
bdadam / 1-ajax.js
Last active February 28, 2017 02:04
Composition
const vehicleToHtml = obj => {
return `<div id="${obj.id}">${obj.name}</div>`;
};
$.ajax({
url: '/get/all/vehicles',
success: vehicles => {
const html = vehicles.map(vehicleToHtml);
// const html = vehicles.map(v => new Vehicle(v)).map(v => v.toHtml());
document.querySelector('#list').innerHTML = html;
@bdadam
bdadam / fp-in-js.txt
Last active December 12, 2017 00:41
Links to some Functional Programming resources in JavaScript in no particular order
Functional Programming Jargon in simple terms:
https://github.com/hemanth/functional-programming-jargon
Professor Frisby's Mostly Adequate Guide to Functional Programming (book):
https://drboolean.gitbooks.io/mostly-adequate-guide/content/
A series on FP in JS from Eric Elliott:
https://medium.com/javascript-scene/the-rise-and-fall-and-rise-of-functional-programming-composable-software-c2d91b424c8c
Some introduction to Monads:
@bdadam
bdadam / download.sh
Last active March 6, 2021 21:23
Download open tabs from Chrome Android
# https://android.stackexchange.com/a/199496
adb forward tcp:9222 localabstract:chrome_devtools_remote
wget -O tabs.json http://localhost:9222/json/list
@bdadam
bdadam / interpolate.test.ts
Created July 5, 2021 08:36
String interpolation
import interpolate from './interpolate';
describe('Interpolate for Translations', () => {
// eslint-disable-next-line jest/no-commented-out-tests
// it('blah', () => {
// expect(interpolate('asdf')).toEqual('asdf');
// expect(interpolate('Hello {0}', ['World!'])).toEqual('Hello World!');
// expect(interpolate('Hello {0} {0}', ['World!'])).toEqual('Hello World! World!');
// expect(interpolate('Hello {0} {1} {2}!', ['World!', 'Welcome', 'here'])).toEqual('Hello World! Welcome here!');
// expect(interpolate('Hello {0} {1} {2}! {1} {2}!', ['World!', 'Welcome', 'here'])).toEqual(
@bdadam
bdadam / readme.md
Created September 6, 2022 23:40
Change Display Brightness Below Minimum
echo 1 | sudo tee /sys/class/backlight/intel_backlight/brightness 
// https://leetcode.com/problems/lru-cache/submissions/
class LRUCache {
obj: Record<number, { val: number; acc: number }>;
capacity: number;
size: number;
acc: number;
cache: Record<number, [val: number, acc: number, key: number]>;
c: Map<number, [val: number, acc: number]>
@bdadam
bdadam / simple-cache.ts
Created October 11, 2022 20:40
SWR Cache
// createCache.ts
export default function createCache(fetchFunction: () => Promise<any>, refreshInterval: number, retryAfter: number) {
let fetchPromise: null | ReturnType<typeof fetchFunction> = null;
const doThinInInterval = () => {
fetchFunction().then((data) => {
fetchPromise = Promise.resolve(data);
})
.catch(() => setTimeout(doThinInInterval, retryAfter));
@bdadam
bdadam / readme.md
Last active February 23, 2023 21:15
Dev Meeting 2022-02-10

Things we are always saying

  • Parts of the code are under-tested
  • Parts of the code are "hard to reason about"
  • Parts of the code are slow

Stateless functions, No side effects, Dependency injection

const state = {