git clone git@gitlab.com:SiliconTao-open-source/linux-code-snippets.git
Host your projects on GitLab.com
#!/bin/bash # Replace the right portion of a line with the content of a file. # 1) Replace the right portion of a line with a marker word # 2) Append after the marker with the content from a file # 3) Remove the marker and new line to pull the next line up. cat > outfile <<!EOF hello there tom How are you today? Where is the dog show? !EOF cat outfile cat > testfile <<!EOF flowers doing? !EOF sed -i outfile -e 's/you.*/REPLACE_MARKER/g' printf "\n\n\n" cat outfile sed -i outfile -e "/REPLACE_MARKER/r testfile" printf "\n\n\n" cat outfile sed -i outfile -e "/REPLACE_MARKER/{:a;N;s/REPLACE_MARKER\n//}" printf "\n\n\n" cat outfile
docker run -p 3000:3000 -it mhart/alpine-node
vi service.js
node service.js
docker container ls --all
docker container start <CONTAINER ID>
docker container ls
docker container attach
node service.js
var http = require('http'); var server = http.createServer( function(req, res) { if (req.url === '/') { res.write("Hello World!"); res.write("I have been expecting you."); res.end(); } if (req.url === '/snarky') { res.write("If you code it, it will crash!"); res.end(); } }); // Port 3000 on IPv4 server.listen(3000, "0.0.0.0");
#!/bin/bash DONE=0 DATE=$(date +%F) YEAR="$(echo $DATE | cut -b1-4)" MONTH="$(echo $DATE | cut -b6-7)" DAY="$(echo $DATE | cut -b9-10 | sed -e 's/^0/ /')" while [ $DONE -eq 0 ]; do clear cal -h ${MONTH} ${YEAR} | GREP_COLOR='47;30' grep "$DAY" -wC6 --color=always read -rsn1 KEY [[ $KEY == $'\x1b' ]] && { read -rsn1 -t 0.1 DC read -rsn1 -t 0.1 KP case $KP in "A") DATE=$(date +%F -d "$DATE 7 day ago");; "B") DATE=$(date +%F -d "$DATE 7 day");; "C") DATE=$(date +%F -d "$DATE 1 day");; "D") DATE=$(date +%F -d "$DATE 1 day ago");; esac } || { DONE=1 } YEAR="$(echo $DATE | cut -b1-4)" MONTH="$(echo $DATE | cut -b6-7)" DAY="$(echo $DATE | cut -b9-10 | sed -e 's/^0/ /')" done echo $DATE # To change the output format use the date command like these examples do # date +%d/%m/%Y -d "$DATE" # date -d "$DATE"
CREATE TABLE microServices ( id INT NOT NULL, packageName CHAR(45) NULL, serviceName CHAR(45) NULL, deployTargets CHAR(45) NULL, PRIMARY KEY (id)); INSERT INTO microServices ( id, packageName, serviceName) SELECT CASE WHEN MAX(id) > 0 THEN MAX(id)+1 ELSE 1 END, 'trucks', 'trucksd' FROM microServices;
<canvas id="myCanvas" width="578" height="200"></canvas>
$(function() { var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); function DrawBox(x, y, w, h) { ctx.beginPath(); ctx.lineWidth = "2"; ctx.strokeStyle = "black"; ctx.moveTo(x, y); ctx.lineTo(x + w, y); ctx.lineTo(x + w, y + h); ctx.lineTo(x, y + h); ctx.lineTo(x, y); ctx.stroke(); } function DrawLine(x1, y1, x2, y2) { ctx.beginPath(); ctx.lineWidth = "2"; ctx.strokeStyle = "red"; ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke(); } DrawBox(10, 10, 40, 20); DrawBox(70, 30, 40, 20); DrawLine(50, 20, 70, 40); DrawBox(70, 70, 40, 20); DrawLine(30, 30, 90, 70); });
| I created a BASH script to test the calculation in this video. It calculates Pi without pre-known values but by adding and subtracting fractions of one over odd numbers. 1/1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 ... It gets more accurate the longer you let it run but only for a short time as fractional math in BASH is limited. |
#!/bin/bash D=1 P=0 i=1 while true; do O="-" (( i++ % 2 )) && O="+" P=$(echo "scale=66; ${P} ${O} 1/${D}" | bc) printf "%0.20f \r" $(echo "scale=21; ${P} * 4" | bc) ((D+=2)) done