This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1D-DCT(Discreet Cosine Transform) | |
function dct(xs) { | |
const pn = Math.PI / xs.length, f = Math.sqrt(2 / xs.length); | |
return xs.map((_, k) => { | |
const c = pn * k; | |
return f * xs.reduce((r, x, n) => r + x * Math.cos(c * (n + 0.5)), 0); | |
}); | |
} | |
function idct(xs) { | |
const xs_ = [xs[0] / 2].concat(xs.slice(1)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clang -std=c11 -mavx avxvec.c -o avxvec | |
#include <x86intrin.h> | |
#include <stdio.h> | |
// see https://software.intel.com/sites/landingpage/IntrinsicsGuide/#techs=AVX | |
int main() { | |
double mem[4] = {1.0, 2.0, 3.0, 4.0}; | |
//__m256d v = _mm256_load_pd(mem); | |
__m256d v = _mm256_set_pd(1, 2, 3, 4); // (e3, e2, e1, e1) | |
__m256d sq = _mm256_mul_pd(v, v); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-*- mode: c++ -*- | |
// build: | |
// xcrun -sdk macosx metal -std=osx-metal1.1 Shaders.metal -o shaders.air | |
// xcrun -sdk macosx metal-ar rcs Shaders.metalar Shaders.air | |
// xcrun -sdk macosx metallib -o Shaders.metallib Shaders.metalar | |
#include <metal_stdlib> | |
kernel void square(const device float* input [[buffer(0)]], | |
device float* output [[buffer(1)]], | |
metal::uint id [[thread_position_in_grid]]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script type="module"> | |
document.querySelector("#run").addEventListener("click", async ev => { | |
const modUrl = new URL("./module.js", location.href).href; | |
//console.log(modUrl); | |
const iframe = document.createElement("iframe"); | |
iframe.style.display = "none"; | |
document.body.append(iframe); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<script src="https://unpkg.com/react@15.3.1/dist/react.js"></script> | |
<script src="https://unpkg.com/react-dom@15.3.1/dist/react-dom.js" | |
></script> | |
<script src="https://unpkg.com/redux@3.6.0/dist/redux.js"></script> | |
<script src="https://unpkg.com/react-redux@4.4.5/dist/react-redux.js" | |
></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge;chrome=1" /> | |
<script src="tetris.js"></script> | |
<script src="tetris-svg.js"></script> | |
</head> | |
<body> | |
<div><svg id="stage"></svg></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clang -Wall -Wextra -std=c11 sizeof.c -o sizeof | |
// emcc -Wall -Wextra -std=c11 sizeof.c -o sizeof.js | |
#include <stdlib.h> | |
#include <stdarg.h> | |
#include <stddef.h> | |
#include <stdio.h> | |
#include <wchar.h> | |
#include <time.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basics of Elliptic Curve Cryptography implementation on Python | |
import collections | |
def inv(n, q): | |
"""div on PN modulo a/b mod q as a * inv(b, q) mod q | |
>>> assert n * inv(n, q) % q == 1 | |
""" | |
for i in range(q): | |
if (n * i) % q == 1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// RSA with node-forge | |
"use strict"; | |
// npm install node-forge | |
const forge = require("node-forge"); | |
new Promise((f, r) => forge.pki.rsa.generateKeyPair( | |
2048, (err, pair) => err ? r(err) : f(pair))) | |
.then(keypair => { | |
const priv = keypair.privateKey; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# docker build -t ruby-1.8.7 . | |
# docker run -it --rm ruby-1.8.7 | |
FROM ubuntu:16.04 | |
WORKDIR /root | |
RUN apt update | |
RUN apt upgrade -y | |
RUN apt install -y ruby-build autoconf subversion bison | |
RUN apt install -y mecab mecab-ipadic-utf8 wget |
NewerOlder