- RAM 100 ns
- SSD 150 mcs
- HDD 10 ms
- Same DC 1 ms
- Global network 100 ms
- TLS handshake 20 ms
- Warm read 10 ms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // How to import from sequelize | |
| const { Sequelize, DataTypes } = require('sequelize'); | |
| // How to instantiate a connection pool to sqlite | |
| const sequelize = new Sequelize('sqlite::memory:', { logging: false }); | |
| // How to define a table | |
| const Account = sequelize.define('Account', { | |
| type: { type: DataTypes.ENUM('savings', 'checking'), allowNull: false }, | |
| name: { type: DataTypes.STRING, allowNull: false }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function cloneThenDeleteNullValues(obj: object) { | |
| const res = Object.entries(obj).reduce((acc: object, [k, v]) => { | |
| if (typeof v !== 'undefined' && v != null) { | |
| acc[k] = v; | |
| } | |
| return acc; | |
| }, {} as object); | |
| return res; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This is experimental! | |
| def type_as_str(v): | |
| return type(v).__name__ | |
| def deep_merge_mappings(a, b, *rest, sequence_behavior='append'): | |
| """ | |
| merges b into a and return merged result | |
| sequence_behavior - specifies what happens if a & b are (or contain) non-string sequences. It must be one of the following: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Pull values from observables (instead of push-subscribe). | |
| // A pull is like a one-time subscription. | |
| // Typically, the onNext argument to pull invokes pull again before finishing. | |
| // This negates the need for a while loop; | |
| // besides, such a loop will pull multiple times without waiting for prior pulls to finish processing. | |
| // There's a bug in this somewhere. A pull after a buffer overflow should first empty buffer, and then err. | |
| // Instead, we get deadlock. Weird. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // I originally made this, trying to solve the problem where I had to use Iterator instead of Observable | |
| // when feeding data to concurrenct workers. | |
| // I really think observable is the wrong thing here. | |
| // Typically, Observables push the values to observers. | |
| // As new values show up, it spawns however many concurrenct invocations of Observer.next it needs. | |
| // Workers typically want to pull each value. | |
| // So, Iterator makes sense. | |
| // Hmm, but ... what if we wanted to pull values from an Observable? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Inspired by VError. | |
| import { none, Option, some, option, None } from "ts-option"; | |
| import * as extsprintf from 'extsprintf'; | |
| import { defined, getType, toPrintable } from "./utilities"; | |
| interface IError { | |
| message: string; | |
| name: string; | |
| stack?: string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*** | |
| Inspired by http://choly.ca/post/typescript-json/ , except this is only for parsing (not stringifying). | |
| If you use this, I'd appreciate some credit and some feedback ... but neither are required. | |
| Copyright license (Apache) is at the bottom. | |
| NOTE THIS WILL PROBABLY NOT WORK if your uglifier changes constructor/class names. This is a pretty common thing, and it makes me sad. | |
| The main problem this solves is that JSON.stringify returns plain old JS objects, not TS instances. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Microsoft.EntityFrameworkCore; | |
| using Microsoft.VisualStudio.TestTools.UnitTesting; | |
| using Moq; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| ... | |
| private static Mock<DbSet<T>> MockDbSet<T>(IEnumerable<T> ls) where T : class | |
| { |
NewerOlder