Skip to content

Instantly share code, notes, and snippets.

public void LoadBitmapFromStream()
{
System.Drawing.Image bmp = System.Drawing.Bitmap.FromFile(@"C:\Temp\test.png");
MemoryStream strm = new MemoryStream();
bmp.Save(strm, System.Drawing.Imaging.ImageFormat.Bmp);
strm.Position = 0;
System.Drawing.Image img = System.Drawing.Image.FromStream(strm);
BitmapImage bi = new BitmapImage();
bi.BeginInit();
@LGM-AdrianHum
LGM-AdrianHum / rewriteoutput.cs
Created February 8, 2016 03:44
Redirect all output from the Console to a TextWriter
static public void Main ()
{
FileStream ostrm;
StreamWriter writer;
TextWriter oldOut = Console.Out;
try
{
ostrm = new FileStream ("./Redirect.txt", FileMode.OpenOrCreate, FileAccess.Write);
writer = new StreamWriter (ostrm);
}
@LGM-AdrianHum
LGM-AdrianHum / UnpackZipFile.cs
Last active February 10, 2016 00:49
Just a snippet that uses System.IO.Compression to copy the data from an embedded files to a string and send it to the console.
using System;
using System.IO;
using System.IO.Compression;
using System.Linq;
namespace CheckZipToString
{
internal class Program
{
private static void Main(string[] args)
@LGM-AdrianHum
LGM-AdrianHum / WebUtils.cs
Last active May 18, 2016 00:08
DownloadAsync for HTTP
public static class WebUtils
{
private static Lazy<IWebProxy> proxy
= new Lazy<IWebProxy>(() => string.IsNullOrEmpty(Settings.Default.WebProxyAddress) ? null :
new WebProxy { Address = new Uri(Settings.Default.WebProxyAddress), UseDefaultCredentials = true });
public static IWebProxy Proxy
{
get { return WebUtils.proxy.Value; }
}
public static void Main(string[] args)
{
List<string> arrHeaders = new List<string>();
Shell32.Shell shell = new Shell32.Shell();
Shell32.Folder objFolder;
objFolder = shell.NameSpace(@"C:\temp\testprop");
for( int i = 0; i < short.MaxValue; i++ )
Function Combine(WorkRng As Range, Optional Sign As String = ",") As String
Dim Rng As Range
Dim OutStr As String
For Each Rng In WorkRng
If Rng.Text <> "," Then
OutStr = OutStr & Rng.Text & Sign
End If
Next
Combine = Left(OutStr, Len(OutStr) - 1)
End Function
/*******Interrupt-based Rotary Encoder Sketch*******
by Simon Merrett, based on insight from Oleg Mazurov, Nick Gammon, rt, Steve Spence
modified at EE to include the select switch
Tutorial at:
http://exploreembedded.com/wiki/Interactive_Menus_for_your_project_with_a_Display_and_an_Encoder
*/
static int pinA = 2; // Our first hardware interrupt pin is digital pin 2
static int pinB = 3; // Our second hardware interrupt pin is digital pin 3
@LGM-AdrianHum
LGM-AdrianHum / OneLineAtATime.cs
Created August 16, 2016 22:19
Read one line of text from a text file at a time until data is exhausted.
int counter = 0;
string line;
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
Console.WriteLine (line);
counter++;
@LGM-AdrianHum
LGM-AdrianHum / OsHelper.cs
Created August 17, 2016 04:59
IterateFiles - Return a IEnumerable of strings.
using System.Collections.Generic;
using System.IO;
namespace SyncFTP
{
public static class OsHelper
{/// <summary>
///
/// </summary>
/// <param name="path"></param>
@LGM-AdrianHum
LGM-AdrianHum / ListboxWithWrapPanel.xaml
Created September 3, 2016 00:42
Create A Listbox With A Wrap Panel as a Host
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem>listbox item 1</ListBoxItem>
<ListBoxItem>listbox item 2</ListBoxItem>
<ListBoxItem>listbox item 3</ListBoxItem>
<ListBoxItem>listbox item 4</ListBoxItem>