Skip to content

Instantly share code, notes, and snippets.

View refactorsaurusrex's full-sized avatar

refactorsaurusrex

View GitHub Profile
@refactorsaurusrex
refactorsaurusrex / git.md
Last active April 13, 2024 16:31
How to retroactively apply gitignore to a repo
  1. Add or update a .gitignore file
  2. Rebase your repo such that the .gitignore from step one is positioned in history prior to the naughty file(s) being commited.
  3. Run this command, where <commit> is the hash for the commit respresented by step 1: git rebase -ix 'git rm -r --cache . && git add . && git commit --amend --no-edit' <commit>
  4. Resolve conflicts as necessary.

Note that if there are only a few file types or directories or individual files, filter-branch is a simpler route to take. These steps are only necessary for large numbers of files / file types. Also note that there may be better ways still of doing this. :-)

@refactorsaurusrex
refactorsaurusrex / jenkinsfile.txt
Last active January 7, 2020 18:55
Jenkinsfile: How to get the author name for the HEAD commit
AUTHOR_NAME = bat (
script: "git show -s --format='%%an' HEAD",
returnStdout: true
).split('\r\n')[2].trim()
echo "The last commit was written by ${AUTHOR_NAME}."
echo "PS - Jenkins sucks giant monkey balls."
@refactorsaurusrex
refactorsaurusrex / wordBoundaries.cs
Created May 26, 2016 20:02
A better way to add line endings at specific positions in a long text string.
var text = "A long string....";
var words = text.Split(' ');
var allLines = words.Skip(1).Aggregate(words.Take(1).ToList(), (lines, word) =>
{
if (lines.Last().Length + word.Length >= 80)
lines.Add(word);
else
lines[lines.Count - 1] += " " + word;
return lines;
});
@refactorsaurusrex
refactorsaurusrex / maybe.cs
Created May 22, 2016 20:46
Maybe<T>, inspired by Mark Seemann
public class Maybe<T> : IEnumerable<T>
{
readonly IEnumerable<T> values;
public Maybe()
{
values = new T[0];
}
public Maybe(T value)
@refactorsaurusrex
refactorsaurusrex / pie.cs
Created December 12, 2015 03:31
C# Pie!
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Confections
{
public class Pie<T> : IReadOnlyCollection<Slice<T>>
{
readonly List<Slice<T>> slices;
@refactorsaurusrex
refactorsaurusrex / GetFiles.cs
Created November 2, 2015 22:26
Recursively navigate the file system, skipping any files or directories that are not accessible.
public static IEnumerable<string> GetFiles(string root, string searchPattern)
{
Stack<string> pending = new Stack<string>();
pending.Push(root);
while (pending.Count != 0)
{
var path = pending.Pop();
string[] next = null;
try
{
@refactorsaurusrex
refactorsaurusrex / JsonDeserializer.cs
Last active October 15, 2018 17:09
Debugging RestSharp Deserialization Errors http://wp.me/p4mdOw-1f9
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using RestSharp;
using RestSharp.Deserializers;
namespace MyAwesomeProject
{
public class JsonDeserializer : IDeserializer
{
@refactorsaurusrex
refactorsaurusrex / selectMenu.html
Created July 4, 2015 19:03
How To Bind A JQueryUI SelectMenu Widget To KnockOut
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.3.0/knockout-min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/sunny/jquery-ui.css">
<script>
$(document).ready(function() {
@refactorsaurusrex
refactorsaurusrex / AzureBlobClient.cs
Last active August 29, 2015 14:23
Simple client for uploading a local directory to an Azure blog storage container.
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
namespace PublishClickOnceToAzure
{
public class AzureBlobClient
{
@refactorsaurusrex
refactorsaurusrex / example.build.xml
Created June 4, 2015 21:37
How to edit the content of a subset of files from within a directory using NAnt. In this example, I iterate recursively through all paths contained within `C:\somePath\dbDirectory\` for all files with the extension of `.sql.template`, load the file, replace all instances of `@DBNAME@` with the value of `${database.name}`, and save the edited fil…
<foreach item="File" property="filename">
<in>
<items>
<include name="C:\somePath\dbDirectory\**.sql.template"/>
</items>
</in>
<do>
<loadfile file="${filename}" property="fileContents">
<filterchain>
<replacetokens>