Skip to content

Instantly share code, notes, and snippets.

@KyleGobel
KyleGobel / PathUtilities.cs
Last active August 29, 2015 14:02
Mapping Path Extensions for easily getting the correct Paths in .net projects. Idea taken from ServiceStack.
using System;
using System.IO;
/// <summary>
/// Mapping Path Extensions
/// </summary>
/// Gist Url: https://gist.github.com/KyleGobel/4b0f2b93014cae7bb52b
public static class PathUtilities
{
private static string MapAbsolutePath(string relativePath, string appendPartialPathModifier)
@KyleGobel
KyleGobel / AnyFile.cs
Created June 9, 2014 21:27
Shows how to create a Log4NetLogger using the ServiceStack logging interfaces
public class ExampleController
{
public ILog Logger {get; set;}
public void AnyMethod(int param1, int param2)
{
Logger.DebugFormat("Parameters are {0}, and {1}", param1, param2);
}
}
@KyleGobel
KyleGobel / HttpUtilExtensions.cs
Created April 27, 2014 06:41
Will service stack take me?? Still missing some PCL stuff, but I don't think this can be done PCL anyway..or if it can it's alot harder and I don't know how
public static class HttpUtilExtensions
{
public static Task<string> PostJsonToUrlAsync(this string url, object data,
Action<HttpWebRequest> requestFilter = null, Action<HttpWebResponse> responseFilter = null,
Action<string> callback = null)
{
return SendStringToUrlAsync(url, method: "POST", requestBody: data.ToJson(), contentType: MimeTypes.Json, accept: MimeTypes.Json,
requestFilter: requestFilter, responseFilter: responseFilter, callback: callback);
}
@KyleGobel
KyleGobel / HipchatMessage.cs
Created April 5, 2014 03:01
Proposed Model: This is what the bot will receive from redis for each Message
namespace Hipchat.Models
{
public class HipchatMessage
{
public int RoomId { get; set; }
public string RoomName { get; set; }
public string MessageSent { get; set; }
public string MentionName { get; set; }
public DateTime DateSent { get; set; }
public string FileUrl { get; set; }
using Xunit;
public class MyTests
{
[Fact] //This means this is a test
public void TestMyGetMethodWorks()
{
var journalService = new JournalService(/* not sure what kinda constructor you have */);
@KyleGobel
KyleGobel / Watermark.cs
Created December 6, 2013 16:47
Watermark For Textbox
/// <summary>
/// Class that provides the Watermark attached property
/// </summary>
public static class WatermarkService
{
/// <summary>
/// Watermark Attached Dependency Property
/// </summary>
public static readonly DependencyProperty WatermarkProperty = DependencyProperty.RegisterAttached(
"Watermark",
var self = this;
var uglyVm = {
object1 : ko.observable("hello there"),
object2 : ko.observable(new (function () {
var self = this;
self.subObject1 = ko.observable("goodbye now");
})(self))
};
@KyleGobel
KyleGobel / RestSharpRX.cs
Created November 22, 2013 02:29
Use RestSharp with ReactiveExtensions and Reactive UI
private IObservable<List<Client>> GetClients()
{
var request = new RestRequest("client/", Method.GET);
var subject = new AsyncSubject<List<Client>>();
_restClient.ExecuteAsync<ClientResponseDTO>(request, response =>
{
subject.OnNext(response.Data.Entities);
subject.OnCompleted();
});
@KyleGobel
KyleGobel / ConvertExample.cs
Created November 20, 2013 20:12
Convert Types of an Expression
class Foo {
public int Value { get; set; }
}
class Bar {
public int Value { get; set; }
}
static class Program {
static void Main() {
Expression<Func<Foo, bool>> predicate =
x => x.Value % 2 == 0;
(function($) {
$.fn.nodoubletapzoom = function() {
$(this).bind('touchstart', function preventZoom(e) {
var t2 = e.timeStamp
, t1 = $(this).data('lastTouch') || t2
, dt = t2 - t1
, fingers = e.originalEvent.touches.length;
$(this).data('lastTouch', t2);
if (!dt || dt > 500 || fingers > 1) return; // not double-tap