Skip to content

Instantly share code, notes, and snippets.

@ralekna
ralekna / getStartOfWeekByLocale.ts
Created October 23, 2023 10:29
Intl.Locale.prototype.getWeekInfo().firstDay replacement function
const LOCALES_TO_START_OF_WEEK = {
'af-ZA': 7,
'am-ET': 7,
'ar-AE': 1,
'ar-BH': 6,
'ar-DZ': 1,
'ar-EG': 6,
'ar-IQ': 6,
'ar-JO': 7,
'ar-KW': 6,
@ralekna
ralekna / xml.pegjs
Created August 5, 2019 12:10
Simple XML gramar for PEG.js
Tag = ContainerTag / SelfClosingTag
ContainerTag = OpeningBracket name:Text attributes:Attributes ClosingBracket children:Tag* OpeningBracket Slash closingName:Text ClosingBracket {
if (name !== closingName) {
throw new Error('Missmatching closing tag')
}
return {name, children, attributes}
}
SelfClosingTag = OpeningBracket name:Text attributes:Attributes _ Slash ClosingBracket { return {name, attributes} }
@ralekna
ralekna / gist:c92be925967703b489a685c8b6c4b4f1
Created March 21, 2017 09:17
Sinon Mongoose mock example
import * as sinon from 'sinon';
import * as Mongoose from 'mongoose';
import { expect } from 'chai';
// test utility
function areObjectIdsEqual(id1: Mongoose.Types.ObjectId | string, id2: Mongoose.Types.ObjectId | string) {
let normalizedId1: Mongoose.Types.ObjectId = new Mongoose.Types.ObjectId(id1.toString());
let normalizedId2: Mongoose.Types.ObjectId = new Mongoose.Types.ObjectId(id2.toString());
return normalizedId1.equals(normalizedId2);
}
@ralekna
ralekna / PrivateFactory.js
Created November 20, 2015 13:33
A JavaScript construct for having private instance fields
function PrivateFactory(scope) {
scope._ = function(fn) {
return function() {
return fn.apply(scope, arguments)
}
}
}
var Greeter = (function() {
#!/bin/bash
# Form from https://gist.github.com/robwierzbowski/5430952/
# Create a remote repo on GitHub and clone it to your computer
# Grabs sensible defaults from the containing folder and `.gitconfig`.
# Refinements welcome.
# Get user input
echo "New repo name:"
read REPONAME