commit
5cf63d7c3c
@ -0,0 +1,5 @@ |
|||||||
|
FROM node |
||||||
|
MAINTAINER Sean |
||||||
|
RUN npm install pig-latin |
||||||
|
ADD piglatin.js piglatin.js |
||||||
|
CMD ["node", "piglatin.js"] |
@ -0,0 +1 @@ |
|||||||
|
All work done by Sean Howard. Licensed under CC0. |
@ -0,0 +1,13 @@ |
|||||||
|
piglatin.sh exists to support the piglatin docker container service. |
||||||
|
|
||||||
|
It requires an external pig latin service to be running, but a docker container is provided to support local development. |
||||||
|
|
||||||
|
.piglatinrc MUST be in the form |
||||||
|
|
||||||
|
`HOST=hostname |
||||||
|
PORT=portname` |
||||||
|
|
||||||
|
If you must either of these then the defaults will be used. Other imports are ignored. |
||||||
|
|
||||||
|
Requirements: |
||||||
|
This requires a standard POSIX bash shell with dos2unix installed to support removing CRLFs from webserver |
@ -0,0 +1,11 @@ |
|||||||
|
version: '2' |
||||||
|
services: |
||||||
|
pig: |
||||||
|
image: node |
||||||
|
build: |
||||||
|
context: . |
||||||
|
dockerfile: ./Dockerfile |
||||||
|
ports: |
||||||
|
- "8124:8124" |
||||||
|
|
||||||
|
|
@ -0,0 +1,8 @@ |
|||||||
|
var piglatin = require('pig-latin'); |
||||||
|
var http = require('http'); |
||||||
|
|
||||||
|
server = http.createServer(function (req, res) { |
||||||
|
res.write(piglatin(req.url.replace("/",""))); |
||||||
|
}); |
||||||
|
server.listen(8124, "0.0.0.0"); |
||||||
|
console.log('Server running at http://127.0.0.1:8124/'); |
@ -0,0 +1,42 @@ |
|||||||
|
#!/bin/bash |
||||||
|
#Should be configurable for users without a local piglatin service |
||||||
|
# set a default hostname |
||||||
|
HOST=localhost |
||||||
|
# set a default port |
||||||
|
PORT=8124 |
||||||
|
# if the .piglatinrc file exists, use this instead of the default |
||||||
|
if [ -f ~/.piglatinrc ]; then |
||||||
|
source ~/.piglatinrc |
||||||
|
fi |
||||||
|
# Since the container will only do one word at a time, parse the words out |
||||||
|
for PIG in $@ |
||||||
|
do |
||||||
|
if [ ${PIG:0:2} = "yt" -o ${PIG:0:2} = "xr" ] |
||||||
|
then |
||||||
|
export DEMANGLE="${PIG:0:2}" |
||||||
|
PIG=`echo $PIG| sed -e "s/^yt/e/" -e "s/^xr/e/"` |
||||||
|
fi |
||||||
|
#this is the easiest way to get the correct line from the container |
||||||
|
WORD=`printf "GET /$PIG HTTP/1.1\n\nclose\n\n"|nc $HOST $PORT|dos2unix|tail -n3|head -n1|sed "s/way$/ay/"` |
||||||
|
RETURN=0 |
||||||
|
if [ "${WORD:0:1}" = "u" ] |
||||||
|
then |
||||||
|
if [ "${WORD: -3}" = "qay" ] |
||||||
|
then |
||||||
|
echo $WORD | sed -e "s/qay/quay/" -e "s/^u//" |
||||||
|
RETURN=1 |
||||||
|
fi |
||||||
|
fi |
||||||
|
if [ $RETURN = 0 ] |
||||||
|
then |
||||||
|
if [ -n "$DEMANGLE" ] |
||||||
|
then |
||||||
|
WORD=`echo $WORD | sed -e "s/^./$DEMANGLE/"` |
||||||
|
fi |
||||||
|
echo $WORD |
||||||
|
fi |
||||||
|
# the container only has one worker so treat it slowly |
||||||
|
sleep 1 |
||||||
|
# merge script output |
||||||
|
done | tr "\n" " "|sed "s/ $//" |
||||||
|
echo |
@ -0,0 +1,40 @@ |
|||||||
|
#!/bin/sh |
||||||
|
|
||||||
|
if [ $# -ne 1 ]; then |
||||||
|
echo "Usage: sh test.sh /path/to/program" 1>&2 |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
|
||||||
|
PROGRAM="$1" |
||||||
|
|
||||||
|
assert_run() { |
||||||
|
OUTPUT="$("$PROGRAM" "$1")" |
||||||
|
if [ "$2" != "$("$PROGRAM" "$1")" ]; then |
||||||
|
echo "$PROGRAM '$1'" 1>&2 |
||||||
|
echo "expected: $2" 1>&2 |
||||||
|
echo "got: $OUTPUT" 1>&2 |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
assert_run "apple" "appleay" |
||||||
|
assert_run "ear" "earay" |
||||||
|
assert_run "igloo" "iglooay" |
||||||
|
assert_run "object" "objectay" |
||||||
|
assert_run "under" "underay" |
||||||
|
assert_run "equal" "equalay" |
||||||
|
assert_run "pig" "igpay" |
||||||
|
assert_run "koala" "oalakay" |
||||||
|
assert_run "yellow" "ellowyay" |
||||||
|
assert_run "xenon" "enonxay" |
||||||
|
assert_run "qat" "atqay" |
||||||
|
assert_run "chair" "airchay" |
||||||
|
assert_run "queen" "eenquay" |
||||||
|
assert_run "square" "aresquay" |
||||||
|
assert_run "therapy" "erapythay" |
||||||
|
assert_run "thrush" "ushthray" |
||||||
|
assert_run "school" "oolschay" |
||||||
|
assert_run "yttria" "yttriaay" |
||||||
|
assert_run "xray" "xrayay" |
||||||
|
|
||||||
|
assert_run "quick fast run" "ickquay astfay unray" |
Loading…
Reference in new issue