Skip to content

Instantly share code, notes, and snippets.

View bh3605's full-sized avatar

Bryson Hair bh3605

View GitHub Profile
@bh3605
bh3605 / ListBoxTableFilter.js
Last active August 29, 2015 14:27
Overview of how filtering using a dropdown search for a listbox in asp.net
function search(e) {
var id = e.target.id;
var val = document.getElementById(id).value.toUpperCase();
var grid = document.getElementById("ct100_ContentPlaceHolder1_dropdownListings");
$('#ctl00_ContentPlaceHolder1_dropdownListings').find('tbody').find('tr').each(function (index, element) {
var blah = $(this).text().toUpperCase();
if ($(this).text().toUpperCase().indexOf(val) < 0)
$(this).hide();
else
@bh3605
bh3605 / StructToObjectConverter.vb
Last active August 29, 2015 14:27
Builds an object type from a struct containing all of the variable members of the struct as properties with getters and setters
imports System.Reflection
imports System.Reflection.Emit
imports System.Threading
''' <summary>
''' The purpose of this class is to take a struct and build and return an object type containing all of
''' the variable members of the struct as properties with getters and setters. You can then make an
''' instance of the object type by calling activator.createinstance(type).
''' Usage: dim converter = new StructConverter()
''' dim structObjectType as Type = converter.buildDynamicProperties(GetType(YourStruct))
@bh3605
bh3605 / VBCompileDateCreator.vb
Last active August 29, 2015 14:27
Figures out application compile date
const PeHeaderOffset as integer = 60
const LinkerTimestampOffset as integer = 8
dim filePath = System.Reflection.Assembly.GetExecutingAssembly().location
dim b(2047) as byte
dim s as IO.FileStream = new IO.FileStream(filePath, IO.FileMode.Open, IO.FileAccess.Read)
try
s.Read(b, 0, 2048)
finally
@bh3605
bh3605 / setFilter.vb
Created August 12, 2015 11:34
Hides sections of data points in a data table and returns a modified copy
private function setExclusionFilter(table as DataTable) as DataTable
dim unit = cbxSelectUnit.text
dim xAxisName = table.columns(0).columnName
dim yAxisName = table.columns(1).columnName
dim unitExclusionRegions = from row in exclusionRegions
where row.field(Of String)("UnitID") = unit and row.field(Of Boolean)("Active") = true
select axis = row.field(Of Char)("Axis"), low = row.field(Of Double)("Low"), high = row.field(Of Double)("High")
dim query as String = ""
@bh3605
bh3605 / FocusedTextBox.vb
Created August 12, 2015 14:56
Gives a textbox an easy way of highlighting when tabbing and clicking
''' <summary>
''' This class adds two events for easy highlighting when tabbing and clicking.
''' Double clicking will unhighlight and leave the cursor at the beginning.
''' Uses the click and doubleclick events.
''' </summary>
public class FocusedTextBox
''' <summary>
''' Adds two events to the given textbox. Will override
''' click and doubleclick events.
@bh3605
bh3605 / confirmmodal.js
Created June 3, 2016 17:55
A simple extensible modal used primarily for confirm dialogs.
(function ($) {
$.fn.confirmModal = function (opts) {
var body = $('body');
var unique = Math.floor(Math.random() * (1e+9));
var clickedOutside = true;
// the innerFrameId allows a body of markup to be inserted w append in lieu of message
// use detach first if the nodes are already in the dom
var defaultOptions = {
confirmModalId: "confirmModal" + unique,
confirmInnerFrameId: "confirmInnerFrame" + unique,
@bh3605
bh3605 / ko.extras.js
Created June 1, 2017 12:59
Helpful js functions for knockout.js library
//given an object and a white list; reset all knockout observables to undefined
var reset = function (obj, whitelist) {
for (var prop in obj) {
if ( obj.hasOwnProperty(prop) && ko.isObservable(obj[prop]) && !ko.isComputed(obj[prop]) && whitelist.indexOf(prop) === -1 ) {
obj[prop](undefined);
}
}
};
//useful for when an object is used for the value property of a dropdown. Usage: "optionsAfterRender: setOptionValue('propertyName')"
@bh3605
bh3605 / knockout.recaptcha.js
Created September 28, 2017 18:52
knockout way of building a recaptcha
/**
* Make sure your page is using <script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
* or if you're using <script src="https://www.google.com/recaptcha/api.js" async defer></script> then comment out
* Recaptcha.create and uncomment the grecaptcha.render.
* based on http://jsfiddle.net/jaGWY/
* docs: https://developers.google.com/recaptcha/intro & http://recaptchamvc.apphb.com/Home/Document
*/
var app = app || {};
app.knockout = app.knockout || {};
@bh3605
bh3605 / knockout.google.map.js
Created September 28, 2017 18:55
A Knockout way of communicating and initializing a google map
var app = app || {};
app.google = app.google || {};
app.google.map = (function ($) {
var model = {
markers: [],
initialized: ko.observable(false),
infoWindow: null,
apiLoaded: ko.observable(false)
};
@bh3605
bh3605 / WhoIsLoggedIn.sql
Created April 2, 2021 15:11
Returns a sql db server's signed in users
SELECT SESSION.login_name AS 'Database User Name'
,MAX(SESSION.login_time) AS 'Login Time'
,SESSION.host_name AS 'PC Name'
,SESSION.program_name AS 'Program Using'
,SESSION.client_interface_name AS 'Interface'
,UM.USER_NAME AS 'User'
FROM master.sys.dm_exec_Sessions SESSION
WHERE SESSION.session_id >= 51 -- All user Sessions
GROUP BY SESSION.login_name
,SESSION.host_name