Skip to content

Instantly share code, notes, and snippets.

View jojonki's full-sized avatar

Junki Ohmura jojonki

View GitHub Profile
@jojonki
jojonki / timeshift_sony_actioncam.py
Created October 27, 2019 03:00
Timeshift modification for Sony's actioncam on Mac
from datetime import datetime
from pytz import timezone
import subprocess
import glob
import xml.etree.ElementTree as ET
# replaced time zones
SRC_TZ_ZONES = ['UTC+09:00', 'UTC+01:00']
# target time zone
TGT_TZ_ZONE = ['Europe/Berlin']
@jojonki
jojonki / global_variables.py
Created February 4, 2019 07:29
Hack for read-only class variables.
class MetaGlobalVariables(type):
@property
def HOGE(cls):
return cls._GlobalVariables__hoge # mangling
class GlobalVariables(object, metaclass=MetaGlobalVariables):
__hoge = 'xxxx'
# read OK
@jojonki
jojonki / simple_viterbi.py
Created January 3, 2019 06:45
Simple viterbi algorithm example
# Use Graham's example.
# http://www.phontron.com/slides/nlp-programming-ja-03-ws.pdf
INF = 1e6
edge_list = [
None, # e0
{ # e1
'id': 1,
'score': 2.5,
'begin_node_id': 0,
@jojonki
jojonki / gist:cb18b14e789eb8bdb2ae2950eef1019f
Created August 22, 2018 22:00
run illustrator in Japanese
defaults write com.adobe.illustrator AppleLanguages '("ja")'
@jojonki
jojonki / load_glove_weight_sample.py
Created August 9, 2018 14:29
Glove embeddings in PyTorch
import numpy as np
import torch
from torch import nn
class Model(nn.Module):
def __init__(self, vocab_size, embd_size, pre_embd_w=None):
super(Model, self).__init__()
self.embd = nn.Embedding(vocab_size, embd_size, padding_idx=0)
@jojonki
jojonki / get_current_git_revision.py
Created June 24, 2018 14:09
Get a current Git revision in python
import subprocess
rev = subprocess.check_output(['git', 'describe', '--always']).strip().decode('utf-8')
liens = [line.rstrip('\n') for line in open('file')]
@jojonki
jojonki / covariance_matrix.py
Last active December 22, 2022 00:42
A simple example of covariance matrix
import numpy as np
data = np.array([[40, 35, 80],
[80, 50, 90],
[20, 55, 40],
[94, 80, 88],
[90, 30, 100]])
print('Input data (N, featuers):', data, data.shape)
N = data.shape[0]
n_dim = data.shape[1]
@jojonki
jojonki / pca_t-SNE_mnist.ipynb
Created April 17, 2018 20:34
Comparison of MNIST visualization between PCA and t-SNE
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jojonki
jojonki / pack_padded_sequence-pad_packed_sequence.ipynb
Created April 17, 2018 14:24
A simple usage of pack_padded_sequence and pad_packed_sequence in pytorch
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.