Skip to content

Instantly share code, notes, and snippets.

@gscattolin
gscattolin / example.js
Created September 10, 2013 17:57
Welcome to your first Gist! Gists are simple code reminders. Whenever you come across a piece of code you think might be useful later on, save it as a Gist. With GistBox, you can also tag the Gist with a label. This is especially useful for keeping them organized by language, project or purpose. For more info about GistBox, visit: http://www.gi…
// log an object to the browser console
console.log({ text: "foobar" });
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:01
Auto Populate a list of class
public static IList<T> AutoPopulate<T>(uint numberofItem) where T : class
{
var constructorInfo = typeof (List<>).MakeGenericType(typeof (T)).GetConstructor(Type.EmptyTypes);
if (constructorInfo != null)
{
var listInstance = (IList<T>)constructorInfo
.Invoke(null);
var rnd = new Random();
for (int ii = 1; ii < numberofItem; ii++)
{
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:02
Plugin
namespace DBB.Plugins.Interfaces
{
public interface IPlugin
{
/// <summary>
/// Gets or sets the plugin's name.
/// </summary>
string Name { get; }
/// <summary>
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:04
YAXLib: Yet Another XML Serialization Library for the .NET Framework
http://yaxlib.codeplex.com/
YAXLib: Yet Another XML Serialization Library for the .NET Framework
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:05
byte array to get object
/// <summary>
/// Function to get object from byte array
/// </summary>
/// <param name="_ByteArray">byte array to get object</param>
/// <returns>object</returns>
public object ByteArrayToObject(byte[] _ByteArray)
{
try
{
// convert byte array to memory stream
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:07
Dispose Good Practice
Type That Owns Disposable Fields Implements IDisposable: Good Practice
public class OwnsDisposableFields : IDisposable
{
private DisposableResource disposableResourceOne;
private DisposableResource disposableResourceTwo;
// Other fields continue to be declared here.
private bool disposed;
~OwnsDisposableFields()
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:08
Enum Enumerator
//Fill a combobox with an enumerator
TypeofItems_cb.Items.Clear();
foreach (var it in Enum.GetValues(typeof(Recipe.ProductType)))
{
TypeofItems_cb.Items.Add(it.ToString());
}
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:08
String Format
String Format for Double
// just two decimal places
String.Format("{0:0.00}", 123.4567); // "123.46"
String.Format("{0:0.00}", 123.4); // "123.40"
String.Format("{0:0.00}", 123.0); // "123.00"
// max. two decimal places
String.Format("{0:0.##}", 123.4567); // "123.46"
String.Format("{0:0.##}", 123.4); // "123.4"
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:14
Ip Validate
/// <summary>
/// method to validate an IP address
/// using regular expressions. The pattern
/// being used will validate an ip address
/// with the range of 1.0.0.0 to 255.255.255.255
/// </summary>
/// <param name="addr">Address to validate</param>
/// <returns></returns>
public bool IsValidIP(string addr)
{
@gscattolin
gscattolin / Read XML using Linq
Created September 10, 2013 18:15
Read XML using Linq
using System.Linq;
using Pdf_Rendering;
using System.IO;
using System.Reflection;
using System.Xml.Linq;
XNamespace namespacexml= "http://www.heidelberg.com";
if (Path.GetExtension(fn).ToLower() != ".xml") { Console.WriteLine("Input file not a pdf file"); return false; }
if (!File.Exists(fn)) { Console.WriteLine("Input file does not exist"); return false; }
XDocument doc = XDocument.Load(fn);