Skip to content

Instantly share code, notes, and snippets.

@jordanyaker
jordanyaker / arr configuration.xml
Last active June 14, 2019 06:06
This is a web.config file for doing reverse proxy with the ARR module from IIS. The configuration file was based on instructions from here: http://blogs.iis.net/carlosag/archive/2010/04/01/setting-up-a-reverse-proxy-using-iis-url-rewrite-and-arr.aspx
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<httpRuntime enableVersionHeader="false" />
</system.web>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite API" stopProcessing="true">
<match url="^api\/(.*)$" />
@jordanyaker
jordanyaker / Many to Many.md
Created November 19, 2013 17:14
The following code is how I managed to configure Many-To-Many relationships in EF 5 without using the actual Many-to-Many mapping which loads all of the data you don't need.

The classes that I use as a base have to map the individual elements. In this case, I have Faqs, Categories, and the bridges.

Faq.cs

    public class Faq {
        public Faq() {
            //... other stuff
            this.WithFaqCategoryBridges = new List<FaqCategory>();
        }

The current configuration should be shown by running the following command:

Get-AdfsProperties | select-object -ExpandProperty WIASupportedUserAgents

In order to update this list with WebKit-based browsers, you can add run the following commands in powershell from the ADFS server:

[System.String[]] $newAgents = "MSAuthHost/1.0/In-Domain", "MSIE 6.0", "MSIE 7.0", "MSIE 8.0", "MSIE 9.0", "MSIE 10.0", "Trident/7.0", "MSIPC", "Windows Rights Management Client", "Mozilla/4.0", "Mozilla/5.0", "Mozilla/5.001"

When querying with EF, you will need to pay special attention to order (i.e., Where, Order, Skip, then Limit). In addition, when you want to query on the fly, the best strategy is to build the query with Expressions:

    Expression<Func<Faq, bool>> func = null;
    if ((categories != null && categories.Length > 0) && (tags != null && tags.Length > 0)) {
        func = f =>
            f.ApplicationId == this.CurrentApplicationId &&
            f.Categories.Any(c => categories.Contains(c.Name)) &&
            f.Tags.Any(t => tags.Contains(t.Name));
    } else if (categories != null && categories.Length > 0) {

When retrieving mail, you need to first fetch the message in an RFC822 format:

client.fetch(response.data, "RFC822").callback do |fetched| ... end

After the message has been fetched, you can then pass the content to the Mail object in order to hydrate an easily manageable object in the following fashion:

mail = Mail.new(fetched[0].attr["RFC822"])
@jordanyaker
jordanyaker / gist:bdc26c5591b158ec3962
Last active August 29, 2015 14:04
Modifications to ActiveAdmin

In order to get custom sub-nav menus with ActiveAdmin, there are several monkey-patches that need to be made. The following are the patches which should work:

lib/active_admin/resource.rb

module ActiveAdmin
  class Resource
    attr_accessor :sub_nav_content
  end
end
@jordanyaker
jordanyaker / gist:057a8dfa042e4ac84f91
Created October 29, 2014 14:17
Row Statistics In SQL Server (Works in Azure)
select t.name ,s.row_count from sys.tables t
join sys.dm_db_partition_stats s
ON t.object_id = s.object_id
and t.type_desc = 'USER_TABLE'
and t.name not like '%dss%'
@jordanyaker
jordanyaker / logging.rb
Created January 22, 2015 14:06
Adding Exception Logging In Rails For All Exceptions
class Exception
alias real_init initialize
def initialize(*args)
real_init *args
unless message == 'Resource temporarily unavailable - read would block' ||
caller.any? { |c| c =~ /.*\/var\/www\/web\/shared\/vendor\/bundle\/ruby\/2\.0\.0\/bin\/rake:23:in/i }
breaker = "------------------------------------------------------"
Rails.logger.info breaker
@jordanyaker
jordanyaker / create_crl_number.sh
Last active March 12, 2019 09:19
Securing Websites With Nginx And Client-Side Certificate Authentication On Linux
touch /etc/ssl/ca/index.txt && echo ’01’ > /etc/ssl/ca/crlnumber
@jordanyaker
jordanyaker / create_user.sh
Created February 3, 2016 21:33
Securing Websites With Nginx And Client-Side Certificate Authentication On Linux
openssl genrsa -des3 -out /etc/ssl/ca/certs/users/USERNAME.key 1024
openssl req -new -key /etc/ssl/ca/certs/users/USERNAME.key \
-out /etc/ssl/ca/certs/users/USERNAME.csr
openssl x509 -req -days 1095 \
-in /etc/ssl/ca/certs/users/USERNAME.csr \
-CA /etc/ssl/ca/certs/ca.crt \
-CAkey /etc/ssl/ca/private/ca.key \
-CAserial /etc/ssl/ca/serial \