Skip to content

Instantly share code, notes, and snippets.

View drewchapin's full-sized avatar

Drew Chapin drewchapin

View GitHub Profile
@drewchapin
drewchapin / bash_coproc_example.sh
Last active January 3, 2024 11:13
Example of how to use the COPROC feature of Bash by showing a progress bar with zenity and updating it.
#!/bin/bash
on_exit() {
echo "#The script has quit unexpectidly on line $1" >&$z
echo "The script has quit unexpectidly on line $1" >&2
exit
}
on_error() {
echo "Error on line $1"
// Add this to pre-build event
// "%CommonProgramFiles(x86)%\microsoft shared\TextTemplating\$(VisualStudioVersion)\TextTransform.exe" -a !!BuildConfiguration!$(Configuration) "$(ProjectDir)Properties\AssemblyInfo.tt"
//
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Text.RegularExpressions" #>
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@drewchapin
drewchapin / ControlsOfType.cs
Created December 12, 2017 02:37
Returns all child and grandchild controls of of the specified type.
/// <summary>
/// Returns all child and grandchild controls of of the specified type.
/// </summary>
/// <typeparam name="T">Type of control to look for</typeparam>
/// <param name="parent">Parent to get list of controls from</param>
/// <returns></returns>
public static IEnumerable<T> ControlsOfType<T>( this Control parent ) where T : Control
{
foreach( Control child in parent.Controls )
{
@drewchapin
drewchapin / ControlDoubleBuffering.cs
Created December 12, 2017 02:36
Turns on or off double buffering for controls that do not expose the property.
/// <summary>
/// Turns on or off double buffering for controls that do not expose the property.
/// </summary>
public static void DoubleBuffered( this Control control, bool value )
{
Type type = control.GetType();
PropertyInfo info = type.GetProperty("DoubleBuffered",BindingFlags.Instance|BindingFlags.NonPublic);
info.SetValue(control,value,null);
}
@drewchapin
drewchapin / DataSetCompressionExtensions.cs
Last active December 16, 2022 17:56
Wrappers for WriteXml() and ReadXml() methods of DataSet and DataTable objects that first compresses the XML using Gzip.
/**
* \author Drew Chapin <drew@drewchapin.com>
* \copyright Public Domain
* \date 2017/12/08
* \details Wrappers for WriteXml() and ReadXml() methods of DataSet and DataTable objects that first compresses the XML using Gzip.
*
* https://gist.github.com/drewchapin/57b3ae7d5c4ba257aa4e02db88388f9e
*
*/
using System;
@drewchapin
drewchapin / SaveColumnSettings.cs
Last active September 26, 2022 06:41
Extension methods to save/load column settings to/from the current user registry for a DataGridView control.
/// <summary>
/// Generate a backslash separated path showing parent\child\grandchild relationship.
/// </summary>
public static string GeneratePath( this Control control )
{
string path = control.Name;
for( Control parent = control.Parent; parent != null; parent = parent.Parent)
path = String.Format("{0}\\{1}",parent.Name,path);
return path;
}
static int Update( SqlConnection sql, DataTable table, string tableName = null )
{
int count = 0;
tableName = tableName ?? table.TableName;
if( String.IsNullOrWhiteSpace(tableName) ) throw new NullReferenceException("tableName cannot be null or empty");
if( sql.State != ConnectionState.Open )
sql.Open();
using( SqlCommand cmd = sql.CreateCommand() )
{
List<string> keys = table.PrimaryKey.Select(x=>x.ColumnName).ToList();
@drewchapin
drewchapin / ShiftTextBoxHistory.cs
Last active July 12, 2017 21:55
Shift TextBox Values
private void ShiftTextBoxHistory( DataRow next )
{
TextBox[][] c = new TextBox[][]
{
new TextBox[]{lastLotNumber1TextBox, lastPartNumber1TextBox, lastBatchNumber1TextBox},
new TextBox[]{lastLotNumber2TextBox, lastPartNumber2TextBox, lastBatchNumber2TextBox},
new TextBox[]{lastLotNumber3TextBox, lastPartNumber3TextBox, lastBatchNumber3TextBox},
new TextBox[]{lastLotNumber4TextBox, lastPartNumber4TextBox, lastBatchNumber4TextBox},
new TextBox[]{lastLotNumber5TextBox, lastPartNumber5TextBox, lastBatchNumber5TextBox},
};
/**
* @author Drew Chapin <drew@drewchapin.com>
* @date 2017/06/27
* @copyright Public Domain
*/
using System.Collections.Generic;
namespace System.Data
#include <Windows.h>
#include <ShObjIdl.h>
#include <iostream>
int main(int argc, char* argv[])
{
HRESULT hResult = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if( SUCCEEDED(hResult) )