Skip to content

Instantly share code, notes, and snippets.

View rally25rs's full-sized avatar

Jeff Valore rally25rs

View GitHub Profile
@rally25rs
rally25rs / nginx_rails_sendfile.md
Last active July 7, 2023 09:17
nginx rails send_file madness

Goal: Have some static content, served by Nginx, but it requires an authenticated user. User auth is through Rails.

Project structure: The actual static files are in /home/vagrant/docs/ The browser will use the URL /help/* to access this content

The Ruby bits: RAILS_ENV=production rails server is used to start a WEBrick on port 3000.

config/environments/production.rb

@rally25rs
rally25rs / MvcMockHelpers.cs
Created January 8, 2012 15:26
MvcMockHelpers.cs - Helper Utility for Mocking MVC3 Controllers with Moq.
using System;
using System.Collections.Specialized;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Moq;
/// <summary>
/// This helper class can be used to set up Moq mocks of MVC3 controllers.
/// Slightly modified from the original version from Scott Hanselman's blog:
@rally25rs
rally25rs / m503_m122.txt
Created February 6, 2020 11:10
Printer settings dump
Send: M503
Recv: echo: G21 ; Units in mm (mm)
Recv:
Recv: echo:Filament settings: Disabled
Recv: echo: M200 D1.75
Recv: echo: M200 D0
Recv: echo:Steps per unit:
Recv: echo: M92 X93.00 Y93.00 Z137.00 E104.00
Recv: echo:Maximum feedrates (units/s):
Recv: echo: M203 X300.00 Y300.00 Z5.00 E25.00
@rally25rs
rally25rs / kendo.binders.class.js
Created August 4, 2014 12:03
Class MVVM binder for Kendo UI
kendo.data.binders.class = kendo.data.Binder.extend({
init: function (target, bindings, options) {
kendo.data.Binder.fn.init.call(this, target, bindings, options);
// get list of class names from our complex binding path object
this._lookups = [];
for (var key in this.bindings.class.path) {
this._lookups.push({
key: key,
path: this.bindings.class.path[key]
@rally25rs
rally25rs / data.json
Created April 29, 2019 17:53
search sample data
[
"V004D000000007826042019160212558 Asap ABC Sales Sales 33019 1556312412 1 NORMAL Platform Toolkit API",
"V004E000000007926042019160212584 Asap ABC Sales Sales 33019 1556312472 1 NORMAL Platform Toolkit API",
"V004F000000008026042019160212609 Asap ABC Sales Sales 33019 1556312532 1 NORMAL Platform Toolkit API",
"V0050000000008126042019160212634 Asap ABC Sales Sales 33019 1556312532 1 NORMAL Platform Toolkit API",
"V0051000000008226042019160212659 Asap ABC Sales Sales 33019 1556312592 1 NORMAL Platform Toolkit API",
"V0052000000008326042019160212685 Asap ABC Sales Sales 33019 1556312652 1 NORMAL Platform Toolkit API",
"V0053000000008426042019160212711 Asap ABC Sales Sales 33019 1556312712 1 NORMAL Platform Toolkit API",
"V0054000000008526042019160212737 Asap ABC Sales Sales 33019 1556312712 1 NORMAL Platform Toolkit API",
"V0055000000008626042019160212761 Asap ABC Sales Sales 33019 1556312772 1 NORMAL Platform Toolkit API",
@rally25rs
rally25rs / FakeDbSet.cs
Created December 18, 2011 02:11
Fake implementation of Entity Framework IDbSet to use for unit testing.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
namespace Rally25rs.Gist.Data
{
@rally25rs
rally25rs / HtmlHelperDisplayNameExtensions.cs
Created November 20, 2011 03:29
Extension methods for ASP.NET MVC3 that provide helpers for getting display names from IEnumerable models.
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web.Mvc;
namespace Web.Extensions
{
public static class HtmlHelperDisplayNameExtensions
{
/// <summary>
@rally25rs
rally25rs / JsonEncodeAnExpandoObjectByWrappingItInADynamicJsonObject.cs
Created July 3, 2012 20:09
Serialize an ExpandoObject to a JSON string by wrapping it in a DynamicJsonObject
// By default, Json.Encode will turn an ExpandoObject into an array of items,
// because internally an ExpandoObject extends IEnumerable<KeyValuePair<string, object>>.
// You can turn it into a non-list JSON string by first wrapping it in a DynamicJsonObject.
[TestMethod]
public void JsonEncodeAnExpandoObjectByWrappingItInADynamicJsonObject()
{
dynamic expando = new ExpandoObject();
expando.Value = 10;
expando.Product = "Apples";
@rally25rs
rally25rs / fileStorage.coffee
Created December 29, 2014 14:22
Cordova File API Wrapper
window.fileStorage =
save: (name, data) ->
deferred = $.Deferred()
fail = (error) =>
deferred.reject(error)
gotFileSystem = (fileSystem) =>
fileSystem.root.getFile(name, { create: true, exclusive: false }, gotFileEntry, fail)
@rally25rs
rally25rs / CodeSample1.cs
Created May 10, 2011 00:27
Code Sample 1 (DynamicMethods and ILEmit)
/* ***
* This is a method from an object-relation-mapping (ORM) tool that I had started to write.
* I eventually stopped working on it, ad instead contributed time to the open source
* SubSonic project instead.
*
* This method is an example of generating DynamicMethods to be used at runtime to check and
* set some properties any an arbitrary type. This was used over straight reflection every time
* because reflection can be fairly slow. The use of a DynamicMethod is much quicker.
* *** */