Skip to content

Instantly share code, notes, and snippets.

var v1 = new VectorMagnitudeAngle(10, Math.PI/4)
var v2 = new Vector(-10/Math.sqrt(2), 10/Math.sqrt(2))
var v3 = v1.Add(v2);
console.log(v3.X()+ ", " +v3.Y())
//outputs: 8.659560562354932e-16, 14.14213562373095
function VectorMagnitudeAngle(r, theta) {
this.X = function() {
return r * Math.cos(theta)
}
this.Y = function() {
return r * Math.sin(theta)
}
this.Add = function(addend) {
function Vector(x, y) {
this.X = function() {
return x;
}
this.Y = function() {
return y;
}
this.Add = function(addend) {
function Vector(x, y) {
this.x = x;
this.y = y;
this.Add = function(addend) {
return new Vector(this.x + addend.x, this.y+addend.y)
}
}
class Vector {
private readonly double _x;
private readonly double _y;
public Vector(double x, double y) {
_x = x;
_y = y;
}
public Vector Add(Vector addend) {
@FreekPaans
FreekPaans / ServicePointMonitor.cs
Last active August 29, 2015 14:24
monitors the servicepointmanager
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
namespace WadGraphEs.MetricsEndpoint.Console {
using System.Reflection;
@FreekPaans
FreekPaans / printservicepointconnections.cs
Created July 7, 2015 06:48
This prints the connections currently open in a servicepoint
private static void PrintServicePointConnections(ServicePoint sp) {
var spType = sp.GetType();
var privateOrPublicInstanceField = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance;
var connectionGroupField = spType.GetField("m_ConnectionGroupList",privateOrPublicInstanceField);
var value = (Hashtable)connectionGroupField.GetValue(sp);
foreach(var key in value.Keys) {
var connectionGroup = value[key];
var groupType = connectionGroup.GetType();
var listField = groupType.GetField("m_ConnectionList",privateOrPublicInstanceField);
var listValue = (ArrayList)listField.GetValue(connectionGroup);
@FreekPaans
FreekPaans / generatepfxcer.cs
Created April 7, 2015 14:13
Generate PFX + cer
const string password= "testpassword";
var pfx= PFXGenerator.GeneratePfx("testcertificate", password);
File.WriteAllBytes("cert.pfx", pfx);
File.WriteAllBytes("cert.cer", PFXGenerator.GetCertificateForBytes(pfx,password));
@FreekPaans
FreekPaans / PFXGenerator.cs
Last active August 29, 2015 14:18
Class to generate X.509 certificates using Mono.Security
public class PFXGenerator {
//adapted from https://github.com/mono/mono/blob/master/mcs/tools/security/makecert.cs
public static byte[] GeneratePfx(string certificateName,string password) {
byte[] sn = GenerateSerialNumber();
string subject = string.Format("CN={0}",certificateName);
DateTime notBefore = DateTime.Now;
DateTime notAfter = DateTime.Now.AddYears(20);
RSA subjectKey = new RSACryptoServiceProvider(2048);
public AddCommissionedEmployee(EmployeeId empId,Name name, Address address, Salary salary, CommissionRate commissionRate)
: base(empId, name,address) {
_salary = salary;
_commissionRate = commissionRate;
}