Skip to content

Instantly share code, notes, and snippets.

View eldavido's full-sized avatar

David R. Albrecht eldavido

View GitHub Profile
# backbone_sync.coffee
# Defines a synchronization strategy that works with the Google Gadgets container
# options hash:
# "manualOverride" defines a callback that takes the "obj" parameters from
# makeRequest; intended for manually inspecting/parsing the service response.
# "success" and "error" are like their Backbone.js equivalents.
# "nocache" if truthy, ignore the value in makeRequest() cache.
Backbone.sync = (method, model, options) ->
syncParams = {}
syncParams[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON
@eldavido
eldavido / gist:4718538
Created February 5, 2013 23:03
David's local server.rb
log_level :info
log_location STDOUT
ssl_verify_mode :verify_none
chef_server_url "http://localhost:4001"
signing_ca_path "/var/chef/ca"
couchdb_database 'chef'
cookbook_path [ "/Users/dra/git/chef/cookbooks" ]
indexer: chef-expander -n1
solr: chef-solr
server: chef-server -N -e production -p 4001
serverweb: chef-server-webui -p 4040 -e production
@eldavido
eldavido / gist:5374007
Created April 12, 2013 18:17
Connect Pingdom status checks to nagios. Written in Ruby w/httparty and optparse
#!/usr/bin/env ruby
require 'httparty'
require 'optparse'
require 'ostruct'
# That was simple
class PingdomAPI
include HTTParty
base_uri 'https://api.pingdom.com/'
@eldavido
eldavido / ReverseProxyHttpEnforcer.cs
Last active November 15, 2017 19:13
Ensure a reverse-proxied ASP.NET Core application uses https
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
namespace interval.Support {
public class ReverseProxyHttpsEnforcer {
private const string ForwardedProtoHeader = "X-Forwarded-Proto";
private readonly RequestDelegate _next;
public ReverseProxyHttpsEnforcer(RequestDelegate next) {
@eldavido
eldavido / Startup.cs
Created November 15, 2017 18:50
Call app.UseReverseProxyHttpsEnforcer in your Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory lf) {
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
} else {
app.UseExceptionHandler("/error");
app.UseReverseProxyHttpsEnforcer();
}
app.UseAuthentication();
app.UseStaticFiles();
@eldavido
eldavido / GetTenderAmount.cs
Last active January 17, 2018 16:37
Code debt example
// Bad version
protected DollarCents Calculate() {
var x = Events.OfType<CardSaleAttached>().Select(e => e.Sale)
.Aggregate(DollarCents.Zero, (a, b) => a + b.SecuredMoney());
var y = Events.OfType<FolioPaymentReceived>()
.Aggregate(DollarCents.Zero, (a, b) => a + b.Amount);
return x + y;
}
// Good version
@eldavido
eldavido / Reservation.cs
Created February 19, 2018 18:09
Can a reservation check in?
public virtual CheckInRequestResult CanCheckIn(EventHydrationContext ehc, IClock clock,
ReservationFolioState fs) {
if (State == ReservationState.CheckedIn) {
return CheckInRequestResult.AlreadyCheckedIn;
}
if (State != ReservationState.Open) {
return CheckInRequestResult.NoOpenReservation;
}
@eldavido
eldavido / TwilioClient.cs
Created July 13, 2018 16:58
Twilio client from interval
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;

Hello World

This is content converted from Markdown!

Here's a JSON sample:

{
  "foo": "bar"
}