Skip to content

Instantly share code, notes, and snippets.

@aloisdg
Last active December 15, 2015 13:47
Show Gist options
  • Save aloisdg/f50ef2c99a8f34b40cf7 to your computer and use it in GitHub Desktop.
Save aloisdg/f50ef2c99a8f34b40cf7 to your computer and use it in GitHub Desktop.
A script to generate a secret santa. Target can be discover by qrcode.
using System;
using System.Net;
using System.Collections.Generic;
// https://dotnetfiddle.net/NC4suH
public class Program
{
static readonly Random _rand = new Random();
public static void Main()
{
var list = new List<string> { "Pier","Noel", "Luke", "Leia", "Han " };
var list2 = new List<string>(list);
cycle(list2);
for (var i = 0; i < list.Count; i++)
{
Console.Write(list[i] + "\t");
PrintData(GetDataAsBytes(CreateQrCodeUrl("Tu es le Secret Santa de " + list2[i])));
}
}
public static void cycle<T>(IList<T> items)
{
for (var i = items.Count; i > 1;)
{
i--;
var j = (int) (_rand.NextDouble() * (i));
var tmp = items[j];
items[j] = items[i];
items[i] = tmp;
}
}
public static string CreateQrCodeUrl(string text)
{
return "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + text;
}
public static byte[] GetDataAsBytes(string url)
{
return new WebClient().DownloadData(url);
}
public static void PrintData(byte[] image)
{
Console.WriteLine("data:image/gif;base64," + Convert.ToBase64String(image));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment