Skip to content

Instantly share code, notes, and snippets.

@FreekPaans
FreekPaans / java-heap.sh
Created March 10, 2015 12:26
print java heap usage
#http://www.journaldev.com/2856/java-jvm-memory-model-and-garbage-collection-monitoring-tuning
jstat -gc 27037 | tail -1 | awk '{ print $3 + $4 + $6 + $8}'
public void Execute() {
var employee = PayrollDatabase.Instance.GetEmployee(_empId);
if(employee!=null) {
Change(employee);
}
}
public void Execute() {
var employee = PayrollDatabase.Instance.GetEmployee(_empId);
if(employee!=Employee.NotFound) {
Change(employee);
}
}
public void Execute() {
EmployeeResult result = PayrollDatabase.Instance.GetEmployee(_empId);
if(result!=EmployeeResult.NotFound) {
Change(result.Employee);
}
}
string PrintMaxValue() {
int maxValue = intSet.Max();
if(maxValue == 0) {
return "Not available";
}
return maxValue.ToString();
}
public AddCommissionedEmployee(int empId,string name,string address,decimal salary,decimal commissionRate)
: base(empId, name,address) {
_salary = salary;
_commissionRate = commissionRate;
}
public AddCommissionedEmployee(EmployeeId empId,Name name, Address address, Salary salary, CommissionRate commissionRate)
: base(empId, name,address) {
_salary = salary;
_commissionRate = commissionRate;
}
@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);
@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 / 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);