Skip to content

Instantly share code, notes, and snippets.

View nuke66's full-sized avatar

nuke nuke66

  • Brisbane, Australia
  • 10:34 (UTC +10:00)
View GitHub Profile
@nuke66
nuke66 / youtube-iframe-hook.js
Last active October 1, 2020 00:36
JS outline for a hook that allows you to detect state changes in embedded YouTube iframe players.
/*
* YouTube iframe hook
*
* Attaches to a tagged YouTube iframe element so we can detect when the video has been watched and take action. In this case update the user profile in Sitecore.
* Handles multiple elements. Does not require url to contain the enablejsapi parameter. Identifies the player via the id of the iframe element and the YouTube video embed code.
*
*/
function onYouTubeIframeAPIReady() {
$(() => {
const IframeElements = $("iframe .youtube-iframe-hook");
@nuke66
nuke66 / lists-example.py
Created February 10, 2020 08:04
python: Lists example
"""
Lists and slicing example
"""
# Append value
x=['a','b','c']
x.append('d') # ['a','b','c','d']
# Append list
x=['a','b','c']
y=['x','y','z']
@nuke66
nuke66 / email-regex.js
Created February 10, 2020 04:19
python: email regex with TLD min of 2 characters
// Email regex with TLD min of 2 chars long
var validateEmail = function (email) {
return /^[^\s@]+@[^\s@\.]+(\.[^\s@\.]{2,})+$/.test(email);
};
console.log(validateEmail("r.ora@nowhere.co.uk"));
@nuke66
nuke66 / get-loop-number.py
Created February 2, 2020 07:08
python: get loop (iteration) count
# Get the current loop count
myList = ['zero','one', 'two', 'three', 'four', 'five']
for idx, x in enumerate(myList):
print(f"{idx}:{x}") # "0:zero", "1:one", "2:two"...
@nuke66
nuke66 / fn_by_ref.py
Created January 28, 2020 22:02
python - function by reference example
"""
Example of calling functions by reference, with some not easy to read code.
"""
# define our functions
def square(x):
return x*x
def cube(x):
@nuke66
nuke66 / mde.py
Last active May 6, 2020 06:25
dmhg: Parse metadata file dump, breaking down the filter types, filters, and metadata
# MDE (MetaData Enhance) - enhance CSV metadata file dump from DoH
from datetime import datetime
# from utils import keyCount
import csv
import sys
import os
"""
Use this curl to query the Solr index and generate the JSON input file. # TODO fix
@nuke66
nuke66 / printformat_examples.py
Last active March 10, 2021 12:15
python - print format examples
""" Print format examples
[pos][sign][width][.precision]type
Positional args
< left aligned
> right aligned
0 leading zeroes
, comma for thousands symbol
= padding after sign but before numeric value
@nuke66
nuke66 / datetime_examples.py
Created January 15, 2020 22:23
python - basic datetime examples
from datetime import datetime, time, timedelta
ex={}
ex[1] = datetime.today() # current time
ex[2] = datetime.now() # current time but with additional tz param
ex[3] = datetime(year=2020,month=1,day=15) # 15Jan2020 date with time of 00:00:00
ex[4] = datetime(2020,1,15,23,59,59,999999) # date with time 23:59:59.999999
ex[5] = datetime.combine(datetime.now(),time(hour=20,minute=30)) # combine datetime + time, todays date @ 20:30
@nuke66
nuke66 / gist:7090c540d98b1100f2584c1c432b5e09
Created January 9, 2020 08:56
curl : solr query data dump to csv example
curl "https://dmhguatsc9-solr.azurewebsites.net/solr/dmhg_filtermetadata_master_index/select?fl=filter_type:filtergroupname_s,filter_name:_name,%20metadata:filtermetadata_sm&fq=haschildren_b:false&q=_templatename:FilterDataItem&rows=1000&sort=filtergroupname_s%20asc,%20_name%20asc&wt=csv" -o metadata_uat.csv
@nuke66
nuke66 / generator-ex1.py
Created January 9, 2020 07:27
python - generator example : simulate having multiple patterns running in sync on a led strip
# better verion of simultaneous fill ranges on a neo pixel ring
led = ['-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-']
def print_led():
for x in led:
print(x,end='')
print()
def fill(start, end, color='*', bgcolor='-'):