Skip to content

Instantly share code, notes, and snippets.

View Jeff-Lewis's full-sized avatar

Jeff Lewis Jeff-Lewis

  • StreetConnect & SchoolBee
  • NYC
View GitHub Profile
@Jeff-Lewis
Jeff-Lewis / ConsoleBufferToHtml.ps1
Created March 24, 2017 05:08 — forked from devlead/ConsoleBufferToHtml.ps1
ConsoleBufferToHtml.ps1 - Powershell script to dump console buffer as html to file.
<#
.SYNOPSIS
This is a Powershell script to dump console buffer as html to file.
.DESCRIPTION
This Powershell script will iterate over the current console buffer and
output it as html preserving colors.
.PARAMETER FilePath
SELECT
o.name as 'TableName' ,
SUM (
CASE
WHEN (index_id < 2) THEN row_count
ELSE 0
END
) as 'RowCount',
LTRIM (STR (SUM (reserved_page_count)/1024 * 8, 15, 0) + ' MB') as'Reserved MB',
/* @flow */
declare module 'dynamoose' {
declare type Throughput = number | ({
read: number;
} | {
write: number;
});
declare type ThroughputConfig = {
throuput: Throughput;
// Custom made dynamoose declaration file.
declare module "dynamoose" {
export function local(url: string): void;
export function model<DataSchema, KeySchema, ModelSchema extends Model<DataSchema>>(
modelName: string,
schema: Schema,
options?: ModelOption
): ModelConstructor<DataSchema, KeySchema, ModelSchema>;
export function setDefaults(options: ModelOption): void;
@Jeff-Lewis
Jeff-Lewis / wordpress-plugin-svn-to-git.md
Created November 11, 2016 21:47 — forked from kasparsd/wordpress-plugin-svn-to-git.md
Using Git with Subversion Mirroring for WordPress Plugin Development
@Jeff-Lewis
Jeff-Lewis / mongooseUniquenessValidation.js
Created August 25, 2016 22:28 — forked from edinella/mongooseUniquenessValidation.js
Mongoose uniqueness validator, case-sensitive or not
// context
var mongoose = require('mongoose');
mongoose.connect('mongodb://...');
/**
* Generates Mongoose uniqueness validator
*
* @param string modelName
* @param string field
* @param boolean caseSensitive
@Jeff-Lewis
Jeff-Lewis / domain-postmortem.md
Created August 8, 2016 18:41
node domain postmortem

domain Module Postmortem

Usability Issues

Implicit Behavior

It's possible for a developer to create a new domain and then simply run domain.enter(). Which then acts as a catch-all for any exception in the future that couldn't be observed by the thrower. Allowing a module author to intercept the exceptions of unrelated code in a different module. Preventing

@Jeff-Lewis
Jeff-Lewis / output.md
Created July 22, 2016 15:31 — forked from brycebaril/output.md
process.nextTick vs setImmediate

@mafintosh asks: "Does anyone have a good code example of when to use setImmediate instead of nextTick?"

https://twitter.com/mafintosh/status/624590818125352960

The answer is "generally anywhere outside of core".

process.nextTick is barely asynchronous. Flow-wise it is asynchronous, but it will trigger before any other asynchronous events can (timers, io, etc.) and thus can starve the event loop.

In this script I show a starved event loop where I just synchronously block, use nextTick and setImmediate

"use strict";
var clsModule = require("continuation-local-storage");
const superagent = require("superagent");
const assert = require("assert");
var http = require("http");
var keepAlive = process.env.KEEP_ALIVE !== "0";
var httpAgent = new http.Agent({
keepAlive: keepAlive,
'use strict';
const asyncWrap = process.binding('async_wrap');
const fs = require('fs');
//
// Track
//
// 1. Setup a global variable to track the context of the async_hook_init_function
let callbackContext = 'root';
process.nextTick(function () {