Skip to content

Instantly share code, notes, and snippets.

View jonfuller's full-sized avatar

Jon Fuller jonfuller

View GitHub Profile
@jonfuller
jonfuller / IdGenerator.cs
Created October 31, 2019 13:31
Generate some readable IDs
public static class IdGenerator
{
private static readonly ConcurrentDictionary<string, IEnumerator<string>> _generators = new ConcurrentDictionary<string, IEnumerator<string>>();
public static string Next(string prefix)
{
var generator = _generators.GetOrAdd(prefix, x => MakeSequence(prefix).GetEnumerator());
generator.MoveNext();
return generator.Current;
}
@jonfuller
jonfuller / HelpMailHandler.cs
Created April 11, 2018 00:54
Blog - Email Interface - Handlers
// ...
public bool CanHandle(MimeMessage message, IEnumerable<(string name, byte[] data)> attachments)
{
return true;
}
// ...
@jonfuller
jonfuller / MailProcessor.cs
Last active April 11, 2018 00:45
Blog - Email Interface - Mail Processor
// snip
var handlers = new IMailProcessor[]
{
new AppleHealthAttachmentMailProcessor(from, settings, customSheets),
new AppleHealthGoogleDriveMailProcessor(from, settings, customSheets),
new SettingsUpdateMailProcessor(from, settingsStore),
new HelpMailProcessor(from), // <-- catch all
};
@jonfuller
jonfuller / retrofit-pom.xml
Created May 22, 2014 20:32
POM's for downloading JAR's
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.doesnt.matter</groupId>
<artifactId>Whatever</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Simple POM to download some dependencies</name>
<url>http://jonfuller.co</url>
<dependencies>
<dependency>
@jonfuller
jonfuller / nodestatus.sh
Created July 17, 2013 13:09
Shell script to use in a Jenkins job for displaying whether a given Jenkins slave node is up or down. Use this as an "execute shell" build step. NB: Must be run on a machine that has bash (i.e. not Windows)
NODE_NAME="name-of-node"
ENDPOINT="http://JENKINSURL_GOES_HERE/computer/api/xml?xpath=computerSet/computer\[displayName='$NODE_NAME'\]/offline/text()"
ENDPOINT_RESULT=$(curl $ENDPOINT 2> /dev/null)
if [ $ENDPOINT_RESULT = "false" ] ; then
exit 0
fi
exit 1
@jonfuller
jonfuller / gist:3986883
Created October 31, 2012 12:56 — forked from Ball/gist:3986836
Defer / disposable in ruby
def using(to_ensure)
begin
yield if block_given?
ensure
to_ensure()
end
obj = SomthingToClose.connect
@jonfuller
jonfuller / status.json
Created January 20, 2011 14:48
Transmission RPC
{
"arguments": {
"fields": [ "id", "name", "percentDone", "totalSize", "rateDownload", "rateUpload" ]
},
"method": "torrent-get"
}
@jonfuller
jonfuller / status.json
Created January 20, 2011 14:48
Transmission RPC
{
"arguments": {
"fields": [ "id", "name", "percentDone", "totalSize", "rateDownload", "rateUpload" ]
},
"method": "torrent-get"
}
@jonfuller
jonfuller / meh.cs
Created August 12, 2010 17:18
Change a value atomically, then set it back after some operation
public class Meh
{
public static void Change<TObj, TProp>(this TObj obj, Expression<Func<TObj, TProp>> propertyExpr, TProp newValue, Action operation)
{
var name = ((MemberExpression)propertyExpr.Body).Member.Name;
var prop = typeof(TObj).GetProperty(name);
var oldValue = prop.GetValue(obj, new object[0]);
try
{
class LineBuilder
{
List<LineItem> _lines;
public LineBuilder WithLine(params string[] names)
{
_lines.AddRange(names.Select(name => new LineItem(name)));
return this;
}