Skip to content

Instantly share code, notes, and snippets.

@charlessolar
charlessolar / gist:515016139f0014cdfc029c7dd553d597
Last active January 13, 2020 11:54
ansible inventory files from terraform
### variables
variable "env" {}
variable "riak_count" {}
variable "elastic_count" {}
### hostname.tpl
${name}-${env}-${format("%02s",index)} ${extra}
### ansible.tpl
### Keybase proof
I hereby claim:
* I am volak on github.
* I am charlessolar (https://keybase.io/charlessolar) on keybase.
* I have a public key ASD5acJoHNEmnZedsb8oi89yDiBPFeiN-2fDtvndby_n2Qo
To claim this, I am signing this object:
'C:\Program Files\Java\jdk1.8.0_101\bin\keytool.exe' -import -alias personal -trustcacerts -file selfsigned.crt -keystore 'C:\Program Files\Java\jre1.8.0_101\lib\security\cacerts'
'C:\Program Files\Java\jdk1.8.0_101\bin\keytool.exe' -import -alias personal -trustcacerts -file selfsigned.crt -keystore 'C:\Program Files\Java\jdk1.8.0_101\jre\lib\security\cacerts'
default pass: changeit
@charlessolar
charlessolar / gist:4826cd1af0fabfac5b8f
Last active March 14, 2018 17:51
Servicestack OAuth JWT Verification
this.GlobalRequestFilters.Add((httpReq, httpResp, requestDto) =>
{
var header = httpReq.Headers["Authorization"];
if( header.IsNullOrEmpty() ) {
httpResp.StatusCode = (int)HttpStatusCode.Unauthorized;
httpResp.EndRequest();
}
try
@charlessolar
charlessolar / gist:f51abe54570eafa679b6
Last active August 29, 2015 14:08
Knockoutjs Form Templating in View Model
// An easy way to create templated form inputs for large knockout projects
// Thanks to knockout 3.2 and components!
// Instead of defining control parameters on the binding or custom element like so:
<unrealistic-component
params='stringValue: "hello",
numericValue: 123,
boolValue: true,
objectValue: { a: 1, b: 2 },
@charlessolar
charlessolar / gist:4aca442373b4216a52b5
Created October 21, 2014 08:17
Integrating Durandal and Pace for page loading indicators
// Put in your main.js define
pace.start({
document: false,
elements: false,
startOnPageLoad: false,
});
router.isNavigating.subscribe((navigating) => {
if( navigating )
@charlessolar
charlessolar / magic.cs
Last active December 6, 2018 10:39
Building objects from a list of property names for Dynamic DTOs - useful for authorization field level filtering and situations when you don't know the type of data a service will return
public static IQueryable<dynamic> ToDynamic<T>(this IQueryable<T> query, ISet<String> fields)
{
var pocoType = typeof(T);
var itemParam = Expression.Parameter(pocoType, "x");
var members = fields.Select(f => Expression.PropertyOrField(itemParam, f));
var addMethod = typeof(IDictionary<string, object>).GetMethod(
"Add", new Type[] { typeof(string), typeof(object) });
@charlessolar
charlessolar / security_v2.cs
Last active August 29, 2015 14:01
Security Concept v2 - Compiles!
public class Security : Descriptor
{
public Security()
{
// When receiving queries of type Queries.GetItem users need permission GetItems
When.Receiving().Queries().OfType<Queries.GetItem>()
.Users().HavePermission("GetItems");
// When recieving queries of type Queries.GetItem users need permission GetItems and users need permission Reading
When.Receiving().Queries().OfType<Queries.GetItem>(s =>
@charlessolar
charlessolar / SecurityConcept.cs
Created May 10, 2014 13:05
Concept of C# fluent security that I am implementing in NES.RavenDB.Example
public class Security : IDescriptor
{
public Security()
{
// Action Target Securable
When.Receiving().Queries().OfType<Queries.GetItem>()
// Actors
.Allow(x => x.Users()
// Rule
.WithPermission("GetItems"))