Skip to content

Instantly share code, notes, and snippets.

View ankona's full-sized avatar
🏠
Working from home

Chris McBride ankona

🏠
Working from home
View GitHub Profile
@ankona
ankona / contentful-single-item-publish.cs
Last active September 26, 2018 23:14
Contentful - Single Item Publish Example Code Snippet
/// <summary>
/// Publishes the content item with the provided ID
/// </summary>
/// <param name="id">The id identifying the item</param>
/// <returns></returns>
public async Task<int> PublishItem(string id)
{
_logger.LogTrace($"PublishItem({id})");
if (string.IsNullOrWhiteSpace(id))
@ankona
ankona / ContentfulTreePublish.cs
Last active September 25, 2018 21:25
Publish a content tree by retrieving all included items under the "parent" item
using AutoMapper;
using KT.Content.Data.Definition;
using KT.Content.Data.Exceptions;
using KT.Content.Data.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Net.Http;
@ankona
ankona / get_token.py
Created July 10, 2018 15:21
retrieve oauth token
#!/usr/bin/env python3
import requests
import argparse
def retrieve_token(token_uri, client_id, client_secret):
r = requests.post(f"{token_uri}",
data={'client_id':f"{client_id}",'grant_type': 'client_credentials','client_secret': f"{client_id}", 'scope': 'targeting-api'},
headers={'Content-Type':'application/x-www-form-urlencoded'})
@ankona
ankona / s3-deploy.sh
Last active June 19, 2018 21:08
s3 upload example
s3_bucket = "demo.wtuo.com"
# report_folder = "s3_bucket/${env.BUILD_NUMBER}"
aws s3 cp dist/ "s3://${s3_bucket}" --recursive --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
@ankona
ankona / docker-stop-all.sh
Created March 30, 2018 16:28
docker stop all
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
@ankona
ankona / update-jenkins-time.groovy
Last active October 16, 2017 20:56
Update time zone in jenkins
System.setProperty('org.apache.commons.jelly.tags.fmt.timeZone', 'America/New_York')
@ankona
ankona / impersonate_test.cs
Created October 6, 2017 20:10
test for impersonation authorization
if (id != base.UserID)
{
var token = this.GetAccessToken().Result;
var currentUser = await _principal.Retrieve(this.User, token);
if (!currentUser.IsImpersonator || !currentUser.CanActAsStudent) {
return Unauthorized();
}
}
@ankona
ankona / git-clean.sh
Last active October 6, 2017 20:33
Remove a file from repo history
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch .vscode/launch.json' --prune-empty --tag-name-filter cat -- --all
git update-index --assume-unchanged FILENAME_TO_IGNORE
@ankona
ankona / decrypt_setting.py
Created May 18, 2017 18:24
Decrypt Value from DynamoDB with key in AWS KMS
"""
Retrieve & Decrypt settings from DDB.
Sample Usage:
foo=$(python settings.py decrypt <my-app> <my-config-value-name>)
echo $foo
foo=$(python settings.py settings <my-app>)
echo $foo
"""
@ankona
ankona / ef-core-vs-dapper.ipynb
Last active April 10, 2017 18:38
ef core comparison to dapper
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.