This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Usage: Form1.Controls.UnBold(Of GroupBox) 'Un-emboldens all control.Font perperties, except for GroupBox | |
Imports System.Runtime.CompilerServices | |
Module Extensions | |
<Extension()> | |
Public Sub UnBold(Of T As Control)(cc As Control.ControlCollection) | |
For Each c As Control In cc | |
If Not TypeOf c Is T AndAlso c.GetType.GetProperty("Font") IsNot Nothing Then | |
Dim RegularFont As New Font(c.Font.FontFamily, c.Font.Size, FontStyle.Regular) | |
c.Font = RegularFont | |
ElseIf c.HasChildren Then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Usage: Form1.Controls.Enabled(Of Button)(False) | |
Imports System.Runtime.CompilerServices | |
Module Extensions | |
<Extension()> | |
Public Sub Enabled(Of T As Control)(cc As Control.ControlCollection, state As Boolean) | |
For Each c As Control In cc ' Iterate through every object in the container | |
If TypeOf c Is T Then ' Check if the object matches the type to set the state on | |
CType(c, T).Enabled = state ' Set the state on the matching object | |
ElseIf c.HasChildren Then ' Check if control is a parent ("Congratulations, omg look at that cute semi-colon!") | |
Enabled(Of T)(c.Controls, state) ' Recurse to handle the children (else maybe get a nanny) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Usage: | |
' Dim MyBytes() As Byte = {0, &HA5} | |
' Console.WriteLine(MyBytes.ToHexString) | |
' 'Prints "00 A5" | |
Imports System.Runtime.CompilerServices | |
Public Module Extensions | |
<Extension()> | |
Public Function ToHexString(a As Byte(), offset As Integer, length As Integer) As String | |
Dim RetVal As New System.Text.StringBuilder((length * 3) - 1) | |
Dim ByteStr As String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'This is a VB version of the C# code by Mike Bevers as of 19 Aug 2015 12:07 at | |
'http://www.mikebevers.be/blog/2010/02/extended-combobox-with-a-selection-changing-event/ | |
'Usage: | |
'Private Sub BetterComboBox1_SelectedIndexChanging( _ | |
' sender As System.Object, _ | |
' e As System.ComponentModel.CancelEventArgs _ | |
') Handles BetterComboBox1.SelectedIndexChanging | |
' | |
' If True Then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Usage: ListBox1.AddLogLine("Log this!") | |
Imports System.Runtime.CompilerServices | |
Module FormExtensions | |
Delegate Sub UpdateLog(lb As ListBox, line As String) | |
<Extension()> | |
Public Sub AddLogLine(lb As ListBox, line As String) | |
If (lb.InvokeRequired) Then 'Invoke from the GUI thread if called from a different one | |
lb.Invoke(New UpdateLog(AddressOf AddLogLine), lb, line) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int my_isnan(double x) | |
{ | |
volatile double tmp = x; /* Prevent optimization by compiler. */ | |
return tmp != x; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int my_inf(double x) | |
{ | |
volatile double tmp = x; /* Prevent optimization by compiler. */ | |
if ((tmp == x) && ((tmp - x) != 0.0)) | |
return x < 0.0 ? -1 : 1; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* bar.c */ | |
#include foo.h | |
int bar (void) | |
{ | |
int a = 5, b = 0; | |
e = foo(a, &b); /* Note b is local, thus test won't know its address. */ | |
/* ... use b ... */ | |
return e; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kind classify_number(int n) | |
{ | |
kind class = error; | |
if (n > 0) { | |
int buf = aliquot_sum(n); | |
if (buf > n) { | |
class = abundant_number; | |
} else if (buf < n) { | |
class = deficient_number; | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
namespace FooProgram | |
{ | |
public static class DerivedClassEnumerator | |
{ | |
// Class that list all the types derived from a given type |