Skip to content

Instantly share code, notes, and snippets.

View codesoda's full-sized avatar

Chris Raethke codesoda

View GitHub Profile
@codesoda
codesoda / select_other.html
Created September 28, 2012 10:44
show/hide text box based on selected drop down
<!--
the select needs
- "has_other" css class
- "data-other" attribute, which points to the id of the element to hide/show (normally a textbox)
- "data-other-text" attribute, which indicates the text which indicates that other has been selected
-->
<select class="has_other" data-other="#textbox_id" data-other-text="...other">
<option>option 1</option>
<option>...other</option>
@codesoda
codesoda / time_for.rb
Created July 9, 2012 12:19
Time ruby code in the console
def time_for
started_at = Time.now
yield
elapsed = Time.now - started_at
end
# elapsed = time_for { 5 * i }
# otherwise Benchmark.measure { 5 * i }
@codesoda
codesoda / gist:1715843
Created February 1, 2012 07:51
Crud Resoruces Routing for ASP.NET MVC
public static class RouteCollectionExtensions
{
private static void MapResources(this RouteCollection routes, string model)
{
MapResources(routes, model, model + "s");
}
private static void MapResources(this RouteCollection routes, string model, string models)
{
// models - index
@codesoda
codesoda / JsonBuilder.cs
Last active July 31, 2017 12:29
A Simple c# class for creating well formed JSON strings when serializing classes with Json.NET is overkill.
public class JsonBuilder
{
private readonly StringBuilder _sb;
private readonly Stack<bool> _hasPreviousProperties;
private bool RequiresComma { get { return _hasPreviousProperties.Count > 0 && _hasPreviousProperties.Peek(); } }
public JsonBuilder() {
_sb = new StringBuilder();