Skip to content

Instantly share code, notes, and snippets.

@ChuckSavage
ChuckSavage / ViewExtensions.cs
Created June 6, 2012 19:58
MonoTouch Swipe Event
using System.Collections.Generic;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;
using MonoTouch.UIKit;
namespace iOSLib
{
public static class ViewExtensions
{
static Dictionary<UIView, Dictionary<UISwipeGestureRecognizerDirection, SwipeClass>>
[DebuggerDisplay("{Title}, Desc({Description}), Link({Link})")]
public class Item
{
public Item(XElement x)
{
Title = x.Element("title").Value;
Description = x.Element("description").Value;
XElement link = x.Element("link");
if(null != link)
Link = link.Value;
@ChuckSavage
ChuckSavage / Paths.cs
Created February 10, 2013 18:59
Paths utility file for adding params to a string Combine.
public class Paths
{
/// <summary>
/// Apply Path.Combine(on path and list)
/// </summary>
/// <param name="path"></param>
/// <param name="list"></param>
/// <returns></returns>
public static string Combine(string path, params string[] list)
{
@ChuckSavage
ChuckSavage / XmlLinqConversionExtensions.cs
Created February 20, 2013 00:06
Convert To/From XmlDocument and XDocument/XElements
using System.Xml;
using System.Xml.Linq;
namespace XmlLib
{
/// <summary>
/// Provides extension methods for simple conversion between System.Xml and System.Xml.Linq classes.
/// </summary>
/// <remarks>From: http://brianary.blogspot.com/2010/02/converting-between-xdocument-and.html</remarks>
public static class XmlLinqConversionExtensions
@ChuckSavage
ChuckSavage / ZipMultiple.cs
Last active January 21, 2022 02:40
It seems an oversight on the .Net team to not enable multiple arrays to be passed to Enumerable.Zip. So I've created up to seven overloaded Zip extensions that borrow from the code by Eric Lippert here: http://blogs.msdn.com/b/ericlippert/archive/2009/05/07/zip-me-up.aspx
using System;
using System.Collections.Generic;
namespace ZipMany
{
/// <summary>
/// Zip multiple arrays (more than 2 since there is a built in Zip for 2 with .Net 4.0)
/// </summary>
public static class ZipMultiple
{
@ChuckSavage
ChuckSavage / ObservableValue
Last active January 21, 2022 02:39
Observe the changes in a value
public class ObservableValue<T> : INotifyPropertyChanged
{
public class MyArgs : PropertyChangedEventArgs
{
public MyArgs(string propertyName, T old, T @new)
: base(propertyName)
{
Old = old;
New = @new;
}
@ChuckSavage
ChuckSavage / MapMagic_AutoSave
Last active October 14, 2016 09:19
MapMagic v1.5 Setting up Auto-Save of Nodes data. Modify MapMagic at your own risk. There is no guarantee that the node file generated by this is useful. Be sure to test it for your own assurance.
Edit MapMagicWindow.cs
Make the following method static, it doesn't reference internal class data, so it is ok.
private static Generator[] SmartCopyGenerators(Generator gen)
Then refactor the SaveGenerator method, extracting the file saving to a public static ExportToFile method
void SaveGenerator(Generator gen, Vector2 pos)
{
@ChuckSavage
ChuckSavage / DisplaySize.cs
Last active October 29, 2016 06:09
NGUI DisplaySize
/*
* Modified this guys code - http://www.zedia.net/2013/ngui-unity3d-getting-screen-size/comment-page-1/
*/
public static class DisplaySize
{
public static float ScreenHeight(this Transform t)
{
UIRoot root = t.root.GetComponent<UIRoot>() ?? NGUITools.FindInParents<UIRoot>(t);
float ratio = (float)root.activeHeight / Screen.height;
return Mathf.Ceil(Screen.height * ratio);
@ChuckSavage
ChuckSavage / AppendImageExtension.cs
Created August 29, 2017 18:29
C# Is file an image and get its type
// Includes a mini-program for checking and fixing files that have no extension
// Only checks for the most common types
// If you create a better version, please upload it here.
using System;
using System.Collections.Generic;
using System.IO;
namespace AppendJPG
{
@ChuckSavage
ChuckSavage / battery_charge_and_drill_load_level.cs
Created November 3, 2018 08:35
Space Engineers Game - Battery Charge and Drill (miner) load level and balancer
// dco.pe/vsb
const float MinValueToActivateRedLights = 5000f;
const float VolumeOfDrills = 33750f; // small ship drill (large is 234375f)
public Program()
{
Runtime.UpdateFrequency = UpdateFrequency.Update100;
}