Skip to content

Instantly share code, notes, and snippets.

@wolf99
wolf99 / ChangeFormControlEnabledState.vb
Last active August 29, 2015 14:19
Change the enabled state of all VB.NET form controls of type T
Private Sub ChangeFormControlEnabledState(Of T As Control)(f As Form, state As Boolean)
Dim c As Control
For Each c In f.Controls
If TypeOf c Is T Then
CType(c, T).Enabled = state
End If
Next
End Sub
@wolf99
wolf99 / caesar.c
Created April 29, 2015 10:41
Minimal caesar cipher implementation for CS50
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<cs50.h> // Can be commented out if using test word
//char c[] = "hello"; // Uncomment these lines to use test word "hello".
//char *p = &c[0];
int main(int argc, char * argv[]) {
char k=(argc>1)?k=atoi(*++argv):0;
if((argc<2)||(k<=0)){printf("Bad number.\n");return 1;}
else{
@wolf99
wolf99 / CAP_setPrescale Raw.c
Last active August 29, 2015 14:20
CAP_setPrescale() for TI F2802x cap.h support drivers files
static void CAP_setPrescale(CAP_Handle capHandle, const CAP_Prescale_e prescale)
{
CAP_Obj *cap = (CAP_Obj *)capHandle;
/* clear the bits */
cap->ECCTL1 &= (~CAP_ECCTL1_PRESCALE_BITS);
/* Set the new value */
cap->ECCTL1 |= (uint16_t)prescale;
@wolf99
wolf99 / TEST_EQUAL_INT_T.c
Last active August 29, 2015 14:23
Macro to test if whole number data types (int, char) are of the same value, type size and signedness
/* Note: 'x' and 'y' arguments must be modifiable lvalues.
* Example usage:
* int16_t a = 5, b = 5;
* TEST_EQUAL_INT_T(int16_t, a, b);
*/
#include <stdint.h> /* Needed for uintmax_t */
#define TEST_EQUAL_INT_T(T, x, y) { uintmax_t _x = (x), _y = (y); /* Save values to temp vars */ \
if (((x) == (y)) /* Check if values are equal*/ \
&& (sizeof(x) == sizeof(T)) /* Check if type sizes match */ \
&& (sizeof(y) == sizeof(T)) \
@wolf99
wolf99 / HaltGoBox.vb
Created August 7, 2015 13:36
A Halt/Go display user control that inherits from a TextBox
Public Class HaltGoBox
Inherits TextBox
Enum HaltGoState
Go = 0
Halt = 1
End Enum
Private _state As HaltGoState
@wolf99
wolf99 / HaltGoLabel.vb
Created August 7, 2015 13:40
A Halt/Go display user control that inherits from a Label
Public Class HaltGoLabel
Inherits Label
Enum HaltGoState
Go = 0
Halt = 1
End Enum
Private _state As HaltGoState
@wolf99
wolf99 / BetterBindingList.vb
Last active August 29, 2015 14:27
BetterBindingList(T) class that adds FindIndex method to inherited BindingList(T) class
Imports System.ComponentModel
Imports System.Diagnostics.Contracts
' The FindIndex methods use code converted from the MSDN C# reference source as of 2015 Aug 17 13:34 GMT at:
' http://referencesource.microsoft.com/#mscorlib/system/collections/generic/list.cs,cadc26eb4ba974e4
Public Class BetterBindingList(Of T)
Inherits BindingList(Of T)
Public Function FindIndex(match As Predicate(Of T)) As Integer
@wolf99
wolf99 / Unbold.vb
Last active August 29, 2015 14:27
Extension to Un-embolden the text of collection of VB.NETcontrols, including any children controls, excepting of a given type T
'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
@wolf99
wolf99 / Enabled.vb
Last active August 29, 2015 14:27
Extensions to change the Enabled state of a given type of VB.NET control in collection of controls, recursing through any child controls
'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)
@wolf99
wolf99 / ToHexString.vb
Last active August 29, 2015 14:27
Extensions to convert VB.NET numeric type data to formatted hexadecimal strings
'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