This file contains 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
Setup: | |
1. Client provides server with Username and P = password | |
2. Server generates N = large Nonce (128bits+), R = 0 | |
3. Server computes Q = H(H(P,N)) and stores (Username, N, Q, R) | |
4. Server send N to client | |
Login: | |
1. Client sends login request to server with Username | |
2. Server generates R = HMAC(large Nonce (128bits) + timestamp, ServerSecret) | |
3. Server sends R and N (looked up from Username) to the client |
This file contains 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() { | |
// using `value =>` makes value the 'this' of the functions below | |
const MaybeMonad = value => ({ | |
value, | |
flatMap(f) { | |
// The point of the maybe is to prevent problems. | |
// Having a "nothing value" indicates a problem, so we short circuit | |
// the return. | |
// This is like SQL NULL in that any operation on nothing |
This file contains 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
CREATE FUNCTION array_xirr(flows double precision[], force_period double precision) RETURNS double precision | |
LANGUAGE plpgsql | |
AS | |
$$ | |
DECLARE | |
v FLOAT8; | |
rate FLOAT8; | |
firstday FLOAT8; | |
period FLOAT8; | |
exp FLOAT8; |
This file contains 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
var webHeaderCollectionType = typeof(WebHeaderCollection); | |
System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(webHeaderCollectionType.TypeHandle); | |
try | |
{ | |
var hInfoFieldInfo = webHeaderCollectionType.GetField("HInfo", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Static); | |
var hInfo = hInfoFieldInfo.GetValue(null); | |
var hInfoType = hInfo.GetType().GetField("HeaderHashTable", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Static); | |
var hashtableOfHeaderInfos = hInfoType.GetValue(hInfo) as Hashtable; | |
foreach (var e in hashtableOfHeaderInfos.Values) | |
{ |
This file contains 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 can be put in [repo]/.git/config for local settings | |
# or ~/.gitconfig for global settings | |
# create a difftool "nodiff" that just returns true | |
# this path is for Mac. On linux it's /bin/true i guess | |
[diff "nodiff"] | |
command = /usr/bin/true | |
# make git ignore white space differences, many different possibilites here |
This file contains 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
// Do not do: | |
var l = new List<Action>{ f, g, h }; | |
l.ForEach(x=>x()); | |
// Instead of: | |
f(); | |
g(); | |
h(); |
This file contains 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
// Do not do: | |
enum What { A, B, C }; | |
void F(string data, What what) | |
{ | |
switch (what) { | |
case A: DoA(data); break; | |
case B: DoB(data); break; | |
case C: DoC(data); break; | |
} |
This file contains 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
// do not write: | |
if (!expr) | |
{ | |
return false; | |
} | |
return true; | |
// instead of |
This file contains 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
private static byte[] GetMultipartFormData( | |
IDictionary<string, string> parameters, | |
string caName, | |
byte[] fileContents, | |
string boundary) | |
{ | |
var formDataStream = new MemoryStream(); | |
byte[] formData; | |
using(formDataStream) |
This file contains 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
var policy = new JObject(); | |
policy["expiration"] = DateTime.UtcNow.AddMinutes(10).ToString("u").Replace(" ", "T"); | |
var cond = new JArray(); | |
policy["conditions"] = cond; | |
cond.Add(new JObject {{"bucket", Bucket}}); | |
cond.Add(new JObject {{"key", filename}}); | |
cond.Add(new JObject {{"acl", "public-read"}}); | |
cond.Add(new JObject {{"Content-Type", "image/jpeg"}}); | |
cond.Add(new JArray("content-length-range", 0, 1024*1024)); |
NewerOlder