Skip to content

Instantly share code, notes, and snippets.

View ShigekiKarita's full-sized avatar
🌴
I may be slow to respond.

Shigeki Karita ShigekiKarita

🌴
I may be slow to respond.
View GitHub Profile
@ShigekiKarita
ShigekiKarita / .spacemacs
Last active March 12, 2017 03:49
my spacemacs config
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
@ShigekiKarita
ShigekiKarita / value.py
Created February 15, 2017 06:29
Python immutable object decorator
from collections import namedtuple
def value(*fields):
def wrapper(class_):
name = class_.__name__
t = namedtuple(name, fields)
return type(name, (class_, t), {})
return wrapper
"""
PTB RNNLM model
according to tf: https://www.tensorflow.org/tutorials/recurrent#run_the_code
perplexity 120 is nice. 80 is great.
"""
from functools import partial
import torch
import torch.nn as nn
import scipy
from scipy import fftpack
from scipy import signal
from scipy.io import wavfile
import matplotlib.pyplot as plt
def add_eps(x):
x[scipy.where(x == 0)] = scipy.finfo(dtype=x.dtype).eps
return x
#include <assert.h>
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <algorithm>
#include <iostream>
#include <limits>
#include <cmath>
#include <utility>
#include <assert.h>
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <algorithm>
#include <iostream>
#include <limits>
#include <cmath>
#include <utility>
@ShigekiKarita
ShigekiKarita / dijkstra.d
Created September 25, 2017 10:06
dlang snippet for graph algorithm
/* library code */
/++
Referrence:
- https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm#Using_a_priority_queue
- http://shifth.hatenablog.com/entry/2015/05/31/104829
+/
auto dijkstra(alias distfun, E, V)(E[V[2]] tree, V start) {
import std.container : Array, PriorityQueue = BinaryHeap;
/++
This is a submodule of numir to provide formatting for ndslices.
Note: This relies on the formatting functionality from Phobos, the D standard
library. As of this writing, parts of it rely on the Garbage Collector and
potentially other non-Better C functionality in D.
+/
module numir.format;
import mir.ndslice : SliceKind, Slice;
import std.traits : isSomeChar, isSomeString;
(setq org-latex-classes '(("ltjsarticle"
"\\documentclass{ltjsarticle}
\\usepackage{url}
\\usepackage{amsmath}
\\usepackage{newtxtext,newtxmath}
\\usepackage{graphicx}
\\usepackage{luatexja}
\\usepackage{hyperref}
[NO-DEFAULT-PACKAGES]
[PACKAGES]
@ShigekiKarita
ShigekiKarita / bf.cpp
Created December 10, 2017 18:49
Brainfuck interpreter in C++11
#include <algorithm>
#include <functional>
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>
// byte array
using Memory = std::vector<unsigned char>;
using Pointer = Memory::iterator;