Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python3
# The alternative script of "cat files|sort|uniq -c|sort -r -n".
import marisa
import sys
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
@tsuchm
tsuchm / timeout_for_webconsole.diff
Last active May 3, 2020 10:20
Patch to add timeout feature for http://web-console.org/
--- webconsole.php~
+++ webconsole.php
@@ -561,12 +561,27 @@
2 => array('pipe', 'w') // STDERR
);
- $process = proc_open($command . ' 2>&1', $descriptors, $pipes);
+ $process = proc_open(escapeshellcmd($command), $descriptors, $pipes);
if (!is_resource($process)) die("Can't execute command.");
@tsuchm
tsuchm / not_depended_packages.pl
Last active July 8, 2022 02:08
List installed packages which are not depended by other installed packages. In other words, list all required packages.
#!/usr/bin/perl
use strict;
&main();
sub main {
open( my $ph, 'dpkg --status |' ) or die;
my %package;
my %depended;
@tsuchm
tsuchm / ldap-health-check.pl
Created March 19, 2020 13:20
LDAP health check daemon
#!/usr/bin/perl
=head1 NAME
ldap-health-check
=head1 INSTALL
First, put this script into /usr/local/bin/ and make it executable.
@tsuchm
tsuchm / postfix_incoming_mailstats
Last active March 12, 2020 14:15
Munin plugins to observe incoming throughput and outgoing throughput
#!/usr/bin/perl
=head1 NAME
postfix_incoming_mailstats - Plugin to monitor the number of mails
received by postfix
=head1 DEFAULT CONFIGURATION
[postfix_incoming_mailstats]
@tsuchm
tsuchm / interfaces
Created March 12, 2020 00:46
An example of /etc/network/interfaces for a dual-homed host
auto lo
iface lo inet loopback
# The 1st network of this host is 192.0.2.0/24.
# This host mainly uses the 1st network to communicate the Internet.
allow-hotplug eth0
iface eth0 inet static
address 192.0.2.30
netmask 255.255.255.0
network 192.0.2.0
@tsuchm
tsuchm / azure-cli.yml
Last active March 9, 2020 02:48
Ansible task file to install Azure CLI
# Ansible task to install Azure CLI.
# These steps are re-implementation of the procedure descrbed at
# https://docs.microsoft.com/cli/azure/install-azure-cli-apt
- name: Install packages required by Azure CLI
apt:
name: ['ca-certificates', 'curl', 'apt-transport-https', 'lsb-release', 'gnupg']
state: present
- name: Add Azure CLI repository key
from chainer import function, training
from chainer import reporter as reporter_module
from chainer.dataset import convert
from collections import defaultdict
class PreciseEvaluator(training.extensions.Evaluator):
""":class:`chainer.training.extensions.Evaluator` module uses
:func:`chainer.reporter.compute_mean` to calculate the mean
accuracy and the mean loss over the multiple mini batches.
@tsuchm
tsuchm / mecab_swig.diff
Created January 17, 2020 09:29
Enforce to use bytes for MeCab even if Python3 is used
--- a/swig/MeCab.i
+++ b/swig/MeCab.i
@@ -3,6 +3,7 @@
%{
#include "mecab.h"
+#define SWIG_PYTHON_STRICT_BYTE_CHAR
/* Workaround for ruby1.9.x */
#if defined SWIGRUBY
#include "ruby/version.h"
@tsuchm
tsuchm / error.log
Created January 17, 2020 08:59
error message when building mecab package from salsa git repo
$ git clone [email protected]:nlp-ja-team/mecab.git
$ cd mecab
$ gbp buildpackage -us -uc --git-dist=stable --git-arch=amd64
(snip)
dpkg-genchanges: warning: debian/changelog(l8): found end of file where expected more change data or trailer
dpkg-genchanges: warning: unknown information field '' in input data in parsed version of changelog
dpkg-genchanges: error: unknown is not a valid version
dpkg-buildpackage: error: dpkg-genchanges subprocess returned exit status 2