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 / GetSerialPortNames.vb
Last active September 2, 2015 17:14
Get a collection serial port names using VB.NET
Private Function GetSerialPortNames() As List(Of String)
Dim PortNames As New List(Of String)
For Each PortName In My.Computer.Ports.SerialPortNames
PortNames.Add(PortName)
Next
Return PortNames
End Function
@wolf99
wolf99 / FillComboBox.vb
Last active September 2, 2015 17:14
Extension to fill a VB.NET ComboBox control from a collection or list of strings
' Requires `Imports System.Runtime.CompilerServices`
Module Extensions
<Extension()>
Public Function Fill(Of T)(cb As Control, cc As ICollection(Of T)) As Integer
Dim cbc As ComboBox = CType(cb, ComboBox)
Dim n As Integer = 0
If cc.Count = 0 Then
Return False
End If
For Each cn In cc
@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 / tasks.json
Last active May 22, 2019 09:57
Visual Studio Code tasks.json for GCC
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
{
"version": "0.1.0",
@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