Skip to content

Instantly share code, notes, and snippets.

@LambdaSix
LambdaSix / .gitignore
Created August 17, 2012 10:56
VS2010-2012 Ignore file
Thumbs.db
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
@LambdaSix
LambdaSix / output
Last active December 10, 2015 21:28
Struct assignment.
$ gcc struct.c -o struct
$ ./struct
a.Bar: 1
b.Bar: 2
a.Bar: 2
b.Bar: 1
@LambdaSix
LambdaSix / cat.rb
Created January 11, 2013 10:01
Ruby /bin/cat in one line
puts ARGF.read
@LambdaSix
LambdaSix / Invoke.cs
Last active December 11, 2015 11:28
To return null or throw an exception? :/
public class ValidationMethods
{
private IDictionary<object, Func<object, object, Boolean>> _functionTable;
public IDictionary<object, Func<object, object, Boolean>> FunctionTable
{
get
{
return _functionTable
?? (_functionTable = new Dictionary<object, Func<object, object, bool>>());
@LambdaSix
LambdaSix / ListPickerHack.cs
Created January 22, 2013 16:22
To prevent ListPicker from raising BackKeyPress on your views. Otherwise, navigating back from a listpicker full screen mode will raise the key back event as if the page had actually gone back. This is probably true for any other controls that open something to fill the screen (LongListSelector, etc)
RootFrame.BackKeyPress += (o, args) =>
{
if (o is PhoneApplicationFrame)
{
var j = o as PhoneApplicationFrame;
var listPicker = "/Microsoft.Phone.Controls.Toolkit;component/ListPicker/ListPickerPage.xaml";
if (j.Source.OriginalString == listPicker)
{
return;
}
@LambdaSix
LambdaSix / RaisePropertyChanged.cs
Last active December 11, 2015 20:28
MVVM Light's RaisePropertyChanged.
/// <summary>
/// Raises the PropertyChanged event if needed.
/// </summary>
/// <typeparam name="T">The type of the property that
/// changed.</typeparam>
/// <param name="propertyExpression">An expression identifying the property
/// that changed.</param>
[SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate",
Justification = "This cannot be an event")]
[SuppressMessage(
@LambdaSix
LambdaSix / ted.c
Created February 1, 2013 14:33
Simple IRC bot.
#include <stdio>
#include <stdlib>
#include <stdarg>
#include <winsock.h>
#include <errno.h>
#define WIN32_LEAN_AND_MEAN
#define _SERVER_PORT 6667
#define _SERVER_HOST "irc.freenode.org"
#define _SECURE_LOGIN
@LambdaSix
LambdaSix / ByteConverter.cs
Created February 4, 2013 16:25
Examples of converting byte arrays to types.
public class StreamByteConverter
{
private byte[] m_Data;
private int m_Size;
private int m_Index;
public Stream( byte[] data, int size, bool fixedSize )
{
m_Data = data;
m_Size = size;
@LambdaSix
LambdaSix / BooleanStringConverter.cs
Created February 7, 2013 11:38
Convert between String and Boolean? in a bad way.
/// <summary>
/// Convert between Boolean? and String
/// </summary>
public class BooleanToStringConverter : IValueConverter
{
public object Convert( object value, Type targetType, object parameter, CultureInfo culture)
{
// bool? to string.
bool castValue = (value as bool?) ?? false;
@LambdaSix
LambdaSix / ColourConvert.cs
Last active December 12, 2015 12:19
Convert Long (6/8 hex colour) to a Color struct.
///<Summary>
/// Converts a hexadecimal colour code (8-hex with alpha) into a .net Color struct.
///</Summary>
///<remarks>
/// If the input string is invalid, will throw an exception from parsing, you
/// should handle this in the callee.
///</remarks>
///<param name="colour">The colour in numerical form. Prefix with # for hexadecimal format.</param>
///<example>
/// Example of converting hexadecimal string and ulong values to a Color.