Skip to content

Instantly share code, notes, and snippets.

View GER-NaN's full-sized avatar

Gerald Eckert GER-NaN

View GitHub Profile
@GER-NaN
GER-NaN / PSAutomation_More.ps1
Created September 11, 2019 13:15
More powershell automation of the IE web browser. These are specific to my app and stand as an example only.
#Needs to be ran as administrator
#Logs in as user and creates a generic listing
##hacker-line that causes this script to run in a new session as administrator if not already elevated
#if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
#{
# Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs;
# exit
#}
@GER-NaN
GER-NaN / PSAutomation.ps1
Last active September 11, 2019 13:15
Automation browser action with powershell
#Needs to be ran as administrator
#Performs a login and logout using a valid account
#Hardcoded local host means you need to have a Visual Studio running an instance of the app, or change the url
#hacker-line that causes this script to run in a new session as administrator if not already elevated
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs;
exit
@GER-NaN
GER-NaN / SqlCommandToQueryString.cs
Last active September 7, 2018 18:43
Converts a .NET SqlCommand object to an executable SQL string. This is useful for debugging queries or to examine the stored procedure parameters. Output returned from calling SqlCommandToQueryString.Convert(...) will be a fully valid SQL command that can be copy/pasted into SSMS.
/// <summary>Converts a SqlCommand object to the equivelant TSQL Query. This can be useful for examining the parameters or debugging generated statements using SSMS.</summary>
/// <remarks>From https://stackoverflow.com/a/4146573/1363780 with style modifications and misc fixes</remarks>
public static class SqlCommandToQueryString
{
/// <summary> Converts the SqlCommand to the equivelant TSQL query string</summary>
/// <param name="cmd">The SqlCommand object to convert</param>
/// <returns>A string representation of the SqlCommand. This will be valid TSQL and can be copy/pasted into SSMS and executed or debugged.</returns>
public static string Convert(SqlCommand cmd)
{
StringBuilder sqlString = new StringBuilder();
@GER-NaN
GER-NaN / GetIdentityValues.sql
Created August 17, 2017 11:42
Query for tables that have an Identity column and get the current value of the the identity column
--Get tables and their current identity
--This is useful to double check ID values when a database has been seeded with initial data and we want to jump the id's up by a few thousand for appearance sake
--For when we dont want people to see ID = 1, Id = 2, Id =3
SELECT
[schema] = s.name,
[table] = t.name,
@GER-NaN
GER-NaN / Comment.cs
Last active July 22, 2017 00:58
MVCComment Poster
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebsiteComments.Models
{
public class Comment
@GER-NaN
GER-NaN / ArticleClasses.cs
Last active July 21, 2017 17:43
Scrape articles and comments
using System.Collections.Generic;
namespace wsbcollector.Article
{
public class MediaEmbed
{
public string content { get; set; }
public int? width { get; set; }
public bool? scrolling { get; set; }
public int? height { get; set; }
@GER-NaN
GER-NaN / LocalizeUtcDate.cshtml
Last active July 11, 2017 17:59
MVC DisplayTemplate view and related javascript code to help with converting UTC stored in database to users local time via JS in the browser
@using SPRI.WebsiteUtilities
@model DateTime
@*
Note: only meant to serve timezone conversions in the USA and maybe NA and SA.
Gives you a label with the date formatted to ISO 8601 format, javascript will understand this and be able to convert for display.
Adds a class that js looks for when converting stuff.
*@
@if (Model.Kind != DateTimeKind.Utc && Model.Kind != DateTimeKind.Unspecified)
{
Debug.WriteLine("DateTime attempted to be localized that was not in UTC format. Display errors will occurr. " + Model.Kind + " " + Model.ToString("O"));
@GER-NaN
GER-NaN / CreateIndexs.sql
Last active July 7, 2017 13:42
Create Sql Server Index on FK's
/*
This will generate a result set where each row is a SQL Statement that will generate an
index for a specific foreign key. The script first checks for the existance of the index
it is about to create and if it exists, the index is dropped. The generated script then
creates the index. The indexes are searched for and created using my own naming guidelines
and an example is given of what the script might generate for an index on TableName and FK
ColumnName.
--TableName.ColumnName
--Delete index if it exsits
@GER-NaN
GER-NaN / SourceCombiner.cs
Last active June 25, 2023 06:59
This will combine multiple .cs files from a solution into a single source file.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Construction;
namespace SourceCombiner
@GER-NaN
GER-NaN / MouseMover.cs
Last active March 31, 2017 17:19
A console app that moves the mouse and performs clicks.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
/*
Ideas from
http://stackoverflow.com/a/2416762/1363780