const groupBy = key => array =>
array.reduce((objectsByKeyValue, obj) => {
const value = obj[key];
objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
return objectsByKeyValue;
export async function wrapErr<T>(p: Promise<T>): Promise<[any, T | undefined]> { | |
try { | |
return [undefined, await p]; | |
} catch (err) { | |
return [err, undefined]; | |
} | |
} | |
let [err, value] = await wrapErr(somePromiseFunc()); | |
if (err) { |
Zach Caceres
Javascript does not have the typical 'private' and 'public' specifiers of more traditional object oriented languages like C# or Java. However, you can achieve the same effect through the clever application of Javascript's function-level scoping. The Revealing Module pattern is a design pattern for Javascript applications that elegantly solves this problem.
The central principle of the Revealing Module pattern is that all functionality and variables should be hidden unless deliberately exposed.
Let's imagine we have a music application where a musicPlayer.js file handles much of our user's experience. We need to access some methods, but shouldn't be able to mess with other methods or variables.
using Microsoft.Extensions.Logging; | |
using Moq; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using Xunit; | |
namespace Knaap.Utilties | |
{ |
- Install cmder_mini (msysgit is already installed, so no need for full version)
- In Cmder, open settings:
Win + Alt + P
- Under Startup > Tasks, add a task called
{bash}
with the following settings:- Task parameters (set icon):
- For Cmder icon:
/icon "%CMDER_ROOT%\cmder.exe"
- For Git icon:
/icon "C:\Program Files (x86)\Git\etc\git.ico"
- For Cmder icon:
- Commands (open Git's bash shell):
- Task parameters (set icon):
"C:\Program Files (x86)\Git\bin\sh.exe" -l -new_console:d:%USERPROFILE%
A lot of these are outright stolen from Edward O'Campo-Gooding's list of questions. I really like his list.
I'm having some trouble paring this down to a manageable list of questions -- I realistically want to know all of these things before starting to work at a company, but it's a lot to ask all at once. My current game plan is to pick 6 before an interview and ask those.
I'd love comments and suggestions about any of these.
I've found questions like "do you have smart people? Can I learn a lot at your company?" to be basically totally useless -- everybody will say "yeah, definitely!" and it's hard to learn anything from them. So I'm trying to make all of these questions pretty concrete -- if a team doesn't have an issue tracker, they don't have an issue tracker.
I'm also mostly not asking about principles, but the way things are -- not "do you think code review is important?", but "Does all code get reviewed?".
namespace System.Collections.Specialized | |
{ | |
using System.Collections.Generic; | |
using System.Linq; | |
/// <summary> | |
/// Represents a collection of associated String keys and String values that can be accessed either with the key | |
/// or with the index. | |
/// </summary> | |
public class NameValueCollection : IEnumerable<KeyValuePair<string, string>> |
namespace My.Common | |
{ | |
using System; | |
using System.Collections.Generic; | |
using System.Threading; | |
using System.Threading.Tasks; | |
public static class AsyncHelpers | |
{ | |
/// <summary> |
-- Firstly, remove PRIMARY KEY attribute of former PRIMARY KEY
ALTER TABLE <table_name> DROP CONSTRAINT <table_name>_pkey;
-- Then change column name of your PRIMARY KEY and PRIMARY KEY candidates properly.
ALTER TABLE <table_name> RENAME COLUMN <primary_key_candidate> TO id;