Programming language cook book

From Review or Discard at Will
Jump to: navigation, search

Mostly just for me to remember stuff

I might use a command once, then not again for years. Hopefully I can jog my memory quickly here. YMMV



# ssh -o StrictHostKeyChecking=no

MS Windows

rem I used this to copy  keys to linux hosts 'cause `ssh-copy-id` wasn't working for me in powershell.
cat C:\Users\jhalb\.ssh\id_rsa | ssh jeffa@rodaw "cat >> ~/.ssh/authorized_keys"


I wanted a json utc datetime for a MQTT payload. Found the arrow module that is much like moment.js for javascript.

import arrow
print (arrow.get(arrow.utcnow()).for_json()

results in: "2015-08-27T15:03:07.427351+00:00" I'd like to trim it further and replace the +00:00 with Z. ??? and less precision on the seconds.

Documentation for ISO 8601


comment a block

What's a quick way to comment/uncomment lines in Vim? (Stack overflow)

ctl v (at start of block)
down arrow (to end of block)
shift I, #
: s/^/# <- more likely

global search and replace





# VirtualHost configuration:
apachectl -S
# Check .conf syntax
apachectl configtest
# What modules loaded?
httpd -M
apachectl -M

Redirect site root to wiki

This works to redirect to www.somedomain.tld from www.somedomain.tld/w - basically to point the root to your wiki as home / first page.

<VirtualHost *:80>
     RewriteEngine on
     RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]

MediaWiki Short URLs

<VirtualHost *:443>
        DocumentRoot /var/www/
        CustomLog       /var/log/httpd/ combined
        ErrorLog        /var/log/httpd/
        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/
        SSLCertificateKeyFile /etc/letsencrypt/live/
        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateChainFile /etc/letsencrypt/live/

        RewriteEngine on
        RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
        alias /wiki /var/www/
        # Redirect / to Main Page
        RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]


Visual Editor


install start stop status

[root@myhost parsoid]#  systemctl daemon-reload  # Do this if when you make changes to a service file
[root@myhost parsoid]#  systemctl start parsoid  # start
[root@myhost parsoid]#  systemctl status parsoid # check status
[root@myhost parsoid]#  systemctl enable parsoid # start parsoid on boot

systemd service file.

Description=Mediawiki Parsoid web service on node.js


ExecStart=/usr/bin/node /opt/parsoid/bin/server.js


# groupadd -g 51 stunnel
# useradd -c "stunnel Daemon" -d /var/run/stunnel -g stunnel -s /bin/false -u 51 stunnel


cert = /etc/letsencrypt/live/redacted/fullchain.pem
key = /etc/letsencrypt/live/recacted/privkey.pem
chroot = /var/run/stunnel
setuid = stunnel
setgid = stunnel
pid = /

accept  = 8143
connect = 8142


Description=SSL tunnel for network daemons


ExecStartPre=-/usr/bin/mkdir /var/run/stunnel
ExecStartPre=/usr/bin/chown -R stunnel:stunnel /var/run/stunnel/
ExecStartPre=-/bin/chmod 700 /var/run/stunnel
ExecStart=/usr/bin/stunnel /etc/stunnel/stunnel.conf
ExecStop=/usr/bin/killall -9 stunnel
# Give up if ping don't get an answer
# RemainAfterExit=yes

Display unformated like code snippets

lang= text bash csharp cpp php xml py javascript (or js) <source lang="bash"> code snippet </source>

My Simple Template

{{ blockquote| text here }}

upgrade and move

  • upgrade php to allow mediawiki upgrade
  • upgrade mediawik to allow for contact page, VisualEditor etc...
  • Implement short URLs for better SEO and they're pretty.

current soon to be old wiki version info

