Skip to content

Instantly share code, notes, and snippets.

View JonHaywood's full-sized avatar

Jon Haywood JonHaywood

View GitHub Profile
@JonHaywood
JonHaywood / gist:a682934fbadc249e5bf99e6e9b35358e
Last active September 9, 2022 20:25 — forked from giannisp/gist:1d8dc9a6ed13876c51ccfe9fefcb311e
Using lodash from Chrome's dev tools console
# How to make lodash available via "_" on console
var el = document.createElement('script');
el.src = 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js';
document.getElementsByTagName('head')[0].appendChild(el);
# Use _.VERSION or any other function to verify that it worked
@JonHaywood
JonHaywood / pqueue.h
Created September 10, 2017 02:22
Priority Queue in C
/* pqueue.h
Header file for pqueue implementation
by: Jonathan Haywood
*/
#define PQUEUESIZE 1000
#define PARENT(i) ((i-1)/2)
#define LEFT(i) ((2*i+1))
-- Search Tables
SELECT c.name AS 'ColumnName'
,t.name AS 'TableName'
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE '%MyName%'
ORDER BY TableName
,ColumnName;
-- Search Tables and Views
public static string[] SplitCsv(string input)
{
Regex csvSplit = new Regex("(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)", RegexOptions.Compiled);
List<string> list = new List<string>();
string curr = null;
foreach (Match match in csvSplit.Matches(input))
{
curr = match.Value;
if (0 == curr.Length)
{
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
// globally available via window
var _OldComponent = window.MyComponent;
var api = window.MyComponent = factory();
api.noConflict = function () {
@JonHaywood
JonHaywood / PhpArrayConverter.cs
Last active August 29, 2015 14:19 — forked from xiangwan/C php Serializer.cs
Class which can serialize and deserialize strings created by PHP's serialize and unserialize methods.
public class PhpArrayConverter
{
//types:
// N = null
// s = string
// i = int
// d = double
// a = array (hashtable)
private readonly NumberFormatInfo numberFormatInfo;
@JonHaywood
JonHaywood / Aes256EncryptionService
Created October 27, 2014 06:16
Aes-256 Encryption in C#
public class Aes256EncryptionService
{
public byte[] GenerateKey()
{
using (var aes = CreateAes256Algorithm())
{
aes.GenerateKey();
return aes.Key;
}
}
@JonHaywood
JonHaywood / Compiler.cs
Created September 22, 2014 02:26
Compile C# Source on-the-fly
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
namespace SourceCompiler
{
/// <summary>
@JonHaywood
JonHaywood / BinaryMediaTypeFormatter
Created September 16, 2014 21:12
BinaryMediaTypeFormatter for Web API 2.2
/// <summary>
/// Based on https://gist.github.com/aliostad/2519771
/// </summary>
public class BinaryMediaTypeFormatter : MediaTypeFormatter
{
private static readonly Type SupportedType = typeof(byte[]);
private bool isAsync;
public BinaryMediaTypeFormatter()
@JonHaywood
JonHaywood / ShowWaitDialog.cs
Created September 11, 2012 21:21
Wait Dialog for Windows Forms
private void ShowWaitDialog(Action codeToRun)
{
ManualResetEvent dialogLoadedFlag = new ManualResetEvent(false);
// open the dialog on a new thread so that the dialog window gets
// drawn. otherwise our long running code will run and the dialog
// window never renders.
(new Thread(() =>
{
Form waitDialog = new Form()