Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Reflection;
using System.Text;
using Common;
using Funq;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface;
@bhameyie
bhameyie / AppHost.cs
Last active December 21, 2015 05:38
Composable Services using Service Stack
using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.IO;
using System.Linq;
using System.Configuration;
using System.Collections.Generic;
using System.Web.Mvc;
using Common;
using ServiceStack.Mvc;
@bhameyie
bhameyie / Restorinator.cs
Last active December 19, 2015 19:48
Restore database from backup with Sql Server
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
public class Restorinator{
@bhameyie
bhameyie / AwsExtensions.cs
Last active December 18, 2015 21:19
File Upload with Url retrieval using AWS S3
public static class AwsExtensions
{
public static string Upload(this AmazonS3 client,UploadImageRequest request)
{
var uploadRequest = new PutObjectRequest { InputStream = request.Image };
uploadRequest.WithBucketName(request.Bucket).WithKey(request.FileIdentifier);
var response = client.PutObject(uploadRequest);
@bhameyie
bhameyie / Multithread.cs
Last active December 18, 2015 16:59
Simple example on how to spawn and wait for a new thread
var resetEvent = new ManualResetEvent(false);
ThreadPool.QueueUserWorkItem(
arg =>
{
var task = new MyTaskRunner();
task.Run(data);
resetEvent.Set();
});
@bhameyie
bhameyie / LoginFormViewModel.coffee
Last active December 18, 2015 15:08
Using Coffeescript with KnockoutJS
class LoginFormViewModel
constructor: -> #from my many attempts, things works out best when you set them up from the constructor
@email= ko.observable("")
@pass= ko.observable("")
@logon= => #notice the fat arrow here
$.post '/Account/Login',
userId: @email()
password: @pass()
(data) -> $('body').append "Successfully posted to the page."
@bhameyie
bhameyie / LoginViewModel.html
Created June 18, 2013 02:07
Coffeescript with KnockoutJS part 2
<form class="form-horizontal" method="POST" id="login-form" action="/Account/Login">
<div class="control-group">
<label class="control-label" for="userId">Email</label>
<div class="controls">
<input id="userId" name="userId" data-bind="value: email" type="text" placeholder="Email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="password">Password</label>
<div class="controls">
@bhameyie
bhameyie / AccountModule.cs
Created June 17, 2013 01:21
A simple account module to handle logging in and off
public class AccountModule : NancyModule
{
private readonly IAuthenticationServiceClient m_authenticationService;
public AccountModule(IAuthenticationServiceClient authenticationService)
: base("/Account")
{
m_authenticationService = authenticationService;
Post["/Login"] = args =>
{
@bhameyie
bhameyie / BlogBootstrapper.cs
Last active December 18, 2015 13:59
Simple Blog bootstrapper
public class BlogBootstrapper : AutofacNancyBootstrapper
{
protected override void ApplicationStartup(Autofac.ILifetimeScope container, Nancy.Bootstrapper.IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
#if DEBUG
StaticConfiguration.DisableErrorTraces = false;
#endif
CookieBasedSessions.Enable(pipelines);
@bhameyie
bhameyie / BloggerModule.cs
Last active December 18, 2015 13:59
A simple Secured Module
public class BloggerModule : SecureModule
{
private readonly IBlogServiceClient m_blogService;
public BloggerModule(IBlogServiceClient blogService)
: base("/blog")
{
m_blogService = blogService;
Get["/{Id}"] = parameters =>
{