Skip to content

Instantly share code, notes, and snippets.

# https://tonak-ai.hatenablog.com/entry/2019/03/26/124537
import torch
import torch.nn as nn
from torch import optim
import torch.nn.functional as F
from torch.autograd import Variable
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
n_vocab = 3
import torch
import torch.nn as nn
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
n_vocab = 3
n_layers = 1
n_embed = 5
def padding_test(x_padding):
embedding = nn.Embedding(n_vocab, n_embed, padding_idx=x_padding)
inputs = [[1,1,2,1,1,2,1],[1,1,2]]
def skipfalse(iterable):
for elem in iterable:
if elem:
yield elem
foo=['abc', False, 'de']
print(skipfalse(foo))
print(list(skipfalse(foo)))
# filter() と lambda を使うと上記コードと同じことができる.
#!/usr/bin/python3
import regex as re
import sys
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
re_quantity = re.compile(r"""
((?:各|お?好みで|あれば|約|軽く)?
#!/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