Skip to content

Instantly share code, notes, and snippets.

View avisek's full-sized avatar

Avisek Das avisek

  • Planet Earth
View GitHub Profile

Nix Flakes Tips and Tricks

This is by no means complete, please add to it and share your own!

1. Shallow Clone nixpkgs

Shallow clone nixpkgs when the full Git history isn't always necessary - this can speed up build times.

The only issue I've had is nix-index-database not working well with the shallow clone. Other than that, no issues after running for a few months.

Fix TypeScript Type Truncation

Fixes TypeScript editors truncating types with "... N more" by increasing defaultMaximumTruncationLength from 160 to 16000 and defaultHoverMaximumTruncationLength from 500 to 50000.

macOS

Cursor:

sed -i '' -e 's/var defaultMaximumTruncationLength = 160;/var defaultMaximumTruncationLength = 16000;/' -e 's/var defaultHoverMaximumTruncationLength = 500;/var defaultHoverMaximumTruncationLength = 50000;/' '/Applications/Cursor.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js'
@avisek
avisek / constrain.js
Created November 13, 2023 17:38
Constrains a number between a minimum and maximum value.
function constrain(value, min, max) {
return Math.min(Math.max(value, min), max)
}
@avisek
avisek / copyOrMoveRecursively.ts
Created November 7, 2023 16:05
Recursively copy and move files & directories using Node.js
function copyRecursively(sourceDir: string, destinationDir: string): void {
const files = fs.readdirSync(sourceDir)
if (!fs.existsSync(destinationDir))
fs.mkdirSync(destinationDir, { recursive: true })
files.forEach(file => {
const sourceFile = path.join(sourceDir, file)
const destinationFile = path.join(destinationDir, file)
@avisek
avisek / colorConversions.js
Last active July 8, 2025 07:27
RGB, HSL, XYZ, LAB, LCH color conversion algorithms in JavaScript
/**
* Color conversion algorithms (RGB, HSL, XYZ, LAB, LCH)
* Derived from jQuery Color Picker Sliders by István Ujj-Mészáros
* Licensed under the Apache License 2.0
* https://github.com/istvan-ujjmeszaros/jquery-colorpickersliders
*/
export function rgbToHsl(rgb) {
const r = rgb.r / 255
const g = rgb.g / 255
@avisek
avisek / ResizeObserverPolyfill.js
Created April 19, 2022 19:53
Tiny ResizeObserver polyfill
// https://codepen.io/dgca/pen/WoJoNB
export const ResizeObserver = window.ResizeObserver || class ResizeObserver {
constructor(callback) {
this.observables = [];
// Array of observed elements that looks like this:
// [{
// el: domNode,
// size: {height: x, width: y}
// }]
this.boundCheck = this.check.bind(this);
@avisek
avisek / delete-folders-via-npm-script.markdown
Last active April 29, 2022 10:46
Delete folders via NPM script

Add below code in package.json script

{
  "scripts": {
     "rmdir": "node -e \"var fs = require('fs'); process.argv.slice(1).map((fpath) => fs.rmdirSync(fpath, { recursive: true })); process.exit(0);\"",
  }
}

Then execute as below in command window

@avisek
avisek / flexbox-holy-albatross-quantity-query.markdown
Created October 3, 2019 07:51
Flexbox Holy Albatross + Quantity Query
function getRandomColor() {
var x = Math.round(0xffffff * Math.random()).toString(16);
var y = (6 - x.length);
var z = '000000';
var z1 = z.substring(0, y);
return '#' + z1 + x;
}
@avisek
avisek / colorpicker-tool.markdown
Created November 2, 2018 08:32
ColorPicker tool