Commit 1ec9ee26 authored by tracey's avatar tracey 💬
Browse files

start

parent ed527b79
node_modules/
web_modules/
{
// "used by npm package.json for cmd: npm test"
"extends": "airbnb-base",
"plugins": [
"compat"
],
"env": {
"browser": true
},
"settings": {
// Mark these as polyfilled - so linting won't squawk about Promise not being supported in IE 11.
"polyfills": [
"Promise", // xxx polyfill lies - no IE, no opera mini
"Object.entries", // xxx polyfill lies
"Object.values", // xxx polyfill lies
"Object.fromEntries" // xxx polyfill lies - no IE, no Edge v18
]
},
"rules": {
// allow `import .. from '.js'` (.js suffix) in JS files
"import/extensions": ["off"],
// this just showed up as necessary w/ `npm i` on Jun11, 2020
"no-multiple-empty-lines": [2, {"max": 2}],
// this just showed up w/ babel + eslint updates to latest versions Sep1,2019
"operator-linebreak": "off",
"import/no-cycle": 0, // it's ok to have cycles with ES Modules and import
// "make sure all used JS compatible with 90%+ of currently used browsers a la caniuse.com"
"compat/compat": "error",
// "allow snakecase var names if dev desires"
"camelcase": "off",
// "allow: x = 3 (for example lining up multiple lines by column)"
"no-multi-spaces": "off",
// "author discretion when using braces around one-liners or same-liners"
"curly": "off",
// "allow ++ or -- at the end fo a for() loop (all other uses are banned per airbnb!)"
"no-plusplus": ["error", {"allowForLoopAfterthoughts": true}],
// "allow JSON/map definitions to column-align values when multiline"
"key-spacing": ["error", {"mode": "minimum"}],
// "allow for (x of array) and for (key in obj) and for (val in array)"
"no-restricted-syntax": ["error", "LabeledStatement", "WithStatement"],
"no-restricted-globals": ["off", "location"],
"nonblock-statement-body-position": "off",
"indent": ["error", 2, {"CallExpression": {"arguments": "first"},
"ArrayExpression": "first",
"FunctionDeclaration": {"parameters": "first"},
"FunctionExpression": {"body": 1, "parameters": 2} }],
"semi": ["error", "never", { "beforeStatementContinuationChars": "always" }]
}
}
package-lock.json
node_modules
FROM node:alpine
MAINTAINER tracey
EXPOSE 80 5000
RUN apk add jq zsh git colordiff
RUN mkdir -m777 /app/
# dont run as root
USER node
WORKDIR /app/
# add JS source code and npm pkgs we use
COPY . /app/
RUN npm install
RUN ln -s /app/zshrc /home/node/.zshrc && \
ln -s /app/aliases /home/node/.aliases
# when this container is invoked like "docker exec .." this is what that will run
CMD [ "./node_modules/.bin/supervisor", ".", "index.js" ]
#[THIS IS ZSH or BASH]
########################################################################
# the zsh/bash functions that may be of interest to most folks:
########################################################################
# [git add ons]
# dif
########################################################################
# there are also some VERY useful utility zsh/bash functions in
# petabox/sw/work/common.sh
#
# [quick PHP cmd-line invocations w/ petabox setup]
# phpr
# phpR
# [quick DB access -- be VERY careful and please treat DB as readonly]
# sql-nt
# sql
# [syntax checking code]
# lint
########################################################################
# load other aliases (when full home dir)
FI=$THOME/petabox/sw/work/common.sh ; [ -e $FI ] && source $FI
FI=$THOME/petabox/tv/bin/aliases ; [ -e $FI ] && source $FI
if [ "$KUBERNETES_SERVICE_PORT_HTTPS" = "443" ]; then
export TERM=xterm-color
fi
alias lesscolored="colordiff | less -R"
alias ciff=colordiff
if [ "$UNAME" != "alpine" ]; then
# make e/f/grep see red!
# ugh, ubuntu/unix sometimes you just suck... (old -v- new UNFRIENDLY way):
# export GREP_OPTIONS=" --color=AUTO "
alias grep=" grep --color"
alias egrep="egrep --color"
alias fgrep="fgrep --color"
fi
ttl() {
if [ "$#" == "0" ]; then
echo "Usage: ttl some title you want ..."
return
fi
echo -n -e "\033]0;""$@""\007"
}
ttlhost() { ttl $(hostname -s); }
function really() {
php -- "$@" <<"EOF" |sort
<?
array_shift($_SERVER['argv']);
foreach ($_SERVER['argv'] as $argn) {
foreach (explode("\n", trim($argn)) as $arg)
echo join("\n", array_map('realpath', glob($arg, GLOB_BRACE))) . "\n";
}
EOF
}
typeset -a TV CAT RD1
PET=$HOME/petabox
[ -e $PET ] || PET=/petabox
WWW=$PET/www/sf
IN=$WWW/includes
COMMON=$WWW/../common
TV=( $(really "
$IN/less/{tv,archive}.less
$IN/tv*
$IN/js/{archive,play8,tv*}.js
$COMMON/{Details,Video,Player,Maps,Graph,Nav}.inc
$COMMON/TV[A-QS-Z]*
$WWW/tv*.php
$WWW/{details,download}.php
$WWW/services/{maker,borrow}.php
$PET/tv/bin/extracTS.c
$PET/tv/bin/utils.c
$PET/tv/*.php
$PET/tv/stats/parse.php
$PET/tv/911about.htm
$PET/etc/cron.d/{homenodes,tv*,rm-old-files}
$PET/etc/systemd/system/tv*
$PET/www/datanode/tvNRT.php
$PET/tv/docker/*
$PET/deriver/inc/NRT.php
$PET/sw/work/fixer.php
")
$(really $(egrep -I '^#!' $PET/tv/bin/* 2>/dev/null |fgrep -v '~' |cut -f1 -d:))
)
CAT=( $(really "
$COMMON/{Catalog,ItemTools}.inc
$PET/sw/work/catalogd.php
$IN/js/catalog.js
") )
RD1=( $(really "
$COMMON/{Details,Facet,Imager,Item,Lists,Metadata,Nav,Search,SearchBar,*Search/*,Tile,Tiles,TilesWrap,Timegraf,Video,Graph,Player}.inc
$COMMON/setup.php
$WWW/{details,collection,index,search,account/index}.php
$WWW/services/{exit.php,post-file.php,views.php}
$IN/{js/{archive,play8,playset,tv*}.js,less/{archive,tv}.less,tv*.js}
") )
unset PET WWW IN COMMON
psf(){ ps fauxwww; }
psc(){ psf | grep --devices=read "$@" | chopper | grep "$@"; }
pscc(){ psc -C${NUM-5} "$@" | grep -v -- devices=read | grep -C${NUM-5} "$@"; }
pscx(){ psf | grep --devices=read -C${NUM-5} "$@" | grep -v -- devices=read | grep -C${NUM-5} "$@" | chopper2 | grep -C10000 "$@"; }
#pscx like pscc but smarter "chopper"
chopper2() { php -R '$COL=$argv[1];$PAD=min($COL-20,90);if(strlen($argn)<$COL){echo "$argn\n";}else{echo substr($argn,0,$COL); $rest=str_split(substr($argn,$COL),($COL-$PAD)); foreach($rest as $l){printf(str_repeat(" ",$PAD)."%-".($COL-$PAD)."s\n",$l);}}' $COLUMNS; }
ipaddy(){
if [ "$#" == "1" ]; then
host "$1" | perl -ane 'print $F[3] if $F[2] eq "address"'
else
ifconfig eth0 | grep 'inet addr' | sed 's/\sBcast.*$//' | sed 's/.*inet addr://' | sed 's/\s//g' 2>/dev/null
fi
}
#export LESSCOLORIZER=pygmentize
export LESS=' -R ';
alias df="df -k"
alias du="du -k"
alias ls="ls -F"
alias l="avoid problems later"
alias ll="avoid problems later"
unalias l
unalias ll
anotb() {
if [ "$#" != "2" ]; then
echo "Usage: <sorted file> <sorted file>"
return
fi
sort -c "$1" && sort -c "$2" && join -v 1 "$1" "$2"
}
# parse "args" column from catalog on stdin and print just the wanted key=val key.
arg() {
urldecode | perl -ne 'chop; if (m|[\?\&]'"$@"'=([^&]*)|) { print "$1\n"; } elsif (m|^'"$@"'=([^&]*)|) { print "$1\n"; } else { print "NULL\n";}'
}
args() {
if [ "$#" != "1" ]; then
echo "usage: args <task_id>"
return
else
# remove anything before "=" sign in case arg was pasted in
# from logfile link like:
# http://archive.org/log_show.php?task_id=1927468
task_id=`echo "$1" | cut -f 2 -d =`
fi
# check catalog first. ONLY check catalog_done if not in catalog
sql-nt select args from catalog where task_id=$task_id | phpR 'print_r(Util::cgi_args_to_array($argn));' | egrep . ||
sql-nt select args from catalog_done where task_id=$task_id limit 1 | phpR 'print_r(Util::cgi_args_to_array($argn));' | egrep .
}
function rm-derivs() {
id=$(basename `pwd`)
if [ ! -e ${id}_files.xml ]; then
echo "NO FILES.XML MAKING ONE..."
echo '<files/>' > ${id}_files.xml
fi
phpr '$f=new FilesXML("'`pwd`'"); $f->delete_derived_files("{*,*/*,*/*/*}");'
fx # prune (now) stale entries from _files.xml
}
function rederive() {
id=$(basename `pwd`);
if [ ! -e "${id}_meta.xml" ]; then
echo
echo
echo NOTE FAKING _meta.xml
echo
echo
echo '<metadata><collection>opensource_movies</collection></metadata>' > ${id}_meta.xml
fi
rm-derivs
echo '<files/>' >| ${id}_files.xml
fx
$PETABOX_HOME/deriver/derive.php
}
#################################################################################
# VERSION CONTROL FUNCTIONS
#################################################################################
giss() { git status -s .; }
gitnix(){ rm "$@"; git checkout "$@"; }
dif() { ( git --no-pager diff "$@" ) || ( svn diff --no-diff-deleted "$@" | colordiff ); }
dif20() { git --no-pager diff -U20 "$@"; }
gg() { git --no-pager grep -I "$@" -- './*' ':!*\.min\.js' ':!*\.min\.js\.map'; }
#################################################################################
# VERSION CONTROL FUNCTIONS
#################################################################################
add (){ perl -p -e '$ tot += $ _; s@.*@$ tot@;'; }
boxx (){ LIKE=$1; shift; ZONE=`phpr 'echo Config::uzone();'`; sql "select node,location,alias,mate,kind,rank,flow,zone,attr,duty from box where zone='$ZONE' "$@" AND (node like '%$LIKE%' OR location like '%$LIKE%')order by node"; }
box2 (){ LIKE=$1; shift; ZONE=`phpr 'echo Config::uzone();'`; sql "select node,location,alias,ip,fqhostname,mate,hardware,kind,rank,rack,cdx,server,flow,zone,attr,duty from box where zone='$ZONE' "$@" AND (node like '%$LIKE%' OR location like '%$LIKE%') AND NOT (node LIKE 'switch%' OR node LIKE 'pdu%') ORDER BY location" | perl -ape '$x=$F[3];chop($x);chop($x);print "-------RACK $x-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n" if ($x && $x ne $prev); $prev=$x;'; }
box3 (){
hosts=`sql-nt 'SELECT * FROM box' | egrep "$@" | perl -F'\t' -ane 'print "$F[4]\n";'| killspace |quotem`;
set -x;
sql 'SELECT * FROM box WHERE node IN ('$hosts') ORDER BY node';
set +x;
}
boxall (){ sql "select node,location,alias,mate,kind,rank,flow,zone,attr,workmax,duty,nagios,site from box order by node"; }
bnota (){ anotb "$2" "$1"; }
chopper (){ CN=$1; if [ "$#" != "1" ]; then CN=$COLUMNS; fi; perl -pe "$ f = chop; $ _ = substr($ _, 0, $CN) . $ f"; }
col (){ perl -pe '$ | = 1; s/^\s+//; s/\t/ /g; tr/ //s' | cut -d ' ' -f "$@"; }
collast (){ perl -ane 'print pop(@F) . chop;' "$@"; }
countdot (){ if [ "$#" = "0" ]; then find . -type f | egrep -v '/\.(git|svn)/' | perl -ne 'print $1 if m=\.([^\.]+$)=' | sort | uniq -c; else find "$@" -type f | egrep -v '/\.(git|svn)/' | perl -ne 'print $1 if m=\.([^\.]+$)=' | sort | uniq -c; fi; }
function files() {
dirs="$@"
[ "$#" = "0" ] && dirs=.
find "$dirs" -type f 2>&1 |fgrep -v .git/ 2>&1 |sort
}
GSTAT=$([ -e /usr/local/bin/gstat ] && echo gstat || echo stat) # ternary
function files+() {
(
files "$@"
find "$dirs" -type l -print0 \
|xargs -0 ${GSTAT?} --format %N \
|perl -pe 's/^.//; s/.$//; s/. \-> ./\t->\t/'
) |sort
}
finddot (){ dot=$1; shift; find . -name "*.$dot" "$@"; }
fx (){ phpr 'FilesXML::setFormats(null,"PRUNE");'; }
hist (){ cat $HOME/.*history*; history; }
# Removes lead and trailing whitespace; compresses interline whitespace; filters out "whitespace only" lines
killr (){ perl -p -i -e "tr/\r//d" "$@"; }
killspace (){ perl -ne 's/\s*(\n)//; $ f = $ 1; s/^\s+//; s/\s+/ /g; next unless m/./; print; print $ f ;'; }
l (){ ls -A -F -l "$@"; }
lc (){ wc -l "$@"; }
list (){ m `which $1`; }
listem (){ tr '\n' ' ' | perl -pe chop; }
lt (){ /bin/ls -A -F -l -tr "$@"; }
m (){ less "$@"; }
me (){ NUM=0; pscc $USER; unset NUM; }
phpl (){ for i in $(ack --type-add php=.inc -f --type php |sort); do php -l $i; done; }
phpl. (){ for i in `giss |egrep '^ M' |col 2- |egrep -v '\.(xml|xsl)$'`; do php -l $i; done; }
phprd (){ echo | php -B '$_REQUEST["cacheDebug"]=1; require @ia;' -E "$@"; }
phprdreCache(){ echo | php -B '$_REQUEST["cacheDebug"]=1; $_REQUEST["reCache"]=1; require @ia;' -E "$@"; }
prevdiff (){ git log -n1 $1 |cat; line; git --no-pager diff $(git log -n2 --pretty=format:"%h" $1|tail -1) $1; }
purge (){ rm -f \#*\# .*~ *~ ~/.*~; }
quotem (){ perl -ne 'chop; print "\x27$_\x27"; print "," unless eof();'; }
rdiff (){ diff -x .git -x .svn -x "*#*" -x "*~" -r "$@"; }
real (){ H=$HOME; if [ "$HOME" == "/root" ]; then H=/home/tracey; fi; source $H/.aliases; }
# screen is a buzzkill when it hijacks my CTL-A!
scr() { if [ "$#" == "0" ]; then export SCREENNUM=1; else export SCREENNUM=$1; fi; env TERM=xterm /usr/bin/screen -e^Oo -xRR -S pooh$SCREENNUM; }
trim (){ perl -pe 's=\<=&lt;=g; s=\>=&gt;=g;' | php -R 'echo(trim($argn));'; }
twm (){ tail -n ${1-500} -f /var/log/catalogd.log; }
urldecode (){ php -R 'echo urldecode($argn)."\n";'; }
wgeto (){ wget -O - "$@"; }
zero (){ echo -n >| "$1"; }
if [ "$UNAME" != "alpine" ]; then
alias ps='ps --columns "$COLUMNS"'
fi
db() { /petabox/sw/bin/dbprint "$@"; }
dbm(){ /petabox/sw/bin/dbprint "SELECT * FROM metadata WHERE identifier='$1'"; }
function show-originals-and-derivs () {
phpr 'EditFixer::show_originals_and_derivs();' "$@"
}
function user {
php -- "$@" <<"EOF"
<?require @ia;
$argn=Util::onearg();
if ($argn[0]=='@')
$row=DB::q1("SELECT * FROM users WHERE", [itemname=>$argn]);
else if (strpos($argn,'@'))
$row=DB::q1("SELECT * FROM users WHERE", [username=>$argn]);
else
$row=DB::q1("SELECT * FROM users WHERE", [id=>$argn]);
unset($row[cryptpw]);
foreach ($row as $k=>$v)
printf("%-15s %s\n", $k, $v);
?>
EOF
}
favicon.ico

5.56 KB

/**
* Main node web server
*/
/* eslint-disable no-console */
import http from 'http'
import { createReadStream } from 'fs'
const TITLE = 'Tracey'
const SLIDES = 'https://archive.org/~tracey/slides'
const ME = {
talks: [{
slug: 'gitlab-commit',
title: 'GitLab Commit 2020',
img: '48_IG_Wall.png',
},
],
}
/**
* Outputs nice micro access.log like entry
* @param string file File being served
* @param int code HTTP status code
*/
function alog(file, code = 200) {
console.log(`${new Date().toISOString().slice(0, 19).replace(/T/, ' ')} ${code} /${file || ''}`)
}
/**
* Returns beginning static markup for @see markup()
*
* @param string title Page / H1 title
*/
function markup_pre() {
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta property="title" content="${TITLE}">
<link href="/services/clusters/node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<style>
.groups {
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
align-items: top;
}
h2 {
margin-top: 75px;
}
h2 img {
max-width: 50px;
max-height: 50px;
}
.groups li {
list-style-type: none;
}
.groups a {
display: block;
}
</style>
</head>
<body>
<div class="container" style="width:98%; max-width:98%">
<h1>${TITLE}</h1>
`
}
async function markup() {
let str = ''
for (const [header, group] of Object.entries(ME)) {
str += `
<h2>${header}</h2>
<div class="groups">`
for (const [project] of group) {
str += `
<div class="card card-body bg-light">
<a href="${SLIDES}${group.slug}">
<img src="${group.img}"/>
</a>
<h3>
<a href="${SLIDES}${group.slug}">${project.title}</a>
</h3>`
}
str += '</div>'
}
return str
}
// Main web server
http.createServer((req, res) => {
let type = 'text/html'
const file = req.url
.slice(1) // nix lead /
.replace(/^services\/clusters\//, '') // sigh - current way paths are proxy-passed to us
if (file === 'node_modules/bootstrap/dist/css/bootstrap.min.css') {
type = 'text/css'
} else if (file.endsWith('.jpg')) {
type = 'image/jpg'
} else if (file.endsWith('.png')) {
type = 'image/png'
} else if (file.endsWith('.svg')) {
type = 'image/svg'
} else if (file === 'favicon.ico') {
type = 'image/x-icon'
} else if (file === '') {
alog()
res.writeHead(200)
res.end(markup_pre().concat(markup()))
return
} else {
alog(file, 404)
res.writeHead(404)
res.end(`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"></head><body>
🇫🇷 Merde, il n'y a rien ici! - Corentin`)
return
}
// static file - send it directly out
alog(file)
res.writeHead(200, { 'Content-Type': type })
createReadStream(file).pipe(res)
}).listen(5000)
{
"name": "tracey",
"description": "pointers to slides/talks and projects",
"author": "tracey",
"license": "AGPL-3.0",
"type": "module",
"browserslist": [
"> 1%"
],
"dependencies": {
"bootstrap": "",
"supervisor": ""
},
"devDependencies": {
"//": [
"v7.3.0 is broken for 'no-cycle' and lint"
],
"eslint": "7.2.0",
"eslint-config-airbnb-base": "",
"eslint-plugin-compat": "",
"eslint-plugin-import": ""
},
"scripts": {
"test": "eslint ."
}
}
export LESSCHARSET="utf-8"
export TOP=~
export PAGER=less # make man use "less", not "more"!
export EDITOR="emacs -nw"
export VISUAL="emacs -nw"
export SHELL=/bin/zsh # espcially for screen
export LANG=en_US.UTF-8 # make it so "ls" of filenames w/ UTF-8 chars work
# eg: "xenial" or "alpine"
export UNAME=$((fgrep CODENAME /etc/lsb-release 2>/dev/null || cat /etc/issue|cut -f3 -d' '|head -1|tr A-Z a-z) |cut -f2 -d=)
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
if [ "$HOME" = "/root" ]; then
export PETABOX_HOME=/petabox
else
export PETABOX_HOME=$HOME/petabox
fi
export MANPATH=/usr/man:/usr/local/man:/usr/share/man
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/local/sbin:/etc:/usr/sbin:$PETABOX_HOME/sw/bin:$PETABOX_HOME/bin:$PETABOX_HOME/tv/bin:$PETABOX_HOME/deriver:/usr/lib/postgresql/9.5/bin;