Skip to content

Instantly share code, notes, and snippets.

View michaelbramwell's full-sized avatar

696d656b michaelbramwell

  • Perth Australia
View GitHub Profile
@michaelbramwell
michaelbramwell / SetTimeZoneFromISO8601Str.php
Created September 7, 2016 03:07
Set Time Zone From ISO8601 String
private function SetTimeZone($dtStr)
{
$newDt = DateTime::createFromFormat(DateTime::ISO8601, $dtStr);
$newDt->setTimezone(new DateTimeZone('Australia/Perth'));
$newDtStr = $newDt->format("c");
return $newDtStr;
}
@michaelbramwell
michaelbramwell / SlackHook.cs
Created June 14, 2016 00:30
Simple Slack WebHook Client
// dependancies: Newtonsoft.Json, RestSharp;
public interface IRpcClient<T>
{
string AccessToken { get; }
string BaseUrl { get; }
T DataStore { get; }
string Host { get; }
string Protocal { get; }
string RelativeUrl { get; }
@michaelbramwell
michaelbramwell / GenericRestRequest.cs
Last active May 6, 2016 07:58
Generic Request with RestRequest lib
public static IRestResponse<T> MakeRequest(string relativeUrl, Func<RestClient, RestRequest, IRestResponse<T>> clientFunc)
{
var client = new RestClient("https://someresource.com");
var request = new RestSharp.RestRequest(relativeUrl);
return clientFunc(client, request);
}
// example call
var request = MakeRequest("/api/whatever", (c, r) => c.Execute<SomeType>(r));
var deserializedSomeTypeData = request.Data;
@michaelbramwell
michaelbramwell / gacInstall.ps1
Created April 20, 2016 08:01
Gac Install Powershell
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
$publish.GacInstall("C:\temp\{dllname}.dll")
iisreset
@michaelbramwell
michaelbramwell / GetFromMemoryCache.cs
Created March 31, 2016 03:13
Generic get/set operation for types that are stored in the <see cref="MemoryCache"/>
public static T GetFromMemoryCache<T>(string key, int cacheTime, Func<T> whenKeyNotFound)
{
var items = MemoryCache.Default;
if (items[key] != null)
{
// return from cache
return (T)items[key];
}
@michaelbramwell
michaelbramwell / SpriteInfo.cs
Last active October 9, 2021 18:01
C# Sprite Generator / Maker (zero config) - generates a sprite-sheet with css classes outputted as a string
internal class SpriteInfo
{
public string Name { get; private set; }
public int X { get; private set; }
public int Y { get; private set; }
public int W { get; private set; }
public int H { get; private set; }
public SpriteInfo(string name, int x, int y, int w, int h)
{
public static class PredicateBuilder
{
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1, Expression<Func<T, bool>> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<T, bool>>(Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters);
}
public static Expression<Func<T, bool>> False<T>()
{
@michaelbramwell
michaelbramwell / GetFromHttpCache.cs
Created March 9, 2016 01:24
Generic get/set operation for types that are stored in the <see cref="HttpContext.Cache"/>
public static T GetFromHttpCache<T>(string key, Cache items, int cacheTime, Func<T> whenKeyNotFound, CacheItemRemovedCallback onRemoveCallback = null)
{
if (items[key] != null)
{
// return from cache
return (T)items[key];
}
// return new item from caller and add to cache
@michaelbramwell
michaelbramwell / myGithubReposAndGists
Created March 6, 2016 06:08
Google Search My Github repos and gists
https://encrypted.google.com/search?hl=en&q=site%3Agist.github.com%2Fmichaelbramwell%20%7C%7C%20site%3Agithub.com%2Fmichaelbramwell
public class HtmlUglifyFilter : Stream
{
private readonly Stream _responseStream;
private long _position;
public HtmlUglifyFilter(Stream inputStream)
{
_responseStream = inputStream;
}