Skip to content

Instantly share code, notes, and snippets.

View g0t4's full-sized avatar
๐Ÿ

Wes Higbee g0t4

๐Ÿ
View GitHub Profile
@g0t4
g0t4 / gist:4271829
Created December 12, 2012 21:34
Why manually replace crap over and over, why not write code to do it if it saves time :)
[Test]
public void METHOD_SCENARIO_EXPECTATION()
{
var path = @"..\..\..\View.spark";
var code = File.ReadAllLines(path);
for (int lineNumber = 0; lineNumber < code.Length; lineNumber++)
{
var line = code[lineNumber];
var classControlLabel = "class=\"control-label\"";
if(line.Contains(classControlLabel))
@g0t4
g0t4 / gist:4271057
Created December 12, 2012 20:01
Mongodb editing file information with c# driver
//Easier to just pull the file collection and edit the files documents, just be careful, example:
public void SaveMetadata(string id, MetadataJson metadata)
{
var gridFs = FilesContext.GetGridFs();
var files = gridFs.Database.GetCollection(gridFs.Settings.FilesCollectionName);
var file = files.FindOneById(new BsonObjectId(id));
var metadataDocument = file["metadata"].AsBsonDocument;
metadataDocument.Set("comment", metadata.comment ?? string.Empty);
@g0t4
g0t4 / gist:4261025
Created December 11, 2012 18:56
KISS & AJAX Deletes
// I run across this type of code often (note ASP.Net MVC)
[HttpPost]
public string Delete(ObjectId id)
{
var record = _Database.Get<Record>(id);
if (record == null)
{
return "No matching record!";
}
@g0t4
g0t4 / gist:3790130
Created September 26, 2012 19:43
Mapping a collection of Components in FluentNhibernate
public class Approved
{
public virtual Guid Id { get; set; }
public virtual IEnumerable<Entry> Entries { get; set; }
}
public class Entry
{
public virtual Guid Id { get; set; }
public virtual Guid Description { get; set; }
@g0t4
g0t4 / gist:3790082
Created September 26, 2012 19:36
Mapping a collection of Guids in FluentNHibernate
public class Approved
{
public virtual Guid Id { get; set; }
public virtual IEnumerable<Guid> EntryIds { get; set; }
}
// Mapping, Table specifies the table name to use, element specifies the column the Guid is stored in, KeyColumn specifies the foreign key in the table to link back to the parent Approved item
HasMany(x => x.EntryIds)
.Table("ApprovedEntryIds")
@g0t4
g0t4 / NotifyIfTakesMoreThan
Created September 20, 2012 21:27
NotifyIfTakesMoreThan
// Sometimes it's easier to make assumptions about performance as a trade off for simplified code, but why not make it easy to notify us when that assumption is violated? Next step might be StopAndNotify
// Usage
using (new NotifyIfTakesMoreThan(TimeSpan.FromMinutes(5), "XYZ Import - checking all data instead of more complex code to optimize it"))
{
//operation
}
// Implementation
@g0t4
g0t4 / gist:1074245
Created July 10, 2011 03:55
Rake task to install missing packages from nuget when not checking in packages
desc "Setup dependencies for nuget packages"
task :dep do
package_folder = File.expand_path('src\\packages')
packages = FileList["**/packages.config"].map{|f| File.expand_path(f)}
packages.each do |file|
sh %Q{nuget install #{file} /OutputDirectory #{package_folder}}
end
end