Skip to content

Instantly share code, notes, and snippets.

@jordanyaker
jordanyaker / nginx_site
Last active March 12, 2019 09:18
Securing Websites With Nginx And Client-Side Certificate Authentication On Linux
upstream unicorn_app_production {
server unix:/var/app/shared/tmp/sockets/unicorn.app_production.sock fail_timeout=0;
}
server {
listen 80;
rewrite ^(.*) https://$host$1 permanent;
}
server {
@jordanyaker
jordanyaker / generate_ca_certificates.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/private/ca.key 4096
openssl req -new -x509 -days 1095 \
-key /etc/ssl/ca/private/ca.key \
-out /etc/ssl/ca/certs/ca.crt
openssl ca -name CA_default -gencrl \
-keyfile /etc/ssl/ca/private/ca.key \
-cert /etc/ssl/ca/certs/ca.crt \
-out /etc/ssl/ca/private/ca.crl \
@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 \
@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 / 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 / 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 / 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

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"])

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) {

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"