Skip to content

Instantly share code, notes, and snippets.

View jhyland87's full-sized avatar

J jhyland87

View GitHub Profile
switch ( true ) {
// Search Applied filter
case /^(search)?applied$/.test( selectStr ):
return { search: 'applied' }
break
// Search Removed filter
case /^(search)?removed$/.test( selectStr ):
return { search: 'removed' }
DESCRIPTION:
Needed a pattern to regex through the console output for all commands, regardless of user/date/time/result. And I have a stupidly advanced PS1 prompt
PATTERN:
^\(\s*[0-9]+\)\[[a-zA-Z0-9\s:]*\|\s*[0-9]{1,5}\:[0-9]{3}\s*(?:\[[0-9]{1,3}\:[0-9]{1,3}\])?\]\{[0-9]{1,4}\}[a-zA-Z0-9\s:@\/~]+\(?:.+\)[\$|#]\s{1}(?<!\n)(.+)$
LINK: https://regex101.com/r/fH8eA4/1
EXAMPLES:
@jhyland87
jhyland87 / file_examples.txt
Created September 1, 2016 17:54
Just me testing out the bash 'file' binary
$ file --brief --no-dereference baz
symbolic link to foo
$ file --mime-type baz
baz: application/x-directory
$ file --brief --no-dereference --mime-type baz
application/x-symlink
$ file --brief --no-dereference --mime-encoding baz
var Utils = {
//...
/**
* Convert a date/timestamp to an epoch timestamp
*
* @param {Date|string} date Either a date in string format, or a Date object
* @param {string} round Since the date inputs are day specific (no hour/minute/second),
* this dictates if it will be rounded up or down. Allowed values are "start", "stop", "up" and "down"
* @param {string} dateFormat Dates input format (default is "mm/dd/yy")
@jhyland87
jhyland87 / xls-to-sql_patterns.re
Last active September 9, 2016 16:59
Evolution of the RegExp pattern for the macro used in the xls-to-sql script
\{(?P<noun>(?:cols?|range))\:(?:(?<=col:)(?P<col>(?:[a-zA-Z]+|[0-9]+))|(?<=cols:)(?P<cols>(?:[a-zA-Z0-9\-\,]+))|(?<=range:)(?P<col_start>(?:[a-zA-Z]+|[0-9]+))\-(?P<col_stop>(?:[a-zA-Z]+|[0-9]+)))\}(?P<modifier>(?:[\?\!]))?
\{ (?# Opening delimiter match)
(?P<noun>(?:cols?|range)) (?# Match the noun (col, cols, or range))
\:
(?:
(?<=col:) (?# Look-behind conditional for the 'col' noun)
(?P<col>(?:[a-zA-Z]+|[0-9]+)) (?# Creates named group 'col' with either alpha or numeric value(s) (but not both))
|
import sys
import re
strings = [
'{cols:a,b,c}',
'{range:b-z}',
'{col:A}',
'{cols:a,b,c:,}',
'{range:b-z:,}',
'{col:1}',
If query provided was:
"UPDATE STOREITEM SET replenish_status = 'N' WHERE COMPANYID = '{col:A}!' AND STOREID = '{col:B}!' AND ITEMID IN ({range:F-*:,}) AND MANAGERID IN ({cols:C,E:,});"
Then it will iterate over each row in said spreadsheet, spitting out queries formatted like so:
UPDATE STOREITEM SET replenish_status = 'N' WHERE COMPANYID = '<Value of column A in current row>' AND STOREID = '<Value of column B in current row>' AND ITEMID IN (<Concatenated string of values from col F to the last col, joined by a comma>) AND MANAGERID IN (<Concatenated string of values in cols C and E>);
@jhyland87
jhyland87 / xls2sql.re
Created September 12, 2016 17:09
SQL Macro stuff
\{
(?:(?# Macro settings start)
\;?
(?# Noun ptrn start)(?P<noun>(?:cols|col|range))\:
(?# Column idx start)(?:
(?P<colgroup>
(?<=cols:)(?# Colgroup 'cols' EG: A,C,E,G)(?P<cols>(?:(?:[a-zA-Z]+|[0-9]+)(?:,(?:[a-zA-Z]+|[0-9]+))+))
|
(?<=range:)(?# Colgroup 'range' EG: A-Z)(?P<col_start>(?:[a-zA-Z]+|[0-9]+))\-(?P<col_stop>(?:[a-zA-Z]+|[0-9]+|\*))
)?
import sys
help_items = [
{
'short' : '-h',
'long' : '--help',
'arg_val' : 'topic',
'required' : False,
'description' : 'Shows the general help menu, or help regarding a specific item or topic.',
'default' : 'general',
$ time xls2sql -i /Users/jhyland/Documents/scripts/python/work/excel-to-sql/excel-templates/ON-DTS\ Replen\ OFF\ -\ 20-rows.xls -q "UPDATE STOREITEM SET replenish_status = 'N' WHERE COMPANYID = '123' AND STOREID = '{col:A}' AND ITEMID IN ({range:B-*;j:,})" --row-start 5
UPDATE STOREITEM SET replenish_status = 'N' WHERE COMPANYID = '123' AND STOREID = '532' AND ITEMID IN (118469,117677,118233,118474,118467,116726,116727,116732,116730,117676,117859,117460,116729,119056,117472,116731,117481,117866,117461,117463,117868,117462,117483,117869,117464,117484,117493,118509,118507,117466,118508,117891,117468,117469,118566,118466,118471,118472,118470,118468,117878,118946,118947,118948,118950,117880,118510,117471,117473,117893,117892,117476,117895,117896,117897,117485,118624,118517,117474,117475,117486,118626,117901,117496,117490,117906,117908,118527,118526,117479,117477,117910,117912,117478,117480,117491,117501,118711,118716,118714,118712,118713);
UPDATE STOREITEM SET replenish_status = 'N' WHERE COMPANYID = '123' AND S