Skip to content

Instantly share code, notes, and snippets.

View pseudomuto's full-sized avatar
📈
☁️ things

David Muto pseudomuto

📈
☁️ things
View GitHub Profile
@pseudomuto
pseudomuto / Guard.cs
Created August 12, 2013 12:15
A simple class for guarding against nulls, etc..
internal static class Guard
{
public static void AgainstNull(string name, object value)
{
if (value == null)
{
throw new ArgumentNullException(name);
}
}
@pseudomuto
pseudomuto / secret_token.rb
Last active December 21, 2015 12:38
Rails Secret Initializer Script. I use this file in `config/initializers/secret_token.rb`
def secure_token
token_file = Rails.root.join(".secret")
unless File.exists?(token_file)
system("rake secret >> #{token_file}")
end
File.read(token_file).chomp
end
@pseudomuto
pseudomuto / 0_simple_class_spec.rb
Last active December 21, 2015 16:09
Blog Code: Drying Out Specs with Shared Examples
require "spec_helper"
describe SimpleClass do
before do
subject.name = "Some Name"
subject.description = "Some Description"
end
its(:name) { should eq("Some Name") }
@pseudomuto
pseudomuto / Feature.cs
Last active March 16, 2017 17:20
Blog Code: Continuous Integration for .NET with Travis and xUnit
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CI.Demo
{
public class Feature
{
public string Name { get; private set; }
@pseudomuto
pseudomuto / Gemfile
Created August 25, 2013 15:56
Blog Code: Testing EmberJS Apps with Rails and QUnit
group :assets do
...
gem "handlebars-source"
gem 'ember-rails'
gem 'ember-source', '1.0.0.rc6.3'
gem 'qunit-rails'
...
end
@pseudomuto
pseudomuto / stack.c
Last active November 17, 2019 10:52
Blog Code: Implementing a Generic Stack in C
#include <stdlib.h>
#include <assert.h>
#include "stack.h"
void stack_new(stack *s, int elementSize, freeFunction freeFn)
{
s->list = malloc(sizeof(list));
// make sure the malloc call didn't fail...
assert(s->list != NULL);
@pseudomuto
pseudomuto / list.c
Created August 25, 2013 16:30
Blog Code: Implementing a Generic Linked List in C
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "list.h"
void list_new(list *list, int elementSize, freeFunction freeFn)
{
assert(elementSize > 0);
list->logicalLength = 0;
@pseudomuto
pseudomuto / HtmlHelperExtensions_methods.cs
Created August 25, 2013 17:11
Blog Code: MVC Razor Helpers Using Delegates
public static HelperResult RenderIf<TType>(this HtmlHelper html, Func<TType, HelperResult> template, TType item, bool condition)
{
return html.RenderIf(template, new TType[] { item }, condition);
}
public static HelperResult RenderIf<TType>(this HtmlHelper html, Func<TType, HelperResult> template, IEnumerable<TType> items, bool condition)
{
if (condition)
{
return new HelperResult(writer =>
@pseudomuto
pseudomuto / CacheManager.cs
Created August 25, 2013 17:19
Blog Code: Efficient Thread-Safe Caching with ASP.NET
public class CacheManager
{
// CLR guarantees thread-safety during initialization
private static Dictionary<string, object> CacheKeyDictionary = new Dictionary<string, object>();
public static TObj GetCachedObject<TObj>(string cacheKey, Func<TObj> creator) where TObj : class
{
var cache = HttpContext.Current.Cache;
var obj = cache[cacheKey] as TObj;
@pseudomuto
pseudomuto / NSDate+OData.h
Created August 25, 2013 18:22
Blog Code: NSData from OData
#import <Foundation/Foundation.h>
@interface NSDate (OData)
- (id)initWithODataString:(NSString *)dateString;
- (NSString *)toODataQueryFormat;
+ (NSDate *)dateFromString:(NSString *)dateString;
@end