Skip to content

Instantly share code, notes, and snippets.

@pdoran
pdoran / ConnectionFactory.cs
Created January 12, 2015 22:11
Count messages in a RabbtiMQ Queue
public class RawBrokerConnectionFactory {
private readonly ConnectionFactory _ConnFactory = new ConnectionFactory();
public RawBrokerConnectionFactory(string host, string username, string password) {
ConfigureConnetionFactory(host, username, password);
}
private void ConfigureConnetionFactory(string host, string username, string password) {
//An outline example
public string GetSomethingFromDBAndFormat(Guid id){
var obj = Session.Get<Something>(id);
var formatString = GetNameFormat(obj);
formatString += GetNamesFromChildren(obj);
return formatString;
}
private string GetNameFormat(Something obj){
//A book example
public string GetSomethingFromDBAndFormat(Guid id){
//Get item from DB
var obj = Session.Get<Something>(id);
var formatString = "";
//check if it is null
if(obj!=null) {
//add the name to return string
formatString += string.Format("Name: {0}",obj.Name);
@pdoran
pdoran / OAuthTokenUtility.cs
Created July 19, 2014 01:48
Utility to generate an Oauthtoken with DotNetOAuth given a certificate public/private key pair
public class OAuthTokenUtility {
private readonly RSACryptoServiceProvider _PublicProvider;
private readonly RSACryptoServiceProvider _PrivateProvider;
public OAuthTokenUtility(X509Certificate2 certificate) {
_PublicProvider = (RSACryptoServiceProvider)certificate.PublicKey.Key;
_PrivateProvider = (RSACryptoServiceProvider)Certificate.PrivateKey;
}
public string Token(string username, double numberOfMinutesToExpireIn, IEnumerable<string> tokens) {
@pdoran
pdoran / CachedGenericReflection.cs
Created July 6, 2014 22:06
CachedGenericReflection.cs
private Dictionary<Type, ConstructorInfo> _CachedLookup;
private object GenericMessageCreationFromCache(object entity) {
Type entityType = entity.GetType();
ConstructorInfo genericConstructor = null;
if (!_CachedLookup.TryGetValue(entityType, out genericConstructor)) {
Type genericType = typeof(Message<>);
Type specificType = genericType.MakeGenericType(entityType);
Type[] constructorParams = new[] { entityType };
genericConstructor = specificType.GetConstructor(constructorParams);
@pdoran
pdoran / GenericReflection.cs
Last active August 29, 2015 14:03
Generic Reflection
public void OnSave(object entity,
object id,
object[] state,
string[] propertyNames,
IType[] types)
{
Type entityType = entity.GetType();
Type genericType = typeof(Message<>);
Type specificType = genericType.MakeGenericType(entityType);
Type[] constructorParams = new[] { entityType };
@pdoran
pdoran / GenericClassExample.cs
Last active August 29, 2015 14:03
Generic Class
public class NHInterceptor : EmptyInterceptor
{
public void OnSave(object entity,
object id,
object[] state,
string[] propertyNames,
IType[] types)
{
var genericObj = new Message<?>(entity);
> sqlite3@2.2.0 install /root/tmp/tmp-32055qma3100/build/package/node_modules/gh
ost/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build
node-pre-gyp http GET http://node-sqlite3.s3.amazonaws.com/Release/node_sqlite3-
v2.2.0-node-v11-sunos-x64.tar.gz
node-pre-gyp http 404 http://node-sqlite3.s3.amazonaws.com/Release/node_sqlite3-
v2.2.0-node-v11-sunos-x64.tar.gz
node-pre-gyp ERR! Source compile required: 404 status code downloading tarball
make: Entering directory `/root/tmp/tmp-32055qma3100/build/package/node_modules/