Skip to content

Instantly share code, notes, and snippets.

@nakagami
nakagami / fixup_metayaml.py
Created Jul 6, 2022
Pelican plugin that adjusts markdown YAML front matter.
View fixup_metayaml.py
# Pelican https://pypi.org/project/pelican/ plugin that adjusts markdown
# YAML front matter created by Netlify CMS https://www.netlifycms.org/ et al.
# to be handled correctly as metadata in pelican.
# This plugin requires PyYAML https://pypi.org/project/PyYAML/ .
import io
import datetime
import yaml
from pelican import signals
from markdown import Markdown
@nakagami
nakagami / get_adult_score.py
Created Jun 2, 2022
get adult score by Microsoft Computer Vision API
View get_adult_score.py
import sys
import os
import json
import http.client
from urllib.parse import urlencode
# Computer Vision API
# https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/
@nakagami
nakagami / gitssh.py
Last active May 3, 2022
Use paramiko to connect to git repository over ssh.
View gitssh.py
#!/usr/bin/env python
################################################################################
# MIT License
#
# Copyright (c) 2021 Hajime Nakagami
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@nakagami
nakagami / pyawabi.ipynb
Created Dec 3, 2021
Install mecab, mecab-ipadic on SageMaker StudioLab. Tokenize by pure-pyawabi.
View pyawabi.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View pbkdf2_hmac_sha256.py
import hashlib
import binascii
def hmac_sha256_digest(key, msg):
pad_key = key + b'\x00' * (64 - (len(key) % 64))
ik = bytes([0x36 ^ b for b in pad_key])
ok = bytes([0x5c ^ b for b in pad_key])
return hashlib.sha256(ok + hashlib.sha256(ik+msg).digest()).digest()
@nakagami
nakagami / dynamic_result.rs
Last active Aug 22, 2021
dynamic return type in Rust
View dynamic_result.rs
// dynamic return type in Rust
#[derive(Clone)]
struct V {
i:i32,
s:String,
}
trait ToVal<T> {
fn to_val(self) -> T;
View awabi.rst

MeCab 辞書を使用した形態素解析器 awabi

Hajime Nakagami <nakagami@gmail.com> 2020-10-10 最終更新

awabi とは

awabi は、 MeCab [1]_ の辞書データを使い形態素解析をする形態素解析器です。

@nakagami
nakagami / darts_sample.cpp
Last active Oct 11, 2019
Darts (Double-ARray Trie System) http://chasen.org/~taku/software/darts/ sample code.
View darts_sample.cpp
#include <iostream>
#include <darts.h>
// Darts http://chasen.org/~taku/software/darts/ sample code
int main (int argc, char **argv)
{
using namespace std;
const Darts::DoubleArray::key_type *str[] = { "ALGOL", "ANSI", "ARCO", "ARPA", "ARPANET", "ASCII" }; // same as char*
View swine_fever.rst

豚コレラと家畜衛生について

2019-09-10 BPLL #37 https://bpstudy.connpass.com/event/143999/

最近、「豚コレラ」という言葉を時々ニュースで聞くが、それが農家や農政に重大な危機であることがあまり知られてないのではないかと思う。 この危機を知ってもらいたい。

お前誰よ

@nakagami
nakagami / qrcode_view.py
Last active May 13, 2021
QR コードを png 画像として返す Django の view関数のコードスニペット
View qrcode_view.py
def qrsample(request):
import qrcode # pip install qrcode, pillow
from django.shortcuts import redirect
from django.http.response import HttpResponse
if request.method == "GET":
redirect('/')
qr = qrcode.QRCode(
error_correction=qrcode.constants.ERROR_CORRECT_H,