Skip to content

Instantly share code, notes, and snippets.

View davecowart's full-sized avatar

Dave Cowart davecowart

  • Homewood, Alabama
View GitHub Profile
using (var file = new System.IO.StreamReader(script)) {
var fileContent = file.ReadToEnd();
if (scriptType == ScriptType.Stylesheet) {
var fromUri = new Uri(context.Server.MapPath("~/"));
var toUri = new Uri(new FileInfo(script).DirectoryName);
var relativeUri = fromUri.MakeRelativeUri(toUri);
fileContent = fileContent.Replace("url(", "url(/" + relativeUri.ToString() + "/");
}
scriptbody.Append(fileContent);
}
on :channel, /^#{self.nick} roll (\d*)d(\d+)($|[\+\-]\d+$)/ do |m, n, d, mod|
total = 0;
dice = n.to_i == 0 ? 1 : [n.to_i.abs, 10].min
dice.times do
result = (Random.new).rand(1..d.to_i.abs)
m.reply "#{m.user.nick} rolls a #{result}"
total += result
end
unless mod.to_i == 0
@davecowart
davecowart / interbot.rb
Created January 12, 2012 22:31
TWSS Cinch bot
on :message, /(.*)/ do |m, text|
url = "http://127.0.0.1:1337/?text=#{URI.escape(text)}"
result = open(url).read
m.reply "That's what she said!" if result == 'true'
end
@davecowart
davecowart / gist:1689572
Created January 27, 2012 16:18
Crazy-ass date sorting
dates.OrderBy(date => date.Date).GroupBy(d => d.Date).Select(list => list.OrderByDescending(date => date.TimeOfDay)).SelectMany(x => x);
using System.Collections.Generic;
namespace FollowMyBuild.Web.Models.ViewModels.Portable {
public class PortableRecursiveComment {
public PortableRecursiveComment() {
Comments = new List<PortableComment>();
}
public int Id { get; set; }
public IEnumerable<PortableComment> Comments { get; set; }
}
@davecowart
davecowart / Repository.cs
Created March 28, 2012 18:24
Dapper Repository
using System;
using System.Collections.Generic;
using System.Linq;
using Dapper;
namespace Example.Data.Dapper {
public class MessageRepository : RepositoryBase, IMessageRepository {
/// <summary>
/// Gets a single message
/// </summary>
@davecowart
davecowart / TapExtension.cs
Created June 22, 2012 18:02
C# implementation of Ruby's tap method
public static class TapExtension {
public static T Tap<T>(this T obj, Action<T> block) {
block.Invoke(obj);
return obj;
}
}
@davecowart
davecowart / vso.ps1
Created July 3, 2012 15:01
VS Open Function
#If you're in a folder with a solution file, it'll open the solution - otherwise it'll just open Visual Studio
Set-Alias vs "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe"
function vso {
$SolutionFile = @(gci *.sln)[0]
vs $SolutionFile
}
@davecowart
davecowart / regex.m
Created August 27, 2012 22:11
Obj-c YouTube Regex
NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?<=(?:v|i)=)[a-zA-Z0-9-]+(?=&)|(?<=(?:v|i)\\/)[^&\n]+|(?<=embed\\/)[^\"&\n]+|(?<=‌​(?:v|i)=)[^&\n]+|(?<=youtu.be\\/)[^&\n]+" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *link = [post objectForKey:@"link"];
NSTextCheckingResult *match = [regex firstMatchInString:link options:0 range:NSMakeRange(0, [link length])];
NSString *identifier = [link substringWithRange:match.range];
NSString *html = [self embedYouTube:identifier frame:webView.frame];
[webView loadHTMLString:html baseURL:nil];
@davecowart
davecowart / S3FileSystem.cs
Created August 31, 2012 20:13
S3 Implementation of IFileSystem for N2CMS
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
using N2.Engine;