Skip to content

Instantly share code, notes, and snippets.

View xanathar's full-sized avatar
🐢
I may be slow to respond. Who am I kidding?. I will be VERY slow to respond.

Marco Mastropaolo xanathar

🐢
I may be slow to respond. Who am I kidding?. I will be VERY slow to respond.
View GitHub Profile
@xanathar
xanathar / OpenFileDialog - SaveFileDialog
Created June 3, 2014 16:49
Quick reminder of WinForms standard file dialogs
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "Save on XML";
sfd.OverwritePrompt = true;
sfd.DefaultExt = "xml";
sfd.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
if (sfd.ShowDialog() == DialogResult.OK)
{
...
@xanathar
xanathar / RegEx-NamedCapture
Created June 3, 2014 16:52
Example of regex w/named capture & lazy static initialization
const string REGEX = @"((?<id>\d+)\:)?(?<par1>\d+)\-(?<par2>\d+)\-(?<par3>\d+)(\/(?<par4>\d+)\-(?<par5>\d+))?";
private static Lazy<Regex> g_RegEx = new Lazy<Regex>(() => new Regex(REGEX,
RegexOptions.ExplicitCapture | RegexOptions.Compiled | RegexOptions.CultureInvariant));
...
Match m = g_RegEx.Value.Match(value);
Group gID = m.Groups["id"] as Group;
@xanathar
xanathar / HttpListener #1
Created June 17, 2014 12:22
HttpListener #1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Net;
using System.Diagnostics;
using System.IO;
using System.Web;
using System.Collections.Specialized;
@xanathar
xanathar / HttpListener #2
Created June 17, 2014 12:29
HttpListener #2 - WCF / MVC way
public class CommandsController : ApiController
{
[HttpGet][HttpPost][HttpDelete]
public void Action1()
{
}
[HttpGet]
[HttpPost]
[HttpDelete]
@xanathar
xanathar / LockHelper
Last active August 29, 2015 14:02
Wrapper of Monitor class for easier deadlock debug
// original source is likely to be https://github.com/thinkpixellab/bot/blob/master/net40-client/Core/LockHelper.cs although I can't verify it anymore.
/// <summary>
/// Provides services of Monitor static class, but while allowing better debugging of deadlocks.
/// </summary>
public class LockHelper
{
/// <summary>
/// Creates a new instance of LockHelper.
@xanathar
xanathar / ExpTree_PropertyAccessors
Created September 11, 2014 14:34
Get/Set instance property using expression trees dynamic code
// This builds untyped accessors. Remove converts for strong typing.
var paramExp = Expression.Parameter(typeof(object), "obj");
var castParamExp = Expression.Convert(paramExp, this.UserDataDescriptor.Type);
var propAccess = Expression.Property(castParamExp, PropertyInfo.Name);
var castPropAccess = Expression.Convert(propAccess, typeof(object));
var lambda = Expression.Lambda<Func<object, object>>(castPropAccess, paramExp);
Func<object, object> getter = lambda.Compile();
@xanathar
xanathar / gist:6954d46af5097218a7fe
Created September 16, 2014 09:53
Image resize w/System.Drawing
// Taken from http://social.msdn.microsoft.com/Forums/vstudio/en-US/a43fe625-a5cd-4438-895f-3ddeec6eb866/image-resizing-using-c?forum=csharpgeneral
public static System.Drawing.Bitmap ResizeImage(System.Drawing.Image image, int width, int height)
{
//a holder for the result
Bitmap result = new Bitmap(width, height);
//use a graphics object to draw the resized image into the bitmap
using (Graphics graphics = Graphics.FromImage(result))
{
@xanathar
xanathar / Log2 - Healing button
Created May 15, 2015 16:39
Button/Crystal hybrid in log2
defineObject{
name = "xan_heal_button",
components = {
{
class = "Crystal",
cooldown = 0,
},
{
class = "Model",
name = "buttonModel",
@xanathar
xanathar / bash_profile
Last active August 29, 2015 14:23
My bash_profile on OS/X
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
export GIT_EDITOR='subl -w'
export EDITOR='subl -w'
export JAVA_HOME=$(/usr/libexec/java_home)
export AKKA_HOME="~/tools/akka-2.3.11"
alias ll='ls -FGlAhp'
@xanathar
xanathar / Unity_InstantiatePrefabByName.cs
Created September 17, 2015 17:32
Instantiate Prefab By Name
using UnityEngine;
using System.Collections;
public class LevelCloner : MonoBehaviour
{
// Use this for initialization
void Start ()
{
Debug.Log ("Enter!");