Skip to content

Instantly share code, notes, and snippets.

@ceddlyburge
ceddlyburge / print_organisation_commits_on_github_since_date.py
Created February 6, 2017 16:55
Print organisation commits on github since date. This queries the github api using a personal access token. The token in this gist has been deleted.
import requests
def print_commit(commit):
if "sha" in commit:
print("{},{},{},\"{}\"".format(commit["sha"], commit["commit"]["author"]["date"], commit["commit"]["author"]["name"], commit["commit"]["message"]).replace("\r", "").replace("\n", ""))
else:
print(commit)
def print_commits(repository_name):
print(repository_name)
@ceddlyburge
ceddlyburge / TidyUp.md
Last active April 11, 2017 16:58
TidyUp class that allows you to use a `using` statement, to ensure that something is done when it goes out of scope.

TidyUp is a class that allows you to use a using statement, to ensure that something is done when it goes out of scope. It makes it obvious what the "end" type action is for a "start" type action, puts both actions next to each other and ensures that the end action gets called.

This code has a minor quality issue, in that the indentLevel++ statement could be a long way away from the indentLevel-- statement, and one could get updated without the other.

public class ObjectWriter
{
	int indentLevel;

	public void WriteRootObject(SomeClass someClass)
import requests
def repositories_json(page):
return requests.get(f"https://api.github.com/orgs/resgroup/repos?type=private&page={page}&per_page=100",
headers={'Authorization': 'token 32511df370378bb51e1c0ae19ccafc7e3bc74dd3'}).json()
def format_repository(repository):
try:
return f"{repository['name']},\"{repository['description']}\",{repository['created_at']},{repository['updated_at']},{repository['pushed_at']},{repository['size']},{repository['language']},{repository['archived']}"
except:
@ceddlyburge
ceddlyburge / SpecificationSpecificClassWithCustomPropertyPartial.cs
Last active October 19, 2020 07:39
Partial setup class for CustomerTestsExcel framework
public partial class SpecificationSpecificClassWithCustomProperty
{
internal SpecificationSpecificClassWithCustomProperty CustomInt_of(int customInt)
{
// The framework requires you to do this
AddValueProperty(GetCurrentMethod(), customInt);
// And then you can do some custom thing with `value` here
// classWithCustomProperty.Setup(m => m.Name).Returns(customInt.ToString());
@ceddlyburge
ceddlyburge / SpecificationSpecificVermeulenNearWakeLengthCalculatorPartial.cs
Created October 19, 2020 07:42
Example partial root setup class for CustomerTestsExcel framework
public partial class SpecificationSpecificVermeulenNearWakeLengthCalculator
{
// For the "Then" section, return the results to assert
internal IEnumerable<IVermeulenNearWakeLength> VermeulenNearWakeLengths { get; private set; }
// For the "When" section, exercising the system under test.
internal void Calculate()
{
VermeulenNearWakeLengths =
new VermeulenNearWakeLengthCalculator(
def count_neighbours(
point
, living_cells
):
/*...*/ namespace BeerSong {
public class BeerSongGenerator {
public string Verses(int begin, int end) { /*...*/ return string.Join("\n", VersesList(begin, end)); }
IEnumerable<string> VersesList(int begin, int end) {
for (int verse = begin; verse >= end; verse--)
yield return Verse(verse); }
string Verse(int verse) => new VerseGenerator(verse).Verse; }
public double CalculateDesignTurbulence(double windSpeed, double designTurbulence, double designTurbulenceShape)
{
return designTurbulence * ((((15 / windSpeed) + designTurbulenceShape) / (1 + designTurbulenceShape)) + (1.28 / windSpeed * 1.44));
}
public double CalculateDesignTurbulence(
double windSpeed,
double designTurbulence
double designTurbulenceShape)
{
return
designTurbulence
*
(
(
public int? Accept(Reservation reservation)
{
if (!IsReservationInFuture(reservation))
return null;
try {
var reservedSeats =
ReadReservations(reservation.Date)
.Sum(r => r.Quantity);