Skip to content

Instantly share code, notes, and snippets.

@creationix
creationix / hidepatch.js
Created March 20, 2013 16:24
Idea to make private properties and methods non-enumerable instead of prefixing them with underscores (in ES5 and above environments of course)
Object.defineProperty(Object.prototype, "hide", {
value: function () {
[].forEach.call(arguments, function (name) {
var descriptor = Object.getOwnPropertyDescriptor(this, name);
if (descriptor.enumerable) {
descriptor.enumerable = false;
Object.defineProperty(this, name, descriptor);
}
}, this);
}
@mjackson
mjackson / color-conversion-algorithms.js
Last active April 14, 2024 08:46
RGB, HSV, and HSL color conversion algorithms in JavaScript
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSL representation
@colemanw
colemanw / font-awesome-mime-type-icons.php
Last active March 11, 2024 04:21 — forked from guedressel/font-awesome-mime-type-icons.php
Font Awesome File Icons: Mapping MIME Types to correct icon classes
<?php
/**
* Get font awesome file icon class for specific MIME Type
* @see https://gist.github.com/guedressel/0daa170c0fde65ce5551
*
*/
function ($mime_type) {
// List of official MIME Types: http://www.iana.org/assignments/media-types/media-types.xhtml
$icon_classes = array(
@MendyLanda
MendyLanda / drizzle-ulid.md
Created November 5, 2023 13:29
Implementing Efficient Binary ULID Storage in MySQL with Drizzle ORM

For anyone considering the use of ULIDs in MySQL with drizzle, here's a ready-to-use ULID type for your convenience.

import { Ulid as ULID } from "id128";

export const ulid = customType<{
  data: string;
  notNull: true;
  default: false;