Skip to content

Instantly share code, notes, and snippets.

View kjlape's full-sized avatar
🤝
nice to meet you

Kaleb Lape kjlape

🤝
nice to meet you
View GitHub Profile
//Goes into OnContentLoaded()
MaterialGroup material = (MaterialGroup)_boardGroup.Find<Surface>().Material;
DiffuseMaterialPart materialPart = (DiffuseMaterialPart)((MaterialPaintGroup)material.MaterialParts
.First(x => x.Name == "ground").MaterialGroup.MaterialParts
.First()).MaterialParts.First();
_boardTexture = materialPart.Texture;
@kjlape
kjlape / Texture2DStuff.cs
Created April 3, 2013 04:45
Some example snippets from around the web related to low-level XNA Texture2D manipulation.
//To convert a Texture2D to an Image :
public static System.Drawing.Image Texture2Image(Texture2D texture)
{
if (texture == null)
{
return null;
}
if (texture.IsDisposed)
Surface s = _scene.Find<Surface>();
Texture2D t = MaterialPaintGroup.GetMaskTextures((MaterialGroup)s.Material).OfType<Texture2D>().First();
RenderTarget2D target = new RenderTarget2D(GraphicsDevice, t.Width, t.Height);
GraphicsDevice.SetRenderTarget(target);
SpriteBatch sb = new SpriteBatch(GraphicsDevice);
@kjlape
kjlape / MaterialPaintGroup.cs
Created April 5, 2013 02:52
Bug fixes for Engine Nine 1.6 as suggested by yufeih.
/// Sets the mask textures of the material group.
/// </summary>
public static void SetMaskTextures(MaterialGroup materialGroup, System.Collections.IList value)
{
if (value == null)
throw new ArgumentNullException("value");
AttachablePropertyServices.SetProperty(materialGroup, MaskTexturesProperty, value);
MaterialPartCollection materialParts = materialGroup.MaterialParts as MaterialPartCollection;
@kjlape
kjlape / CreateTicketTables.sql
Last active December 25, 2015 16:49
Script for finding the current status of each ticket.
-- MSSQL Table structure for Compsys Ticketing app.
CREATE TABLE Employee (
id int IDENTITY(1,1) PRIMARY KEY,
email varchar(64) NOT NULL,
f_name varchar(64) NOT NULL,
l_name varchar(64) NOT NULL
);
CREATE TABLE Role (
id int IDENTITY(1,1) PRIMARY KEY,
@kjlape
kjlape / RxUIViewBoilerplate.snippet
Created October 22, 2013 16:05
Stop retyping the same ReactiveUI boilerplate code. Use a snippet!
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>RxUI IViewFor Implementation</Title>
<Author>Kaleb Lape</Author>
<Description>Helps relieve the RxUI IViewFor boilerplate strain.</Description>
<Shortcut>snipiviewfor</Shortcut>
</Header>
@kjlape
kjlape / IMutableDependencyResolverMixins.cs
Last active December 27, 2015 02:58
Messing with ReactiveUI dependency resolver. Just for fun.
public static class IMutableDependencyResolverMixins
{
public static void Register<T>(this IMutableDependencyResolver This, Func<Func<T>, object> factory, Type serviceType, string contract = null)
{
This.Register(() => factory(() => This.GetService<T>(contract)), serviceType, contract);
}
public static void Register<T1, T2>(this IMutableDependencyResolver This, Func<Func<T1>, Func<T2>, object> factory, Type serviceType, string contract = null)
{
This.Register(() => factory(() => This.GetService<T1>(contract),() => This.GetService<T2>()), serviceType, contract);
@kjlape
kjlape / TicketingSession.cs
Last active December 28, 2015 08:39
How to turn off the default database initialization in Entity Framework 6 Code First.
using AdmitOne.Domain.Entities;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
namespace AdmitOne.Persistence.Ticketing
{
public class TicketingSession : Session
{
public TicketingSession() : base(new TicketingContext()) { }
@kjlape
kjlape / copyVB6proj.py
Last active December 30, 2015 07:29
Barebones script for copying all files necessary to build a given Visual Basic 6.0 project file, or any file with a complete listing of all project dependencies.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import string
from fileinput import input
from os.path import dirname, basename, isdir, isfile, join, splitext
from shutil import copy2
def copyProject(project, destinationDir = ""):
projectDir = dirname(project)
public static Func<A, R> Memoize<A, R>(this Func<A, R> f)
{
var cache = new System.Collections.Concurrent.ConcurrentDictionary<A, R>();
return a => cache.GetOrAdd(a, f);
}