Skip to content

Instantly share code, notes, and snippets.

View kocubinski's full-sized avatar

Matt Kocubinski kocubinski

View GitHub Profile
@kocubinski
kocubinski / FileSystemCache.cs
Created January 13, 2016 17:05
A simple write-invalidated cache for JSON on the file system.
public interface ICache<out T>
{
T Get(string key);
}
public class CacheObject<T>
{
public T Value { get; set; }
public DateTime CachedDate { get; set; }
@kocubinski
kocubinski / ac-web.el
Last active August 29, 2015 14:02
Auto-complete css class names from CSS files in project
(require 'find-file-in-project)
(defvar css-regexp "\\.\\(-?[_a-zA-Z]+[_a-zA-Z0-9-]*\\)\\s-*{")
(defun parse-css-class-names ()
(make-local-variable 'ffip-patterns)
(setq ffip-patterns '("*.css"))
(let (matches)
(dolist (f (mapcar 'cdr (ffip-project-files)))
;; Dynamic form population based on Christophe Grand's suggestions found here:
;; http://bit.ly/72NkNS
(ns dynamic-form
(:refer-clojure :exclude [empty complement])
(:use net.cgrand.enlive-html)
(:import [java.io File]))
(defn populate-select [options]
(fn [node]
// ## Theme and UserControl Inversion of Control
//
// BaseClasses or Interfaces which UserControls derive from are bound to an implemenation for a given theme.
// This gives complete flexibility over which programs are using which controls, and
// a container to tie it all together rather than just ConfigKeys
// and 'if..then' statements sprinkled throughout the codebase. Pages query ThemeService (see *Resolve* method)
// for which UserControl to render, and based on the current program a path to the proper UserControl is returned.
//
// In this case ThemeService is our IOC container, and the bindings are defined below in C#.
// Currently there are two themes ("Default" or "Facelift"), and are put in a static hash-table. When *Resolve* is
@kocubinski
kocubinski / site_config.php
Last active January 1, 2016 22:49
PHP for managing SiteConfiguration tables.
<?php
/*
This code is meant to function with two tables like:
config_key
| id | key_name | default_value |
|----+-------------+---------------|
| 1 | ProgramName | s:0:""; |
| 2 | IsEnabled | b:0; |
@kocubinski
kocubinski / RollbackAttribute.cs
Created August 27, 2013 13:34
NUnit Attribute to Rollback a transaction contained in the tagged method.
/// <summary>
/// Rollback Attribute wraps test execution into a transaction and cancels the transaction once the test is finished.
/// You can use this attribute on single test methods or test classes/suites
/// </summary>
public class RollbackAttribute : Attribute, ITestAction
{
private TransactionScope _transaction;
public void BeforeTest(TestDetails testDetails)
{
@kocubinski
kocubinski / cprint.clj
Created May 12, 2013 16:23
ClojureCLR println with colors in Windows cmd.exe
(assembly-load "ClojureClrEx")
(ns clync.core
(:use [clojure.clr.pinvoke :only [dllimports]]))
(dllimports
"Kernel32.dll"
(GetStdHandle IntPtr [Int32])
(SetConsoleTextAttribute Boolean [IntPtr UInt32]))
@kocubinski
kocubinski / ConfigProvider.tt
Created May 3, 2013 20:10
T4 Text Template .ttinclude to find and parse app.config for a connection string.
<#@ Assembly Name="EnvDTE" #>
<#@ Assembly Name="System.Configuration.dll" #>
<#@ import namespace="System.Configuration" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ IntelliSenseLanguage processor="tangibleT4Editor" language="C#" #>
<#+
string GetConnectionString()
{
var host = (IServiceProvider)Host;
@kocubinski
kocubinski / DbEnum.tt
Created May 3, 2013 20:08
A T4 text template to generate a C# enum code from an external data source.
<#@ template debug="true" hostSpecific="true" #>
<#@ output extension=".cs" #>
<#@ Assembly Name="System.Core.dll" #>
<#@ Assembly Name="System.Xml.dll" #>
<#@ Assembly Name="System.Configuration.dll" #>
<#@ Assembly Name="System.Security.dll" #>
<#@ Assembly Name="System.Xml.Linq.dll" #>
<#@ Assembly Name="System.Data.dll" #>
<#@ Assembly Name="System.Configuration.dll" #>
<#@ import namespace="System" #>
@kocubinski
kocubinski / PageDataSource.cs
Created April 13, 2013 20:33
A page data source that works with ASP.NET Web Sites.
/// <summary>
/// Represents an ObjectDataSource that binds to its hosting page or user control
/// </summary>
[ToolboxData("<{0}:PageDataSource runat=server></{0}:PageDataSource>")]
public class PageDataSource : ObjectDataSource
{
public PageDataSource()
: this(String.Empty, String.Empty)
{
}