Skip to content

Instantly share code, notes, and snippets.

View ryanlewis's full-sized avatar

Ryan Lewis ryanlewis

  • Leeds, United Kingdom
  • 01:33 (UTC +01:00)
View GitHub Profile
@ryanlewis
ryanlewis / Program.cs
Created July 29, 2013 23:00
LinqToTwitter example to fetch tweet data for a particular tweet
using System;
using System.Linq;
using System.Text.RegularExpressions;
using LinqToTwitter;
namespace TweetTest
{
internal class Program
{
private static readonly Regex TweetStatusRegex = new Regex(@"^https?:\/\/twitter\.com\/(?:#!\/)?(\w+)\/status(es)?\/(\d+)$");
@ryanlewis
ryanlewis / gist:6112001
Last active December 20, 2015 09:59
Get difference between two commits. Powershell snippet to filter out a list of changed files by extension from git diff --stat
git diff 1.0.2 HEAD --stat=200
git diff 1.0.2 HEAD --stat=500 | where {$_ -Match ".cshtml|.css"} | %{$line=$_.split(" "); write-host $line[1] }
git diff 1.0.2 HEAD --stat=200 | where {$_ -Match ".cshtml|.cs"} | %{$l=$_.split(" "); $file=$l[1]; $file=$file.replace("Umbraco.Site", ""); write-host $file }
@ryanlewis
ryanlewis / twitter-responsive.css
Created October 15, 2013 20:41
User style for twitter.com to make the main desktop design responsive
@media screen and (max-width:840px) {
.wrapper {
width: 100%;
padding-left: 0;
padding-right: 0;
background: none !important;
}
.dashboard, .content-main {
width: auto ;
@ryanlewis
ryanlewis / cleanImageGenCache.js
Last active December 28, 2015 10:29
Remove all the ImageGen cache files and directories from a root media folder. npm install underscore q optimist OR npm install underscore q optimist -g
#!/usr/bin/env node
var _ = require('underscore');
var fs = require('fs');
var Q = require('q');
var argv = require('optimist')
.usage('Usage: $0 -base [directory')
.demand(['base'])
.describe('base', 'Media directory')
.argv;
@ryanlewis
ryanlewis / ContourInAnonymousLoadBalancing.cs
Created July 27, 2016 12:47
Using Umbraco Contour in an anonymous load balanced scenario (v7.3+)
public class ContourFormRefreshPayload
{
public Guid Id { get; set; }
}
public class ContourFormCacheRefresher : JsonCacheRefresherBase<ContourFormCacheRefresher>
{
public static string Id = "AA2970FD-8785-42C2-A289-A7A6614CAE45";
protected override ContourFormCacheRefresher Instance => this;
public override Guid UniqueIdentifier => new Guid(Id);
@ryanlewis
ryanlewis / StringExtensions.cs
Last active August 31, 2016 08:14
.FormatWith() extension method that we use with some of our Umbraco sites
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
namespace MyUmbracoSite.Core.Extensions
{
public static class StringExtensions
{
// http://bendetat.com/the-greatest-string-formatwith-implementation-in-the-world.html
@ryanlewis
ryanlewis / copy-k8s-resources-across-namespaces.sh
Created July 25, 2017 19:36 — forked from simonswine/copy-k8s-resources-across-namespaces.sh
Copying kubernetes resources accross namespaces
kubectl get rs,secrets -o json --namespace old | jq '.items[].metadata.namespace = "new"' | kubectl create-f -
@ryanlewis
ryanlewis / Pager.cshtml
Created August 27, 2013 16:41
A Razor/ASP.NET MVC pager that is adaptable for any project (Developed for Umbraco)
@model Epiphany.Web.Models.PagerViewModel
@{
var showPages = 5;
var maxPage = (int) Math.Ceiling((decimal) Model.Total/Model.PageSize);
}
@*[[ PAGER PAGE:@Model.Page PAGESIZE:@Model.PageSize TOTAL:@Model.Total MAXPAGE:@maxPage ]]*@
<div class="pagination">
@ryanlewis
ryanlewis / leaky_bucket.lua
Created March 16, 2021 00:06 — forked from florentchauveau/leaky_bucket.lua
Redis script (Lua) to implement a leaky bucket
-- Redis script to implement a leaky bucket
-- see https://medium.com/callr-techblog/rate-limiting-for-distributed-systems-with-redis-and-lua-eeea745cb260
-- (c) Florent CHAUVEAU <florent.chauveau@gmail.com>
local ts = tonumber(ARGV[1])
local cps = tonumber(ARGV[2])
local key = KEYS[1]
-- remove tokens < min (older than now() -1s)
local min = ts -1
@ryanlewis
ryanlewis / umbraco-jul-fix.ps1
Created July 22, 2014 10:54
Powershell script to resolve the Umbraco security advisory released 21 July 2014
Param(
[Parameter(Mandatory=$true)] $path
)
$proxyHtm = @"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Repo proxy</title>
</head>