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
using System; | |
using System.Linq; | |
using System.Net; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace Server | |
{ | |
public static class Program |
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
// cons :: a -> b -> (a -> b -> t) -> t | |
// cons a b = \x -> x a b | |
static Func<Func<TA, TB, dynamic>, dynamic> Cons<TA, TB>(TA a, TB b) | |
{ | |
return f=>f(a,b); | |
} | |
// NOTE: you can not write: | |
// static Func<Func<TA, TB, TC>, TC> Cons<TA, TB>(TA a, TB b) | |
// { |
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
// 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
// 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
private static byte[] GetMultipartFormData( | |
IDictionary<string, string> parameters, | |
string caName, | |
byte[] fileContents, | |
string boundary) | |
{ | |
var formDataStream = new MemoryStream(); | |
byte[] formData; | |
using(formDataStream) |
NewerOlder