Skip to content

Instantly share code, notes, and snippets.

View grafi-tt's full-sized avatar

Shunsuke Shimizu grafi-tt

View GitHub Profile
void setup() {
Serial.begin(9600);
analogReference(DEFAULT);
}
unsigned int co2mon(unsigned long delta) {
static const unsigned int SensorIn = A0;
static const unsigned int BaseVoltage = 480;
static const unsigned int PollInterval = 10;
fn byte_to_ascii(byte: u8) -> [u8; 8] {
let diag = 0b10000000_01000000_00100000_00010000_00001000_00000100_00000010_00000001u64;
let mut byte_ascii = byte as u64 * diag;
byte_ascii &= 0x8080808080808080;
byte_ascii >>= 7;
byte_ascii += 0x3030303030303030;
byte_ascii.to_le_bytes()
}
@grafi-tt
grafi-tt / a.md
Last active February 6, 2020 00:42
import numpy as np
def show_board(black_board, white_board):
black_bytes = black_board.to_bytes(8, byteorder='big')
black_array = np.unpackbits(np.frombuffer(black_bytes, dtype=np.uint8))
white_bytes = white_board.to_bytes(8, byteorder='big')
white_array = np.unpackbits(np.frombuffer(white_bytes, dtype=np.uint8))
chars = (black_array * (ord(b'b') - ord(b'-')) +
### 課題3(上級者向け)
SUID (Set User ID) ビットを使って、`sudo` コマンドのように root ユーザーとして他のコマンドを実行できるコマンドを作れ。
**注意: 絶対にこのコマンドを実用してはならない。**
ヒント: C で書いたプログラムから `execvp` 関数を用いる。スクリプトファイルのすり替えに対処不能というセキュリティ上の問題から、SUID ビットはコンパイルされたプログラムに対してのみ機能する。
<details>
<summary>解答</summary>
__device__ static inline void multfly_device_gen_round_(uint32_t *u, uint32_t *v) {
int lane = threadIdx.x & 3;
uint32_t mulu = UINT32_C(2718281829);
uint32_t mulv = UINT32_C(3141592653);
uint32_t incr = UINT32_C(0x33123456);
*u += multfly_device_rotl_(incr, lane);
*v += *u;
*v ^= multfly_device_rotl_(*u, 8);
*v *= mulv;
// distributed under public domain
// work in progress
#include <stdint.h>
#include <string.h>
static int multfly_rotl(uint32_t k, int n) {
return (k << n) | (k >> (32 - n));
}
diff --git a/chainerx_cc/chainerx/native/reduce.h b/chainerx_cc/chainerx/native/reduce.h
index 2b61319de..73db5bad2 100644
--- a/chainerx_cc/chainerx/native/reduce.h
+++ b/chainerx_cc/chainerx/native/reduce.h
@@ -11,19 +11,83 @@ namespace chainerx {
namespace native {
namespace reduce_detail {
+constexpr int64_t ExpandLen = 8;
+constexpr int64_t SerialLen = 16;
# Modification of Chainer's code
# See https://github.com/chainer/chainer/blob/master/LICENSE
import numpy
import chainer
from chainer import backend
from chainer.backends import cuda
from chainer import configuration
from chainer import function_node
import chainer
import chainer.functions as F
import chainer.links as L
import numpy as np
from chainer import dataset, initializer
from chainer.backends import cuda
def cipher_ctx(key):
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes