Skip to content

Instantly share code, notes, and snippets.

View royashbrook's full-sized avatar

Roy Ashbrook royashbrook

View GitHub Profile
@royashbrook
royashbrook / GenericHTMLTagWrapper.js
Created August 4, 2020 00:44
Generic javascript function to generate other html wrapper functions.
// this simply generates helper html wrappers
// whatever tags you want helpers for can be listed in the htmlhelpers array
const htmlhelpers = ['h4','table','thead','tbody','tr','td','th','div'];
// this function generates other functions based on the tag that is passed into it
// also any extra attributes or other properties can be added as an argument
const tagwrapper = (tag,txt,att='')=>`<${tag}${att.length===0?'':' ' + att}>${txt}</${tag}>`;
// loop through the tags we want wrapper functions for, and generate eval statements
for(const s of htmlhelpers){eval(`var ${s} = (txt,att='')=>tagwrapper('${s}',txt,att);`)}
// the output of this will be functions that allow you to write something like:
// h4('hello world')
@royashbrook
royashbrook / GenerateSql.ps1
Last active July 1, 2020 01:52
cli for password hashing using dotnetcore identity with no user
# this is actually just output from running in powershell,
# but I'll just add my comments in here along with the output
## First of all, I am going to set an alias to the compiled exe
└[C:\git\h]> set-alias h "C:\git\h\bin\Release\netcoreapp3.1\win-x64\h.exe"
## Generate a users file, I'm using a tab here because if you
## select this from a database query window, it'll be tab seperated
## `t is a tab character in powershell
## This first line puts a header row in there
@royashbrook
royashbrook / FileCreationInformation.ps1
Created June 24, 2020 15:56
Some examples of ways to upload files to o365/SPO
function Copy-File-SPO(
$user, #username
$pass, #password
$site, #sp site url
$list, #sp list name
$dest, #dest path in list
$path #path for gci
){
# check for and load dependency dlls
@royashbrook
royashbrook / convertUserAgentStringToSimpleName.ps1
Last active June 18, 2020 16:35
Parsing User-Agent info out of Azure App Service http Logs and getting friendly names
# in the example,they use numbers for the keys, but state they can be other things.
# i just left them as numbers to match their setup. i'm guessing you could use
# (new-guid).guid instead and avoid the ln var all together if that's your thing.
# note that i am not using the 'count' value from up above for this as it's not needed
# i just wanted that to look at when i was originally examining the $agentinfo results
# i usually don't end powershell lines in semicolons, but i actually ran this as a
# oneliner and spread it out here for readability.
$ln=1;
$hash=[ordered]@{};
$agentinfo | %{ $hash.add("$ln",$_.Name);$ln++};
@royashbrook
royashbrook / FixLagSameDayLastMonth.sql
Created June 10, 2020 16:12
Lag for same day last month with fix for missing end of month days
/* don't lock, be deadlock victim if needed */
set transaction isolation level read uncommitted
set deadlock_priority -10
/* generate sales data */
declare @SalesByDay as table (
[SalesDate] datetime not null primary key
, [TotalSales] decimal(19,2) not null
)
declare @mindate date = '20200101', @maxdate date = '20200630'
@royashbrook
royashbrook / BootswatchThemeSwitcher.js
Last active June 8, 2020 13:40
Simple console commands to add a bootswatch theme switcher to top of page
// I switched a basic bootstrap template site over to using bootswatch,
// but I wanted to swap the themes on it so i could see some of the colors and
// font sizes as i still had some items from the old theme in there.
// There are probably lots of ways to do this, but this is how I did it
// Go to https://www.bootstrapcdn.com/bootswatch and then you can run this on the
// page with all of the cdn links to copy and use with hashes, etc
//var vals = [...document.querySelectorAll('input[id*="html_"]')].map(x => [x.id.replace('html_', ''), x.value]).reduce(
// (acc, val) => (acc[val[0]] = val[1], acc), {}
//);
@royashbrook
royashbrook / RandomJS.js
Created May 16, 2020 01:02
Random Javascript Things
//some utility functions.
const tagwrapper = (tag,txt,att='') => `<${tag}${att.length===0?'':' ' + att}>${txt}</${tag}>`;
const htmlhelpers = ['h4','table','thead','tbody','tr','td','th','div']; //etc
for(const s of htmlhelpers){eval(`var ${s} = (txt,att='')=>tagwrapper('${s}',txt,att);`)}
const groupByArr = (x, key) => x.reduce((rv, x)=> { (rv[x[key]] = rv[x[key]] || []).push(x); return rv; }, []);
const groupByObj = (x, key) => x.reduce((rv, x)=> { (rv[x[key]] = rv[x[key]] || []).push(x); return rv; }, {});
const setElementHTML = (id,html) => {
const ctx = $(id)
ctx.empty();
ctx.html(html)
function l($t){
"{0}`t-`t{1}" -f (Get-Date), $t
}
function bcpCsv($f,$t,$b,$cs)
{
l "Importing file $f to table $t using batchsize $b and connection $cs"
l "creating datatable using target table schema"
$dt = (getData "select top 0 * from $t" $cs)
$cols = $dt.columns.columnname
# references:
# https://community.spiceworks.com/topic/380201-using-powershell-to-check-for-new-files-in-a-directory
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/register-objectevent
# https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher
# you can change $p to whatever path you want, you can also add file filters, and add more events
# i am monitoring a folder for all create/delete events and color coding output
$p = $pwd.path
$w = New-Object System.IO.FileSystemWatcher $p
$w.IncludeSubdirectories = $true
@royashbrook
royashbrook / sna.md
Last active May 3, 2018 21:17
service now helpers

service now helper scripts for automating some common tasks in the browser as bookmarklets

these are only tested and used with chrome currently