Installed software
Product	Version
MediaWiki	1.21.1
PHP	5.3.3 (apache2handler)
MySQL	5.1.73
Entry point URLs
Entry point	URL
Article path	/wiki/index.php/$1
Script path	/wiki
index.php	/wiki/index.php
api.php	/wiki/api.php
load.php	/wiki/load.php
Installed extensions
Special pages
ContactPage (Version 2.2)	Contact form for visitors	Daniel Kinzler and Sam Reed
Renameuser	Adds a special page to rename a user (need renameuser right)	Ævar Arnfjörð Bjarmason and Aaron Schulz
Parser hooks
ParserFunctions (Version 1.5.1)	Enhance parser with logical functions	Tim Starling, Robert Rohde, Ross McClure and Juraj Simlovic
SyntaxHighlight (Version	Provides syntax highlighting <syntaxhighlight> using GeSHi - Generic Syntax Highlighter	Brion Vibber, Tim Starling, Rob Church and Niklas Laxström
Media handlers
PDF Handler	Handler for viewing PDF files in image mode.	Martin Seidel and Mike Połtyn
Gadgets	Lets users select custom CSS and JavaScript gadgets in their preferences	Daniel Kinzler and Max Semenik
WikiEditor (Version 0.3.1)	Provides an extendable wikitext editing interface and many feature-providing modules	Trevor Parscal, Roan Kattouw, Nimish Gautam and Adam Miller
Parser extension tags
<gallery>, <nowiki>, <pre>, <source> and <syntaxhighlight>
Parser function hooks
anchorencode, basepagename, basepagenamee, canonicalurl, canonicalurle, defaultsort, displaytitle, expr, filepath, formatdate, formatnum, fullpagename, fullpagenamee, fullurl, fullurle, gender, grammar, if, ifeq, iferror, ifexist, ifexpr, int, language, lc, lcfirst, localurl, localurle, namespace, namespacee, namespacenumber, ns, nse, numberingroup, numberofactiveusers, numberofadmins, numberofarticles, numberofedits, numberoffiles, numberofpages, numberofusers, numberofviews, padleft, padright, pagename, pagenamee, pagesincategory, pagesize, plural, protectionlevel, rel2abs, special, speciale, subjectpagename, subjectpagenamee, subjectspace, subjectspacee, subpagename, subpagenamee, switch, tag, talkpagename, talkpagenamee, talkspace, talkspacee, time, timel, titleparts, uc, ucfirst and urlencode

Fedora fc.22

I opened up node.js on port 3000 with this command.

firewall-cmd --permanent --add-port=3000/tcp
# be sure to reload
 firewall-cmd --reload
# tail a log with colored warnings
#> tail -f /var/log/maillog|egrep --ignore-case  --line-buffered --color=auto 'reject|ERROR|WARN|$'


I wanted to create a .zip file for my FDDSE project from the command line. Perhaps in a batch file.

7z a -tzip FDDSE

VS 2015 IISExpress

netsh http show urlacl
netsh http add urlacl url=http://localhost:60262/ user=everyone
netsh http delete urlacl url=http://*:60262/
I 'ended' Microsoft.VsHub.Server.HttpHostx64.exe with TaskManager
// punch a hole in the firewall
// oopps just noticed I'm running public profile at home on nat. Another toDo
C:\Users\jeffa>netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=60262 profile=private remoteip=localsubnet action=allow

C:\Users\jeffa>netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=60262 profile=public remoteip=localsubnet action=allow

CentOS 7

Nifty resources

yum etc...

  • yum list installed
  • repoquery --list php56u
  • yum search all php-imap
  • yum install php56u-imap
  • rpm -qi postfix # show currently installed info


  • bconsole
    • status client

smtp etc...

postfix flush
postmap -q  mysql:/
dovecot -n ; display configuration / check configuration syntax
echo `hostname` `cat /etc/*elease*` "this is some blah blah testing body text" | mail -s "Testing 1 2 3" somebody@somewhere.tld

Find a message ID.

[root@redacted cron.d]# mailq
-Queue ID-  --Size-- ----Arrival Time---- -Sender/Recipient-------
B077861458      758 Sat Jan 20 08:17:22
(connect to[2606:2800:220:1:248:1893:25c8:1946]:25: Network is unreachable)

-- 0 Kbytes in 1 Request.
# Read it.
[root@dediserve1 conf]# postcat -q A9D1061AF9
# Delete it.
[root@dediserve1 cron.d]# postsuper -d B077861458
postsuper: B077861458: removed
postsuper: Deleted: 1 message
[root@redacted cron.d]# mailq
Mail queue is empty
[root@redacted cron.d]#

[root@thehost]# certbot certificates
[root@thehost]# certbot delete # prompted for certs to remove
[root@thehost]# certbot delete --cert-name delthisdname 


find ./ -exec ls -l {} + | less
sed -i 's/findstring/replacestring/g' *


edit /etc/systemd/system.conf add LogLevel=debug for increased logging when debugging systemctl start something

systemctl cat bacula-fd will display the current bacula-fd.service file


iptables -L --line-numbers
iptables -D INPUT 3

iptables -L
iptables -S

service iptables save

Debian 9


I'm attempting to install Stretch on a pair of 4TB drives in a Raid 1 configuration.

Some linke and notes


hosts and flush

I like to put the dns of the new site in hosts before I change name service enabling to verify proper operation first.

Elevate your privileges to Administrator

Edit c:\Windows\System32\Drivers\etc\hosts

ipconfig /flushdns

Once done testing don't forget to remove temporary ip from hosts

Network shares mostly samba

# Samba stuff you probably want to remember
smbclient -L \\ -U wmctv
mount -t cifs -o username=wmctv // /tmp/wmctv
PS C:\Users\jhalb> net use
New connections will be remembered.

Status       Local     Remote                    Network

OK                     \\\tns1snap  Microsoft Windows Network
OK                     \\debbie\IPC$             Microsoft Windows Network
The command completed successfully.

PS C:\Users\jhalb> net use /delete \\\tns1snap
\\\tns1snap was deleted successfully.

PS C:\Users\jhalb> net use
New connections will be remembered.

Status       Local     Remote                    Network

OK                     \\debbie\IPC$             Microsoft Windows Network
The command completed successfully.

PS C:\Users\jhalb> net use \\\work /user:uwork uwork
The command completed successfully.

PS C:\Users\jhalb>

Not yet organized

Stuff I need to integrate into some order but I'm busy with other stuff and don't want to forget

  • journalctl -b -u fail2ban
  • fail2ban-client status
    • fail2ban-client status jail_name

disk stuff

is grub installed?

[root@seven ~]# dd if=/dev/sda bs=1 count=512 | grep -aob GRUB
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.00301491 s, 170 kB/s
[root@seven ~]#

install boot on /dev/sdb

[root@seven ~]# grub2-install /dev/sdb
Installing for i386-pc platform.
grub2-install: warning: Couldn't find physical volume `(null)'. Some modules may be missing from core image..
grub2-install: warning: Couldn't find physical volume `(null)'. Some modules may be missing from core image..
Installation finished. No error reported.
[root@seven ~]#