Difference between revisions of "Programming language cook book"

From Review or Discard at Will
Jump to: navigation, search
(smtp etc...: mailq and postsuperuser delete)
(Visual Editor: add parsoid service file)
Line 67: Line 67:
 
</source>
 
</source>
 
===Visual Editor===
 
===Visual Editor===
 +
====parsoid====
 +
install start stop status
 +
<source lang=bash>
 +
[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
 +
</source>
 +
systemd service file.
 +
<source lang="xml">
 +
[Unit]
 +
Description=Mediawiki Parsoid web service on node.js
 +
Documentation=http://www.mediawiki.org/wiki/Parsoid
 +
Wants=local-fs.target network.target
 +
After=local-fs.target network.target
 +
 +
[Install]
 +
WantedBy=multi-user.target
 +
 +
[Service]
 +
Type=simple
 +
User=nobody
 +
Group=nobody
 +
WorkingDirectory=/opt/parsoid
 +
EnvironmentFile=-/etc/parsoid/parsoid.env
 +
ExecStart=/usr/bin/node /opt/parsoid/bin/server.js
 +
KillMode=process
 +
Restart=on-success
 +
PrivateTmp=true
 +
StandardOutput=syslog
 +
</source>
 +
 
====stunnel====
 
====stunnel====
 
<source lang="bash">
 
<source lang="bash">

Revision as of 03:24, 22 January 2018

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.

Python

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

vim

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, #
  or
: s/^/# <- more likely
esc

global search and replace

:
%s/findString/replaceString/g

Apache

Resources

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]
</VirtualHost>

MediaWiki Short URLs

<VirtualHost *:443>
        ServerName www.redacted.info
        ServerAlias redacted.info
        DocumentRoot /var/www/redacted.info
        CustomLog       /var/log/httpd/redacted.info-access.log combined
        ErrorLog        /var/log/httpd/redacted.info-error.log
        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/redacted.com/cert.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/redacted.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateChainFile /etc/letsencrypt/live/redacted.com/chain.pem

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

Visual Editor

parsoid

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.

[Unit]
Description=Mediawiki Parsoid web service on node.js
Documentation=http://www.mediawiki.org/wiki/Parsoid
Wants=local-fs.target network.target
After=local-fs.target network.target

[Install]
WantedBy=multi-user.target

[Service]
Type=simple
User=nobody
Group=nobody
WorkingDirectory=/opt/parsoid
EnvironmentFile=-/etc/parsoid/parsoid.env
ExecStart=/usr/bin/node /opt/parsoid/bin/server.js
KillMode=process
Restart=on-success
PrivateTmp=true
StandardOutput=syslog

stunnel

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

/etc/stunnel/stunnel.conf

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

[parsoid]
accept  = 8143
connect = 8142

/lib/systemd/system/stunnel.service

[Unit]
Description=SSL tunnel for network daemons
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target
Alias=stunnel.target

[Service]
Type=forking
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
RuntimeDirectory=stunnel
# Give up if ping don't get an answer
TimeoutSec=600
Restart=always
#PrivateTmp=false
PrivateTmp=false
EnvironmentFile=-/etc/stunnel/stunnel.conf
#PermissionsStartOnly=true
# RemainAfterExit=yes

Mediawiki

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 }}

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|$'

7-zip

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

7z a -tzip FDDSE.zip FDDSE

VS 2015 IISExpress

.vs\config\applicationhost.config
%userprofile%\Documents\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
Ok.


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

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

bacula

  • bconsole
    • status client

smtp etc...

mailq
postfix flush
postmap -q anexample.com  mysql:/afilenameWithQuery.cf
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 and delete it.

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

-- 0 Kbytes in 1 Request.
[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]#

letscncrypt

https://crt.sh/?q=dediserve1.jhalbrecht.net
</source
===stuff...===
<source lang="bash">
find ./ -exec ls -l {} + | less
sed -i 's/findstring/replacestring/g' *