Skip to content

Instantly share code, notes, and snippets.

@royashbrook
royashbrook / code.gs
Created Nov 9, 2020
Google App Script for Stripe Client Keys
View code.gs
// this is a google script method of getting a client key from stripe
// this means you don't have to get a server to take stripe payments because
// this can be your server. at the time of this script creation, you are
// limited to 20k per month. in order to 'deploy' this you'll have to
// go to https://script.google.com/ and create a new script, replace the
// body of the initial script file with this and then deploy it as a web app
// you'll have to give it the required permissions it asks for the first time
// and ensure you set it up for anonymous access.
// this function will just return the secret key for the client from stripe
@royashbrook
royashbrook / JSZip.js
Created Sep 16, 2020
From JSZip to unzipit
View JSZip.js
//import or add cdn for global, url should be passed in somehow
fetch(url)
.then(r=>r.blob())
.then(JSZip.loadAsync)
.then(zip=>zip.files[Object.keys(zip.files)[0]].async('string'))
.then(JSON.parse)
@royashbrook
royashbrook / downloadjsonascsv.js
Created Sep 4, 2020
Button Handler to download some JSON as CSV
View downloadjsonascsv.js
//bind onclick to downloadcsv.
//o should be the json you want to turn into a table
//h should be a string array for the header row, or this can be null and it will use the keys from the first record
//n is the name of the file, csv will be appended. if omitted it will just be 'data.csv'
export const downloadcsv = (o,h,n = 'data') => {
downloadFile( toCSV(o,h) , n + '.csv', 'text/csv' );
}
const toCSV = (o,h) => {
const a = (v) => `"${v.join(`","`)}"`
let csv = []
@royashbrook
royashbrook / Animation.js
Last active Sep 4, 2020
ChartJS Bar Chart Label Plugin
View Animation.js
//comments in blogpost
myoptions.events = []
myoptions.animation = {
duration: 0,
onComplete: function () {
let chartInstance = this.chart
let ctx = chartInstance.chart.ctx
ctx.textAlign = 'center'
function formatLabel(value) {
@royashbrook
royashbrook / GenericHTMLTagWrapper.js
Created Aug 4, 2020
Generic javascript function to generate other html wrapper functions.
View GenericHTMLTagWrapper.js
// 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 Jul 1, 2020
cli for password hashing using dotnetcore identity with no user
View GenerateSql.ps1
# 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 Jun 24, 2020
Some examples of ways to upload files to o365/SPO
View FileCreationInformation.ps1
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 Jun 18, 2020
Parsing User-Agent info out of Azure App Service http Logs and getting friendly names
View convertUserAgentStringToSimpleName.ps1
# 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 Jun 10, 2020
Lag for same day last month with fix for missing end of month days
View FixLagSameDayLastMonth.sql
/* 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 Jun 8, 2020
Simple console commands to add a bootswatch theme switcher to top of page
View BootswatchThemeSwitcher.js
// 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), {}
//);
You can’t perform that action at this time.